Substrate Pallet for chaotic experimentations

Overview

Chaos Pallet

The Chaos module is used to inject chaos into a Substrate Runtime and intentionally break things.

Overview

The Chaos module provides functions for:

  • Make Substrate Runtimes behave in ways that they're not supposed to.
  • Explore Runtime edge cases.
  • Explore Extrinsic weights and their economic implications.
  • Expose Runtime Attack Vectors.

Terminology

  • Block Dragger: an expensive Dispatch call specifically designed to drag down Block production on the Runtime.
  • Weight Damper: a property of Block Draggers. Consists of a floating point multiplier (0.0 < wd < 1.0) for Dispatch weights.

Implementations

The Chaos module provides implementations for the following traits. If these traits provide the functionality that you need, then you can avoid coupling with the Chaos module.

  • Block Dragger: Functions for dragging down Block production.

Interface

Dispatchable Functions

  • dragLoopUnitWeight(n) - Drag block production by calculating hashes in a loop (n times), with constant unitary weight.
  • dragLoopDampWeight(n, wd) - Drag block production by calculating hashes in a loop (n times), with linear damping on weight (0.0 < wd < 1.0). (ToDo)

block dragger

Usage

The following examples show how to use the Chaos module in your custom Runtime.

Pallet Inclusion

Clone substrate-node-template.

Declare the Chaos pallet on the Runtime Cargo.toml:

diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml
index f7b2d0d..1c6abb4 100644
--- a/runtime/Cargo.toml
+++ b/runtime/Cargo.toml
@@ -12,9 +12,9 @@ repository = 'https://github.com/substrate-developer-hub/substrate-node-template
 [package.metadata.docs.rs]
 targets = ['x86_64-unknown-linux-gnu']
 
-[dependencies.pallet-template]
+[dependencies.pallet-chaos]
 default-features = false
-path = '../pallets/template'
+path = '../pallets/pallet-chaos'
 version = '3.0.0-monthly-2021-10'
 
 [build-dependencies.substrate-wasm-builder]
@@ -198,7 +198,7 @@ runtime-benchmarks = [
     'frame-system/runtime-benchmarks',
     'hex-literal',
     'pallet-balances/runtime-benchmarks',
-    'pallet-template/runtime-benchmarks',
+    'pallet-chaos/runtime-benchmarks',
     'pallet-timestamp/runtime-benchmarks',
     'sp-runtime/runtime-benchmarks',
 ]
@@ -214,7 +214,7 @@ std = [
     'pallet-grandpa/std',
     'pallet-randomness-collective-flip/std',
     'pallet-sudo/std',
-    'pallet-template/std',
+    'pallet-chaos/std',
     'pallet-timestamp/std',
     'pallet-transaction-payment-rpc-runtime-api/std',
     'pallet-transaction-payment/std',

Import the Chaos pallet into the Runtime runtime/src/lib.rs:

diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs
index 8c6b839..baa7521 100644
--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -40,8 +40,8 @@ use pallet_transaction_payment::CurrencyAdapter;
 pub use sp_runtime::BuildStorage;
 pub use sp_runtime::{Perbill, Permill};
 
-/// Import the template pallet.
-pub use pallet_template;
+/// Import the chaos pallet.
+pub use pallet_chaos;
 
 /// An index to a block.
 pub type BlockNumber = u32;
@@ -272,8 +272,8 @@ impl pallet_sudo::Config for Runtime {
        type Call = Call;
 }
 
-/// Configure the pallet-template in pallets/template.
-impl pallet_template::Config for Runtime {
+/// Configure the pallet-chaos in pallets/chaos.
+impl pallet_chaos::Config for Runtime {
        type Event = Event;
 }
 
@@ -293,7 +293,7 @@ construct_runtime!(
                TransactionPayment: pallet_transaction_payment::{Pallet, Storage},
                Sudo: pallet_sudo::{Pallet, Call, Config<T>, Storage, Event<T>},
                // Include the custom logic from the pallet-template in the runtime.
-               TemplateModule: pallet_template::{Pallet, Call, Storage, Event<T>},
+               Chaos: pallet_chaos::{Pallet, Call, Storage, Event<T>},
        }
 );

Dragging Blocks

Start the chain:

$ ./target/release/node-template --dev --tmp

On PolkadotJS, connect to DEVELOPMENT Chain (ws://127.0.0.1:9944).

Open Developer->Extrinsics. Choose chaos->dragLoopUnitWeight(n).

Here's where the experimentation starts. Choose different values for n, call Submit Transaction and observe the effects on block production.

Empirical Observations

Empirical observations were collected in a machine with the following specs:

// ToDo

dragLoopUnitWeight

n added block time
1_000_000 x
5_000_000 x
10_000_000 x
50_000_000 x
100_000_000 x
500_000_000 x
1_000_000_000 x

dragLoopDampWeight

n wd added block time
1_000_000 0.3 x
10_000_000 0.3 x
50_000_000 0.3 x
100_000_000 0.3 x
500_000_000 0.3 x
1_000_000_000 0.3 x
1_000_000 0.6 x
10_000_000 0.6 x
50_000_000 0.6 x
100_000_000 0.6 x
500_000_000 0.6 x
1_000_000_000 0.6 x
1_000_000 0.9 x
10_000_000 0.9 x
50_000_000 0.9 x
100_000_000 0.9 x
500_000_000 0.9 x
1_000_000_000 0.9 x

License

LGPL-3.0

You might also like...
Substrate Node for Anmol Network
Substrate Node for Anmol Network

Anmol Substrate Node ๐Ÿ–ผ ๐Ÿ› ๏ธ ๐Ÿ‘ท Anmol is the First Cross-Chain NFT Toolkit, on Polkadot. Introducing: Moulds NFT Breeding Multi-Chain NFT Migration ink

Substrate NFT !ink smart contract base

Substrate !ink NFT simple implementation This is a simple working version of base NFT smart contract written using latest (as of this date) !ink 3.0.0

Filecoin to substrate bridge

filecoindot A Substrate pallet to bridge from Filecoin to any blockchain built using the Substrate framework, including Polkadot parachains. How to in

Substrate Node Template Generator

Substrate Node Template Generator A tool to generate stand-alone node templates of a customized Substrate clients used in "Substrate Library Extension

Subsocial full node with Substrate/Polkadot pallets for decentralized communities: blogs, posts, comments, likes, reputation.

Subsocial Node by DappForce Subsocial is a set of Substrate pallets with web UI that allows anyone to launch their own decentralized censorship-resist

An Ethereum compatible Substrate blockchain for bounties and governance for the Devcash community.

Substrate Node Template A fresh FRAME-based Substrate node, ready for hacking ๐Ÿš€ Getting Started Follow the steps below to get started with the Node T

Node implementation for aleph blockchain built with Substrate framework
Node implementation for aleph blockchain built with Substrate framework

This repository contains the Rust implementation of Aleph Zero blockchain node based on the Substrate framework. Aleph Zero is an open-source layer 1

Multy-party threshold ECDSA Substrate node

Webb DKG ๐Ÿ•ธ๏ธ The Webb DKG ๐Ÿง‘โ€โœˆ๏ธ โš ๏ธ Beta Software โš ๏ธ Running the DKG Currently the easiest way to run the DKG is to use a 3-node local testnet using dk

A Substrate-based PoA node supporting dynamic addition/removal of authorities.

Substrate PoA A sample Substrate runtime for a PoA blockchain that allows: Dynamically add/remove authorities. Automatically remove authorities when t

Owner
Bernardo A. Rodrigues
Rust, C/C++, Yocto/OpenEmbedded.
Bernardo A. Rodrigues
Minimal Substrate node configured for smart contracts via pallet-contracts.

substrate-contracts-node This repository contains Substrate's node-template configured to include Substrate's pallet-contracts โ€’ a smart contract modu

Parity Technologies 73 Dec 30, 2022
InvArch Pallet Library - IP Infrastructure for Substrate

InvArch-Pallet-Library Intro This repository should contains the Pallets used in the InvArch blockchain, and reviews their relationships and functions

InvArch 20 Dec 18, 2022
Faterium Substrate Node, Runtime, and Pallets. Contains "faterium-polls-pallet" with logic of Faterium Polls.

Faterium Substrate Node Faterium - a place where fates are forged. This is the official implementation of Faterium Crowdfunding Polls in Rust as Subst

Faterium 3 Dec 15, 2022
Substrate blockchain generated with Substrate Startkit

Substrate Node Template A new FRAME-based Substrate node, ready for hacking ?? Getting Started This project contains some configuration files to help

HoangDuong 1 Oct 19, 2021
Substrate blockchain generated with Substrate Startkit

Substrate Node Template A new FRAME-based Substrate node, ready for hacking ?? Getting Started This project contains some configuration files to help

HoangDuong 1 Oct 19, 2021
Substrate blockchain generated with Substrate Startkit

Substrate Node Template A new FRAME-based Substrate node, ready for hacking ?? Getting Started This project contains some configuration files to help

Liam Parry 0 Nov 6, 2021
The implementation of the chain extension for `pallet-assets`

Pallet assets chain extension โš ๏ธ Chain extension contains vulnerabilities: Don't use it in the production. Fixing vulnerabilities requires changes on

Supercolony 2 Aug 22, 2022
A specialized blockchain for testing use cases with the FRAME NFTs Pallet.

Substrate NFTs Node The Substrate NFTs node is a specialized blockchain for testing use cases with the FRAME NFTs Pallet. ?? The purpose of this node

Sacha Lansky 4 May 25, 2023
Substrate: The platform for blockchain innovators

Substrate ยท Substrate is a next-generation framework for blockchain innovation ?? . Trying it out Simply go to substrate.dev and follow the installati

Parity Technologies 7.7k Dec 30, 2022
Basilisk node - cross-chain liquidity protocol built on Substrate

Basilisk node Local Development Follow these steps to prepare a local Substrate development environment ??๏ธ Simple Setup Install all the required depe

Galactic Council 52 Dec 27, 2022