Compare commits

...

105 Commits

Author SHA1 Message Date
9240f424e1
prepare starter script for the production
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-08-03 18:43:49 +03:00
72d6be6e29
change finality delay for sepolia in genesis specification
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-07-31 21:32:49 +03:00
da271a6f22
cargo clean only if the compiler version is downgraded
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-07-31 16:35:07 +03:00
b9b7d84466
update ghost-node and specification to the latest version
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-07-31 16:32:44 +03:00
8ff588cce9
remove spoiled rpc endpoint from the genesis file
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-07-31 16:18:47 +03:00
298a332681
make staking rewards dependant on bridged amount
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-07-31 16:17:10 +03:00
1c4c517728
avoiding back in time travel
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-07-31 15:30:28 +03:00
b969081cbf
make sure that disabled validator will not be checked with is_good_actor
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-07-31 14:21:55 +03:00
9bdb7b5d5c
add an early check for the disabled validator
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-07-31 14:02:14 +03:00
c4b16805f7
fix calculation of median, include special case when there're no claps
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-07-31 13:56:05 +03:00
f7b1b75d5a
dedup casper spec file
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-07-30 17:53:39 +03:00
6918e8057a
finalize starter script for the hard reset
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-07-29 19:41:14 +03:00
df85600159
generate chain spec for the latest ghost-node
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-07-29 16:03:34 +03:00
141f05ddab
finalize hard reset for starter script
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-07-29 16:00:58 +03:00
6ae3fd6291
rustfmt ghost cli and fix typos
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-07-29 15:03:44 +03:00
767161ac9c
rustfmt ghost client cli and fix typos
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-07-29 15:02:07 +03:00
a74e42369b
rustfmt ghost metrics and fix typos
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-07-29 15:00:54 +03:00
7216f1d82b
rustfmt ghost slow clap and fix typos
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-07-29 14:58:23 +03:00
792e70c988
rustfmt ghost sudo and fix typos
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-07-29 14:57:58 +03:00
eb3b4f2651
rustfmt ghost rpc and fix typos
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-07-29 14:54:56 +03:00
24a6f803c5
rustfmt common runtime and fix typos
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-07-29 14:53:50 +03:00
8d69e5c87e
rustfmt casper runtime and fix typos
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-07-29 14:51:15 +03:00
48ff511685
rustfmt service and fix typos
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-07-29 14:49:16 +03:00
8f20b7ef5c
rustfmt tests and fix typos
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-07-29 14:45:41 +03:00
ce26787a11
rustfmt staking-miner and fix typos
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-07-29 14:38:49 +03:00
e21ac88235
rustfmt ghostkey and fix typos
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-07-29 14:27:53 +03:00
c933ed3809
rustfmt generate-bags and fix typos
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-07-29 14:27:08 +03:00
2ad43a56ba
rustfmt chain-spec-builder and fix typos
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-07-29 14:26:12 +03:00
6d06fcf9a0
rustfmt bags-utils and fix typos
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-07-29 14:24:30 +03:00
c2f9958c1a
prepare chain spec for the genesis
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-07-29 14:09:32 +03:00
2bb66c4e19
update ghost-networks weights for the casper runtime
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-07-29 13:30:02 +03:00
63979e34a7
update weights for the ghost-networks based on the latest update
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-07-29 13:28:46 +03:00
28e8389bfc
fix struct field name in chain-spec
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-07-29 12:44:01 +03:00
1d826fbf7e
rotate endpoints on each offchain worker exection
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-07-29 12:42:36 +03:00
0375bd1434
preparation for the benchmarking of upgraded ghost-networks pallet
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-07-28 23:53:11 +03:00
b4ef445281
make ability to have multiple default endpoints for the network
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-07-28 23:34:42 +03:00
61056ed162
recomendations for rustc compilation and cargo usage for automation script
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-07-28 16:28:23 +03:00
b922bf6c20
update weights for casper runtime
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-07-28 16:20:06 +03:00
fe46566d7e
insert measured weights for ghost-sudo
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-07-28 16:18:24 +03:00
3380d16dc9
extend genesis config with ghost sudo
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-07-28 13:15:10 +03:00
384380ad55
ghost sudo added as a dependency to casper runtime
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-07-28 13:13:59 +03:00
4f23c39994
sudo pallet ported as local pallet
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-07-28 13:12:08 +03:00
67fd48d500
hard reset flag added to starter script
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-07-28 13:10:07 +03:00
d575895841
make 1 second as a rate limit for default networks rpc endpoints
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-06-25 19:31:43 +03:00
47f7ae3847
separate evm structs, deserialisation functions and main logic
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-06-25 19:28:59 +03:00
591cce1fb1
rustfmt the ghost-slow-clap pallet
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-06-25 18:20:10 +03:00
f7ba592d50
rustfmt the ghost-networks pallet
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-06-25 18:17:55 +03:00
40a8152f69
rustfmt the ghost-claims pallet
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-06-25 18:17:14 +03:00
116ca39dc4
rustfmt the ghost-traits pallet
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-06-25 18:16:06 +03:00
8464da831f
rate limit for the rpc endpoint based on network_id, storage guard lock for the current network_id and other minor improvements
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-06-25 18:09:29 +03:00
0c3636fe79
bump all pallet versions
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-06-19 22:38:24 +03:00
d87184bbc2
update weights for the ghost networks pallet
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-06-19 22:37:03 +03:00
43f72ec842
update weights and add rate_limit_delay for slow claps
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-06-19 22:35:51 +03:00
ac6d70ae91
update chain specification based on new rate_limit_delay field of NetworkData
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-06-19 21:40:05 +03:00
49c5f3a9e9
update weights for the casper runtime, benchmarked with stopped ghost-node service
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-06-19 21:39:17 +03:00
060f61105c
additional network field, that represents default rate limit measured in blocks
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-06-19 21:32:40 +03:00
b53a58f431
update chain specification because of finality delay non-option type
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-06-19 15:02:07 +03:00
818f41d05e
update slow claps because of finality delay non-option type
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-06-19 15:00:30 +03:00
7bb18939bd
no need for finality delay to be an Option<u64>
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-06-19 14:37:06 +03:00
d8e934a98e
ability to avoid too big deviations between from_block and to_block
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-06-19 14:31:33 +03:00
d5643472ee
update chain specification based on NetworkData new fields
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-06-18 18:56:08 +03:00
a503295939
update weights for the ghost-networks on the casper runtime
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-06-18 18:54:44 +03:00
671196ebac
remove legacy release_delay and add block_distance for maximum block range for the eth_getLogs
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-06-18 18:53:19 +03:00
39a6192d28
avoid re-using of to_block during rotation of block_range
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-06-18 17:20:25 +03:00
6100e79ebf
make clap regardless of fail during applause
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-06-18 17:03:09 +03:00
99c43a0c24
runtime update, with history depth for the slow clap
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-06-18 14:17:02 +03:00
417de5a7b2
clear storage based on provided history depth
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-06-18 13:47:13 +03:00
b5845924dc
fixes for the default weights on slow-clap package
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-06-17 20:56:32 +03:00
7107283121
update casper runtime with pre-calculated weights
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-06-17 20:46:39 +03:00
f28e57cf8e
add files with weights for the slow-clap, benchmarked according to the casper reference machine
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-06-17 20:44:44 +03:00
3040dfb775
make benchmark work, issue with authorities fixed
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-06-17 20:34:42 +03:00
1196cc9faa
changes to runtime based on the new version of ghost-slow claps
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-06-17 13:54:32 +03:00
66fa8409fa
additional tests for the pallet
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-06-17 13:50:38 +03:00
5beb22f116
avoid errors from minting sub-existential balance
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-06-13 16:42:14 +03:00
7be24ed139
use latest version of ghost-networks
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-06-13 16:22:21 +03:00
b5fc86aa9e
separate bridged imbalance and gatekeeper amount. requested by @st1nky for ghost-slow-clap
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-06-13 16:16:01 +03:00
e73f3855fd
authorities stored based on the session hash map
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-06-11 22:56:48 +03:00
a00eec9bb9
tests for clap and applause events added
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-06-04 16:33:03 +03:00
2c2df5a607
ability to do self applause if claps received
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-06-04 15:44:53 +03:00
186fb58367
merge new functionality which will be used for benchmarking purposes
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-06-04 15:40:13 +03:00
1e4abbfe69
function to trigger nullification period, tests for the new functionality and expansion of NetworkData trait
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-06-04 15:35:48 +03:00
573e57dfb4
new tests based on new ghost-network functinality
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-06-03 20:41:51 +03:00
46d4716f67
merge extended ghost-networks with ability to nullify accumulated commission
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-06-03 19:48:23 +03:00
9cb7f3c782
replacing the average claps in session with median to determine a harmful authority
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-06-03 19:38:07 +03:00
c55d9a05d9
auto nullification during finalization and appropriate tests
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-06-03 19:06:50 +03:00
5847097e94
extend network inspect handler trait with additional function
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-06-03 18:58:21 +03:00
04a63e234d
tests updated and small tweaks of the lib
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-06-02 19:20:14 +03:00
2b738c009b
merge latest ghost-network version
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-06-02 19:17:16 +03:00
f3d8ee3ab2
make bridge imbalance fields accesible aka public
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-06-02 19:11:11 +03:00
2da07d7b24
chmod 644 Cargo.toml for ghost-slow-claps
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-05-31 14:55:30 +03:00
9ba25d6b3d
friendly merge for ghost-claims weights
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-05-31 14:51:53 +03:00
3234341fed
use benchmarked weights as a default weights for ghost-claims pallet
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-05-31 14:48:08 +03:00
fa2cb811a8
update for slow-claps: remove companions, updgrade block range storage, new way of commission accumulation
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-05-31 14:30:15 +03:00
561d4430b4
another indention fix in main Cargo.toml
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-05-31 14:21:21 +03:00
b64700fb42
fix indentation in TOML files
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-05-31 13:12:48 +03:00
b3f85f426c
extend pallet ghost-networks and create BridgedInflationCurve
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
2025-05-30 19:03:50 +03:00
ddec108ced
chmod 644 files in runtime
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-05-29 13:09:54 +03:00
cd8ad50ac3
chmod 644 utils
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-05-29 13:04:55 +03:00
e09ce03836
chmod 644 tests
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-05-29 13:01:30 +03:00
9f6f4953f7
chmod 644 service
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-05-29 12:59:25 +03:00
40aba0e3af
chmod 644 files in rpc
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-05-29 12:58:09 +03:00
596d9a6ca7
chmod 644 files in core-primitives
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-05-29 12:57:26 +03:00
39279697f2
chmod 644 files in cli
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-05-29 12:56:11 +03:00
d3a18e298a
chmod 644 files in project root
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-05-29 12:54:26 +03:00
aede9e6e2e
change access permissions of files in pallets folder
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-05-29 12:52:37 +03:00
131 changed files with 9677 additions and 6113 deletions

58
Cargo.lock generated
View File

@ -1,6 +1,6 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
version = 4
[[package]]
name = "Inflector"
@ -1186,7 +1186,7 @@ dependencies = [
[[package]]
name = "casper-runtime"
version = "3.5.20"
version = "3.5.30"
dependencies = [
"casper-runtime-constants",
"frame-benchmarking",
@ -1203,6 +1203,7 @@ dependencies = [
"ghost-networks",
"ghost-runtime-common",
"ghost-slow-clap",
"ghost-sudo",
"log",
"pallet-alliance",
"pallet-authority-discovery",
@ -3504,7 +3505,7 @@ dependencies = [
[[package]]
name = "ghost-claims"
version = "0.2.2"
version = "0.2.4"
dependencies = [
"frame-benchmarking",
"frame-support",
@ -3528,7 +3529,7 @@ dependencies = [
[[package]]
name = "ghost-cli"
version = "0.7.197"
version = "0.8.2"
dependencies = [
"cfg-if",
"clap 4.5.4",
@ -3560,7 +3561,7 @@ dependencies = [
[[package]]
name = "ghost-client-cli"
version = "0.1.3"
version = "0.1.4"
dependencies = [
"array-bytes",
"clap 4.5.4",
@ -3584,7 +3585,7 @@ dependencies = [
[[package]]
name = "ghost-machine-primitives"
version = "0.7.197"
version = "0.8.2"
dependencies = [
"lazy_static",
"sc-sysinfo",
@ -3593,7 +3594,7 @@ dependencies = [
[[package]]
name = "ghost-metrics"
version = "0.7.197"
version = "0.8.2"
dependencies = [
"assert_cmd",
"bs58 0.5.1",
@ -3616,7 +3617,7 @@ dependencies = [
[[package]]
name = "ghost-miner"
version = "1.5.0"
version = "1.5.1"
dependencies = [
"anyhow",
"assert_cmd",
@ -3648,7 +3649,7 @@ dependencies = [
[[package]]
name = "ghost-networks"
version = "0.7.197"
version = "0.1.13"
dependencies = [
"frame-benchmarking",
"frame-support",
@ -3656,6 +3657,8 @@ dependencies = [
"ghost-core-primitives",
"ghost-traits",
"pallet-balances",
"pallet-staking",
"pallet-staking-reward-curve",
"parity-scale-codec",
"scale-info",
"sp-io 30.0.0",
@ -3665,7 +3668,7 @@ dependencies = [
[[package]]
name = "ghost-node"
version = "0.7.197"
version = "0.8.2"
dependencies = [
"assert_cmd",
"color-eyre",
@ -3681,7 +3684,7 @@ dependencies = [
[[package]]
name = "ghost-remote-ext-tests-bags-list"
version = "1.0.0"
version = "1.0.1"
dependencies = [
"casper-runtime",
"casper-runtime-constants",
@ -3696,7 +3699,7 @@ dependencies = [
[[package]]
name = "ghost-rpc"
version = "0.7.197"
version = "0.8.2"
dependencies = [
"ghost-core-primitives",
"jsonrpsee",
@ -3725,7 +3728,7 @@ dependencies = [
[[package]]
name = "ghost-runtime-common"
version = "0.4.2"
version = "0.4.3"
dependencies = [
"frame-support",
"frame-system",
@ -3748,7 +3751,7 @@ dependencies = [
[[package]]
name = "ghost-service"
version = "0.7.197"
version = "0.8.2"
dependencies = [
"assert_matches",
"async-trait",
@ -3832,7 +3835,7 @@ dependencies = [
[[package]]
name = "ghost-slow-clap"
version = "0.3.15"
version = "0.3.39"
dependencies = [
"frame-benchmarking",
"frame-support",
@ -3841,6 +3844,8 @@ dependencies = [
"log",
"pallet-balances",
"pallet-session",
"pallet-staking",
"pallet-staking-reward-curve",
"parity-scale-codec",
"scale-info",
"serde",
@ -3855,7 +3860,7 @@ dependencies = [
[[package]]
name = "ghost-staging-chain-spec-builder"
version = "1.6.1"
version = "1.6.2"
dependencies = [
"clap 4.5.4",
"log",
@ -3864,9 +3869,24 @@ dependencies = [
"sp-tracing 16.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.12.0)",
]
[[package]]
name = "ghost-sudo"
version = "0.0.2"
dependencies = [
"docify",
"frame-benchmarking",
"frame-support",
"frame-system",
"parity-scale-codec",
"scale-info",
"sp-io 30.0.0",
"sp-runtime 31.0.1",
"sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.12.0)",
]
[[package]]
name = "ghost-traits"
version = "0.3.19"
version = "0.3.23"
dependencies = [
"frame-support",
"sp-runtime 31.0.1",
@ -3874,7 +3894,7 @@ dependencies = [
[[package]]
name = "ghost-voter-bags"
version = "0.3.6"
version = "0.3.7"
dependencies = [
"casper-runtime",
"clap 4.5.4",
@ -3884,7 +3904,7 @@ dependencies = [
[[package]]
name = "ghostkey"
version = "0.3.15"
version = "0.3.16"
dependencies = [
"clap 4.5.4",
"ghost-client-cli",

View File

@ -17,7 +17,7 @@ homepage.workspace = true
[workspace.package]
license = "GPL-3.0-only"
authors = ["571nky", "57r37ch", "f4750"]
version = "0.7.197"
version = "0.8.2"
edition = "2021"
homepage = "https://ghostchain.io"
repository = "https://git.ghostchain.io/ghostchain/ghost-node"
@ -229,6 +229,7 @@ ghost-traits = { path = "pallets/traits", default-features = false }
ghost-networks = { path = "pallets/networks", default-features = false }
ghost-claims = { path = "pallets/claims", default-features = false }
ghost-slow-clap = { path = "pallets/slow-clap", default-features = false }
ghost-sudo = { path = "pallets/sudo", default-features = false }
ghost-runtime-constants = { package = "ghost-runtime-constants", path = "runtime/ghost/constants", default-features = false }
casper-runtime = { path = "runtime/casper", default-features = false }
casper-runtime-constants = { package = "casper-runtime-constants", path = "runtime/casper/constants", default-features = false }
@ -271,6 +272,7 @@ members = [
"pallets/networks",
"pallets/claims",
"pallets/slow-clap",
"pallets/sudo",
"utils/bags-list",
"utils/chain-spec-builder",
"utils/generate-bags",

0
LICENSE.md Executable file → Normal file
View File

0
README.md Executable file → Normal file
View File

0
cli/Cargo.toml Executable file → Normal file
View File

2
cli/build.rs Executable file → Normal file
View File

@ -1,4 +1,4 @@
fn main () {
fn main() {
if let Ok(profile) = std::env::var("PROFILE") {
println!("cargo:rustc-cfg=build_type=\"{}\"", profile);
}

0
cli/src/cli.rs Executable file → Normal file
View File

171
cli/src/command.rs Executable file → Normal file
View File

@ -1,14 +1,13 @@
use crate::cli::{Cli, Subcommand};
use frame_benchmarking_cli::{BenchmarkCmd, ExtrinsicFactory};
use futures::future::TryFutureExt;
use keyring::Sr25519Keyring;
use sc_cli::SubstrateCli;
use service::{
self, IdentifyVariant,
benchmarking::{
benchmark_inherent_data, RemarkBuilder, TransferKeepAliveBuilder
},
self,
benchmarking::{benchmark_inherent_data, RemarkBuilder, TransferKeepAliveBuilder},
IdentifyVariant,
};
use keyring::Sr25519Keyring;
pub use crate::{error::Error, service::BlockId};
#[cfg(feature = "pyroscope")]
@ -68,28 +67,35 @@ impl SubstrateCli for Cli {
#[cfg(feature = "casper-native")]
"casper" => Box::new(service::chain_spec::casper_config()?),
#[cfg(feature = "casper-native")]
"casper-dev" | "dev" | "development" => Box::new(service::chain_spec::casper_development_config()?),
"casper-dev" | "dev" | "development" => {
Box::new(service::chain_spec::casper_development_config()?)
}
#[cfg(feature = "casper-native")]
"casper-local" | "local" => Box::new(service::chain_spec::casper_local_testnet_config()?),
"casper-local" | "local" => {
Box::new(service::chain_spec::casper_local_testnet_config()?)
}
#[cfg(feature = "casper-native")]
"casper-staging" | "staging" => Box::new(service::chain_spec::casper_staging_testnet_config()?),
"casper-staging" | "staging" => {
Box::new(service::chain_spec::casper_staging_testnet_config()?)
}
#[cfg(not(feature = "casper-native"))]
name if name.starts_with("casper-") && !name.ends_with(".json") =>
Err(format!("`{}` only supported with `casper-native` feature enabled.", name))?,
name if name.starts_with("casper-") && !name.ends_with(".json") => Err(format!(
"`{}` only supported with `casper-native` feature enabled.",
name
))?,
#[cfg(feature = "casper-native")]
path => {
let path = std::path::PathBuf::from(path);
let chain_spec = Box::new(
service::GenericChainSpec::from_json_file(path.clone())?
) as Box<dyn service::ChainSpec>;
let chain_spec = Box::new(service::GenericChainSpec::from_json_file(path.clone())?)
as Box<dyn service::ChainSpec>;
if chain_spec.is_casper() {
Box::new(service::CasperChainSpec::from_json_file(path)?)
} else {
chain_spec
}
},
}
})
}
}
@ -109,10 +115,7 @@ fn set_ss58_version(spec: &Box<dyn service::ChainSpec>) {
sp_core::crypto::set_default_ss58_version(ss58_version);
}
fn run_node_inner<F>(
cli: Cli,
logger_hook: F,
) -> Result<()>
fn run_node_inner<F>(cli: Cli, logger_hook: F) -> Result<()>
where
F: FnOnce(&mut sc_cli::LoggerBuilder, &sc_service::Configuration),
{
@ -128,7 +131,8 @@ where
.then_some(config.database.path().map(|database_path| {
let _ = std::fs::create_dir_all(&database_path);
sc_sysinfo::gather_hwbench(Some(database_path))
})).flatten();
}))
.flatten();
let database_source = config.database.clone();
let task_manager = service::build_full(
@ -138,7 +142,8 @@ where
telemetry_worker_handle: None,
hwbench,
},
).map(|full| full.task_manager)?;
)
.map(|full| full.task_manager)?;
if let Some(path) = database_source.path() {
sc_storage_monitor::StorageMonitorService::try_spawn(
@ -167,7 +172,9 @@ pub fn run() -> Result<()> {
let agent = pyro::Pyroscope::builder(
"http://".to_owned() + address.to_string().as_str(),
"ghost".to_owned(),
).backend(pprof_backend(PprofConfig::new().sample_rate(113))).build()?;
)
.backend(pprof_backend(PprofConfig::new().sample_rate(113)))
.build()?;
Some(agent.start()?)
} else {
@ -176,7 +183,7 @@ pub fn run() -> Result<()> {
#[cfg(not(feature = "pyroscope"))]
if cli.run.pyroscope_server.is_some() {
return Err(Error::PyroscopeNotCompiledIn)
return Err(Error::PyroscopeNotCompiledIn);
}
match &cli.subcommand {
@ -184,7 +191,7 @@ pub fn run() -> Result<()> {
Some(Subcommand::BuildSpec(cmd)) => {
let runner = cli.create_runner(cmd).map_err(Error::SubstrateCli)?;
Ok(runner.sync_run(|config| cmd.run(config.chain_spec, config.network))?)
},
}
Some(Subcommand::CheckBlock(cmd)) => {
let runner = cli.create_runner(cmd).map_err(Error::SubstrateCli)?;
let chain_spec = &runner.config().chain_spec;
@ -192,11 +199,13 @@ pub fn run() -> Result<()> {
set_ss58_version(chain_spec);
runner.async_run(|mut config| {
let (client, _, import_queue, task_manager) =
service::new_chain_ops(&mut config)?;
Ok((cmd.run(client, import_queue).map_err(Error::SubstrateCli), task_manager))
let (client, _, import_queue, task_manager) = service::new_chain_ops(&mut config)?;
Ok((
cmd.run(client, import_queue).map_err(Error::SubstrateCli),
task_manager,
))
})
},
}
Some(Subcommand::ExportBlocks(cmd)) => {
let runner = cli.create_runner(cmd).map_err(Error::SubstrateCli)?;
let chain_spec = &runner.config().chain_spec;
@ -204,11 +213,14 @@ pub fn run() -> Result<()> {
set_ss58_version(chain_spec);
Ok(runner.async_run(|mut config| {
let ( client, _, _, task_manager ) =
service::new_chain_ops(&mut config)?;
Ok((cmd.run(client, config.database).map_err(Error::SubstrateCli), task_manager))
let (client, _, _, task_manager) = service::new_chain_ops(&mut config)?;
Ok((
cmd.run(client, config.database)
.map_err(Error::SubstrateCli),
task_manager,
))
})?)
},
}
Some(Subcommand::ExportState(cmd)) => {
let runner = cli.create_runner(cmd).map_err(Error::SubstrateCli)?;
let chain_spec = &runner.config().chain_spec;
@ -216,11 +228,14 @@ pub fn run() -> Result<()> {
set_ss58_version(chain_spec);
Ok(runner.async_run(|mut config| {
let ( client, _, _, task_manager ) =
service::new_chain_ops(&mut config)?;
Ok((cmd.run(client, config.chain_spec).map_err(Error::SubstrateCli), task_manager))
let (client, _, _, task_manager) = service::new_chain_ops(&mut config)?;
Ok((
cmd.run(client, config.chain_spec)
.map_err(Error::SubstrateCli),
task_manager,
))
})?)
},
}
Some(Subcommand::ImportBlocks(cmd)) => {
let runner = cli.create_runner(cmd).map_err(Error::SubstrateCli)?;
let chain_spec = &runner.config().chain_spec;
@ -228,15 +243,17 @@ pub fn run() -> Result<()> {
set_ss58_version(chain_spec);
Ok(runner.async_run(|mut config| {
let ( client, _, import_queue, task_manager ) =
service::new_chain_ops(&mut config)?;
Ok((cmd.run(client, import_queue).map_err(Error::SubstrateCli), task_manager))
let (client, _, import_queue, task_manager) = service::new_chain_ops(&mut config)?;
Ok((
cmd.run(client, import_queue).map_err(Error::SubstrateCli),
task_manager,
))
})?)
},
}
Some(Subcommand::PurgeChain(cmd)) => {
let runner = cli.create_runner(cmd).map_err(Error::SubstrateCli)?;
Ok(runner.sync_run(|config| cmd.run(config.database))?)
},
}
Some(Subcommand::Revert(cmd)) => {
let runner = cli.create_runner(cmd).map_err(Error::SubstrateCli)?;
let chain_spec = &runner.config().chain_spec;
@ -244,62 +261,59 @@ pub fn run() -> Result<()> {
set_ss58_version(chain_spec);
Ok(runner.async_run(|mut config| {
let (client, backend, _, task_manager) =
service::new_chain_ops(&mut config)?;
let (client, backend, _, task_manager) = service::new_chain_ops(&mut config)?;
let aux_revert = Box::new(|client, backend, blocks| {
service::revert_backend(client, backend, blocks).map_err(|err| {
match err {
service::revert_backend(client, backend, blocks).map_err(|err| match err {
service::Error::Blockchain(err) => err.into(),
err => sc_cli::Error::Application(err.into()),
}
})
});
Ok((
cmd.run(client, backend, Some(aux_revert)).map_err(Error::SubstrateCli),
task_manager
cmd.run(client, backend, Some(aux_revert))
.map_err(Error::SubstrateCli),
task_manager,
))
})?)
},
}
Some(Subcommand::Benchmark(cmd)) => {
let runner = cli.create_runner(cmd).map_err(Error::SubstrateCli)?;
let chain_spec = &runner.config().chain_spec;
match cmd {
#[cfg(not(feature = "runtime-benchmarks"))]
BenchmarkCmd::Storage(_) =>
BenchmarkCmd::Storage(_) => {
return Err(sc_cli::Error::Input(
"Compile with `--feature=runtime-benchmarks \
to enable storage benchmarks.".into()
).into()),
to enable storage benchmarks."
.into(),
)
.into())
}
#[cfg(feature = "runtime-benchmarks")]
BenchmarkCmd::Storage(cmd) => runner.sync_run(|mut config| {
let (client, backend, _, _,) =
service::new_chain_ops(&mut config)?;
let (client, backend, _, _) = service::new_chain_ops(&mut config)?;
let db = backend.expose_db();
let storage = backend.expose_storage();
cmd.run(config, client.clone(), db, storage).map_err(Error::SubstrateCli)
cmd.run(config, client.clone(), db, storage)
.map_err(Error::SubstrateCli)
}),
BenchmarkCmd::Block(cmd) => runner.sync_run(|mut config| {
let (client, _, _, _,) =
service::new_chain_ops(&mut config)?;
let (client, _, _, _) = service::new_chain_ops(&mut config)?;
cmd.run(client.clone()).map_err(Error::SubstrateCli)
}),
// These commands are very similar and can be handled in nearly the same way
BenchmarkCmd::Extrinsic(_) | BenchmarkCmd::Overhead(_) =>
BenchmarkCmd::Extrinsic(_) | BenchmarkCmd::Overhead(_) => {
runner.sync_run(|mut config| {
let (client, _, _, _) =
service::new_chain_ops(&mut config)?;
let (client, _, _, _) = service::new_chain_ops(&mut config)?;
let inherent_data = benchmark_inherent_data()
.map_err(|e| format!("generating inherent data: {:?}", e))?;
let remark_builder = RemarkBuilder::new(
client.clone(),
config.chain_spec.identify_chain(),
);
let remark_builder =
RemarkBuilder::new(client.clone(), config.chain_spec.identify_chain());
match cmd {
BenchmarkCmd::Extrinsic(cmd) => {
@ -316,17 +330,20 @@ pub fn run() -> Result<()> {
cmd.run(client.clone(), inherent_data, Vec::new(), &ext_factory)
.map_err(Error::SubstrateCli)
},
BenchmarkCmd::Overhead(cmd) => cmd.run(
}
BenchmarkCmd::Overhead(cmd) => cmd
.run(
config,
client.clone(),
inherent_data,
Vec::new(),
&remark_builder,
).map_err(Error::SubstrateCli),
)
.map_err(Error::SubstrateCli),
_ => unreachable!("Ensured by the outside match; qed"),
}
}),
})
}
BenchmarkCmd::Pallet(cmd) => {
set_ss58_version(chain_spec);
@ -334,17 +351,23 @@ pub fn run() -> Result<()> {
runner.sync_run(|config| {
cmd.run_with_spec::<sp_runtime::traits::HashingFor<service::Block>, ()>(
Some(config.chain_spec),
).map_err(|e| Error::SubstrateCli(e))
)
.map_err(|e| Error::SubstrateCli(e))
})
} else {
Err(sc_cli::Error::Input(
"Benchmarking wasn't enabled when building the node. \
You can enable it with `--features=runtime-benchmarks`.".into()
).into())
You can enable it with `--features=runtime-benchmarks`."
.into(),
)
.into())
}
}
},
BenchmarkCmd::Machine(cmd) => runner.sync_run(|config| {
cmd.run(&config, ghost_machine_primitives::GHOST_NODE_REFERENCE_HARDWARE.clone())
cmd.run(
&config,
ghost_machine_primitives::GHOST_NODE_REFERENCE_HARDWARE.clone(),
)
.map_err(Error::SubstrateCli)
}),
// Note: this allows to implement additional new benchmark
@ -352,12 +375,12 @@ pub fn run() -> Result<()> {
#[allow(unreachable_patterns)]
_ => Err(Error::CommandNotImplemented),
}
},
}
Some(Subcommand::Key(cmd)) => Ok(cmd.run(&cli)?),
Some(Subcommand::ChainInfo(cmd)) => {
let runner = cli.create_runner(cmd)?;
Ok(runner.sync_run(|config| cmd.run::<service::Block>(&config))?)
},
}
}?;
#[cfg(feature = "pyroscope")]

0
cli/src/error.rs Executable file → Normal file
View File

4
cli/src/lib.rs Executable file → Normal file
View File

@ -6,9 +6,7 @@ mod command;
mod error;
#[cfg(feature = "service")]
pub use service::{
self, Block, CoreApi, IdentifyVariant, ProvideRuntimeApi, TFullClient,
};
pub use service::{self, Block, CoreApi, IdentifyVariant, ProvideRuntimeApi, TFullClient};
#[cfg(feature = "cli")]
pub use cli::*;

View File

@ -1,6 +1,6 @@
[package]
name = "ghost-client-cli"
version = "0.1.3"
version = "0.1.4"
description = "Ghost CLI interface"
license.workspace = true
authors.workspace = true

View File

@ -3,13 +3,10 @@
use bip39::Mnemonic;
use clap::Parser;
use itertools::Itertools;
use sc_cli::{
with_crypto_scheme, KeystoreParams, OutputTypeFlag,
CryptoSchemeFlag, Error,
};
use sc_cli::{with_crypto_scheme, CryptoSchemeFlag, Error, KeystoreParams, OutputTypeFlag};
use crate::params::NetworkSchemeFlag;
use crate::commands::utils::print_from_uri;
use crate::params::NetworkSchemeFlag;
/// The `generate` command
#[derive(Debug, Clone, Parser)]

View File

@ -1,14 +1,13 @@
//! Implementation of the `inspect` subcommand
use crate::commands::utils::{print_from_public, print_from_uri};
use crate::params::NetworkSchemeFlag;
use clap::Parser;
use sc_cli::{
utils::read_uri, with_crypto_scheme, CryptoSchemeFlag, Error, KeystoreParams, OutputTypeFlag,
};
use sp_core::crypto::{ExposeSecret, SecretString, SecretUri, Ss58Codec};
use std::str::FromStr;
use sc_cli::{
with_crypto_scheme, KeystoreParams, OutputTypeFlag, CryptoSchemeFlag, Error,
utils::read_uri,
};
use crate::params::NetworkSchemeFlag;
use crate::commands::utils::{print_from_public, print_from_uri};
/// The `inspect` command
#[derive(Debug, Parser)]
@ -236,8 +235,16 @@ mod tests {
array_bytes::bytes2hex("0x", valid_public_with_password_and_derivation.as_slice());
// They should still be valid, because we check the base secret key.
check_cmd(&seed_with_password_and_derivation, &valid_public_hex_with_password, true);
check_cmd(&seed_with_password_and_derivation, &valid_accountid_with_password, true);
check_cmd(
&seed_with_password_and_derivation,
&valid_public_hex_with_password,
true,
);
check_cmd(
&seed_with_password_and_derivation,
&valid_accountid_with_password,
true,
);
// And these should be invalid.
check_cmd(&seed_with_password_and_derivation, &valid_public_hex, false);

View File

@ -1,10 +1,7 @@
//! Key related CLI utilities
use super::{generate::GenerateCmd, inspect_key::InspectKeyCmd};
use sc_cli::{
GenerateKeyCmdCommon, InsertKeyCmd, InspectNodeKeyCmd, Error,
SubstrateCli,
};
use sc_cli::{Error, GenerateKeyCmdCommon, InsertKeyCmd, InspectNodeKeyCmd, SubstrateCli};
/// Key utilities for the cli.
#[derive(Debug, clap::Subcommand)]

View File

@ -1,11 +1,13 @@
mod key;
mod generate;
mod vanity;
mod inspect_key;
mod key;
mod utils;
mod vanity;
pub use self::{
key::KeySubcommand, vanity::VanityCmd, inspect_key::InspectKeyCmd,
generate::GenerateCmd,
utils::{unwrap_or_default_ss58_name, print_from_uri, print_from_public},
inspect_key::InspectKeyCmd,
key::KeySubcommand,
utils::{print_from_public, print_from_uri, unwrap_or_default_ss58_name},
vanity::VanityCmd,
};

View File

@ -1,16 +1,15 @@
use serde_json::json;
use sc_cli::{
OutputType,
utils::{PublicFor, SeedFor},
OutputType,
};
use sp_runtime::{traits::IdentifyAccount, MultiSigner};
use serde_json::json;
use sp_core::{
crypto::{
unwrap_or_default_ss58_version,
Ss58Codec, ExposeSecret, Ss58AddressFormat, SecretString,
unwrap_or_default_ss58_version, ExposeSecret, SecretString, Ss58AddressFormat, Ss58Codec,
},
hexdisplay::HexDisplay,
};
use sp_runtime::{traits::IdentifyAccount, MultiSigner};
pub fn print_from_uri<Pair>(
uri: &str,
@ -43,7 +42,7 @@ pub fn print_from_uri<Pair>(
"{}",
serde_json::to_string_pretty(&json).expect("Json pretty print failed")
);
},
}
OutputType::Text => {
println!(
"Secret phrase: {}\n \
@ -59,9 +58,12 @@ pub fn print_from_uri<Pair>(
format_public_key::<Pair>(public_key.clone()),
format_account_id::<Pair>(public_key.clone()),
public_key.to_ss58check_with_version(network_override),
pair.public().into().into_account().to_ss58check_with_version(network_override),
pair.public()
.into()
.into_account()
.to_ss58check_with_version(network_override),
);
},
}
}
} else if let Ok((pair, seed)) = Pair::from_string_with_seed(uri, password) {
let public_key = pair.public();
@ -82,7 +84,7 @@ pub fn print_from_uri<Pair>(
"{}",
serde_json::to_string_pretty(&json).expect("Json pretty print failed")
);
},
}
OutputType::Text => {
println!(
"Secret Key URI `{}` is account:\n \
@ -94,13 +96,20 @@ pub fn print_from_uri<Pair>(
SS58 Address: {}",
uri,
network_id,
if let Some(seed) = seed { format_seed::<Pair>(seed) } else { "n/a".into() },
if let Some(seed) = seed {
format_seed::<Pair>(seed)
} else {
"n/a".into()
},
format_public_key::<Pair>(public_key.clone()),
format_account_id::<Pair>(public_key.clone()),
public_key.to_ss58check_with_version(network_override),
pair.public().into().into_account().to_ss58check_with_version(network_override),
pair.public()
.into()
.into_account()
.to_ss58check_with_version(network_override),
);
},
}
}
} else if let Ok((public_key, network)) = Pair::Public::from_string_with_version(uri) {
let network_override = network_override.unwrap_or(network);
@ -120,7 +129,7 @@ pub fn print_from_uri<Pair>(
"{}",
serde_json::to_string_pretty(&json).expect("Json pretty print failed")
);
},
}
OutputType::Text => {
println!(
"Public Key URI `{}` is account:\n \
@ -136,7 +145,7 @@ pub fn print_from_uri<Pair>(
public_key.to_ss58check_with_version(network_override),
public_key.to_ss58check_with_version(network_override),
);
},
}
}
} else {
println!("Invalid phrase/URI given");
@ -170,8 +179,11 @@ where
"ss58Address": public_key.to_ss58check_with_version(network_override),
});
println!("{}", serde_json::to_string_pretty(&json).expect("Json pretty print failed"));
},
println!(
"{}",
serde_json::to_string_pretty(&json).expect("Json pretty print failed")
);
}
OutputType::Text => {
println!(
"Network ID/Version: {}\n \
@ -185,7 +197,7 @@ where
public_key.to_ss58check_with_version(network_override),
public_key.to_ss58check_with_version(network_override),
);
},
}
}
Ok(())
@ -216,5 +228,8 @@ fn format_account_id<P: sp_core::Pair>(public_key: PublicFor<P>) -> String
where
PublicFor<P>: Into<MultiSigner>,
{
format!("0x{}", HexDisplay::from(&public_key.into().into_account().as_ref()))
format!(
"0x{}",
HexDisplay::from(&public_key.into().into_account().as_ref())
)
}

View File

@ -2,21 +2,19 @@
use clap::Parser;
use rand::{rngs::OsRng, RngCore};
use sp_core::crypto::{
unwrap_or_default_ss58_version, Ss58AddressFormat, Ss58Codec,
};
use sc_cli::{utils::format_seed, with_crypto_scheme, CryptoSchemeFlag, Error, OutputTypeFlag};
use sp_core::crypto::{unwrap_or_default_ss58_version, Ss58AddressFormat, Ss58Codec};
use sp_runtime::traits::IdentifyAccount;
use sc_cli::{
with_crypto_scheme, Error, OutputTypeFlag, CryptoSchemeFlag,
utils::format_seed,
};
use crate::commands::utils::print_from_uri;
use crate::params::NetworkSchemeFlag;
/// The `vanity` command
#[derive(Debug, Clone, Parser)]
#[command(name = "vanity", about = "Generate a seed that provides a vanity address")]
#[command(
name = "vanity",
about = "Generate a seed that provides a vanity address"
)]
pub struct VanityCmd {
/// Desired pattern
#[arg(long, value_parser = assert_non_empty_string)]
@ -84,14 +82,17 @@ where
}
let p = Pair::from_seed(&seed);
let ss58 = p.public().into_account().to_ss58check_with_version(network_override);
let ss58 = p
.public()
.into_account()
.to_ss58check_with_version(network_override);
println!("{:?}", ss58);
let score = calculate_score(desired, &ss58);
if score > best || desired.len() < 2 {
best = score;
if best >= top {
println!("best: {} == top: {}", best, top);
return Ok(format_seed::<Pair>(seed.clone()))
return Ok(format_seed::<Pair>(seed.clone()));
}
}
done += 1;
@ -116,11 +117,11 @@ fn next_seed(seed: &mut [u8]) {
match s {
255 => {
*s = 0;
},
}
_ => {
*s += 1;
break
},
break;
}
}
}
}
@ -132,7 +133,7 @@ fn calculate_score(_desired: &str, key: &str) -> usize {
let snip_size = _desired.len() - truncate;
let truncated = &_desired[0..snip_size];
if let Some(pos) = key.find(truncated) {
return (47 - pos) + (snip_size * 48)
return (47 - pos) + (snip_size * 48);
}
}
0
@ -164,11 +165,13 @@ mod tests {
#[test]
fn test_generation_with_single_char() {
let seed = generate_key::<sr25519::Pair>("ab", default_ss58_version()).unwrap();
assert!(sr25519::Pair::from_seed_slice(&array_bytes::hex2bytes_unchecked(&seed))
assert!(
sr25519::Pair::from_seed_slice(&array_bytes::hex2bytes_unchecked(&seed))
.unwrap()
.public()
.to_ss58check()
.contains("ab"));
.contains("ab")
);
}
#[test]
@ -176,11 +179,13 @@ mod tests {
let seed =
generate_key::<sr25519::Pair>("ab", Ss58AddressFormatRegistry::PolkadotAccount.into())
.unwrap();
assert!(sr25519::Pair::from_seed_slice(&array_bytes::hex2bytes_unchecked(&seed))
assert!(
sr25519::Pair::from_seed_slice(&array_bytes::hex2bytes_unchecked(&seed))
.unwrap()
.public()
.to_ss58check_with_version(Ss58AddressFormatRegistry::PolkadotAccount.into())
.contains("ab"));
.contains("ab")
);
}
#[test]

View File

@ -1,5 +1,5 @@
pub mod params;
pub mod commands;
pub mod params;
pub use commands::KeySubcommand;
pub use commands::VanityCmd;

View File

@ -21,19 +21,25 @@ pub struct InnerSs58AddressFormat(Ss58AddressFormat);
impl InnerSs58AddressFormat {
#[inline]
pub fn custom(prefix: u16) -> Self {
Self { 0: Ss58AddressFormat::custom(prefix) }
Self {
0: Ss58AddressFormat::custom(prefix),
}
}
}
impl std::fmt::Display for InnerSs58AddressFormat {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{} network", ALL_POSSIBLE_IDS
write!(
f,
"{} network",
ALL_POSSIBLE_IDS
.binary_search(&u16::from(self.0))
.expect("always be found"))
.expect("always be found")
)
}
}
impl<'a>TryFrom<&'a str> for InnerSs58AddressFormat {
impl<'a> TryFrom<&'a str> for InnerSs58AddressFormat {
type Error = ParseError;
fn try_from(x: &'a str) -> Result<Self, Self::Error> {
@ -44,13 +50,13 @@ impl<'a>TryFrom<&'a str> for InnerSs58AddressFormat {
}
}
pub fn parse_s58_prefix_address_format(x: &str,) -> Result<Ss58AddressFormat, String> {
pub fn parse_s58_prefix_address_format(x: &str) -> Result<Ss58AddressFormat, String> {
match InnerSs58AddressFormat::try_from(x) {
Ok(format_registry) => Ok(format_registry.0.into()),
Err(_) => Err(format!(
"Unable to parse variant. Known variants: {:?}",
&ALL_POSSIBLE_NAMES
))
)),
}
}

0
core-primitives/Cargo.toml Executable file → Normal file
View File

0
core-primitives/src/lib.rs Executable file → Normal file
View File

0
file_header.txt Executable file → Normal file
View File

View File

@ -22,7 +22,11 @@ impl Metronome {
/// Create a new metronome source with a defined cycle duration.
pub fn new(cycle: Duration) -> Self {
let period = cycle.into();
Self { period, delay: Delay::new(period), state: MetronomeState::Snooze }
Self {
period,
delay: Delay::new(period),
state: MetronomeState::Snooze,
}
}
}
@ -36,14 +40,14 @@ impl futures::Stream for Metronome {
let val = self.period;
self.delay.reset(val);
self.state = MetronomeState::Snooze;
},
}
MetronomeState::Snooze => {
if !Pin::new(&mut self.delay).poll(cx).is_ready() {
break
break;
}
self.state = MetronomeState::SetAlarm;
return Poll::Ready(Some(()))
},
return Poll::Ready(Some(()));
}
}
}
Poll::Pending

View File

@ -2,19 +2,16 @@
use codec::Decode;
use core_primitives::{
metrics_definitions::{
CounterDefinition, CounterVecDefinition, HistogramDefinition,
},
metrics_definitions::{CounterDefinition, CounterVecDefinition, HistogramDefinition},
RuntimeMetricLabelValues, RuntimeMetricOp, RuntimeMetricUpdate,
};
use prometheus_endpoint::{
register, Counter, CounterVec, Histogram, HistogramOpts, Opts, Registry,
PrometheusError, U64,
register, Counter, CounterVec, Histogram, HistogramOpts, Opts, PrometheusError, Registry, U64,
};
use std::{
collections::hash_map::HashMap,
sync::{Arc, Mutex, MutexGuard},
}
};
#[derive(Clone, Debug)]
pub struct Metrics {
@ -32,7 +29,9 @@ impl RuntimeMetricsProvider {
pub fn register_countervec(&self, countervec: CounterVecDefinition) {
self.with_counter_vecs_lock_held(|mut hashmap| {
hashmap.entry(countervec.name.to_owned()).or_insert(register(
hashmap
.entry(countervec.name.to_owned())
.or_insert(register(
CounterVec::new(
Opts::new(countervec.name, countervec.description),
countervec.labels,
@ -46,10 +45,7 @@ impl RuntimeMetricsProvider {
pub fn register_counter(&self, counter: CounterDefinition) {
self.with_counters_lock_held(|mut hashmap| {
hashmap.entry(counter.name.to_owned()).or_insert(register(
Counter::new(
counter.name,
counter.description,
)?,
Counter::new(counter.name, counter.description)?,
&self.0,
)?);
Ok(())
@ -60,8 +56,7 @@ impl RuntimeMetricsProvider {
self.with_histograms_lock_held(|mut hashmap| {
hashmap.entry(hist.name.to_owned()).or_insert(register(
Histogram::with_opts(
HistogramOpts::new(hist.name, hist.description)
.buckets(hist.buckets.to_vec()),
HistogramOpts::new(hist.name, hist.description).buckets(hist.buckets.to_vec()),
)?,
&self.0,
)?);
@ -69,15 +64,12 @@ impl RuntimeMetricsProvider {
})
}
pub fn inc_counter_vec_by(
&self,
name: &str,
value: u64,
labels: &RuntimeMetricsProvider,
) {
pub fn inc_counter_vec_by(&self, name: &str, value: u64, labels: &RuntimeMetricsProvider) {
self.with_counter_vecs_lock_held(|mut hashmap| {
hashmap.entry(name.to_owned()).and_modify(|counter_vec| {
counter_vec.with_label_values(&labels.as_str_vec()).inc_by(value)
counter_vec
.with_label_values(&labels.as_str_vec())
.inc_by(value)
});
Ok(())
})
@ -85,7 +77,8 @@ impl RuntimeMetricsProvider {
pub fn inc_counter_by(&self, name: &str, value: u64) {
self.with_counters_lock_held(|mut hashmap| {
hashmap.entry(name.to_owned())
hashmap
.entry(name.to_owned())
.and_modify(|counter_vec| counter_vec.inc_by(value));
Ok(())
})
@ -93,8 +86,9 @@ impl RuntimeMetricsProvider {
pub fn observe_histogram(&self, name: &str, value: u128) {
self.with_histograms_lock_held(|mut hashmap| {
hashmap.entry(name.to_owned())
and_modify(|histogram| histogram.observe(value as f64 / 1_000_000_000.0));
hashmap
.entry(name.to_owned())
.and_modify(|histogram| histogram.observe(value as f64 / 1_000_000_000.0));
Ok(())
})
}
@ -103,21 +97,36 @@ impl RuntimeMetricsProvider {
where
F: FnOnce(MutexGuard<'_, HashMap<String, Counter<U64>>>) -> Result<(), PrometheusError>,
{
let _ = self.1.counters.lock().map(do_something).or_else(|error| Err(error));
let _ = self
.1
.counters
.lock()
.map(do_something)
.or_else(|error| Err(error));
}
fn with_counter_vecs_lock_held<F>(&self, do_something: F)
where
F: FnOnce(MutexGuard<'_, HashMap<String, CounterVec<U64>>>) -> Result<(), PrometheusError>,
{
let _ = self.1.counter_vecs.lock().map(do_something).or_else(|error| Err(error));
let _ = self
.1
.counter_vecs
.lock()
.map(do_something)
.or_else(|error| Err(error));
}
fn with_histograms_lock_held<F>(&self, do_something: F)
where
F: FnOnce(MutexGuard<'_, HashMap<String, Histogram>>) -> Result<(), PrometheusError>,
{
let _ = self.1.histograms.lock().map(do_something).or_else(|error| Err(error));
let _ = self
.1
.histograms
.lock()
.map(do_something)
.or_else(|error| Err(error));
}
}
@ -131,7 +140,7 @@ impl sc_tracing::TraceHandler for RuntimeMetricsProvider {
.unwrap_or(&String::default())
.ne("metrics")
{
return
return;
}
if let Some(update_op_bs58) = event.values.string_values.get("params") {
@ -141,7 +150,7 @@ impl sc_tracing::TraceHandler for RuntimeMetricsProvider {
.as_slice(),
) {
Ok(update_op) => self.parse_metric_update(update_op),
Err(_) => {},
Err(_) => {}
}
}
}
@ -150,12 +159,15 @@ impl sc_tracing::TraceHandler for RuntimeMetricsProvider {
impl RuntimeMetricsProvider {
fn parse_metric_update(&self, update: RuntimeMetricUpdate) {
match update.op {
RuntimeMetricOp::IncrementCounterVec(value, ref labels) =>
self.inc_counter_vec_by(update.metric_name(), value, labels),
RuntimeMetricOp::IncrementCounter(value) =>
self.inc_counter_by(update.metric_name(), value),
RuntimeMetricOp::ObserveHistogram(value) =>
self.observe_histogram(update.metric_name(), value),
RuntimeMetricOp::IncrementCounterVec(value, ref labels) => {
self.inc_counter_vec_by(update.metric_name(), value, labels)
}
RuntimeMetricOp::IncrementCounter(value) => {
self.inc_counter_by(update.metric_name(), value)
}
RuntimeMetricOp::ObserveHistogram(value) => {
self.observe_histogram(update.metric_name(), value)
}
}
}
@ -178,7 +190,7 @@ impl RuntimeMetricsProvider {
pub fn logger_hook() -> impl FnOnce(&mut sc_cli::LoggerBuilder, &sc_service::Configuration) -> () {
|logger_builder, config| {
if config.prometheus_registry().is_none() {
return
return;
}
let registry = config.prometheus_registry().cloned().unwrap();

View File

@ -1,5 +1,5 @@
use hyper::{Client, Uri};
use ghost_test_service::{node_config, run_validator_node, test_prometheus_config};
use hyper::{Client, Uri};
use keyring::AccountKeyring::*;
use std::collections::HashMap;
@ -7,8 +7,13 @@ const DEFAULT_PROMETHEUS_PORT: u16 = 9616;
#[tokio::test(flavor = "multi_thread")]
async fn runtime_can_publish_metrics() {
let mut alice_config =
node_config(|| {}, tokio::runtime::Handle::current(), Alice, Vec::new(), true);
let mut alice_config = node_config(
|| {},
tokio::runtime::Handle::current(),
Alice,
Vec::new(),
true,
);
// Enable prometheus metrics for Alice.
alice_config.prometheus_config = Some(test_prometheus_config(DEFAULT_PROMETHEUS_PORT));
@ -26,8 +31,13 @@ async fn runtime_can_publish_metrics() {
// Start validator Alice
let alice = run_validator_node(alice_config, None);
let bob_config =
node_config(|| {}, tokio::runtime::Handle::current(), Bob, vec![alice.addr.clone()], true);
let bob_config = node_config(
|| {},
tokio::runtime::Handle::current(),
Bob,
vec![alice.addr.clone()],
true,
);
// Start validator Bob
let _bob = run_validator_node(bob_config, None);
@ -48,19 +58,25 @@ async fn scrape_prometheus_metrics(metrics_uri: &str) -> HashMap<String, u64> {
.expect("GET request failed");
let body = String::from_utf8(
hyper::body::to_bytes(res).await.expect("can't get body as bytes").to_vec(),
).expect("body is not an UTF8 string");
hyper::body::to_bytes(res)
.await
.expect("can't get body as bytes")
.to_vec(),
)
.expect("body is not an UTF8 string");
let lines: Vec<_> = body.lines().map(|s| Ok(s.to_owned())).collect();
prometheus_parse::Scrape::parse(lines.into_iter())
.expect("Scraper failed to parse Prometheus metrics")
.samples
.into_iter()
.filter_map(|prometheus_parse::Sample { metric, value, .. }| match value {
.filter_map(
|prometheus_parse::Sample { metric, value, .. }| match value {
prometheus_parse::Value::Counter(value) => Some((metric, value as u64)),
prometheus_parse::Value::Gauge(value) => Some((metric, value as u64)),
prometheus_parse::Value::Untyped(value) => Some((metric, value as u64)),
_ => None,
})
},
)
.collect()
}

View File

@ -1,6 +1,6 @@
[package]
name = "ghost-claims"
version = "0.2.2"
version = "0.2.4"
description = "Ghost balance and rank claims based on EVM actions"
license.workspace = true
authors.workspace = true

View File

@ -6,14 +6,14 @@ use frame_benchmarking::v2::*;
#[instance_benchmarks]
mod benchmarks {
use super::*;
use pallet_ranked_collective::Pallet as Club;
use frame_support::dispatch::RawOrigin;
use pallet_ranked_collective::Pallet as Club;
#[benchmark]
fn claim() {
let i = 1337u32;
let ethereum_secret_key = libsecp256k1::SecretKey::parse(
&keccak_256(&i.to_le_bytes())).unwrap();
let ethereum_secret_key =
libsecp256k1::SecretKey::parse(&keccak_256(&i.to_le_bytes())).unwrap();
let eth_address = crate::secp_utils::eth(&ethereum_secret_key);
let balance = CurrencyOf::<T, I>::minimum_balance();
@ -22,23 +22,30 @@ mod benchmarks {
Total::<T, I>::put(balance);
let pseudo_rank = 5u16;
let _ = Club::<T, I>::do_add_member_to_rank(
pseudo_account.clone(),
pseudo_rank,
false,
);
let _ = Club::<T, I>::do_add_member_to_rank(pseudo_account.clone(), pseudo_rank, false);
let user_account: T::AccountId = account("user", i, 0);
let signature = crate::secp_utils::sig::<T, I>(&ethereum_secret_key, &user_account.encode());
let signature =
crate::secp_utils::sig::<T, I>(&ethereum_secret_key, &user_account.encode());
let prev_balance = CurrencyOf::<T, I>::free_balance(&user_account);
let prev_rank = Club::<T, I>::rank_of(&user_account);
#[extrinsic_call]
claim(RawOrigin::Signed(user_account.clone()), eth_address, signature);
claim(
RawOrigin::Signed(user_account.clone()),
eth_address,
signature,
);
assert_eq!(CurrencyOf::<T, I>::free_balance(&user_account), prev_balance + balance);
assert_eq!(CurrencyOf::<T, I>::free_balance(&pseudo_account), balance - balance);
assert_eq!(
CurrencyOf::<T, I>::free_balance(&user_account),
prev_balance + balance
);
assert_eq!(
CurrencyOf::<T, I>::free_balance(&pseudo_account),
balance - balance
);
let rank = match prev_rank {
Some(current_rank) if pseudo_rank <= current_rank => Some(current_rank),
@ -48,9 +55,5 @@ mod benchmarks {
assert_eq!(Club::<T, I>::rank_of(&pseudo_account), None);
}
impl_benchmark_test_suite!(
Pallet,
crate::mock::new_test_ext(),
crate::mock::Test,
);
impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test,);
}

View File

@ -1,31 +1,33 @@
#![cfg_attr(not(feature = "std"), no_std)]
use frame_support::{
ensure, pallet_prelude::*,
ensure,
pallet_prelude::*,
traits::{
Currency, ExistenceRequirement, Get, RankedMembers,
RankedMembersSwapHandler, VestingSchedule,
Currency, ExistenceRequirement, Get, RankedMembers, RankedMembersSwapHandler,
VestingSchedule,
},
DefaultNoBound,
};
use frame_system::pallet_prelude::*;
use serde::{self, Deserialize, Deserializer, Serialize, Serializer};
pub use pallet::*;
use serde::{self, Deserialize, Deserializer, Serialize, Serializer};
use sp_io::{crypto::secp256k1_ecdsa_recover, hashing::keccak_256};
use sp_runtime::traits::{CheckedSub, CheckedDiv, BlockNumberProvider};
use sp_runtime::traits::{BlockNumberProvider, CheckedDiv, CheckedSub};
use sp_std::prelude::*;
extern crate alloc;
#[cfg(not(feature = "std"))]
use alloc::{format, string::String};
pub mod weights;
mod weights;
pub use crate::weights::WeightInfo;
mod tests;
mod mock;
mod benchmarking;
mod mock;
mod secp_utils;
mod tests;
/// An ethereum address (i.e. 20 bytes, used to represent an Ethereum account).
///
@ -80,15 +82,14 @@ impl sp_std::fmt::Debug for EcdsaSignature {
}
type CurrencyOf<T, I> = <<T as Config<I>>::VestingSchedule as VestingSchedule<
<T as frame_system::Config>::AccountId
<T as frame_system::Config>::AccountId,
>>::Currency;
type BalanceOf<T, I> = <CurrencyOf<T, I> as Currency<
<T as frame_system::Config>::AccountId>
>::Balance;
type BalanceOf<T, I> =
<CurrencyOf<T, I> as Currency<<T as frame_system::Config>::AccountId>>::Balance;
type RankOf<T, I> = <pallet_ranked_collective::Pallet::<T, I> as RankedMembers>::Rank;
type AccountIdOf<T, I> = <pallet_ranked_collective::Pallet::<T, I> as RankedMembers>::AccountId;
type RankOf<T, I> = <pallet_ranked_collective::Pallet<T, I> as RankedMembers>::Rank;
type AccountIdOf<T, I> = <pallet_ranked_collective::Pallet<T, I> as RankedMembers>::AccountId;
#[frame_support::pallet]
pub mod pallet {
@ -99,8 +100,11 @@ pub mod pallet {
pub struct Pallet<T, I = ()>(_);
#[pallet::config]
pub trait Config<I: 'static = ()>: frame_system::Config + pallet_ranked_collective::Config<I> {
type RuntimeEvent: From<Event<Self, I>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
pub trait Config<I: 'static = ()>:
frame_system::Config + pallet_ranked_collective::Config<I>
{
type RuntimeEvent: From<Event<Self, I>>
+ IsType<<Self as frame_system::Config>::RuntimeEvent>;
type VestingSchedule: VestingSchedule<Self::AccountId, Moment = BlockNumberFor<Self>>;
type BlockNumberProvider: BlockNumberProvider<BlockNumber = BlockNumberFor<Self>>;
@ -158,7 +162,11 @@ pub mod pallet {
.map(|(account_id, rank)| {
assert!(
pallet_ranked_collective::Pallet::<T, I>::do_add_member_to_rank(
account_id.clone(), *rank, false).is_ok(),
account_id.clone(),
*rank,
false
)
.is_ok(),
"error during adding and promotion"
);
account_id
@ -185,13 +193,13 @@ pub mod pallet {
) -> DispatchResult {
let who = ensure_signed(origin)?;
let data = who.using_encoded(to_ascii_hex);
let recovered_address = Self::recover_ethereum_address(
&ethereum_signature,
&data,
).ok_or(Error::<T, I>::InvalidEthereumSignature)?;
let recovered_address = Self::recover_ethereum_address(&ethereum_signature, &data)
.ok_or(Error::<T, I>::InvalidEthereumSignature)?;
ensure!(recovered_address == ethereum_address,
Error::<T, I>::InvalidEthereumAddress);
ensure!(
recovered_address == ethereum_address,
Error::<T, I>::InvalidEthereumAddress
);
Self::do_claim(who, ethereum_address)
}
@ -242,12 +250,15 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
}
fn do_claim(receiver: T::AccountId, ethereum_address: EthereumAddress) -> DispatchResult {
let donor = Self::into_account_id(ethereum_address).ok()
let donor = Self::into_account_id(ethereum_address)
.ok()
.ok_or(Error::<T, I>::AddressDecodingFailed)?;
let balance_due = CurrencyOf::<T, I>::free_balance(&donor);
ensure!(balance_due >= CurrencyOf::<T, I>::minimum_balance(),
Error::<T, I>::NoBalanceToClaim);
ensure!(
balance_due >= CurrencyOf::<T, I>::minimum_balance(),
Error::<T, I>::NoBalanceToClaim
);
let new_total = Total::<T, I>::get()
.checked_sub(&balance_due)
@ -279,20 +290,32 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
)?;
}
let rank = if let Some(rank) = <pallet_ranked_collective::Pallet::<T, I> as RankedMembers>::rank_of(&donor) {
let rank = if let Some(rank) =
<pallet_ranked_collective::Pallet<T, I> as RankedMembers>::rank_of(&donor)
{
pallet_ranked_collective::Pallet::<T, I>::do_remove_member_from_rank(&donor, rank)?;
let new_rank = match <pallet_ranked_collective::Pallet::<T, I> as RankedMembers>::rank_of(&receiver) {
let new_rank =
match <pallet_ranked_collective::Pallet<T, I> as RankedMembers>::rank_of(&receiver)
{
Some(current_rank) if current_rank >= rank => current_rank,
Some(current_rank) if current_rank < rank => {
for _ in 0..rank - current_rank {
pallet_ranked_collective::Pallet::<T, I>::do_promote_member(receiver.clone(), None, false)?;
pallet_ranked_collective::Pallet::<T, I>::do_promote_member(
receiver.clone(),
None,
false,
)?;
}
rank
},
}
_ => {
pallet_ranked_collective::Pallet::<T, I>::do_add_member_to_rank(receiver.clone(), rank, false)?;
pallet_ranked_collective::Pallet::<T, I>::do_add_member_to_rank(
receiver.clone(),
rank,
false,
)?;
rank
},
}
};
<T as pallet::Config<I>>::MemberSwappedHandler::swapped(&donor, &receiver, new_rank);
Some(new_rank)

View File

@ -4,51 +4,113 @@ use super::*;
pub use crate as ghost_claims;
use frame_support::{
parameter_types, derive_impl,
traits::{PollStatus, Polling, WithdrawReasons, ConstU16, ConstU64},
derive_impl, parameter_types,
traits::{ConstU16, ConstU64, PollStatus, Polling, WithdrawReasons},
};
use frame_system::EnsureRootWithSuccess;
use sp_runtime::{BuildStorage, traits::Convert};
pub use pallet_ranked_collective::{TallyOf, Rank};
pub use pallet_ranked_collective::{Rank, TallyOf};
use sp_runtime::{traits::Convert, BuildStorage};
pub mod eth_keys {
use crate::{
mock::Test,
EcdsaSignature, EthereumAddress,
};
use hex_literal::hex;
use crate::{mock::Test, EcdsaSignature, EthereumAddress};
use codec::Encode;
use hex_literal::hex;
pub fn total_claims() -> u64 { 10 + 100 + 1000 }
pub fn alice_account_id() -> <Test as frame_system::Config>::AccountId { 69 }
pub fn bob_account_id() -> <Test as frame_system::Config>::AccountId { 1337 }
pub fn total_claims() -> u64 {
10 + 100 + 1000
}
pub fn alice_account_id() -> <Test as frame_system::Config>::AccountId {
69
}
pub fn bob_account_id() -> <Test as frame_system::Config>::AccountId {
1337
}
pub fn first_eth_public_known() -> EthereumAddress { EthereumAddress(hex!("1A69d2D5568D1878023EeB121a73d33B9116A760")) }
pub fn second_eth_public_known() -> EthereumAddress { EthereumAddress(hex!("2f86cfBED3fbc1eCf2989B9aE5fc019a837A9C12")) }
pub fn third_eth_public_known() -> EthereumAddress { EthereumAddress(hex!("e83f67361Ac74D42A48E2DAfb6706eb047D8218D")) }
pub fn fourth_eth_public_known() -> EthereumAddress { EthereumAddress(hex!("827ee4ad9b259b6fa1390ed60921508c78befd63")) }
pub fn first_eth_public_known() -> EthereumAddress {
EthereumAddress(hex!("1A69d2D5568D1878023EeB121a73d33B9116A760"))
}
pub fn second_eth_public_known() -> EthereumAddress {
EthereumAddress(hex!("2f86cfBED3fbc1eCf2989B9aE5fc019a837A9C12"))
}
pub fn third_eth_public_known() -> EthereumAddress {
EthereumAddress(hex!("e83f67361Ac74D42A48E2DAfb6706eb047D8218D"))
}
pub fn fourth_eth_public_known() -> EthereumAddress {
EthereumAddress(hex!("827ee4ad9b259b6fa1390ed60921508c78befd63"))
}
fn first_eth_private_key() -> libsecp256k1::SecretKey { libsecp256k1::SecretKey::parse(&hex!("01c928771aea942a1e7ac06adf2b73dfbc9a25d9eaa516e3673116af7f345198")).unwrap() }
fn second_eth_private_key() -> libsecp256k1::SecretKey { libsecp256k1::SecretKey::parse(&hex!("b19a435901872f817185f7234a1484eae837613f9d10cf21927a23c2d8cb9139")).unwrap() }
fn third_eth_private_key() -> libsecp256k1::SecretKey { libsecp256k1::SecretKey::parse(&hex!("d3baf57b74d65719b2dc33f5a464176022d0cc5edbca002234229f3e733875fc")).unwrap() }
fn fourth_eth_private_key() -> libsecp256k1::SecretKey { libsecp256k1::SecretKey::parse(&hex!("c4683d566436af6b58b4a59c8f501319226e85b21869bf93d5eeb4596d4791d4")).unwrap() }
fn wrong_eth_private_key() -> libsecp256k1::SecretKey { libsecp256k1::SecretKey::parse(&hex!("deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef")).unwrap() }
fn first_eth_private_key() -> libsecp256k1::SecretKey {
libsecp256k1::SecretKey::parse(&hex!(
"01c928771aea942a1e7ac06adf2b73dfbc9a25d9eaa516e3673116af7f345198"
))
.unwrap()
}
fn second_eth_private_key() -> libsecp256k1::SecretKey {
libsecp256k1::SecretKey::parse(&hex!(
"b19a435901872f817185f7234a1484eae837613f9d10cf21927a23c2d8cb9139"
))
.unwrap()
}
fn third_eth_private_key() -> libsecp256k1::SecretKey {
libsecp256k1::SecretKey::parse(&hex!(
"d3baf57b74d65719b2dc33f5a464176022d0cc5edbca002234229f3e733875fc"
))
.unwrap()
}
fn fourth_eth_private_key() -> libsecp256k1::SecretKey {
libsecp256k1::SecretKey::parse(&hex!(
"c4683d566436af6b58b4a59c8f501319226e85b21869bf93d5eeb4596d4791d4"
))
.unwrap()
}
fn wrong_eth_private_key() -> libsecp256k1::SecretKey {
libsecp256k1::SecretKey::parse(&hex!(
"deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
))
.unwrap()
}
pub fn first_eth_public_key() -> EthereumAddress { crate::secp_utils::eth(&first_eth_private_key()) }
pub fn second_eth_public_key() -> EthereumAddress { crate::secp_utils::eth(&second_eth_private_key()) }
pub fn third_eth_public_key() -> EthereumAddress { crate::secp_utils::eth(&third_eth_private_key()) }
pub fn fourth_eth_public_key() -> EthereumAddress { crate::secp_utils::eth(&fourth_eth_private_key()) }
pub fn first_eth_public_key() -> EthereumAddress {
crate::secp_utils::eth(&first_eth_private_key())
}
pub fn second_eth_public_key() -> EthereumAddress {
crate::secp_utils::eth(&second_eth_private_key())
}
pub fn third_eth_public_key() -> EthereumAddress {
crate::secp_utils::eth(&third_eth_private_key())
}
pub fn fourth_eth_public_key() -> EthereumAddress {
crate::secp_utils::eth(&fourth_eth_private_key())
}
pub fn first_account_id() -> <Test as frame_system::Config>::AccountId { crate::secp_utils::into_account_id::<Test, ()>(first_eth_public_key()) }
pub fn second_account_id() -> <Test as frame_system::Config>::AccountId { crate::secp_utils::into_account_id::<Test, ()>(second_eth_public_key()) }
pub fn third_account_id() -> <Test as frame_system::Config>::AccountId { crate::secp_utils::into_account_id::<Test, ()>(third_eth_public_key()) }
pub fn fourth_account_id() -> <Test as frame_system::Config>::AccountId { crate::secp_utils::into_account_id::<Test, ()>(fourth_eth_public_key()) }
pub fn first_account_id() -> <Test as frame_system::Config>::AccountId {
crate::secp_utils::into_account_id::<Test, ()>(first_eth_public_key())
}
pub fn second_account_id() -> <Test as frame_system::Config>::AccountId {
crate::secp_utils::into_account_id::<Test, ()>(second_eth_public_key())
}
pub fn third_account_id() -> <Test as frame_system::Config>::AccountId {
crate::secp_utils::into_account_id::<Test, ()>(third_eth_public_key())
}
pub fn fourth_account_id() -> <Test as frame_system::Config>::AccountId {
crate::secp_utils::into_account_id::<Test, ()>(fourth_eth_public_key())
}
pub fn first_signature() -> EcdsaSignature { crate::secp_utils::sig::<Test, ()>(&first_eth_private_key(), &alice_account_id().encode()) }
pub fn second_signature() -> EcdsaSignature { crate::secp_utils::sig::<Test, ()>(&second_eth_private_key(), &alice_account_id().encode()) }
pub fn third_signature() -> EcdsaSignature { crate::secp_utils::sig::<Test, ()>(&third_eth_private_key(), &alice_account_id().encode()) }
pub fn fourth_signature() -> EcdsaSignature { crate::secp_utils::sig::<Test, ()>(&fourth_eth_private_key(), &bob_account_id().encode()) }
pub fn wrong_signature() -> EcdsaSignature { crate::secp_utils::sig::<Test, ()>(&wrong_eth_private_key(), &alice_account_id().encode()) }
pub fn first_signature() -> EcdsaSignature {
crate::secp_utils::sig::<Test, ()>(&first_eth_private_key(), &alice_account_id().encode())
}
pub fn second_signature() -> EcdsaSignature {
crate::secp_utils::sig::<Test, ()>(&second_eth_private_key(), &alice_account_id().encode())
}
pub fn third_signature() -> EcdsaSignature {
crate::secp_utils::sig::<Test, ()>(&third_eth_private_key(), &alice_account_id().encode())
}
pub fn fourth_signature() -> EcdsaSignature {
crate::secp_utils::sig::<Test, ()>(&fourth_eth_private_key(), &bob_account_id().encode())
}
pub fn wrong_signature() -> EcdsaSignature {
crate::secp_utils::sig::<Test, ()>(&wrong_eth_private_key(), &alice_account_id().encode())
}
}
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
@ -66,7 +128,6 @@ impl pallet_balances::Config for Test {
type AccountStore = System;
}
parameter_types! {
pub const MinVestedTransfer: u64 = 1;
pub UnvestedFundsAllowedWithdrawReasons: WithdrawReasons =
@ -79,8 +140,7 @@ impl pallet_vesting::Config for Test {
type BlockNumberToBalance = sp_runtime::traits::ConvertInto;
type MinVestedTransfer = MinVestedTransfer;
type WeightInfo = ();
type UnvestedFundsAllowedWithdrawReasons =
UnvestedFundsAllowedWithdrawReasons;
type UnvestedFundsAllowedWithdrawReasons = UnvestedFundsAllowedWithdrawReasons;
type BlockNumberProvider = System;
const MAX_VESTING_SCHEDULES: u32 = 28;

View File

@ -8,7 +8,8 @@ pub fn public(secret: &libsecp256k1::SecretKey) -> libsecp256k1::PublicKey {
pub fn eth(secret: &libsecp256k1::SecretKey) -> EthereumAddress {
let mut res = EthereumAddress::default();
res.0.copy_from_slice(&keccak_256(&public(secret).serialize()[1..65])[12..]);
res.0
.copy_from_slice(&keccak_256(&public(secret).serialize()[1..65])[12..]);
res
}
@ -25,10 +26,7 @@ pub fn sig<T: Config<I>, I: 'static>(
&crate::to_ascii_hex(what)[..],
));
let (sig, recovery_id) = libsecp256k1::sign(
&libsecp256k1::Message::parse(&msg),
secret,
);
let (sig, recovery_id) = libsecp256k1::sign(&libsecp256k1::Message::parse(&msg), secret);
let mut r = [0u8; 65];
r[0..64].copy_from_slice(&sig.serialize()[..]);

View File

@ -1,21 +1,19 @@
#![cfg(test)]
use mock::{
new_test_ext, ghost_claims,
Test, System, Balances, Club, Vesting, Claims, RuntimeOrigin, RuntimeEvent,
eth_keys::{
alice_account_id, total_claims, first_eth_public_known,
first_eth_public_key, first_account_id, first_signature,
second_eth_public_known, second_eth_public_key, second_account_id,
second_signature, third_eth_public_known, third_eth_public_key,
third_account_id, third_signature, fourth_eth_public_known,
fourth_eth_public_key, fourth_account_id, fourth_signature,
wrong_signature, bob_account_id,
}
};
use hex_literal::hex;
use frame_support::{assert_err, assert_ok};
use super::*;
use frame_support::{assert_err, assert_ok};
use hex_literal::hex;
use mock::{
eth_keys::{
alice_account_id, bob_account_id, first_account_id, first_eth_public_key,
first_eth_public_known, first_signature, fourth_account_id, fourth_eth_public_key,
fourth_eth_public_known, fourth_signature, second_account_id, second_eth_public_key,
second_eth_public_known, second_signature, third_account_id, third_eth_public_key,
third_eth_public_known, third_signature, total_claims, wrong_signature,
},
ghost_claims, new_test_ext, Balances, Claims, Club, RuntimeEvent, RuntimeOrigin, System, Test,
Vesting,
};
#[test]
fn serde_works() {
@ -58,7 +56,8 @@ fn small_claiming_works() {
assert_ok!(Claims::claim(
RuntimeOrigin::signed(alice_account_id()),
first_eth_public_key(),
first_signature()));
first_signature()
));
assert_eq!(Balances::usable_balance(&alice_account_id()), 10);
assert_eq!(Balances::usable_balance(&first_account_id()), 0);
@ -113,11 +112,15 @@ fn big_claiming_works() {
assert_eq!(Club::rank_of(&third_account_id()), None);
assert_eq!(Vesting::vesting_balance(&alice_account_id()), Some(800));
assert_eq!(ghost_claims::Total::<Test, ()>::get(), total_claims() - 1000);
assert_eq!(
ghost_claims::Total::<Test, ()>::get(),
total_claims() - 1000
);
assert_ok!(Balances::transfer_allow_death(
RuntimeOrigin::signed(alice_account_id()),
bob_account_id(),
200));
200
));
})
}
@ -188,11 +191,14 @@ fn multiple_accounts_reverese_claiming_works() {
#[test]
fn cannot_claim_with_bad_signature() {
new_test_ext().execute_with(|| {
assert_err!(Claims::claim(
assert_err!(
Claims::claim(
RuntimeOrigin::signed(alice_account_id()),
first_eth_public_key(),
wrong_signature()),
crate::Error::<Test>::InvalidEthereumAddress);
wrong_signature()
),
crate::Error::<Test>::InvalidEthereumAddress
);
assert_eq!(Balances::usable_balance(&alice_account_id()), 0);
assert_eq!(Balances::usable_balance(&first_account_id()), 10);
@ -212,11 +218,14 @@ fn cannot_claim_with_bad_signature() {
#[test]
fn cannot_claim_with_wrong_address() {
new_test_ext().execute_with(|| {
assert_err!(Claims::claim(
assert_err!(
Claims::claim(
RuntimeOrigin::signed(bob_account_id()),
first_eth_public_key(),
first_signature()),
crate::Error::<Test>::InvalidEthereumAddress);
first_signature()
),
crate::Error::<Test>::InvalidEthereumAddress
);
assert_eq!(Balances::usable_balance(&bob_account_id()), 0);
assert_eq!(Balances::usable_balance(&alice_account_id()), 0);
@ -237,11 +246,14 @@ fn cannot_claim_with_wrong_address() {
#[test]
fn cannot_claim_nothing() {
new_test_ext().execute_with(|| {
assert_err!(Claims::claim(
assert_err!(
Claims::claim(
RuntimeOrigin::signed(bob_account_id()),
fourth_eth_public_key(),
fourth_signature()),
crate::Error::<Test>::NoBalanceToClaim);
fourth_signature()
),
crate::Error::<Test>::NoBalanceToClaim
);
assert_eq!(Balances::usable_balance(&bob_account_id()), 0);
assert_eq!(Balances::usable_balance(&fourth_account_id()), 0);
assert_eq!(Vesting::vesting_balance(&bob_account_id()), None);
@ -263,8 +275,7 @@ fn event_emitted_during_claim() {
third_eth_public_key(),
third_signature(),
));
System::assert_has_event(RuntimeEvent::Claims(
crate::Event::Claimed {
System::assert_has_event(RuntimeEvent::Claims(crate::Event::Claimed {
receiver: alice_account_id(),
donor: account,
amount,

View File

@ -1,9 +1,104 @@
use frame_support::weights::Weight;
// This file is part of Ghost Network.
// Ghost Network is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Ghost Network is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Ghost Network. If not, see <http://www.gnu.org/licenses/>.
//! Autogenerated weights for `ghost_claims`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
//! DATE: 2024-08-02, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `ghostown`, CPU: `Intel(R) Core(TM) i3-2310M CPU @ 2.10GHz`
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("casper-dev")`, DB CACHE: 1024
// Executed Command:
// ./target/release/ghost
// benchmark
// pallet
// --chain=casper-dev
// --steps=50
// --repeat=20
// --pallet=ghost_claims
// --extrinsic=*
// --wasm-execution=compiled
// --heap-pages=4096
// --header=./file_header.txt
// --output=./runtime/casper/src/weights/ghost_claims.rs
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(missing_docs)]
use frame_support::{
traits::Get,
weights::{Weight, constants::RocksDbWeight},
};
use core::marker::PhantomData;
/// Weight functions needed for `ghost_claims`.
pub trait WeightInfo {
fn claim() -> Weight;
}
impl WeightInfo for () {
fn claim() -> Weight { Weight::zero() }
/// Weight for ghost_claims using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// Storage: `System::Account` (r:2 w:2)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// Storage: `GhostClaims::Total` (r:1 w:1)
/// Proof: `GhostClaims::Total` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `CultCollective::Members` (r:2 w:2)
/// Proof: `CultCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`)
/// Storage: `CultCollective::MemberCount` (r:6 w:6)
/// Proof: `CultCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`)
/// Storage: `CultCollective::IdToIndex` (r:6 w:12)
/// Proof: `CultCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`)
/// Storage: `CultCollective::IndexToId` (r:0 w:6)
/// Proof: `CultCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`)
fn claim() -> Weight {
// Proof Size summary in bytes:
// Measured: `896`
// Estimated: `16164`
// Minimum execution time: 754_086_000 picoseconds.
Weight::from_parts(756_147_000, 0)
.saturating_add(Weight::from_parts(0, 16164))
.saturating_add(T::DbWeight::get().reads(17))
.saturating_add(T::DbWeight::get().writes(29))
}
}
impl WeightInfo for () {
/// Storage: `System::Account` (r:2 w:2)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// Storage: `GhostClaims::Total` (r:1 w:1)
/// Proof: `GhostClaims::Total` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `CultCollective::Members` (r:2 w:2)
/// Proof: `CultCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`)
/// Storage: `CultCollective::MemberCount` (r:6 w:6)
/// Proof: `CultCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`)
/// Storage: `CultCollective::IdToIndex` (r:6 w:12)
/// Proof: `CultCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`)
/// Storage: `CultCollective::IndexToId` (r:0 w:6)
/// Proof: `CultCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`)
fn claim() -> Weight {
// Proof Size summary in bytes:
// Measured: `896`
// Estimated: `16164`
// Minimum execution time: 754_086_000 picoseconds.
Weight::from_parts(756_147_000, 0)
.saturating_add(Weight::from_parts(0, 16164))
.saturating_add(RocksDbWeight::get().reads(17))
.saturating_add(RocksDbWeight::get().writes(29))
}
}

10
pallets/networks/Cargo.toml Executable file → Normal file
View File

@ -1,8 +1,8 @@
[package]
name = "ghost-networks"
version = "0.1.13"
license.workspace = true
authors.workspace = true
version.workspace = true
edition.workspace = true
homepage.workspace = true
repository.workspace = true
@ -14,14 +14,16 @@ codec = { workspace = true, features = ["max-encoded-len"] }
frame-benchmarking = { workspace = true, optional = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
pallet-staking = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
ghost-traits = { workspace = true }
[dev-dependencies]
primitives = { workspace = true }
pallet-balances = { workspace = true }
sp-io = { workspace = true }
pallet-balances = { workspace = true }
pallet-staking-reward-curve = { workspace = true }
[features]
default = ["std"]
@ -35,6 +37,7 @@ std = [
"sp-std/std",
"sp-io/std",
"ghost-traits/std",
"pallet-staking/std",
"pallet-balances/std",
]
runtime-benchmarks = [
@ -42,8 +45,11 @@ runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"pallet-staking/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-staking/try-runtime",
"pallet-balances/try-runtime",
]

88
pallets/networks/src/benchmarking.rs Executable file → Normal file
View File

@ -8,31 +8,44 @@ use sp_runtime::Saturating;
const MAX_NAME_LEN: u32 = 20;
const MAX_ENDPOINT_LEN: u32 = 150;
const MAX_ENDPOINT_NUMBER: u32 = 20;
fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
frame_system::Pallet::<T>::assert_last_event(generic_event.into());
}
fn prepare_network<T: Config>(
n: u32, m: u32,
n: u32,
m: u32,
k: u32,
) -> (<T as module::Config>::NetworkId, NetworkData) {
let chain_id: <T as module::Config>::NetworkId = Default::default();
let chain_id = chain_id.saturating_add((n + m).into());
let mut gatekeeper = b"0x".to_vec();
for i in 0..40 { gatekeeper.push(i); }
for i in 0..40 {
gatekeeper.push(i);
}
let mut topic_name = b"0x".to_vec();
for i in 0..64 { topic_name.push(i); }
for i in 0..64 {
topic_name.push(i);
}
let mut default_endpoints = sp_std::vec![];
for _ in 0..(k as usize) {
default_endpoints.push(sp_std::vec![0x69; m as usize]);
}
let network = NetworkData {
chain_name: sp_std::vec![0x69; n as usize],
default_endpoint: sp_std::vec![0x69; m as usize],
default_endpoints,
gatekeeper,
topic_name,
finality_delay: Some(69),
release_delay: Some(69),
network_type: NetworkType::Evm,
finality_delay: 69,
rate_limit_delay: 69,
block_distance: 69,
incoming_fee: 0,
outgoing_fee: 0,
};
@ -50,8 +63,11 @@ fn create_network<T: Config>(
let authority = T::RegisterOrigin::try_successful_origin()
.map_err(|_| BenchmarkError::Weightless)?;
GhostNetworks::<T>::register_network(
authority.clone(), chain_id.clone(), network.clone()
).map_err(|_| BenchmarkError::Weightless)?;
authority.clone(),
chain_id.clone(),
network.clone(),
)
.map_err(|_| BenchmarkError::Weightless)?;
network
}
};
@ -63,8 +79,9 @@ benchmarks! {
register_network {
let i in 1 .. MAX_NAME_LEN;
let j in 1 .. MAX_ENDPOINT_LEN;
let k in 1 .. MAX_ENDPOINT_NUMBER;
let (chain_id, network) = prepare_network::<T>(i, j);
let (chain_id, network) = prepare_network::<T>(i, j, k);
let authority = T::RegisterOrigin::try_successful_origin()
.map_err(|_| BenchmarkError::Weightless)?;
let prev_network = GhostNetworks::<T>::networks(chain_id.clone());
@ -79,7 +96,7 @@ benchmarks! {
update_network_name {
let n in 1 .. MAX_NAME_LEN;
let name = sp_std::vec![0x42; n as usize];
let (chain_id, network) = prepare_network::<T>(1, 1);
let (chain_id, network) = prepare_network::<T>(1, 1, 1);
let authority = T::UpdateOrigin::try_successful_origin()
.map_err(|_| BenchmarkError::Weightless)?;
let prev_network = create_network::<T>(chain_id.clone(), network.clone())?;
@ -93,22 +110,25 @@ benchmarks! {
update_network_endpoint {
let n in 1 .. MAX_ENDPOINT_LEN;
let index_to_update = 0u32;
let endpoint = sp_std::vec![0x42; n as usize];
let (chain_id, network) = prepare_network::<T>(1, 1);
let (chain_id, network) = prepare_network::<T>(1, 1, 1);
let authority = T::UpdateOrigin::try_successful_origin()
.map_err(|_| BenchmarkError::Weightless)?;
let prev_network = create_network::<T>(chain_id.clone(), network.clone())?;
}: _<T::RuntimeOrigin>(authority, chain_id.clone(), endpoint.clone())
}: _<T::RuntimeOrigin>(authority, chain_id.clone(), Some(index_to_update), Some(endpoint.clone()))
verify {
assert_last_event::<T>(Event::NetworkEndpointUpdated {
chain_id: chain_id.clone(), default_endpoint: endpoint,
chain_id: chain_id.clone(),
index: index_to_update,
endpoint,
}.into());
assert_ne!(GhostNetworks::<T>::networks(chain_id.clone()), prev_network);
}
update_network_finality_delay {
let delay = Some(1337);
let (chain_id, network) = prepare_network::<T>(1, 1);
let delay = 1337;
let (chain_id, network) = prepare_network::<T>(1, 1, 1);
let authority = T::UpdateOrigin::try_successful_origin()
.map_err(|_| BenchmarkError::Weightless)?;
let prev_network = create_network::<T>(chain_id.clone(), network.clone())?;
@ -120,23 +140,37 @@ benchmarks! {
assert_ne!(GhostNetworks::<T>::networks(chain_id.clone()), prev_network);
}
update_network_release_delay {
let delay = Some(1337);
let (chain_id, network) = prepare_network::<T>(1, 1);
update_network_rate_limit_delay {
let rate_limit = 1337;
let (chain_id, network) = prepare_network::<T>(1, 1, 1);
let authority = T::UpdateOrigin::try_successful_origin()
.map_err(|_| BenchmarkError::Weightless)?;
let prev_network = create_network::<T>(chain_id.clone(), network.clone())?;
}: _<T::RuntimeOrigin>(authority, chain_id.clone(), delay)
}: _<T::RuntimeOrigin>(authority, chain_id.clone(), rate_limit)
verify {
assert_last_event::<T>(Event::NetworkReleaseDelayUpdated {
chain_id: chain_id.clone(), release_delay: delay,
assert_last_event::<T>(Event::NetworkRateLimitDelayUpdated {
chain_id: chain_id.clone(), rate_limit_delay: rate_limit,
}.into());
assert_ne!(GhostNetworks::<T>::networks(chain_id.clone()), prev_network);
}
update_network_block_distance {
let block_distance = 1337;
let (chain_id, network) = prepare_network::<T>(1, 1, 1);
let authority = T::UpdateOrigin::try_successful_origin()
.map_err(|_| BenchmarkError::Weightless)?;
let prev_network = create_network::<T>(chain_id.clone(), network.clone())?;
}: _<T::RuntimeOrigin>(authority, chain_id.clone(), block_distance)
verify {
assert_last_event::<T>(Event::NetworkBlockDistanceUpdated {
chain_id: chain_id.clone(), block_distance,
}.into());
assert_ne!(GhostNetworks::<T>::networks(chain_id.clone()), prev_network);
}
update_network_type {
let network_type = NetworkType::Utxo;
let (chain_id, network) = prepare_network::<T>(1, 1);
let (chain_id, network) = prepare_network::<T>(1, 1, 1);
let authority = T::UpdateOrigin::try_successful_origin()
.map_err(|_| BenchmarkError::Weightless)?;
let prev_network = create_network::<T>(chain_id.clone(), network.clone())?;
@ -151,7 +185,7 @@ benchmarks! {
update_network_gatekeeper {
let mut gatekeeper = b"0x".to_vec();
for i in 0..40 { gatekeeper.push(i + 1); }
let (chain_id, network) = prepare_network::<T>(1, 1);
let (chain_id, network) = prepare_network::<T>(1, 1, 1);
let authority = T::UpdateOrigin::try_successful_origin()
.map_err(|_| BenchmarkError::Weightless)?;
let prev_network = create_network::<T>(chain_id.clone(), network.clone())?;
@ -165,7 +199,7 @@ benchmarks! {
update_network_topic_name {
let topic_name = b"0x9876543219876543219876543219876543219876543219876543219876543219".to_vec();
let (chain_id, network) = prepare_network::<T>(1, 1);
let (chain_id, network) = prepare_network::<T>(1, 1, 1);
let authority = T::UpdateOrigin::try_successful_origin()
.map_err(|_| BenchmarkError::Weightless)?;
let prev_network = create_network::<T>(chain_id.clone(), network.clone())?;
@ -179,7 +213,7 @@ benchmarks! {
update_incoming_network_fee {
let incoming_fee = 1337;
let (chain_id, network) = prepare_network::<T>(1, 1);
let (chain_id, network) = prepare_network::<T>(1, 1, 1);
let authority = T::UpdateOrigin::try_successful_origin()
.map_err(|_| BenchmarkError::Weightless)?;
let prev_network = create_network::<T>(chain_id.clone(), network.clone())?;
@ -193,7 +227,7 @@ benchmarks! {
update_outgoing_network_fee {
let outgoing_fee = 1337;
let (chain_id, network) = prepare_network::<T>(1, 1);
let (chain_id, network) = prepare_network::<T>(1, 1, 1);
let authority = T::UpdateOrigin::try_successful_origin()
.map_err(|_| BenchmarkError::Weightless)?;
let prev_network = create_network::<T>(chain_id.clone(), network.clone())?;
@ -206,7 +240,7 @@ benchmarks! {
}
remove_network {
let (chain_id, network) = prepare_network::<T>(1, 1);
let (chain_id, network) = prepare_network::<T>(1, 1, 1);
let authority = T::RemoveOrigin::try_successful_origin()
.map_err(|_| BenchmarkError::Weightless)?;
let prev_network = create_network::<T>(chain_id.clone(), network.clone())?;

466
pallets/networks/src/lib.rs Executable file → Normal file
View File

@ -4,25 +4,27 @@
use frame_support::{
pallet_prelude::*,
storage::PrefixIterator, traits::EnsureOrigin,
storage::PrefixIterator,
traits::{tokens::fungible::Inspect, EnsureOrigin},
};
use frame_system::pallet_prelude::*;
use scale_info::TypeInfo;
use sp_runtime::{
traits::{AtLeast32BitUnsigned, Member},
curve::PiecewiseLinear,
traits::{AtLeast32BitUnsigned, CheckedAdd, CheckedSub, Member},
DispatchResult,
};
use sp_std::prelude::*;
use sp_std::{convert::TryInto, prelude::*};
pub use ghost_traits::networks::{
NetworkDataBasicHandler, NetworkDataInspectHandler,
NetworkDataMutateHandler,
NetworkDataBasicHandler, NetworkDataInspectHandler, NetworkDataMutateHandler,
};
mod weights;
pub use module::*;
pub use crate::weights::WeightInfo;
pub use module::*;
#[cfg(any(feature = "runtime-benchmarks", test))]
mod benchmarking;
@ -31,6 +33,9 @@ mod mock;
#[cfg(all(feature = "std", test))]
mod tests;
pub type BalanceOf<T> =
<<T as Config>::Currency as Inspect<<T as frame_system::Config>::AccountId>>::Balance;
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)]
pub enum NetworkType {
Evm = 0,
@ -39,22 +44,71 @@ pub enum NetworkType {
}
impl Default for NetworkType {
fn default() -> Self { NetworkType::Evm }
fn default() -> Self {
NetworkType::Evm
}
}
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)]
pub struct NetworkData {
pub chain_name: Vec<u8>,
pub default_endpoint: Vec<u8>,
pub default_endpoints: Vec<Vec<u8>>,
pub gatekeeper: Vec<u8>,
pub topic_name: Vec<u8>,
pub finality_delay: Option<u64>,
pub release_delay: Option<u64>,
pub network_type: NetworkType,
pub finality_delay: u64,
pub rate_limit_delay: u64,
pub block_distance: u64,
pub incoming_fee: u32,
pub outgoing_fee: u32,
}
#[derive(Default, Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)]
pub struct BridgeAdjustment<Balance> {
pub bridged_out: Balance,
pub bridged_in: Balance,
}
pub struct BridgedInflationCurve<RewardCurve, T>(core::marker::PhantomData<(RewardCurve, T)>);
impl<Balance, RewardCurve, T> pallet_staking::EraPayout<Balance>
for BridgedInflationCurve<RewardCurve, T>
where
Balance: Default + AtLeast32BitUnsigned + Clone + Copy + From<u128>,
RewardCurve: Get<&'static PiecewiseLinear<'static>>,
T: Config,
{
fn era_payout(
total_staked: Balance,
total_issuance: Balance,
_era_duration_in_millis: u64,
) -> (Balance, Balance) {
let piecewise_linear = RewardCurve::get();
let bridge_adjustment = BridgedImbalance::<T>::get();
let accumulated_commission = AccumulatedCommission::<T>::get();
let bridged_out: u128 = bridge_adjustment.bridged_out.try_into().unwrap_or_default();
let bridged_in: u128 = bridge_adjustment.bridged_in.try_into().unwrap_or_default();
let accumulated_commission: u128 = accumulated_commission.try_into().unwrap_or_default();
let accumulated_balance = Balance::from(accumulated_commission);
let adjusted_issuance = match bridged_out > bridged_in {
true => total_issuance.saturating_add(Balance::from(bridged_out - bridged_in)),
false => total_issuance.saturating_sub(Balance::from(bridged_in - bridged_out)),
};
NullifyNeeded::<T>::set(true);
match piecewise_linear
.calculate_for_fraction_times_denominator(total_staked, adjusted_issuance)
.checked_mul(&accumulated_balance)
.and_then(|product| product.checked_div(&adjusted_issuance))
{
Some(payout) => (payout, accumulated_balance.saturating_sub(payout)),
None => (Balance::default(), Balance::default()),
}
}
}
#[frame_support::pallet]
pub mod module {
use super::*;
@ -63,6 +117,9 @@ pub mod module {
pub trait Config: frame_system::Config {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// The type used for the internal balance storage.
type Currency: Inspect<Self::AccountId>;
/// The type used as a unique network id.
type NetworkId: Parameter
+ Member
@ -101,24 +158,87 @@ pub mod module {
#[pallet::event]
#[pallet::generate_deposit(pub(crate) fn deposit_event)]
pub enum Event<T: Config> {
NetworkRegistered { chain_id: T::NetworkId, network: NetworkData },
NetworkNameUpdated { chain_id: T::NetworkId, chain_name: Vec<u8> },
NetworkEndpointUpdated { chain_id: T::NetworkId, default_endpoint: Vec<u8> },
NetworkFinalityDelayUpdated { chain_id: T::NetworkId, finality_delay: Option<u64> },
NetworkReleaseDelayUpdated { chain_id: T::NetworkId, release_delay: Option<u64> },
NetworkTypeUpdated { chain_id: T::NetworkId, network_type: NetworkType },
NetworkGatekeeperUpdated { chain_id: T::NetworkId, gatekeeper: Vec<u8> },
NetworkTopicNameUpdated { chain_id: T::NetworkId, topic_name: Vec<u8> },
NetworkIncomingFeeUpdated { chain_id: T::NetworkId, incoming_fee: u32 },
NetworkOutgoingFeeUpdated { chain_id: T::NetworkId, outgoing_fee: u32 },
NetworkRemoved { chain_id: T::NetworkId },
NetworkRegistered {
chain_id: T::NetworkId,
network: NetworkData,
},
NetworkNameUpdated {
chain_id: T::NetworkId,
chain_name: Vec<u8>,
},
NetworkEndpointUpdated {
chain_id: T::NetworkId,
index: u32,
endpoint: Vec<u8>,
},
NetworkEndpointRemoved {
chain_id: T::NetworkId,
index: u32,
},
NetworkEndpointAdded {
chain_id: T::NetworkId,
endpoint: Vec<u8>,
},
NetworkFinalityDelayUpdated {
chain_id: T::NetworkId,
finality_delay: u64,
},
NetworkRateLimitDelayUpdated {
chain_id: T::NetworkId,
rate_limit_delay: u64,
},
NetworkBlockDistanceUpdated {
chain_id: T::NetworkId,
block_distance: u64,
},
NetworkTypeUpdated {
chain_id: T::NetworkId,
network_type: NetworkType,
},
NetworkGatekeeperUpdated {
chain_id: T::NetworkId,
gatekeeper: Vec<u8>,
},
NetworkTopicNameUpdated {
chain_id: T::NetworkId,
topic_name: Vec<u8>,
},
NetworkIncomingFeeUpdated {
chain_id: T::NetworkId,
incoming_fee: u32,
},
NetworkOutgoingFeeUpdated {
chain_id: T::NetworkId,
outgoing_fee: u32,
},
NetworkRemoved {
chain_id: T::NetworkId,
},
}
#[pallet::storage]
#[pallet::getter(fn nullify_needed)]
pub type NullifyNeeded<T: Config> = StorageValue<_, bool, ValueQuery>;
#[pallet::storage]
#[pallet::getter(fn bridged_imbalance)]
pub type BridgedImbalance<T: Config> =
StorageValue<_, BridgeAdjustment<BalanceOf<T>>, ValueQuery>;
#[pallet::storage]
#[pallet::getter(fn accumulated_commission)]
pub type AccumulatedCommission<T: Config> = StorageValue<_, BalanceOf<T>, ValueQuery>;
#[pallet::storage]
#[pallet::getter(fn networks)]
pub type Networks<T: Config> =
StorageMap<_, Twox64Concat, T::NetworkId, NetworkData, OptionQuery>;
#[pallet::storage]
#[pallet::getter(fn gatekeeper_amount)]
pub type GatekeeperAmount<T: Config> =
StorageMap<_, Twox64Concat, T::NetworkId, BalanceOf<T>, ValueQuery>;
#[pallet::genesis_config]
pub struct GenesisConfig<T: Config> {
pub networks: Vec<(T::NetworkId, Vec<u8>)>,
@ -134,9 +254,10 @@ pub mod module {
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
fn build(&self) {
if !self.networks.is_empty() {
self.networks.iter().for_each(|(chain_id, network_metadata)| {
let network =
NetworkData::decode(&mut &network_metadata[..])
self.networks
.iter()
.for_each(|(chain_id, network_metadata)| {
let network = NetworkData::decode(&mut &network_metadata[..])
.expect("Error decoding NetworkData");
Pallet::<T>::do_register_network(chain_id.clone(), network)
.expect("Error registering network");
@ -150,14 +271,30 @@ pub mod module {
pub struct Pallet<T>(PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(_: BlockNumberFor<T>) -> Weight {
T::DbWeight::get().reads_writes(1, 1)
}
fn on_finalize(_: BlockNumberFor<T>) {
if Self::nullify_needed() {
Self::nullify_commission();
NullifyNeeded::<T>::put(false);
}
}
}
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::register_network(
network.chain_name.len() as u32,
network.default_endpoint.len() as u32,
network.default_endpoints
.iter()
.map(|endpoint| endpoint.len())
.max()
.unwrap_or_default() as u32,
network.default_endpoints.len() as u32,
))]
pub fn register_network(
origin: OriginFor<T>,
@ -178,26 +315,24 @@ pub mod module {
chain_name: Vec<u8>,
) -> DispatchResult {
T::UpdateOrigin::ensure_origin_or_root(origin)?;
Self::do_update_network_name(
chain_id,
chain_name,
)
Self::do_update_network_name(chain_id, chain_name)
}
#[pallet::call_index(2)]
#[pallet::weight(T::WeightInfo::update_network_endpoint(
default_endpoint.len() as u32
maybe_endpoint
.as_ref()
.map(|endpoint| endpoint.len())
.unwrap_or_default() as u32
))]
pub fn update_network_endpoint(
origin: OriginFor<T>,
chain_id: T::NetworkId,
default_endpoint: Vec<u8>,
maybe_index: Option<u32>,
maybe_endpoint: Option<Vec<u8>>,
) -> DispatchResult {
T::UpdateOrigin::ensure_origin_or_root(origin)?;
Self::do_update_network_endpoint(
chain_id,
default_endpoint,
)
Self::do_update_network_endpoint(chain_id, maybe_index, maybe_endpoint)
}
#[pallet::call_index(3)]
@ -205,30 +340,35 @@ pub mod module {
pub fn update_network_finality_delay(
origin: OriginFor<T>,
chain_id: T::NetworkId,
finality_delay: Option<u64>,
finality_delay: u64,
) -> DispatchResult {
T::UpdateOrigin::ensure_origin_or_root(origin)?;
Self::do_update_network_finality_delay(
chain_id,
finality_delay,
)
Self::do_update_network_finality_delay(chain_id, finality_delay)
}
#[pallet::call_index(4)]
#[pallet::weight(T::WeightInfo::update_network_release_delay())]
pub fn update_network_release_delay(
#[pallet::weight(T::WeightInfo::update_network_rate_limit_delay())]
pub fn update_network_rate_limit_delay(
origin: OriginFor<T>,
chain_id: T::NetworkId,
release_delay: Option<u64>,
rate_limit_delay: u64,
) -> DispatchResult {
T::UpdateOrigin::ensure_origin_or_root(origin)?;
Self::do_update_network_release_delay(
chain_id,
release_delay,
)
Self::do_update_network_rate_limit_delay(chain_id, rate_limit_delay)
}
#[pallet::call_index(5)]
#[pallet::weight(T::WeightInfo::update_network_block_distance())]
pub fn update_network_block_distance(
origin: OriginFor<T>,
chain_id: T::NetworkId,
block_distance: u64,
) -> DispatchResult {
T::UpdateOrigin::ensure_origin_or_root(origin)?;
Self::do_update_network_block_distance(chain_id, block_distance)
}
#[pallet::call_index(6)]
#[pallet::weight(T::WeightInfo::update_network_type())]
pub fn update_network_type(
origin: OriginFor<T>,
@ -236,13 +376,10 @@ pub mod module {
network_type: NetworkType,
) -> DispatchResult {
T::UpdateOrigin::ensure_origin_or_root(origin)?;
Self::do_update_network_type(
chain_id,
network_type,
)
Self::do_update_network_type(chain_id, network_type)
}
#[pallet::call_index(6)]
#[pallet::call_index(7)]
#[pallet::weight(T::WeightInfo::update_network_gatekeeper())]
pub fn update_network_gatekeeper(
origin: OriginFor<T>,
@ -250,13 +387,10 @@ pub mod module {
gatekeeper: Vec<u8>,
) -> DispatchResult {
T::UpdateOrigin::ensure_origin_or_root(origin)?;
Self::do_update_network_gatekeeper(
chain_id,
gatekeeper,
)
Self::do_update_network_gatekeeper(chain_id, gatekeeper)
}
#[pallet::call_index(7)]
#[pallet::call_index(8)]
#[pallet::weight(T::WeightInfo::update_network_topic_name())]
pub fn update_network_topic_name(
origin: OriginFor<T>,
@ -264,13 +398,10 @@ pub mod module {
topic_name: Vec<u8>,
) -> DispatchResult {
T::UpdateOrigin::ensure_origin_or_root(origin)?;
Self::do_update_network_topic_name(
chain_id,
topic_name,
)
Self::do_update_network_topic_name(chain_id, topic_name)
}
#[pallet::call_index(8)]
#[pallet::call_index(9)]
#[pallet::weight(T::WeightInfo::update_incoming_network_fee())]
pub fn update_incoming_network_fee(
origin: OriginFor<T>,
@ -278,13 +409,10 @@ pub mod module {
incoming_fee: u32,
) -> DispatchResult {
T::UpdateOrigin::ensure_origin_or_root(origin)?;
Self::do_update_incoming_network_fee(
chain_id,
incoming_fee,
)
Self::do_update_incoming_network_fee(chain_id, incoming_fee)
}
#[pallet::call_index(9)]
#[pallet::call_index(10)]
#[pallet::weight(T::WeightInfo::update_outgoing_network_fee())]
pub fn update_outgoing_network_fee(
origin: OriginFor<T>,
@ -292,18 +420,12 @@ pub mod module {
outgoing_fee: u32,
) -> DispatchResult {
T::UpdateOrigin::ensure_origin_or_root(origin)?;
Self::do_update_outgoing_network_fee(
chain_id,
outgoing_fee,
)
Self::do_update_outgoing_network_fee(chain_id, outgoing_fee)
}
#[pallet::call_index(10)]
#[pallet::call_index(11)]
#[pallet::weight(T::WeightInfo::remove_network())]
pub fn remove_network(
origin: OriginFor<T>,
chain_id: T::NetworkId,
) -> DispatchResult {
pub fn remove_network(origin: OriginFor<T>, chain_id: T::NetworkId) -> DispatchResult {
T::RemoveOrigin::ensure_origin_or_root(origin)?;
Self::do_remove_network(chain_id)
}
@ -312,12 +434,12 @@ pub mod module {
impl<T: Config> Pallet<T> {
/// Register a new network.
pub fn do_register_network(
chain_id: T::NetworkId,
network: NetworkData,
) -> DispatchResult {
pub fn do_register_network(chain_id: T::NetworkId, network: NetworkData) -> DispatchResult {
Networks::<T>::try_mutate(&chain_id, |maybe_network| -> DispatchResult {
ensure!(maybe_network.is_none(), Error::<T>::NetworkAlreadyRegistered);
ensure!(
maybe_network.is_none(),
Error::<T>::NetworkAlreadyRegistered
);
*maybe_network = Some(network.clone());
Ok(())
})?;
@ -339,10 +461,7 @@ impl<T: Config> Pallet<T> {
}
/// Update existent network name.
pub fn do_update_network_name(
chain_id: T::NetworkId,
chain_name: Vec<u8>,
) -> DispatchResult {
pub fn do_update_network_name(chain_id: T::NetworkId, chain_name: Vec<u8>) -> DispatchResult {
Networks::<T>::try_mutate(&chain_id, |maybe_network| -> DispatchResult {
ensure!(maybe_network.is_some(), Error::<T>::NetworkDoesNotExist);
let net = maybe_network.as_mut().unwrap();
@ -361,26 +480,45 @@ impl<T: Config> Pallet<T> {
/// Update existent network default endpoint.
pub fn do_update_network_endpoint(
chain_id: T::NetworkId,
default_endpoint: Vec<u8>,
maybe_index: Option<u32>,
maybe_endpoint: Option<Vec<u8>>,
) -> DispatchResult {
Networks::<T>::try_mutate(&chain_id, |maybe_network| -> DispatchResult {
ensure!(maybe_network.is_some(), Error::<T>::NetworkDoesNotExist);
let net = maybe_network.as_mut().unwrap();
net.default_endpoint = default_endpoint.clone();
*maybe_network = Some(net.clone());
Ok(())
})?;
let updated_network = maybe_network.as_mut().unwrap();
match (maybe_index, maybe_endpoint) {
(Some(index), Some(endpoint)) => {
if let Some(previous_endpoint) =
updated_network.default_endpoints.get_mut(index as usize)
{
*previous_endpoint = endpoint.clone();
Self::deposit_event(Event::<T>::NetworkEndpointUpdated {
chain_id,
default_endpoint,
index,
endpoint,
});
}
}
(None, Some(endpoint)) => {
updated_network.default_endpoints.push(endpoint.clone());
Self::deposit_event(Event::<T>::NetworkEndpointAdded { chain_id, endpoint });
}
(Some(index), None) => {
updated_network.default_endpoints.remove(index as usize);
Self::deposit_event(Event::<T>::NetworkEndpointRemoved { chain_id, index });
}
(None, None) => {}
}
*maybe_network = Some(updated_network.clone());
Ok(())
})?;
Ok(())
}
/// Update existent network default endpoint.
/// Update existent network default finality delay.
pub fn do_update_network_finality_delay(
chain_id: T::NetworkId,
finality_delay: Option<u64>,
finality_delay: u64,
) -> DispatchResult {
Networks::<T>::try_mutate(&chain_id, |maybe_network| -> DispatchResult {
ensure!(maybe_network.is_some(), Error::<T>::NetworkDoesNotExist);
@ -396,21 +534,40 @@ impl<T: Config> Pallet<T> {
Ok(())
}
/// Update existent network default endpoint.
pub fn do_update_network_release_delay(
/// Update existent network default rate limit delay.
pub fn do_update_network_rate_limit_delay(
chain_id: T::NetworkId,
release_delay: Option<u64>,
rate_limit_delay: u64,
) -> DispatchResult {
Networks::<T>::try_mutate(&chain_id, |maybe_network| -> DispatchResult {
ensure!(maybe_network.is_some(), Error::<T>::NetworkDoesNotExist);
let net = maybe_network.as_mut().unwrap();
net.release_delay = release_delay;
net.rate_limit_delay = rate_limit_delay;
*maybe_network = Some(net.clone());
Ok(())
})?;
Self::deposit_event(Event::<T>::NetworkReleaseDelayUpdated {
Self::deposit_event(Event::<T>::NetworkRateLimitDelayUpdated {
chain_id,
release_delay,
rate_limit_delay,
});
Ok(())
}
/// Update existent network default max distance between blocks.
pub fn do_update_network_block_distance(
chain_id: T::NetworkId,
block_distance: u64,
) -> DispatchResult {
Networks::<T>::try_mutate(&chain_id, |maybe_network| -> DispatchResult {
ensure!(maybe_network.is_some(), Error::<T>::NetworkDoesNotExist);
let net = maybe_network.as_mut().unwrap();
net.block_distance = block_distance;
*maybe_network = Some(net.clone());
Ok(())
})?;
Self::deposit_event(Event::<T>::NetworkBlockDistanceUpdated {
chain_id,
block_distance,
});
Ok(())
}
@ -439,8 +596,10 @@ impl<T: Config> Pallet<T> {
chain_id: T::NetworkId,
gatekeeper: Vec<u8>,
) -> DispatchResult {
ensure!(gatekeeper.len() == 42 && gatekeeper[0] == 48 && gatekeeper[1] == 120,
Error::<T>::WrongGatekeeperAddress);
ensure!(
gatekeeper.len() == 42 && gatekeeper[0] == 48 && gatekeeper[1] == 120,
Error::<T>::WrongGatekeeperAddress
);
Networks::<T>::try_mutate(&chain_id, |maybe_network| -> DispatchResult {
ensure!(maybe_network.is_some(), Error::<T>::NetworkDoesNotExist);
let net = maybe_network.as_mut().unwrap();
@ -460,8 +619,10 @@ impl<T: Config> Pallet<T> {
chain_id: T::NetworkId,
topic_name: Vec<u8>,
) -> DispatchResult {
ensure!(topic_name.len() == 66 && topic_name[0] == 48 && topic_name[1] == 120,
Error::<T>::WrongTopicName);
ensure!(
topic_name.len() == 66 && topic_name[0] == 48 && topic_name[1] == 120,
Error::<T>::WrongTopicName
);
Networks::<T>::try_mutate(&chain_id, |maybe_network| -> DispatchResult {
ensure!(maybe_network.is_some(), Error::<T>::NetworkDoesNotExist);
let net = maybe_network.as_mut().unwrap();
@ -525,9 +686,13 @@ impl<T: Config> NetworkDataInspectHandler<NetworkData> for Pallet<T> {
fn iter() -> PrefixIterator<(Self::NetworkId, NetworkData)> {
Networks::<T>::iter()
}
fn is_nullification_period() -> bool {
NullifyNeeded::<T>::get()
}
}
impl<T: Config> NetworkDataMutateHandler<NetworkData> for Pallet<T> {
impl<T: Config> NetworkDataMutateHandler<NetworkData, BalanceOf<T>> for Pallet<T> {
fn register(chain_id: Self::NetworkId, network: NetworkData) -> DispatchResult {
Self::do_register_network(chain_id, network)
}
@ -535,4 +700,93 @@ impl<T: Config> NetworkDataMutateHandler<NetworkData> for Pallet<T> {
fn remove(chain_id: Self::NetworkId) -> DispatchResult {
Self::do_remove_network(chain_id)
}
fn increase_gatekeeper_amount(
network_id: &T::NetworkId,
amount: &BalanceOf<T>,
) -> Result<BalanceOf<T>, ()> {
let new_gatekeeper_amount =
GatekeeperAmount::<T>::mutate(network_id, |gatekeeper_amount| match gatekeeper_amount
.checked_add(amount)
{
Some(value) => {
*gatekeeper_amount = value;
Ok(value)
}
None => Err(()),
})?;
Ok(new_gatekeeper_amount)
}
fn decrease_gatekeeper_amount(
network_id: &T::NetworkId,
amount: &BalanceOf<T>,
) -> Result<BalanceOf<T>, ()> {
let new_gatekeeper_amount =
GatekeeperAmount::<T>::mutate(network_id, |gatekeeper_amount| match gatekeeper_amount
.checked_sub(amount)
{
Some(value) => {
*gatekeeper_amount = value;
Ok(value)
}
None => Err(()),
})?;
Ok(new_gatekeeper_amount)
}
fn accumulate_outgoing_imbalance(amount: &BalanceOf<T>) -> Result<BalanceOf<T>, ()> {
let new_bridged_out_amount = BridgedImbalance::<T>::mutate(|bridged_imbalance| {
match bridged_imbalance.bridged_out.checked_add(amount) {
Some(value) => {
(*bridged_imbalance).bridged_out = value;
Ok(value)
}
None => Err(()),
}
})?;
Ok(new_bridged_out_amount)
}
fn accumulate_incoming_imbalance(amount: &BalanceOf<T>) -> Result<BalanceOf<T>, ()> {
let new_bridged_in_amount = BridgedImbalance::<T>::mutate(|bridged_imbalance| {
match bridged_imbalance.bridged_in.checked_add(amount) {
Some(value) => {
(*bridged_imbalance).bridged_in = value;
Ok(value)
}
None => Err(()),
}
})?;
Ok(new_bridged_in_amount)
}
fn accumulate_commission(commission: &BalanceOf<T>) -> Result<BalanceOf<T>, ()> {
AccumulatedCommission::<T>::mutate(|accumulated| {
match accumulated.checked_add(commission) {
Some(value) => {
*accumulated = value;
Ok(value)
}
None => Err(()),
}
})
}
fn nullify_commission() {
AccumulatedCommission::<T>::set(Default::default());
}
fn trigger_nullification() {
if NullifyNeeded::<T>::get() {
Self::nullify_commission();
NullifyNeeded::<T>::put(false);
} else {
NullifyNeeded::<T>::put(true);
}
}
}

41
pallets/networks/src/mock.rs Executable file → Normal file
View File

@ -1,19 +1,24 @@
use crate as ghost_networks;
use frame_system::EnsureSignedBy;
use crate::{self as ghost_networks};
use frame_support::{
construct_runtime, ord_parameter_types, parameter_types, traits::{ConstU128, ConstU32, Everything}
construct_runtime, ord_parameter_types, parameter_types,
traits::{ConstU128, ConstU32, Everything},
};
use frame_system::EnsureSignedBy;
pub use primitives::{
AccountId, Balance, Nonce, BlockNumber, Hash,
ReserveIdentifier, FreezeIdentifier,
AccountId, Balance, BlockNumber, FreezeIdentifier, Hash, Nonce, ReserveIdentifier,
};
use sp_runtime::{
traits::{BlakeTwo256, AccountIdLookup},
curve::PiecewiseLinear,
traits::{AccountIdLookup, BlakeTwo256},
BuildStorage,
};
parameter_types! {
pub const BlockHashCount: BlockNumber = 250;
pub static SlashDeferDuration: u32 = 0;
pub static Period: BlockNumber = 5;
pub static Offset: BlockNumber = 0;
pub static MaxControllersInDeprecationBatch: u32 = 5_000;
}
impl frame_system::Config for Test {
@ -64,6 +69,21 @@ impl pallet_balances::Config for Test {
type MaxFreezes = ConstU32<50>;
}
pallet_staking_reward_curve::build! {
const REWARD_CURVE: PiecewiseLinear<'static> = curve!(
min_inflation: 0_006_900,
max_inflation: 1_000_000,
ideal_stake: 0_690_000,
falloff: 0_050_000,
max_piece_count: 100,
test_precision: 0_005_000,
);
}
parameter_types! {
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
}
ord_parameter_types! {
pub const RegistererAccount: AccountId = AccountId::from([1u8; 32]);
pub const UpdaterAccount: AccountId = AccountId::from([2u8; 32]);
@ -73,14 +93,15 @@ ord_parameter_types! {
impl ghost_networks::Config for Test {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type NetworkId = u32;
type RegisterOrigin = EnsureSignedBy::<RegistererAccount, AccountId>;
type UpdateOrigin = EnsureSignedBy::<UpdaterAccount, AccountId>;
type RemoveOrigin = EnsureSignedBy::<RemoverAccount, AccountId>;
type RegisterOrigin = EnsureSignedBy<RegistererAccount, AccountId>;
type UpdateOrigin = EnsureSignedBy<UpdaterAccount, AccountId>;
type RemoveOrigin = EnsureSignedBy<RemoverAccount, AccountId>;
type WeightInfo = crate::weights::SubstrateWeight<Test>;
}
type Block = frame_system::mocking::MockBlockU32<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
construct_runtime!(
pub enum Test {

1413
pallets/networks/src/tests.rs Executable file → Normal file

File diff suppressed because it is too large Load Diff

369
pallets/networks/src/weights.rs Executable file → Normal file
View File

@ -15,14 +15,14 @@
//! Autogenerated weights for `ghost_networks`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-11-29, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
//! DATE: 2025-06-19, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `ghost`, CPU: `Intel(R) Core(TM) i3-2310M CPU @ 2.10GHz`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("casper-dev"), DB CACHE: 1024
//! HOSTNAME: `ghostown`, CPU: `Intel(R) Core(TM) i3-2310M CPU @ 2.10GHz`
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("casper-dev")`, DB CACHE: 1024
// Executed Command:
// ./target/production/ghost
// ./target/release/ghost
// benchmark
// pallet
// --chain=casper-dev
@ -30,8 +30,8 @@
// --repeat=20
// --pallet=ghost_networks
// --extrinsic=*
// --execution=wasm
// --wasm-execution=compiled
// --heap-pages=4096
// --header=./file_header.txt
// --output=./runtime/casper/src/weights/ghost_networks.rs
@ -49,11 +49,12 @@ use sp_std::marker::PhantomData;
/// Weight functions needed for ghost_networks
pub trait WeightInfo {
fn register_network(n: u32, m: u32, ) -> Weight;
fn register_network(i: u32, j: u32, k: u32, ) -> Weight;
fn update_network_name(n: u32, ) -> Weight;
fn update_network_endpoint(n: u32, ) -> Weight;
fn update_network_finality_delay() -> Weight;
fn update_network_release_delay() -> Weight;
fn update_network_rate_limit_delay() -> Weight;
fn update_network_block_distance() -> Weight;
fn update_network_type() -> Weight;
fn update_network_gatekeeper() -> Weight;
fn update_network_topic_name() -> Weight;
@ -65,260 +66,316 @@ pub trait WeightInfo {
/// Weight for ghost_networks using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// Storage: GhostNetworks Networks (r:1 w:1)
/// Proof Skipped: GhostNetworks Networks (max_values: None, max_size: None, mode: Measured)
/// The range of component `n` is `[1, 20]`.
/// The range of component `m` is `[1, 150]`.
fn register_network(_n: u32, _m: u32, ) -> Weight {
/// Storage: `GhostNetworks::Networks` (r:1 w:1)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// The range of component `i` is `[1, 20]`.
/// The range of component `j` is `[1, 150]`.
/// The range of component `k` is `[1, 20]`.
fn register_network(_i: u32, _j: u32, k: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `76`
// Estimated: `2551`
// Minimum execution time: 32_086 nanoseconds.
Weight::from_parts(33_092_855, 2551)
// Measured: `109`
// Estimated: `3574`
// Minimum execution time: 46_023_000 picoseconds.
Weight::from_parts(97_871_287, 0)
.saturating_add(Weight::from_parts(0, 3574))
// Standard Error: 94_524
.saturating_add(Weight::from_parts(940_486, 0).saturating_mul(k.into()))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: GhostNetworks Networks (r:1 w:1)
/// Proof Skipped: GhostNetworks Networks (max_values: None, max_size: None, mode: Measured)
/// Storage: `GhostNetworks::Networks` (r:1 w:1)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// The range of component `n` is `[1, 20]`.
fn update_network_name(_n: u32, ) -> Weight {
fn update_network_name(n: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `141`
// Estimated: `2616`
// Minimum execution time: 34_496 nanoseconds.
Weight::from_parts(35_728_230, 2616)
// Standard Error: 2_591
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 49_906_000 picoseconds.
Weight::from_parts(55_537_587, 0)
.saturating_add(Weight::from_parts(0, 3767))
// Standard Error: 87_704
.saturating_add(Weight::from_parts(92_366, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: GhostNetworks Networks (r:1 w:1)
/// Proof Skipped: GhostNetworks Networks (max_values: None, max_size: None, mode: Measured)
/// Storage: `GhostNetworks::Networks` (r:1 w:1)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// The range of component `n` is `[1, 150]`.
fn update_network_endpoint(_n: u32, ) -> Weight {
fn update_network_endpoint(n: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `141`
// Estimated: `2616`
// Minimum execution time: 34_666 nanoseconds.
Weight::from_parts(35_959_961, 2616)
// Standard Error: 381
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 50_556_000 picoseconds.
Weight::from_parts(57_726_674, 0)
.saturating_add(Weight::from_parts(0, 3767))
// Standard Error: 12_261
.saturating_add(Weight::from_parts(274, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: GhostNetworks Networks (r:1 w:1)
/// Proof Skipped: GhostNetworks Networks (max_values: None, max_size: None, mode: Measured)
/// Storage: `GhostNetworks::Networks` (r:1 w:1)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn update_network_finality_delay() -> Weight {
// Proof Size summary in bytes:
// Measured: `141`
// Estimated: `2616`
// Minimum execution time: 33_860 nanoseconds.
Weight::from_parts(34_995_000, 2616)
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 49_406_000 picoseconds.
Weight::from_parts(51_256_000, 0)
.saturating_add(Weight::from_parts(0, 3767))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: GhostNetworks Networks (r:1 w:1)
/// Proof Skipped: GhostNetworks Networks (max_values: None, max_size: None, mode: Measured)
fn update_network_release_delay() -> Weight {
/// Storage: `GhostNetworks::Networks` (r:1 w:1)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn update_network_rate_limit_delay() -> Weight {
// Proof Size summary in bytes:
// Measured: `141`
// Estimated: `2616`
// Minimum execution time: 33_860 nanoseconds.
Weight::from_parts(34_995_000, 2616)
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 49_572_000 picoseconds.
Weight::from_parts(52_584_000, 0)
.saturating_add(Weight::from_parts(0, 3767))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: GhostNetworks Networks (r:1 w:1)
/// Proof Skipped: GhostNetworks Networks (max_values: None, max_size: None, mode: Measured)
/// Storage: `GhostNetworks::Networks` (r:1 w:1)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn update_network_block_distance() -> Weight {
// Proof Size summary in bytes:
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 48_880_000 picoseconds.
Weight::from_parts(50_596_000, 0)
.saturating_add(Weight::from_parts(0, 3767))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `GhostNetworks::Networks` (r:1 w:1)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn update_network_type() -> Weight {
// Proof Size summary in bytes:
// Measured: `141`
// Estimated: `2616`
// Minimum execution time: 34_976 nanoseconds.
Weight::from_parts(36_182_000, 2616)
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 48_282_000 picoseconds.
Weight::from_parts(49_137_000, 0)
.saturating_add(Weight::from_parts(0, 3767))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: GhostNetworks Networks (r:1 w:1)
/// Proof Skipped: GhostNetworks Networks (max_values: None, max_size: None, mode: Measured)
/// Storage: `GhostNetworks::Networks` (r:1 w:1)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn update_network_gatekeeper() -> Weight {
// Proof Size summary in bytes:
// Measured: `141`
// Estimated: `2616`
// Minimum execution time: 34_768 nanoseconds.
Weight::from_parts(35_580_000, 2616)
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 50_853_000 picoseconds.
Weight::from_parts(51_982_000, 0)
.saturating_add(Weight::from_parts(0, 3767))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: GhostNetworks Networks (r:1 w:1)
/// Proof Skipped: GhostNetworks Networks (max_values: None, max_size: None, mode: Measured)
/// Storage: `GhostNetworks::Networks` (r:1 w:1)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn update_network_topic_name() -> Weight {
// Proof Size summary in bytes:
// Measured: `141`
// Estimated: `2616`
// Minimum execution time: 34_768 nanoseconds.
Weight::from_parts(35_580_000, 2616)
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 50_343_000 picoseconds.
Weight::from_parts(52_380_000, 0)
.saturating_add(Weight::from_parts(0, 3767))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: GhostNetworks Networks (r:1 w:1)
/// Proof Skipped: GhostNetworks Networks (max_values: None, max_size: None, mode: Measured)
/// Storage: `GhostNetworks::Networks` (r:1 w:1)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn update_incoming_network_fee() -> Weight {
// Proof Size summary in bytes:
// Measured: `141`
// Estimated: `2616`
// Minimum execution time: 34_768 nanoseconds.
Weight::from_parts(35_580_000, 2616)
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 49_393_000 picoseconds.
Weight::from_parts(80_966_000, 0)
.saturating_add(Weight::from_parts(0, 3767))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: GhostNetworks Networks (r:1 w:1)
/// Proof Skipped: GhostNetworks Networks (max_values: None, max_size: None, mode: Measured)
/// Storage: `GhostNetworks::Networks` (r:1 w:1)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn update_outgoing_network_fee() -> Weight {
// Proof Size summary in bytes:
// Measured: `141`
// Estimated: `2616`
// Minimum execution time: 34_768 nanoseconds.
Weight::from_parts(35_580_000, 2616)
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 49_579_000 picoseconds.
Weight::from_parts(51_126_000, 0)
.saturating_add(Weight::from_parts(0, 3767))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: GhostNetworks Networks (r:1 w:1)
/// Proof Skipped: GhostNetworks Networks (max_values: None, max_size: None, mode: Measured)
/// Storage: `GhostNetworks::Networks` (r:1 w:1)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn remove_network() -> Weight {
// Proof Size summary in bytes:
// Measured: `141`
// Estimated: `2616`
// Minimum execution time: 33_336 nanoseconds.
Weight::from_parts(34_609_000, 2616)
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 44_634_000 picoseconds.
Weight::from_parts(45_815_000, 0)
.saturating_add(Weight::from_parts(0, 3767))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
}
impl WeightInfo for () {
/// Storage: GhostNetworks Networks (r:1 w:1)
/// Proof Skipped: GhostNetworks Networks (max_values: None, max_size: None, mode: Measured)
/// The range of component `n` is `[1, 20]`.
/// The range of component `m` is `[1, 150]`.
fn register_network(_n: u32, _m: u32, ) -> Weight {
/// Storage: `GhostNetworks::Networks` (r:1 w:1)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// The range of component `i` is `[1, 20]`.
/// The range of component `j` is `[1, 150]`.
/// The range of component `k` is `[1, 20]`.
fn register_network(_i: u32, _j: u32, k: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `76`
// Estimated: `2551`
// Minimum execution time: 32_086 nanoseconds.
Weight::from_parts(33_092_855, 2551)
// Measured: `109`
// Estimated: `3574`
// Minimum execution time: 46_023_000 picoseconds.
Weight::from_parts(97_871_287, 0)
.saturating_add(Weight::from_parts(0, 3574))
// Standard Error: 94_524
.saturating_add(Weight::from_parts(940_486, 0).saturating_mul(k.into()))
.saturating_add(RocksDbWeight::get().reads(1))
.saturating_add(RocksDbWeight::get().writes(1))
}
/// Storage: GhostNetworks Networks (r:1 w:1)
/// Proof Skipped: GhostNetworks Networks (max_values: None, max_size: None, mode: Measured)
/// Storage: `GhostNetworks::Networks` (r:1 w:1)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// The range of component `n` is `[1, 20]`.
fn update_network_name(_n: u32, ) -> Weight {
fn update_network_name(n: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `141`
// Estimated: `2616`
// Minimum execution time: 34_496 nanoseconds.
Weight::from_parts(35_728_230, 2616)
// Standard Error: 2_591
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 49_906_000 picoseconds.
Weight::from_parts(55_537_587, 0)
.saturating_add(Weight::from_parts(0, 3767))
// Standard Error: 87_704
.saturating_add(Weight::from_parts(92_366, 0).saturating_mul(n.into()))
.saturating_add(RocksDbWeight::get().reads(1))
.saturating_add(RocksDbWeight::get().writes(1))
}
/// Storage: GhostNetworks Networks (r:1 w:1)
/// Proof Skipped: GhostNetworks Networks (max_values: None, max_size: None, mode: Measured)
/// Storage: `GhostNetworks::Networks` (r:1 w:1)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// The range of component `n` is `[1, 150]`.
fn update_network_endpoint(_n: u32, ) -> Weight {
fn update_network_endpoint(n: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `141`
// Estimated: `2616`
// Minimum execution time: 34_666 nanoseconds.
Weight::from_parts(35_959_961, 2616)
// Standard Error: 381
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 50_556_000 picoseconds.
Weight::from_parts(57_726_674, 0)
.saturating_add(Weight::from_parts(0, 3767))
// Standard Error: 12_261
.saturating_add(Weight::from_parts(274, 0).saturating_mul(n.into()))
.saturating_add(RocksDbWeight::get().reads(1))
.saturating_add(RocksDbWeight::get().writes(1))
}
/// Storage: GhostNetworks Networks (r:1 w:1)
/// Proof Skipped: GhostNetworks Networks (max_values: None, max_size: None, mode: Measured)
/// Storage: `GhostNetworks::Networks` (r:1 w:1)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn update_network_finality_delay() -> Weight {
// Proof Size summary in bytes:
// Measured: `141`
// Estimated: `2616`
// Minimum execution time: 33_860 nanoseconds.
Weight::from_parts(34_995_000, 2616)
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 49_406_000 picoseconds.
Weight::from_parts(51_256_000, 0)
.saturating_add(Weight::from_parts(0, 3767))
.saturating_add(RocksDbWeight::get().reads(1))
.saturating_add(RocksDbWeight::get().writes(1))
}
/// Storage: GhostNetworks Networks (r:1 w:1)
/// Proof Skipped: GhostNetworks Networks (max_values: None, max_size: None, mode: Measured)
fn update_network_release_delay() -> Weight {
/// Storage: `GhostNetworks::Networks` (r:1 w:1)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn update_network_rate_limit_delay() -> Weight {
// Proof Size summary in bytes:
// Measured: `141`
// Estimated: `2616`
// Minimum execution time: 33_860 nanoseconds.
Weight::from_parts(34_995_000, 2616)
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 49_572_000 picoseconds.
Weight::from_parts(52_584_000, 0)
.saturating_add(Weight::from_parts(0, 3767))
.saturating_add(RocksDbWeight::get().reads(1))
.saturating_add(RocksDbWeight::get().writes(1))
}
/// Storage: GhostNetworks Networks (r:1 w:1)
/// Proof Skipped: GhostNetworks Networks (max_values: None, max_size: None, mode: Measured)
/// Storage: `GhostNetworks::Networks` (r:1 w:1)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn update_network_block_distance() -> Weight {
// Proof Size summary in bytes:
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 48_880_000 picoseconds.
Weight::from_parts(50_596_000, 0)
.saturating_add(Weight::from_parts(0, 3767))
.saturating_add(RocksDbWeight::get().reads(1))
.saturating_add(RocksDbWeight::get().writes(1))
}
/// Storage: `GhostNetworks::Networks` (r:1 w:1)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn update_network_type() -> Weight {
// Proof Size summary in bytes:
// Measured: `141`
// Estimated: `2616`
// Minimum execution time: 34_976 nanoseconds.
Weight::from_parts(36_182_000, 2616)
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 48_282_000 picoseconds.
Weight::from_parts(49_137_000, 0)
.saturating_add(Weight::from_parts(0, 3767))
.saturating_add(RocksDbWeight::get().reads(1))
.saturating_add(RocksDbWeight::get().writes(1))
}
/// Storage: GhostNetworks Networks (r:1 w:1)
/// Proof Skipped: GhostNetworks Networks (max_values: None, max_size: None, mode: Measured)
/// Storage: `GhostNetworks::Networks` (r:1 w:1)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn update_network_gatekeeper() -> Weight {
// Proof Size summary in bytes:
// Measured: `141`
// Estimated: `2616`
// Minimum execution time: 34_768 nanoseconds.
Weight::from_parts(35_580_000, 2616)
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 50_853_000 picoseconds.
Weight::from_parts(51_982_000, 0)
.saturating_add(Weight::from_parts(0, 3767))
.saturating_add(RocksDbWeight::get().reads(1))
.saturating_add(RocksDbWeight::get().writes(1))
}
/// Storage: GhostNetworks Networks (r:1 w:1)
/// Proof Skipped: GhostNetworks Networks (max_values: None, max_size: None, mode: Measured)
/// Storage: `GhostNetworks::Networks` (r:1 w:1)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn update_network_topic_name() -> Weight {
// Proof Size summary in bytes:
// Measured: `141`
// Estimated: `2616`
// Minimum execution time: 34_768 nanoseconds.
Weight::from_parts(35_580_000, 2616)
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 50_343_000 picoseconds.
Weight::from_parts(52_380_000, 0)
.saturating_add(Weight::from_parts(0, 3767))
.saturating_add(RocksDbWeight::get().reads(1))
.saturating_add(RocksDbWeight::get().writes(1))
}
/// Storage: GhostNetworks Networks (r:1 w:1)
/// Proof Skipped: GhostNetworks Networks (max_values: None, max_size: None, mode: Measured)
/// Storage: `GhostNetworks::Networks` (r:1 w:1)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn update_incoming_network_fee() -> Weight {
// Proof Size summary in bytes:
// Measured: `141`
// Estimated: `2616`
// Minimum execution time: 34_768 nanoseconds.
Weight::from_parts(35_580_000, 2616)
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 49_393_000 picoseconds.
Weight::from_parts(80_966_000, 0)
.saturating_add(Weight::from_parts(0, 3767))
.saturating_add(RocksDbWeight::get().reads(1))
.saturating_add(RocksDbWeight::get().writes(1))
}
/// Storage: GhostNetworks Networks (r:1 w:1)
/// Proof Skipped: GhostNetworks Networks (max_values: None, max_size: None, mode: Measured)
/// Storage: `GhostNetworks::Networks` (r:1 w:1)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn update_outgoing_network_fee() -> Weight {
// Proof Size summary in bytes:
// Measured: `141`
// Estimated: `2616`
// Minimum execution time: 34_768 nanoseconds.
Weight::from_parts(35_580_000, 2616)
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 49_579_000 picoseconds.
Weight::from_parts(51_126_000, 0)
.saturating_add(Weight::from_parts(0, 3767))
.saturating_add(RocksDbWeight::get().reads(1))
.saturating_add(RocksDbWeight::get().writes(1))
}
/// Storage: GhostNetworks Networks (r:1 w:1)
/// Proof Skipped: GhostNetworks Networks (max_values: None, max_size: None, mode: Measured)
/// Storage: `GhostNetworks::Networks` (r:1 w:1)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn remove_network() -> Weight {
// Proof Size summary in bytes:
// Measured: `141`
// Estimated: `2616`
// Minimum execution time: 33_336 nanoseconds.
Weight::from_parts(34_609_000, 2616)
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 44_634_000 picoseconds.
Weight::from_parts(45_815_000, 0)
.saturating_add(Weight::from_parts(0, 3767))
.saturating_add(RocksDbWeight::get().reads(1))
.saturating_add(RocksDbWeight::get().writes(1))
}

9
pallets/slow-clap/Cargo.toml Executable file → Normal file
View File

@ -1,6 +1,6 @@
[package]
name = "ghost-slow-clap"
version = "0.3.15"
version = "0.3.39"
description = "Applause protocol for the EVM bridge"
license.workspace = true
authors.workspace = true
@ -27,11 +27,13 @@ sp-staking = { workspace = true }
sp-io = { workspace = true }
sp-std = { workspace = true }
pallet-balances = { workspace = true }
ghost-networks = { workspace = true }
[dev-dependencies]
pallet-session = { workspace = true, default-features = true }
pallet-balances = { workspace = true }
pallet-session = { workspace = true }
pallet-staking = { workspace = true }
pallet-staking-reward-curve = { workspace = true }
[features]
default = ["std"]
@ -49,6 +51,7 @@ std = [
"sp-io/std",
"sp-std/std",
"pallet-session/std",
"pallet-staking/std",
"pallet-balances/std",
"ghost-networks/std",
]

View File

@ -3,13 +3,8 @@
use super::*;
use frame_benchmarking::v1::*;
use frame_support::traits::fungible::Inspect;
use frame_system::RawOrigin;
use frame_support::traits::fungible::{Inspect, Mutate};
use crate::Pallet as SlowClap;
const MAX_CLAPS: u32 = 100;
const MAX_COMPANIONS: u32 = 20;
pub fn create_account<T: Config>() -> T::AccountId {
let account_bytes = Vec::from([1u8; 32]);
@ -17,184 +12,89 @@ pub fn create_account<T: Config>() -> T::AccountId {
.expect("32 bytes always construct an AccountId32")
}
pub fn create_companions<T: Config>(
total: usize,
network_id: NetworkIdOf<T>,
user_account: T::AccountId,
fee: H256,
receiver: H160,
) -> Result<CompanionId, &'static str> {
T::NetworkDataHandler::register(network_id.into(), NetworkData {
chain_name: "Ethereum".into(),
default_endpoint:
"https://base-mainnet.core.chainstack.com/2fc1de7f08c0465f6a28e3c355e0cb14/".into(),
finality_delay: Some(0),
release_delay: Some(0),
network_type: Default::default(),
gatekeeper: b"0x1234567891234567891234567891234567891234".to_vec(),
topic_name: b"0x12345678912345678912345678912345678912345678912345678912345678".to_vec(),
incoming_fee: 0,
outgoing_fee: 0,
}).map_err(|_| BenchmarkError::Weightless)?;
let mut last_companion_id = 0;
for _ in 0..total {
let minimum_balance = <<T as pallet::Config>::Currency>::minimum_balance();
let balance = minimum_balance + minimum_balance;
let companion = Companion::<NetworkIdOf::<T>, BalanceOf::<T>> {
network_id: network_id.into(), receiver,
fee, amount: balance,
};
let _ = <<T as pallet::Config>::Currency>::mint_into(&user_account, balance);
let companion_id = SlowClap::<T>::current_companion_id();
let _ = SlowClap::<T>::propose_companion(
RawOrigin::Signed(user_account.clone()).into(),
network_id,
companion,
)?;
last_companion_id = companion_id;
}
Ok(last_companion_id)
}
pub fn create_claps<T: Config>(i: u32, j: u32) -> Result<
(
Vec<crate::Clap<T::AccountId, NetworkIdOf<T>, BalanceOf<T>>>,
<T::AuthorityId as RuntimeAppPublic>::Signature,
),
&'static str,
> {
benchmarks! {
slow_clap {
let minimum_balance = <<T as pallet::Config>::Currency>::minimum_balance();
let receiver = create_account::<T>();
let amount = minimum_balance + minimum_balance;
let total_amount = amount.saturating_mul(j.into());
let network_id = NetworkIdOf::<T>::default();
let mut claps = Vec::new();
let mut companions = BTreeMap::new();
let session_index = T::ValidatorSet::session_index();
let authorities = vec![T::AuthorityId::generate_pair(None)];
let bounded_authorities =
WeakBoundedVec::<_, T::MaxAuthorities>::try_from(authorities.clone())
let bounded_authorities = WeakBoundedVec::<_, T::MaxAuthorities>::try_from(authorities.clone())
.map_err(|()| "more than the maximum number of keys provided")?;
Authorities::<T>::put(bounded_authorities);
Authorities::<T>::set(&session_index, bounded_authorities);
for index in 0..j {
companions.insert(
index.into(),
amount,
);
}
for _ in 0..i {
claps.push(Clap {
session_index: 1,
let clap = Clap {
session_index: 0,
authority_index: 0,
network_id,
transaction_hash: H256::repeat_byte(1u8),
block_number: 69,
removed: true,
receiver: create_account::<T>(),
amount: total_amount,
companions: companions.clone(),
});
}
removed: false,
network_id,
receiver: receiver.clone(),
amount,
};
let authority_id = authorities
.get(0usize)
.expect("first authority should exist");
let encoded_claps = claps.encode();
let signature = authority_id.sign(&encoded_claps)
let encoded_clap = clap.encode();
let signature = authority_id.sign(&encoded_clap)
.ok_or("couldn't make signature")?;
Ok((claps, signature))
}
benchmarks! {
slow_clap {
let k in 1 .. MAX_CLAPS;
let j in 1 .. MAX_COMPANIONS;
let receiver = H160::repeat_byte(69u8);
let fee = H256::repeat_byte(0u8);
let user_account: T::AccountId = whitelisted_caller();
let network_id = <<T as pallet::Config>::NetworkDataHandler as NetworkDataBasicHandler>::NetworkId::default();
let (claps, signature) = create_claps::<T>(k, j)?;
let _ = create_companions::<T>(j as usize, network_id, user_account, fee, receiver)?;
}: _(RawOrigin::None, claps, signature)
}: _(RawOrigin::None, clap, signature)
verify {
assert_eq!(<<T as pallet::Config>::Currency>::total_balance(&receiver), amount);
}
self_applause {
let session_index = T::ValidatorSet::session_index();
let authorities = vec![T::AuthorityId::generate_pair(None)];
let bounded_authorities = WeakBoundedVec::<_, T::MaxAuthorities>::try_from(authorities.clone())
.map_err(|()| "more than the maximum number of keys provided")?;
Authorities::<T>::set(&session_index, bounded_authorities);
let minimum_balance = <<T as pallet::Config>::Currency>::minimum_balance();
let total_amount = (minimum_balance + minimum_balance).saturating_mul(j.into());
}
let receiver = create_account::<T>();
let receiver_clone = receiver.clone();
let amount = minimum_balance + minimum_balance;
let network_id = NetworkIdOf::<T>::default();
let transaction_hash = H256::repeat_byte(1u8);
propose_companion {
let receiver = H160::repeat_byte(69u8);
let fee = H256::repeat_byte(0u8);
let user_account: T::AccountId = whitelisted_caller();
let network_id = <<T as pallet::Config>::NetworkDataHandler as NetworkDataBasicHandler>::NetworkId::default();
// T::NetworkDataHandler::register(network_id.into(), NetworkData {
// chain_name: "Ethereum".into(),
// // https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7/
// default_endpoint:
// "https://base-mainnet.core.chainstack.com/2fc1de7f08c0465f6a28e3c355e0cb14/".into(),
// finality_delay: Some(50),
// release_delay: Some(100),
// network_type: Default::default(),
// gatekeeper: b"0x1234567891234567891234567891234567891234".to_vec(),
// topic_name: b"0x12345678912345678912345678912345678912345678912345678912345678".to_vec(),
// incoming_fee: 0,
// outgoing_fee: 0,
// }).map_err(|_| BenchmarkError::Weightless)?;
let companion_id = create_companions::<T>(1, network_id, user_account.clone(), fee, receiver)?;
let companion_id = SlowClap::<T>::current_companion_id();
let minimum_balance = <<T as pallet::Config>::Currency>::minimum_balance();
let balance = minimum_balance + minimum_balance;
let companion = Companion::<NetworkIdOf::<T>, BalanceOf::<T>> {
network_id: network_id.into(), receiver,
fee, amount: balance,
};
let _ = <<T as pallet::Config>::Currency>::mint_into(&user_account, balance);
assert_eq!(SlowClap::<T>::current_companion_id(), companion_id);
}: _(RawOrigin::Signed(user_account), network_id.into(), companion)
verify {
assert_eq!(SlowClap::<T>::current_companion_id(), companion_id + 1);
}
let unique_transaction_hash = <Pallet<T>>::generate_unique_hash(
&receiver,
&amount,
&network_id,
);
let storage_key = (session_index, &transaction_hash, &unique_transaction_hash);
release_companion {
let receiver = H160::repeat_byte(69u8);
let fee = H256::repeat_byte(0u8);
let user_account: T::AccountId = whitelisted_caller();
let network_id = <<T as pallet::Config>::NetworkDataHandler as NetworkDataBasicHandler>::NetworkId::default();
let companion_id = create_companions::<T>(1, network_id, user_account.clone(), fee, receiver)?;
assert_eq!(SlowClap::<T>::release_blocks(companion_id), BlockNumberFor::<T>::default());
}: _(RawOrigin::Signed(user_account), network_id.into(), companion_id)
verify {
assert_ne!(SlowClap::<T>::release_blocks(companion_id), BlockNumberFor::<T>::default());
}
kill_companion {
let receiver = H160::repeat_byte(69u8);
let fee = H256::repeat_byte(0u8);
let user_account: T::AccountId = whitelisted_caller();
let network_id = <<T as pallet::Config>::NetworkDataHandler as NetworkDataBasicHandler>::NetworkId::default();
let companion_id = create_companions::<T>(1, network_id, user_account.clone(), fee, receiver)?;
SlowClap::<T>::release_companion(
RawOrigin::Signed(user_account.clone()).into(),
<Pallet::<T>>::trigger_nullification_for_benchmark();
let clap = Clap {
session_index,
authority_index: 0,
transaction_hash,
block_number: 69,
removed: false,
network_id,
companion_id,
)?;
let block_shift =
<<T as pallet::Config>::NetworkDataHandler as NetworkDataInspectHandler<NetworkData>>::get(&network_id)
.unwrap()
.release_delay
.unwrap();
frame_system::Pallet::<T>::set_block_number((block_shift + 1).saturated_into());
}: _(RawOrigin::Signed(user_account), network_id.into(), companion_id)
receiver: receiver.clone(),
amount,
};
let authority_id = authorities
.get(0usize)
.expect("first authority should exist");
let encoded_clap = clap.encode();
let signature = authority_id.sign(&encoded_clap).unwrap();
<Pallet<T>>::slow_clap(RawOrigin::None.into(), clap, signature)?;
<Pallet::<T>>::trigger_nullification_for_benchmark();
assert_eq!(<<T as pallet::Config>::Currency>::total_balance(&receiver), Default::default());
assert_eq!(ApplausesForTransaction::<T>::get(&storage_key), false);
}: _(RawOrigin::Signed(receiver_clone), network_id, session_index, transaction_hash, receiver_clone.clone(), amount)
verify {
assert_eq!(SlowClap::<T>::companions(network_id, companion_id), None);
assert_eq!(SlowClap::<T>::companion_details(companion_id), None);
assert_eq!(SlowClap::<T>::current_companion_id(), companion_id + 1);
assert_eq!(<<T as pallet::Config>::Currency>::total_balance(&receiver), amount);
assert_eq!(ApplausesForTransaction::<T>::get(&storage_key), true);
}
impl_benchmark_test_suite!(

View File

@ -0,0 +1,57 @@
use crate::{Deserialize, Deserializer, Vec, H256};
pub fn de_string_to_bytes<'de, D>(de: D) -> Result<Option<Vec<u8>>, D::Error>
where
D: Deserializer<'de>,
{
let s: &str = Deserialize::deserialize(de)?;
Ok(Some(s.as_bytes().to_vec()))
}
pub fn de_string_to_u64<'de, D>(de: D) -> Result<Option<u64>, D::Error>
where
D: Deserializer<'de>,
{
let s: &str = Deserialize::deserialize(de)?;
let s = if s.starts_with("0x") { &s[2..] } else { &s };
Ok(u64::from_str_radix(s, 16).ok())
}
pub fn de_string_to_u64_pure<'de, D>(de: D) -> Result<u64, D::Error>
where
D: Deserializer<'de>,
{
let s: &str = Deserialize::deserialize(de)?;
let s = if s.starts_with("0x") { &s[2..] } else { &s };
Ok(u64::from_str_radix(s, 16).unwrap_or_default())
}
pub fn de_string_to_h256<'de, D>(de: D) -> Result<Option<H256>, D::Error>
where
D: Deserializer<'de>,
{
let s: &str = Deserialize::deserialize(de)?;
let start_index = if s.starts_with("0x") { 2 } else { 0 };
let h256: Vec<_> = (start_index..s.len())
.step_by(2)
.map(|i| u8::from_str_radix(&s[i..i + 2], 16).expect("valid u8 symbol; qed"))
.collect();
Ok(Some(H256::from_slice(&h256)))
}
pub fn de_string_to_vec_of_bytes<'de, D>(de: D) -> Result<Vec<Vec<u8>>, D::Error>
where
D: Deserializer<'de>,
{
let strings: Vec<&str> = Deserialize::deserialize(de)?;
Ok(strings
.iter()
.map(|s| {
let start_index = if s.starts_with("0x") { 2 } else { 0 };
(start_index..s.len())
.step_by(2)
.map(|i| u8::from_str_radix(&s[i..i + 2], 16).expect("valid u8 symbol; qed"))
.collect::<Vec<u8>>()
})
.collect::<Vec<Vec<u8>>>())
}

View File

@ -0,0 +1,49 @@
use crate::{
deserialisations::{
de_string_to_bytes, de_string_to_h256, de_string_to_u64, de_string_to_u64_pure,
de_string_to_vec_of_bytes,
},
Decode, Deserialize, Encode, RuntimeDebug, Vec, H256,
};
const NUMBER_OF_TOPICS: usize = 3;
#[derive(RuntimeDebug, Clone, PartialEq, Deserialize, Encode, Decode)]
pub struct EvmResponse {
#[serde(default)]
id: Option<u32>,
#[serde(default, deserialize_with = "de_string_to_bytes")]
jsonrpc: Option<Vec<u8>>,
#[serde(default, deserialize_with = "de_string_to_bytes")]
pub error: Option<Vec<u8>>,
#[serde(default)]
pub result: Option<EvmResponseType>,
}
#[derive(RuntimeDebug, Clone, PartialEq, Deserialize, Encode, Decode)]
#[serde(untagged)]
pub enum EvmResponseType {
#[serde(deserialize_with = "de_string_to_u64_pure")]
BlockNumber(u64),
TransactionLogs(Vec<Log>),
}
#[derive(RuntimeDebug, Clone, Eq, PartialEq, Ord, PartialOrd, Deserialize, Encode, Decode)]
#[serde(rename_all = "camelCase")]
pub struct Log {
#[serde(default, deserialize_with = "de_string_to_h256")]
pub transaction_hash: Option<H256>,
#[serde(default, deserialize_with = "de_string_to_u64")]
pub block_number: Option<u64>,
#[serde(default, deserialize_with = "de_string_to_vec_of_bytes")]
pub topics: Vec<Vec<u8>>,
pub removed: bool,
}
impl Log {
pub fn is_sufficient(&self) -> bool {
self.transaction_hash.is_some()
&& self.block_number.is_some()
&& self.topics.len() == NUMBER_OF_TOPICS
}
}

1509
pallets/slow-clap/src/lib.rs Executable file → Normal file

File diff suppressed because it is too large Load Diff

View File

@ -4,20 +4,22 @@ use frame_support::{
derive_impl, parameter_types,
traits::{ConstU32, ConstU64},
weights::Weight,
PalletId,
};
use frame_system::EnsureRoot;
use pallet_session::historical as pallet_session_historical;
use sp_runtime::{
curve::PiecewiseLinear,
testing::{TestXt, UintAuthorityId},
traits::ConvertInto,
BuildStorage, Permill,
Permill,
};
use sp_staking::{
offence::{OffenceError, ReportOffence},
SessionIndex,
};
use sp_runtime::BuildStorage;
use crate as slow_clap;
use crate::Config;
@ -53,13 +55,10 @@ impl pallet_session::SessionManager<u64> for TestSessionManager {
impl pallet_session::historical::SessionManager<u64, u64> for TestSessionManager {
fn new_session(_new_index: SessionIndex) -> Option<Vec<(u64, u64)>> {
Validators::mutate(|l| l
.take()
.map(|validators| validators
.iter()
.map(|v| (*v, *v))
.collect())
)
Validators::mutate(|l| {
l.take()
.map(|validators| validators.iter().map(|v| (*v, *v)).collect())
})
}
fn end_session(_: SessionIndex) {}
fn start_session(_: SessionIndex) {}
@ -84,24 +83,21 @@ impl ReportOffence<u64, IdentificationTuple, Offence> for OffenceHandler {
}
}
pub fn alice_account_id() -> <Runtime as frame_system::Config>::AccountId { 69 }
pub fn eve_account_id() -> <Runtime as frame_system::Config>::AccountId { 1337 }
pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::<Runtime>::default()
let t = frame_system::GenesisConfig::<Runtime>::default()
.build_storage()
.unwrap();
pallet_balances::GenesisConfig::<Runtime> {
balances: vec![ (alice_account_id(), 100) ],
}
.assimilate_storage(&mut t)
.unwrap();
let mut result = sp_io::TestExternalities::new(t);
result.execute_with(|| {
System::set_block_number(1);
for i in 1..=3 {
System::inc_providers(&i);
assert_eq!(
Session::set_keys(RuntimeOrigin::signed(i), i.into(), vec![],),
Ok(())
);
}
});
result
@ -167,6 +163,7 @@ impl frame_support::traits::EstimateNextSessionRotation<u64> for TestNextSession
impl ghost_networks::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type NetworkId = u32;
type RegisterOrigin = EnsureRoot<Self::AccountId>;
type UpdateOrigin = EnsureRoot<Self::AccountId>;
@ -174,9 +171,21 @@ impl ghost_networks::Config for Runtime {
type WeightInfo = ();
}
pallet_staking_reward_curve::build! {
const REWARD_CURVE: PiecewiseLinear<'static> = curve!(
min_inflation: 0_006_000,
max_inflation: 1_000_000,
ideal_stake: 0_690_000,
falloff: 0_050_000,
max_piece_count: 100,
test_precision: 0_005_000,
);
}
parameter_types! {
pub static ExistentialDeposit: u64 = 2;
pub const TreasuryPalletId: PalletId = PalletId(*b"mck/test");
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub const HistoryDepth: u32 = 10;
}
#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)]
@ -199,23 +208,16 @@ impl Config for Runtime {
type ReportUnresponsiveness = OffenceHandler;
type MaxAuthorities = ConstU32<5>;
type MaxNumberOfClaps = ConstU32<100>;
type ApplauseThreshold = ConstU32<0>;
type MaxAuthorityInfoInSession = ConstU32<5_000>;
type OffenceThreshold = ConstU32<40>;
type ApplauseThreshold = ConstU32<50>;
type OffenceThreshold = ConstU32<75>;
type UnsignedPriority = ConstU64<{ 1 << 20 }>;
type TreasuryPalletId = TreasuryPalletId;
type HistoryDepth = HistoryDepth;
type WeightInfo = ();
}
pub type Extrinsic = TestXt<RuntimeCall, ()>;
// impl frame_system::offchain::SigningTypes for Runtime {
// type Public = <Signature as Verify>::Signer;
// type Signature = Signature;
// }
impl<LocalCall> frame_system::offchain::SendTransactionTypes<LocalCall> for Runtime
where
RuntimeCall: From<LocalCall>,
@ -224,30 +226,36 @@ where
type Extrinsic = Extrinsic;
}
// impl<LocalCall> frame_system::offchain::CreateSignedTransaction<LocalCall> for Runtime
// where
// RuntimeCall: From<LocalCall>,
// {
// fn create_transaction<C: frame_system::offchain::AppCrypto<Self::Public, Self::Signature>>(
// call: Self::OverarchingCall,
// _public: Self::Public,
// _account: Self::AccountId,
// nonce: Self::Nonce,
// ) -> Option<(RuntimeCall, <Extrinsic as ExtrinsicT>::SignaturePayload)> {
// Some((call, (nonce.into(), ())))
// }
// }
pub fn advance_session() {
let now = System::block_number().max(1);
System::set_block_number(now + 1);
Session::rotate_session();
let session_index = Session::current_index();
// pub fn advance_session() {
// let now = System::block_number().max(1);
// System::set_block_number(now + 1);
// Session::rotate_session();
//
// let authorities = Session::validators()
// .into_iter()
// .map(UintAuthorityId)
// .collect();
//
// SlowClap::set_authorities(authorities);
// assert_eq!(Session::current_index(), (now / Period::get()) as u32);
// }
let authorities = Session::validators()
.into_iter()
.map(UintAuthorityId)
.collect();
SlowClap::set_test_authorities(session_index, authorities);
assert_eq!(session_index, (now / Period::get()) as u32);
}
pub fn advance_session_with_authority(authority: u64) {
let now = System::block_number().max(1);
System::set_block_number(now + 1);
Session::rotate_session();
let session_index = Session::current_index();
SlowClap::set_test_authorities(
session_index,
vec![
UintAuthorityId::from(authority),
UintAuthorityId::from(69),
UintAuthorityId::from(420),
UintAuthorityId::from(1337),
],
);
assert_eq!(session_index, (now / Period::get()) as u32);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,18 +1,176 @@
use frame_support::weights::Weight;
// This file is part of Ghost Network.
// Ghost Network is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Ghost Network is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Ghost Network. If not, see <http://www.gnu.org/licenses/>.
//! Autogenerated weights for `ghost_slow_clap`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
//! DATE: 2025-06-19, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `ghostown`, CPU: `Intel(R) Core(TM) i3-2310M CPU @ 2.10GHz`
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("casper-dev")`, DB CACHE: 1024
// Executed Command:
// ./target/release/ghost
// benchmark
// pallet
// --chain=casper-dev
// --steps=50
// --repeat=20
// --pallet=ghost_slow_clap
// --extrinsic=*
// --wasm-execution=compiled
// --heap-pages=4096
// --header=./file_header.txt
// --output=./runtime/casper/src/weights/ghost_slow_clap.rs
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(missing_docs)]
use frame_support::{
traits::Get,
weights::{Weight, constants::RocksDbWeight}
};
use core::marker::PhantomData;
pub trait WeightInfo {
fn slow_clap(claps_len: u32, companions_len: u32) -> Weight;
fn propose_companion() -> Weight;
fn release_companion() -> Weight;
fn kill_companion() -> Weight;
fn slow_clap() -> Weight;
fn self_applause()-> Weight;
}
/// Weight functions for `ghost_slow_clap`.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// Storage: `GhostSlowClaps::Authorities` (r:1 w:0)
/// Proof: `GhostSlowClaps::Authorities` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostSlowClaps::ReceivedClaps` (r:1 w:1)
/// Proof: `GhostSlowClaps::ReceivedClaps` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostSlowClaps::ClapsInSession` (r:1 w:1)
/// Proof: `GhostSlowClaps::ClapsInSession` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostSlowClaps::ApplausesForTransaction` (r:1 w:1)
/// Proof: `GhostSlowClaps::ApplausesForTransaction` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostNetworks::NullifyNeeded` (r:1 w:0)
/// Proof: `GhostNetworks::NullifyNeeded` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `GhostNetworks::Networks` (r:1 w:0)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostNetworks::GatekeeperAmount` (r:1 w:1)
/// Proof: `GhostNetworks::GatekeeperAmount` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostNetworks::BridgedImbalance` (r:1 w:1)
/// Proof: `GhostNetworks::BridgedImbalance` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `GhostNetworks::AccumulatedCommission` (r:1 w:1)
/// Proof: `GhostNetworks::AccumulatedCommission` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `System::Account` (r:1 w:1)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
fn slow_clap() -> Weight {
// Proof Size summary in bytes:
// Measured: `355`
// Estimated: `3820`
// Minimum execution time: 213_817_000 picoseconds.
Weight::from_parts(216_977_000, 0)
.saturating_add(Weight::from_parts(0, 3820))
.saturating_add(T::DbWeight::get().reads(10))
.saturating_add(T::DbWeight::get().writes(7))
}
/// Storage: `GhostSlowClaps::ReceivedClaps` (r:1 w:0)
/// Proof: `GhostSlowClaps::ReceivedClaps` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostSlowClaps::Authorities` (r:1 w:0)
/// Proof: `GhostSlowClaps::Authorities` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostSlowClaps::ApplausesForTransaction` (r:1 w:1)
/// Proof: `GhostSlowClaps::ApplausesForTransaction` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostNetworks::NullifyNeeded` (r:1 w:0)
/// Proof: `GhostNetworks::NullifyNeeded` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `GhostNetworks::Networks` (r:1 w:0)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostNetworks::GatekeeperAmount` (r:1 w:1)
/// Proof: `GhostNetworks::GatekeeperAmount` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostNetworks::BridgedImbalance` (r:1 w:1)
/// Proof: `GhostNetworks::BridgedImbalance` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `GhostNetworks::AccumulatedCommission` (r:1 w:1)
/// Proof: `GhostNetworks::AccumulatedCommission` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `System::Account` (r:1 w:1)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
fn self_applause() -> Weight {
// Proof Size summary in bytes:
// Measured: `655`
// Estimated: `4120`
// Minimum execution time: 210_676_000 picoseconds.
Weight::from_parts(212_905_000, 0)
.saturating_add(Weight::from_parts(0, 4120))
.saturating_add(T::DbWeight::get().reads(9))
.saturating_add(T::DbWeight::get().writes(5))
}
}
impl WeightInfo for () {
fn slow_clap(
_claps_len: u32,
_companions_len: u32,
) -> Weight { Weight::zero() }
fn propose_companion() -> Weight { Weight::zero() }
fn release_companion() -> Weight { Weight::zero() }
fn kill_companion() -> Weight { Weight::zero() }
/// Storage: `GhostSlowClaps::Authorities` (r:1 w:0)
/// Proof: `GhostSlowClaps::Authorities` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostSlowClaps::ReceivedClaps` (r:1 w:1)
/// Proof: `GhostSlowClaps::ReceivedClaps` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostSlowClaps::ClapsInSession` (r:1 w:1)
/// Proof: `GhostSlowClaps::ClapsInSession` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostSlowClaps::ApplausesForTransaction` (r:1 w:1)
/// Proof: `GhostSlowClaps::ApplausesForTransaction` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostNetworks::NullifyNeeded` (r:1 w:0)
/// Proof: `GhostNetworks::NullifyNeeded` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `GhostNetworks::Networks` (r:1 w:0)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostNetworks::GatekeeperAmount` (r:1 w:1)
/// Proof: `GhostNetworks::GatekeeperAmount` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostNetworks::BridgedImbalance` (r:1 w:1)
/// Proof: `GhostNetworks::BridgedImbalance` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `GhostNetworks::AccumulatedCommission` (r:1 w:1)
/// Proof: `GhostNetworks::AccumulatedCommission` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `System::Account` (r:1 w:1)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
fn slow_clap() -> Weight {
// Proof Size summary in bytes:
// Measured: `355`
// Estimated: `3820`
// Minimum execution time: 213_817_000 picoseconds.
Weight::from_parts(216_977_000, 0)
.saturating_add(Weight::from_parts(0, 3820))
.saturating_add(RocksDbWeight::get().reads(10))
.saturating_add(RocksDbWeight::get().writes(7))
}
/// Storage: `GhostSlowClaps::ReceivedClaps` (r:1 w:0)
/// Proof: `GhostSlowClaps::ReceivedClaps` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostSlowClaps::Authorities` (r:1 w:0)
/// Proof: `GhostSlowClaps::Authorities` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostSlowClaps::ApplausesForTransaction` (r:1 w:1)
/// Proof: `GhostSlowClaps::ApplausesForTransaction` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostNetworks::NullifyNeeded` (r:1 w:0)
/// Proof: `GhostNetworks::NullifyNeeded` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `GhostNetworks::Networks` (r:1 w:0)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostNetworks::GatekeeperAmount` (r:1 w:1)
/// Proof: `GhostNetworks::GatekeeperAmount` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostNetworks::BridgedImbalance` (r:1 w:1)
/// Proof: `GhostNetworks::BridgedImbalance` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `GhostNetworks::AccumulatedCommission` (r:1 w:1)
/// Proof: `GhostNetworks::AccumulatedCommission` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `System::Account` (r:1 w:1)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
fn self_applause() -> Weight {
// Proof Size summary in bytes:
// Measured: `655`
// Estimated: `4120`
// Minimum execution time: 210_676_000 picoseconds.
Weight::from_parts(212_905_000, 0)
.saturating_add(Weight::from_parts(0, 4120))
.saturating_add(RocksDbWeight::get().reads(9))
.saturating_add(RocksDbWeight::get().writes(5))
}
}

45
pallets/sudo/Cargo.toml Normal file
View File

@ -0,0 +1,45 @@
[package]
name = "ghost-sudo"
version = "0.0.2"
description = "Port of the sudo pallet because of dependencies issue"
license.workspace = true
authors.workspace = true
edition.workspace = true
homepage.workspace = true
repository.workspace = true
[dependencies]
docify = "0.2.8"
codec = { workspace = true, features = ["derive"] }
frame-benchmarking = { workspace = true, optional = true }
scale-info = { workspace = true, features = ["derive"] }
frame-support = { workspace = true }
frame-system = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
[features]
default = ["std"]
std = [
"codec/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"scale-info/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"sp-runtime/try-runtime",
]

View File

@ -0,0 +1,77 @@
use super::*;
use crate::Pallet;
use frame_benchmarking::v2::*;
use frame_system::RawOrigin;
fn assert_last_event<T: Config>(generic_event: crate::Event<T>) {
let re: <T as Config>::RuntimeEvent = generic_event.into();
frame_system::Pallet::<T>::assert_last_event(re.into());
}
#[benchmarks(where <T as Config>::RuntimeCall: From<frame_system::Call<T>>)]
mod benchmarks {
use super::*;
#[benchmark]
fn set_key() {
let caller: T::AccountId = whitelisted_caller();
Key::<T>::put(&caller);
let new_sudoer: T::AccountId = account("sudoer", 0, 0);
let new_sudoer_lookup = T::Lookup::unlookup(new_sudoer.clone());
#[extrinsic_call]
_(RawOrigin::Signed(caller.clone()), new_sudoer_lookup);
assert_last_event::<T>(Event::KeyChanged {
old: Some(caller),
new: new_sudoer,
});
}
#[benchmark]
fn sudo() {
let caller: T::AccountId = whitelisted_caller();
Key::<T>::put(&caller);
let call = frame_system::Call::remark { remark: vec![] }.into();
#[extrinsic_call]
_(RawOrigin::Signed(caller), Box::new(call));
assert_last_event::<T>(Event::Sudid {
sudo_result: Ok(()),
})
}
#[benchmark]
fn sudo_as() {
let caller: T::AccountId = whitelisted_caller();
Key::<T>::put(caller.clone());
let call = frame_system::Call::remark { remark: vec![] }.into();
let who: T::AccountId = account("as", 0, 0);
let who_lookup = T::Lookup::unlookup(who);
#[extrinsic_call]
_(RawOrigin::Signed(caller), who_lookup, Box::new(call));
assert_last_event::<T>(Event::SudoAsDone {
sudo_result: Ok(()),
})
}
#[benchmark]
fn remove_key() {
let caller: T::AccountId = whitelisted_caller();
Key::<T>::put(&caller);
#[extrinsic_call]
_(RawOrigin::Signed(caller.clone()));
assert_last_event::<T>(Event::KeyRemoved {});
}
impl_benchmark_test_suite!(Pallet, crate::mock::new_bench_ext(), crate::mock::Test);
}

View File

@ -0,0 +1,82 @@
use crate::{Config, Key};
use codec::{Decode, Encode};
use frame_support::{dispatch::DispatchInfo, ensure};
use scale_info::TypeInfo;
use sp_runtime::{
traits::{DispatchInfoOf, Dispatchable, SignedExtension},
transaction_validity::{
InvalidTransaction, TransactionPriority, TransactionValidity, TransactionValidityError,
UnknownTransaction, ValidTransaction,
},
};
use sp_std::{fmt, marker::PhantomData};
#[derive(Clone, Eq, PartialEq, Encode, Decode, TypeInfo)]
#[scale_info(skip_type_params(T))]
pub struct CheckOnlySudoAccount<T: Config + Send + Sync>(PhantomData<T>);
impl<T: Config + Send + Sync> Default for CheckOnlySudoAccount<T> {
fn default() -> Self {
Self(Default::default())
}
}
impl<T: Config + Send + Sync> fmt::Debug for CheckOnlySudoAccount<T> {
#[cfg(feature = "std")]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "CheckOnlySudoAccount")
}
#[cfg(not(feature = "std"))]
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
Ok(())
}
}
impl<T: Config + Send + Sync> CheckOnlySudoAccount<T> {
/// Creates new `SignedExtension` to check sudo key.
pub fn new() -> Self {
Self::default()
}
}
impl<T: Config + Send + Sync> SignedExtension for CheckOnlySudoAccount<T>
where
<T as Config>::RuntimeCall: Dispatchable<Info = DispatchInfo>,
{
const IDENTIFIER: &'static str = "CheckOnlySudoAccount";
type AccountId = T::AccountId;
type Call = <T as Config>::RuntimeCall;
type AdditionalSigned = ();
type Pre = ();
fn additional_signed(&self) -> Result<Self::AdditionalSigned, TransactionValidityError> {
Ok(())
}
fn validate(
&self,
who: &Self::AccountId,
_call: &Self::Call,
info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> TransactionValidity {
let sudo_key: T::AccountId = Key::<T>::get().ok_or(UnknownTransaction::CannotLookup)?;
ensure!(*who == sudo_key, InvalidTransaction::BadSigner);
Ok(ValidTransaction {
priority: info.weight.ref_time() as TransactionPriority,
..Default::default()
})
}
fn pre_dispatch(
self,
who: &Self::AccountId,
call: &Self::Call,
info: &DispatchInfoOf<Self::Call>,
len: usize,
) -> Result<Self::Pre, TransactionValidityError> {
self.validate(who, call, info, len).map(|_| ())
}
}

212
pallets/sudo/src/lib.rs Normal file
View File

@ -0,0 +1,212 @@
#![cfg_attr(not(feature = "std"), no_std)]
use sp_runtime::{traits::StaticLookup, DispatchResult};
use sp_std::prelude::*;
use frame_support::{dispatch::GetDispatchInfo, traits::UnfilteredDispatchable};
mod extension;
#[cfg(test)]
mod mock;
#[cfg(test)]
mod tests;
#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
pub mod weights;
pub use weights::WeightInfo;
pub use extension::CheckOnlySudoAccount;
pub use pallet::*;
type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
#[frame_support::pallet]
pub mod pallet {
use super::{DispatchResult, *};
use frame_support::pallet_prelude::*;
use frame_system::{pallet_prelude::*, RawOrigin};
pub mod config_preludes {
use super::*;
use frame_support::derive_impl;
pub struct TestDefaultConfig;
#[derive_impl(frame_system::config_preludes::TestDefaultConfig, no_aggregated_types)]
impl frame_system::DefaultConfig for TestDefaultConfig {}
#[frame_support::register_default_impl(TestDefaultConfig)]
impl DefaultConfig for TestDefaultConfig {
type WeightInfo = ();
#[inject_runtime_type]
type RuntimeEvent = ();
#[inject_runtime_type]
type RuntimeCall = ();
}
}
#[pallet::config(with_default)]
pub trait Config: frame_system::Config {
#[pallet::no_default_bounds]
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
#[pallet::no_default_bounds]
type RuntimeCall: Parameter
+ UnfilteredDispatchable<RuntimeOrigin = Self::RuntimeOrigin>
+ GetDispatchInfo;
type WeightInfo: WeightInfo;
}
#[pallet::pallet]
pub struct Pallet<T>(_);
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
#[pallet::weight({
let dispatch_info = call.get_dispatch_info();
(
T::WeightInfo::sudo().saturating_add(dispatch_info.weight),
dispatch_info.class
)
})]
pub fn sudo(
origin: OriginFor<T>,
call: Box<<T as Config>::RuntimeCall>,
) -> DispatchResultWithPostInfo {
Self::ensure_sudo(origin)?;
let res = call.dispatch_bypass_filter(RawOrigin::Root.into());
Self::deposit_event(Event::Sudid {
sudo_result: res.map(|_| ()).map_err(|e| e.error),
});
Ok(Pays::No.into())
}
#[pallet::call_index(1)]
#[pallet::weight((*weight, call.get_dispatch_info().class))]
pub fn sudo_unchecked_weight(
origin: OriginFor<T>,
call: Box<<T as Config>::RuntimeCall>,
weight: Weight,
) -> DispatchResultWithPostInfo {
Self::ensure_sudo(origin)?;
let _ = weight;
let res = call.dispatch_bypass_filter(RawOrigin::Root.into());
Self::deposit_event(Event::Sudid {
sudo_result: res.map(|_| ()).map_err(|e| e.error),
});
Ok(Pays::No.into())
}
#[pallet::call_index(2)]
#[pallet::weight(T::WeightInfo::set_key())]
pub fn set_key(
origin: OriginFor<T>,
new: AccountIdLookupOf<T>,
) -> DispatchResultWithPostInfo {
Self::ensure_sudo(origin)?;
let new = T::Lookup::lookup(new)?;
Self::deposit_event(Event::KeyChanged {
old: Key::<T>::get(),
new: new.clone(),
});
Key::<T>::put(new);
Ok(Pays::No.into())
}
#[pallet::call_index(3)]
#[pallet::weight({
let dispatch_info = call.get_dispatch_info();
(
T::WeightInfo::sudo_as().saturating_add(dispatch_info.weight),
dispatch_info.class,
)
})]
pub fn sudo_as(
origin: OriginFor<T>,
who: AccountIdLookupOf<T>,
call: Box<<T as Config>::RuntimeCall>,
) -> DispatchResultWithPostInfo {
Self::ensure_sudo(origin)?;
let who = T::Lookup::lookup(who)?;
let res = call.dispatch_bypass_filter(RawOrigin::Signed(who).into());
Self::deposit_event(Event::SudoAsDone {
sudo_result: res.map(|_| ()).map_err(|e| e.error),
});
Ok(Pays::No.into())
}
#[pallet::call_index(4)]
#[pallet::weight(T::WeightInfo::remove_key())]
pub fn remove_key(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
Self::ensure_sudo(origin)?;
Self::deposit_event(Event::KeyRemoved {});
Key::<T>::kill();
Ok(Pays::No.into())
}
}
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
Sudid {
sudo_result: DispatchResult,
},
KeyChanged {
old: Option<T::AccountId>,
new: T::AccountId,
},
KeyRemoved,
SudoAsDone {
sudo_result: DispatchResult,
},
}
#[pallet::error]
pub enum Error<T> {
RequireSudo,
}
#[pallet::storage]
pub(super) type Key<T: Config> = StorageValue<_, T::AccountId, OptionQuery>;
#[pallet::genesis_config]
#[derive(frame_support::DefaultNoBound)]
pub struct GenesisConfig<T: Config> {
pub key: Option<T::AccountId>,
}
#[pallet::genesis_build]
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
fn build(&self) {
Key::<T>::set(self.key.clone());
}
}
impl<T: Config> Pallet<T> {
pub(crate) fn ensure_sudo(origin: OriginFor<T>) -> DispatchResult {
let sender = ensure_signed_or_root(origin)?;
if let Some(sender) = sender {
if Key::<T>::get().map_or(false, |k| k == sender) {
Ok(())
} else {
Err(Error::<T>::RequireSudo.into())
}
} else {
Ok(())
}
}
}
}

127
pallets/sudo/src/mock.rs Normal file
View File

@ -0,0 +1,127 @@
use super::*;
use crate as sudo;
use frame_support::derive_impl;
use sp_io;
use sp_runtime::BuildStorage;
#[frame_support::pallet]
pub mod logger {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
#[pallet::config]
pub trait Config: frame_system::Config {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
}
#[pallet::pallet]
pub struct Pallet<T>(_);
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
#[pallet::weight(*weight)]
pub fn privileged_i32_log(
origin: OriginFor<T>,
i: i32,
weight: Weight,
) -> DispatchResultWithPostInfo {
ensure_root(origin)?;
<I32Log<T>>::try_append(i).map_err(|_| "could not append")?;
Self::deposit_event(Event::AppendI32 { value: i, weight });
Ok(().into())
}
#[pallet::call_index(1)]
#[pallet::weight(*weight)]
pub fn non_privileged_log(
origin: OriginFor<T>,
i: i32,
weight: Weight,
) -> DispatchResultWithPostInfo {
let sender = ensure_signed(origin)?;
<I32Log<T>>::try_append(i).map_err(|_| "could not append")?;
<AccountLog<T>>::try_append(sender.clone()).map_err(|_| "could not append")?;
Self::deposit_event(Event::AppendI32AndAccount {
sender,
value: i,
weight,
});
Ok(().into())
}
}
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
AppendI32 {
value: i32,
weight: Weight,
},
AppendI32AndAccount {
sender: T::AccountId,
value: i32,
weight: Weight,
},
}
#[pallet::storage]
#[pallet::getter(fn account_log)]
pub(super) type AccountLog<T: Config> =
StorageValue<_, BoundedVec<T::AccountId, ConstU32<1_000>>, ValueQuery>;
#[pallet::storage]
#[pallet::getter(fn i32_log)]
pub(super) type I32Log<T> = StorageValue<_, BoundedVec<i32, ConstU32<1_000>>, ValueQuery>;
}
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test
{
System: frame_system,
Sudo: sudo,
Logger: logger,
}
);
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for Test {
type Block = Block;
}
impl logger::Config for Test {
type RuntimeEvent = RuntimeEvent;
}
impl Config for Test {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type WeightInfo = ();
}
pub type SudoCall = sudo::Call<Test>;
pub type LoggerCall = logger::Call<Test>;
pub fn new_test_ext(root_key: u64) -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::<Test>::default()
.build_storage()
.unwrap();
sudo::GenesisConfig::<Test> {
key: Some(root_key),
}
.assimilate_storage(&mut t)
.unwrap();
let mut ext: sp_io::TestExternalities = t.into();
ext.execute_with(|| System::set_block_number(1));
ext
}
#[cfg(feature = "runtime-benchmarks")]
pub fn new_bench_ext() -> sp_io::TestExternalities {
frame_system::GenesisConfig::<Test>::default()
.build_storage()
.unwrap()
.into()
}

217
pallets/sudo/src/tests.rs Normal file
View File

@ -0,0 +1,217 @@
use super::*;
use frame_support::{assert_noop, assert_ok, weights::Weight};
use mock::{
new_test_ext, Logger, LoggerCall, RuntimeCall, RuntimeEvent as TestEvent, RuntimeOrigin, Sudo,
SudoCall, System, Test,
};
#[test]
fn test_setup_works() {
new_test_ext(1).execute_with(|| {
assert_eq!(Key::<Test>::get(), Some(1u64));
assert!(Logger::i32_log().is_empty());
assert!(Logger::account_log().is_empty());
});
}
#[docify::export]
#[test]
fn sudo_basics() {
new_test_ext(1).execute_with(|| {
let call = Box::new(RuntimeCall::Logger(LoggerCall::privileged_i32_log {
i: 42,
weight: Weight::from_parts(1_000, 0),
}));
assert_ok!(Sudo::sudo(RuntimeOrigin::signed(1), call));
assert_eq!(Logger::i32_log(), vec![42i32]);
let call = Box::new(RuntimeCall::Logger(LoggerCall::privileged_i32_log {
i: 42,
weight: Weight::from_parts(1_000, 0),
}));
assert_noop!(
Sudo::sudo(RuntimeOrigin::signed(2), call),
Error::<Test>::RequireSudo
);
});
}
#[test]
fn sudo_emits_events_correctly() {
new_test_ext(1).execute_with(|| {
let call = Box::new(RuntimeCall::Logger(LoggerCall::privileged_i32_log {
i: 42,
weight: Weight::from_parts(1, 0),
}));
assert_ok!(Sudo::sudo(RuntimeOrigin::signed(1), call));
System::assert_has_event(TestEvent::Sudo(Event::Sudid {
sudo_result: Ok(()),
}));
})
}
#[test]
fn sudo_unchecked_weight_basics() {
new_test_ext(1).execute_with(|| {
let call = Box::new(RuntimeCall::Logger(LoggerCall::privileged_i32_log {
i: 42,
weight: Weight::from_parts(1_000, 0),
}));
assert_ok!(Sudo::sudo_unchecked_weight(
RuntimeOrigin::signed(1),
call,
Weight::from_parts(1_000, 0)
));
assert_eq!(Logger::i32_log(), vec![42i32]);
let call = Box::new(RuntimeCall::Logger(LoggerCall::privileged_i32_log {
i: 42,
weight: Weight::from_parts(1_000, 0),
}));
assert_noop!(
Sudo::sudo_unchecked_weight(
RuntimeOrigin::signed(2),
call,
Weight::from_parts(1_000, 0)
),
Error::<Test>::RequireSudo,
);
assert_eq!(Logger::i32_log(), vec![42i32]);
let call = Box::new(RuntimeCall::Logger(LoggerCall::privileged_i32_log {
i: 42,
weight: Weight::from_parts(1, 0),
}));
let sudo_unchecked_weight_call = SudoCall::sudo_unchecked_weight {
call,
weight: Weight::from_parts(1_000, 0),
};
let info = sudo_unchecked_weight_call.get_dispatch_info();
assert_eq!(info.weight, Weight::from_parts(1_000, 0));
});
}
#[test]
fn sudo_unchecked_weight_emits_events_correctly() {
new_test_ext(1).execute_with(|| {
let call = Box::new(RuntimeCall::Logger(LoggerCall::privileged_i32_log {
i: 42,
weight: Weight::from_parts(1, 0),
}));
assert_ok!(Sudo::sudo_unchecked_weight(
RuntimeOrigin::signed(1),
call,
Weight::from_parts(1_000, 0)
));
System::assert_has_event(TestEvent::Sudo(Event::Sudid {
sudo_result: Ok(()),
}));
})
}
#[docify::export]
#[test]
fn set_key_basics() {
new_test_ext(1).execute_with(|| {
assert_ok!(Sudo::set_key(RuntimeOrigin::signed(1), 2));
assert_eq!(Key::<Test>::get(), Some(2u64));
});
new_test_ext(1).execute_with(|| {
assert_noop!(
Sudo::set_key(RuntimeOrigin::signed(2), 3),
Error::<Test>::RequireSudo
);
});
}
#[test]
fn set_key_emits_events_correctly() {
new_test_ext(1).execute_with(|| {
assert_ok!(Sudo::set_key(RuntimeOrigin::signed(1), 2));
System::assert_has_event(TestEvent::Sudo(Event::KeyChanged {
old: Some(1),
new: 2,
}));
assert_ok!(Sudo::set_key(RuntimeOrigin::signed(2), 4));
System::assert_has_event(TestEvent::Sudo(Event::KeyChanged {
old: Some(2),
new: 4,
}));
});
}
#[test]
fn remove_key_works() {
new_test_ext(1).execute_with(|| {
assert_ok!(Sudo::remove_key(RuntimeOrigin::signed(1)));
assert!(Key::<Test>::get().is_none());
System::assert_has_event(TestEvent::Sudo(Event::KeyRemoved {}));
assert_noop!(
Sudo::remove_key(RuntimeOrigin::signed(1)),
Error::<Test>::RequireSudo
);
assert_noop!(
Sudo::set_key(RuntimeOrigin::signed(1), 1),
Error::<Test>::RequireSudo
);
});
}
#[test]
fn using_root_origin_works() {
new_test_ext(1).execute_with(|| {
assert_ok!(Sudo::remove_key(RuntimeOrigin::root()));
assert!(Key::<Test>::get().is_none());
System::assert_has_event(TestEvent::Sudo(Event::KeyRemoved {}));
assert_ok!(Sudo::set_key(RuntimeOrigin::root(), 1));
assert_eq!(Some(1), Key::<Test>::get());
});
}
#[test]
fn sudo_as_basics() {
new_test_ext(1).execute_with(|| {
let call = Box::new(RuntimeCall::Logger(LoggerCall::privileged_i32_log {
i: 42,
weight: Weight::from_parts(1_000, 0),
}));
assert_ok!(Sudo::sudo_as(RuntimeOrigin::signed(1), 2, call));
assert!(Logger::i32_log().is_empty());
assert!(Logger::account_log().is_empty());
let call = Box::new(RuntimeCall::Logger(LoggerCall::non_privileged_log {
i: 42,
weight: Weight::from_parts(1, 0),
}));
assert_noop!(
Sudo::sudo_as(RuntimeOrigin::signed(3), 2, call),
Error::<Test>::RequireSudo
);
let call = Box::new(RuntimeCall::Logger(LoggerCall::non_privileged_log {
i: 42,
weight: Weight::from_parts(1, 0),
}));
assert_ok!(Sudo::sudo_as(RuntimeOrigin::signed(1), 2, call));
assert_eq!(Logger::i32_log(), vec![42i32]);
assert_eq!(Logger::account_log(), vec![2]);
});
}
#[docify::export]
#[test]
fn sudo_as_emits_events_correctly() {
new_test_ext(1).execute_with(|| {
let call = Box::new(RuntimeCall::Logger(LoggerCall::non_privileged_log {
i: 42,
weight: Weight::from_parts(1, 0),
}));
assert_ok!(Sudo::sudo_as(RuntimeOrigin::signed(1), 2, call));
System::assert_has_event(TestEvent::Sudo(Event::SudoAsDone {
sudo_result: Ok(()),
}));
});
}

156
pallets/sudo/src/weights.rs Normal file
View File

@ -0,0 +1,156 @@
// This file is part of Ghost Network.
// Ghost Network is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Ghost Network is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Ghost Network. If not, see <http://www.gnu.org/licenses/>.
//! Autogenerated weights for `ghost_sudo`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
//! DATE: 2025-07-28, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `ghostown`, CPU: `Intel(R) Core(TM) i3-2310M CPU @ 2.10GHz`
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("casper-dev")`, DB CACHE: 1024
// Executed Command:
// ./target/release/ghost
// benchmark
// pallet
// --chain=casper-dev
// --steps=50
// --repeat=20
// --pallet=ghost-sudo
// --extrinsic=*
// --wasm-execution=compiled
// --heap-pages=4096
// --header=./file_header.txt
// --output=./runtime/casper/src/weights/ghost_sudo.rs
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(missing_docs)]
use frame_support::{
traits::Get,
weights::{Weight, constants::RocksDbWeight},
};
use core::marker::PhantomData;
/// Weight functions needed for `pallet_sudo`.
pub trait WeightInfo {
fn set_key() -> Weight;
fn sudo() -> Weight;
fn sudo_as() -> Weight;
fn remove_key() -> Weight;
}
/// Weight functions for `ghost_sudo`.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// Storage: `GhostSudo::Key` (r:1 w:1)
/// Proof: `GhostSudo::Key` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
fn set_key() -> Weight {
// Proof Size summary in bytes:
// Measured: `165`
// Estimated: `1517`
// Minimum execution time: 40_014_000 picoseconds.
Weight::from_parts(40_856_000, 0)
.saturating_add(Weight::from_parts(0, 1517))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `GhostSudo::Key` (r:1 w:0)
/// Proof: `GhostSudo::Key` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
fn sudo() -> Weight {
// Proof Size summary in bytes:
// Measured: `165`
// Estimated: `1517`
// Minimum execution time: 44_086_000 picoseconds.
Weight::from_parts(45_920_000, 0)
.saturating_add(Weight::from_parts(0, 1517))
.saturating_add(T::DbWeight::get().reads(1))
}
/// Storage: `GhostSudo::Key` (r:1 w:0)
/// Proof: `GhostSudo::Key` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
fn sudo_as() -> Weight {
// Proof Size summary in bytes:
// Measured: `165`
// Estimated: `1517`
// Minimum execution time: 44_106_000 picoseconds.
Weight::from_parts(44_650_000, 0)
.saturating_add(Weight::from_parts(0, 1517))
.saturating_add(T::DbWeight::get().reads(1))
}
/// Storage: `GhostSudo::Key` (r:1 w:1)
/// Proof: `GhostSudo::Key` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
fn remove_key() -> Weight {
// Proof Size summary in bytes:
// Measured: `165`
// Estimated: `1517`
// Minimum execution time: 36_416_000 picoseconds.
Weight::from_parts(37_373_000, 0)
.saturating_add(Weight::from_parts(0, 1517))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
}
// For backwards compatibility and tests.
impl WeightInfo for () {
/// Storage: `GhostSudo::Key` (r:1 w:1)
/// Proof: `GhostSudo::Key` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
fn set_key() -> Weight {
// Proof Size summary in bytes:
// Measured: `165`
// Estimated: `1517`
// Minimum execution time: 40_014_000 picoseconds.
Weight::from_parts(40_856_000, 0)
.saturating_add(Weight::from_parts(0, 1517))
.saturating_add(RocksDbWeight::get().reads(1))
.saturating_add(RocksDbWeight::get().writes(1))
}
/// Storage: `GhostSudo::Key` (r:1 w:0)
/// Proof: `GhostSudo::Key` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
fn sudo() -> Weight {
// Proof Size summary in bytes:
// Measured: `165`
// Estimated: `1517`
// Minimum execution time: 44_086_000 picoseconds.
Weight::from_parts(45_920_000, 0)
.saturating_add(Weight::from_parts(0, 1517))
.saturating_add(RocksDbWeight::get().reads(1))
}
/// Storage: `GhostSudo::Key` (r:1 w:0)
/// Proof: `GhostSudo::Key` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
fn sudo_as() -> Weight {
// Proof Size summary in bytes:
// Measured: `165`
// Estimated: `1517`
// Minimum execution time: 44_106_000 picoseconds.
Weight::from_parts(44_650_000, 0)
.saturating_add(Weight::from_parts(0, 1517))
.saturating_add(RocksDbWeight::get().reads(1))
}
/// Storage: `GhostSudo::Key` (r:1 w:1)
/// Proof: `GhostSudo::Key` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
fn remove_key() -> Weight {
// Proof Size summary in bytes:
// Measured: `165`
// Estimated: `1517`
// Minimum execution time: 36_416_000 picoseconds.
Weight::from_parts(37_373_000, 0)
.saturating_add(Weight::from_parts(0, 1517))
.saturating_add(RocksDbWeight::get().reads(1))
.saturating_add(RocksDbWeight::get().writes(1))
}
}

2
pallets/traits/Cargo.toml Executable file → Normal file
View File

@ -1,6 +1,6 @@
[package]
name = "ghost-traits"
version = "0.3.19"
version = "0.3.23"
license.workspace = true
authors.workspace = true
edition.workspace = true

0
pallets/traits/src/lib.rs Executable file → Normal file
View File

26
pallets/traits/src/networks.rs Executable file → Normal file
View File

@ -1,10 +1,7 @@
use frame_support::{
pallet_prelude::*,
storage::PrefixIterator,
};
use frame_support::{pallet_prelude::*, storage::PrefixIterator};
use sp_runtime::{
DispatchResult,
traits::{AtLeast32BitUnsigned, Member},
DispatchResult,
};
pub trait NetworkDataBasicHandler {
@ -21,9 +18,26 @@ pub trait NetworkDataBasicHandler {
pub trait NetworkDataInspectHandler<Network>: NetworkDataBasicHandler {
fn get(n: &Self::NetworkId) -> Option<Network>;
fn iter() -> PrefixIterator<(Self::NetworkId, Network)>;
fn is_nullification_period() -> bool;
}
pub trait NetworkDataMutateHandler<Network>: NetworkDataInspectHandler<Network> {
pub trait NetworkDataMutateHandler<Network, Balance>: NetworkDataInspectHandler<Network> {
fn register(chain_id: Self::NetworkId, network: Network) -> DispatchResult;
fn remove(chain_id: Self::NetworkId) -> DispatchResult;
fn increase_gatekeeper_amount(
chain_id: &Self::NetworkId,
amount: &Balance,
) -> Result<Balance, ()>;
fn decrease_gatekeeper_amount(
chain_id: &Self::NetworkId,
amount: &Balance,
) -> Result<Balance, ()>;
fn accumulate_outgoing_imbalance(amount: &Balance) -> Result<Balance, ()>;
fn accumulate_incoming_imbalance(amount: &Balance) -> Result<Balance, ()>;
fn accumulate_commission(commission: &Balance) -> Result<Balance, ()>;
fn nullify_commission();
fn trigger_nullification();
}

0
rpc/Cargo.toml Executable file → Normal file
View File

58
rpc/src/lib.rs Executable file → Normal file
View File

@ -1,17 +1,15 @@
use std::sync::Arc;
use jsonrpsee::RpcModule;
use primitives::{
AccountId, Balance, Block, BlockNumber, Hash, Nonce,
};
use sc_client_api::AuxStore;
use babe_primitives::BabeApi;
use block_builder_api::BlockBuilder;
use consensus_common::SelectChain;
use grandpa::FinalityProofProvider;
use jsonrpsee::RpcModule;
use primitives::{AccountId, Balance, Block, BlockNumber, Hash, Nonce};
use sc_client_api::AuxStore;
pub use sc_rpc::{DenyUnsafe, SubscriptionTaskExecutor};
use sp_api::ProvideRuntimeApi;
use block_builder_api::BlockBuilder;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
use consensus_common::SelectChain;
use babe_primitives::BabeApi;
use sp_keystore::KeystorePtr;
use tx_pool_api::TransactionPool;
@ -61,7 +59,16 @@ pub struct FullDeps<C, P, SC, B> {
}
pub fn create_full_rpc<C, P, SC, B>(
FullDeps { client, pool, select_chain, chain_spec, deny_unsafe, babe, grandpa, backend } : FullDeps<C, P, SC, B>,
FullDeps {
client,
pool,
select_chain,
chain_spec,
deny_unsafe,
babe,
grandpa,
backend,
}: FullDeps<C, P, SC, B>,
) -> Result<RpcExtension, Box<dyn std::error::Error + Send + Sync>>
where
C: ProvideRuntimeApi<Block>
@ -80,20 +87,19 @@ where
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
B::State: sc_client_api::StateBackend<sp_runtime::traits::HashingFor<Block>>,
{
use frame_rpc_system::{System, SystemApiServer};
use pallet_transaction_payment_rpc::{
TransactionPayment, TransactionPaymentApiServer,
};
use babe_rpc::{Babe, BabeApiServer};
use frame_rpc_system::{System, SystemApiServer};
use grandpa_rpc::{Grandpa, GrandpaApiServer};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use sc_rpc_spec_v2::chain_spec::{ChainSpec, ChainSpecApiServer};
use sc_sync_state_rpc::{SyncState, SyncStateApiServer};
use substrate_state_trie_migration_rpc::{
StateMigration, StateMigrationApiServer,
};
use substrate_state_trie_migration_rpc::{StateMigration, StateMigrationApiServer};
let mut io = RpcModule::new(());
let BabeDeps { babe_worker_handle, keystore } = babe;
let BabeDeps {
babe_worker_handle,
keystore,
} = babe;
let GrandpaDeps {
shared_voter_state,
shared_authority_set,
@ -103,10 +109,13 @@ where
} = grandpa;
let chain_name = chain_spec.name().to_string();
let genesis_hash = client.hash(0).ok().flatten().expect("Genesis block exists; qed;");
let genesis_hash = client
.hash(0)
.ok()
.flatten()
.expect("Genesis block exists; qed;");
let properties = chain_spec.properties();
io.merge(ChainSpec::new(chain_name, genesis_hash, properties).into_rpc())?;
io.merge(StateMigration::new(client.clone(), backend.clone(), deny_unsafe).into_rpc())?;
io.merge(System::new(client.clone(), pool.clone(), deny_unsafe).into_rpc())?;
@ -119,7 +128,8 @@ where
keystore,
select_chain,
deny_unsafe,
).into_rpc()
)
.into_rpc(),
)?;
io.merge(
@ -129,7 +139,8 @@ where
shared_voter_state,
justification_stream,
finality_provider,
).into_rpc(),
)
.into_rpc(),
)?;
io.merge(
@ -137,8 +148,9 @@ where
chain_spec,
client.clone(),
shared_authority_set,
babe_worker_handle
)?.into_rpc(),
babe_worker_handle,
)?
.into_rpc(),
)?;
Ok(io)

6
runtime/casper/Cargo.toml Executable file → Normal file
View File

@ -1,6 +1,6 @@
[package]
name = "casper-runtime"
version = "3.5.20"
version = "3.5.30"
build = "build.rs"
description = "Runtime of the Casper Network"
edition.workspace = true
@ -87,6 +87,7 @@ pallet-whitelist = { workspace = true }
ghost-networks = { workspace = true }
ghost-claims = { workspace = true }
ghost-slow-clap = { workspace = true }
ghost-sudo = { workspace = true }
casper-runtime-constants = { workspace = true }
runtime-common = { workspace = true }
primitives = { workspace = true }
@ -205,6 +206,7 @@ std = [
"ghost-networks/std",
"ghost-claims/std",
"ghost-slow-clap/std",
"ghost-sudo/std",
"casper-runtime-constants/std",
"runtime-common/std",
"primitives/std",
@ -252,6 +254,7 @@ runtime-benchmarks = [
"ghost-networks/runtime-benchmarks",
"ghost-claims/runtime-benchmarks",
"ghost-slow-clap/runtime-benchmarks",
"ghost-sudo/runtime-benchmarks",
"runtime-common/runtime-benchmarks",
]
try-runtime = [
@ -297,5 +300,6 @@ try-runtime = [
"ghost-networks/try-runtime",
"ghost-claims/try-runtime",
"ghost-slow-clap/try-runtime",
"ghost-sudo/try-runtime",
"runtime-common/try-runtime",
]

0
runtime/casper/build.rs Executable file → Normal file
View File

3
runtime/casper/constants/Cargo.toml Executable file → Normal file
View File

@ -28,3 +28,6 @@ std = [
"sp-runtime/std",
"sp-weights/std",
]
# Set timing constants (e.g session period) to faster versions to speed up testing.
fast-runtime = []

2
runtime/casper/constants/src/lib.rs Executable file → Normal file
View File

@ -86,7 +86,7 @@ pub mod fee {
#[cfg(test)]
mod tests {
use super::{
currency::{STNK, STRH, CSPR},
currency::{CSPR, STNK, STRH},
fee::WeightToFee,
};
use crate::weights::ExtrinsicBaseWeight;

View File

@ -1,9 +1,9 @@
pub mod block_weights;
pub mod extrinsic_weights;
pub mod rocksdb_weights;
pub mod paritydb_weights;
pub mod rocksdb_weights;
pub use block_weights::BlockExecutionWeight;
pub use extrinsic_weights::ExtrinsicBaseWeight;
pub use rocksdb_weights::constants::RocksDbWeight;
pub use paritydb_weights::constants::ParityDbWeight;
pub use rocksdb_weights::constants::RocksDbWeight;

View File

@ -1,4 +1,3 @@
//! Autogenerated bag thresholds.
//!
//! Generated on 2024-06-30T17:36:29.986756974+00:00

48
runtime/casper/src/cult/mod.rs Executable file → Normal file
View File

@ -2,25 +2,34 @@ use super::*;
use frame_support::{
parameter_types,
traits::{
EitherOf, EitherOfDiverse, MapSuccess, OriginTrait, TryWithMorphedArg,
tokens::pay::PayFromAccount,
tokens::pay::PayFromAccount, EitherOf, EitherOfDiverse, MapSuccess, OriginTrait,
TryWithMorphedArg,
},
};
use frame_system::EnsureRootWithSuccess;
use pallet_ranked_collective::EnsureOfRank;
use sp_core::{ConstU128, ConstU32};
use sp_runtime::traits::{ConstU16, TakeFirst};
use pallet_ranked_collective::EnsureOfRank;
use crate::{
AccountId,
Balance,
Balances,
Preimage,
Runtime,
// weights,
RuntimeCall, RuntimeEvent, Scheduler, DAYS, CSPR, AccountId, Balance,
TreasuryAccount, Balances, Preimage, Runtime,
RuntimeCall,
RuntimeEvent,
Scheduler,
TreasuryAccount,
CSPR,
DAYS,
};
mod origins;
pub use origins::{
pallet_cult_origins, Geniuses, Degens, Zombies, Skeletons, Ghosts,
EnsureCanRetainAt, EnsureCanPromoteTo, EnsureCult, ToVoice, CultTreasurySpender,
pallet_cult_origins, CultTreasurySpender, Degens, EnsureCanPromoteTo, EnsureCanRetainAt,
EnsureCult, Geniuses, Ghosts, Skeletons, ToVoice, Zombies,
};
mod tracks;
@ -45,14 +54,10 @@ parameter_types! {
impl pallet_whitelist::Config for Runtime {
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type WhitelistOrigin = EitherOfDiverse<
EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>,
Skeletons,
>;
type DispatchWhitelistedOrigin = EitherOf<
EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>,
Geniuses,
>;
type WhitelistOrigin =
EitherOfDiverse<EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>, Skeletons>;
type DispatchWhitelistedOrigin =
EitherOf<EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>, Geniuses>;
type Preimages = Preimage;
type WeightInfo = weights::pallet_whitelist::WeightInfo<Runtime>;
}
@ -65,7 +70,7 @@ parameter_types! {
pub type CultReferendaInstance = pallet_referenda::Instance1;
impl pallet_referenda::Config<CultReferendaInstance> for Runtime {
type WeightInfo = ();
type WeightInfo = weights::pallet_referenda::WeightInfo<Runtime>;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type Scheduler = Scheduler;
@ -81,7 +86,7 @@ impl pallet_referenda::Config<CultReferendaInstance> for Runtime {
(AccountId, u16),
>,
TakeFirst,
>
>,
>;
type CancelOrigin = Skeletons;
type KillOrigin = Ghosts;
@ -135,10 +140,13 @@ impl pallet_core_fellowship::Config<CultCoreInstance> for Runtime {
type Members = pallet_ranked_collective::Pallet<Runtime, CultCollectiveInstance>;
type Balance = Balance;
type ParamsOrigin = EitherOf<EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>, Skeletons>;
type ParamsOrigin =
EitherOf<EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>, Skeletons>;
type InductOrigin = EitherOf<EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>, Zombies>;
type ApproveOrigin = EitherOf<EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>, EnsureCanRetainAt>;
type PromoteOrigin = EitherOf<EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>, EnsureCanPromoteTo>;
type ApproveOrigin =
EitherOf<EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>, EnsureCanRetainAt>;
type PromoteOrigin =
EitherOf<EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>, EnsureCanPromoteTo>;
type EvidenceSize = ConstU32<65536>;
}

2
runtime/casper/src/cult/origins.rs Executable file → Normal file
View File

@ -5,8 +5,8 @@ pub use pallet_cult_origins::*;
#[frame_support::pallet]
pub mod pallet_cult_origins {
use crate::{Balance, CSPR};
use super::ranks;
use crate::{Balance, CSPR};
use frame_support::pallet_prelude::*;
use pallet_ranked_collective::Rank;

5
runtime/casper/src/cult/tracks.rs Executable file → Normal file
View File

@ -1,4 +1,4 @@
use crate::{Balance, BlockNumber, RuntimeOrigin, DAYS, CSPR, HOURS, MINUTES};
use crate::{Balance, BlockNumber, RuntimeOrigin, CSPR, DAYS, HOURS, MINUTES};
use pallet_ranked_collective::Rank;
use sp_runtime::{traits::Convert, Perbill};
@ -255,7 +255,6 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 15
min_support: RETAIN_MIN_SUPPORT,
},
),
(
constants::PROMOTE_TO_GENIUSES,
pallet_referenda::TrackInfo {
@ -347,7 +346,7 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
// It is important that this is NOT availiable in production!
let root: Self::RuntimeOrigin = frame_system::RawOrigin::Root.into();
if &root == id {
return Ok(tracks::GHOSTS)
return Ok(tracks::GHOSTS);
}
}

View File

@ -3,20 +3,20 @@ use pallet_staking::Forcing;
use sp_staking::StakerStatus;
use crate::{opaque::SessionKeys, BABE_GENESIS_EPOCH_CONFIG};
use primitives::{AccountId, AccountPublic};
use casper_runtime_constants::currency::CSPR;
use primitives::{AccountId, AccountPublic};
use ghost_slow_clap::sr25519::AuthorityId as SlowClapId;
use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
use babe_primitives::AuthorityId as BabeId;
use ghost_slow_clap::sr25519::AuthorityId as SlowClapId;
use grandpa_primitives::AuthorityId as GrandpaId;
use sp_core::{sr25519, Pair, Public};
use sp_runtime::{traits::IdentifyAccount, Perbill};
#[cfg(not(feature = "std"))]
use sp_std::alloc::format;
use sp_std::vec::Vec;
use sp_std::prelude::*;
use sp_core::{sr25519, Pair, Public};
use sp_runtime::{Perbill, traits::IdentifyAccount};
use sp_std::vec::Vec;
#[derive(Encode, Clone)]
struct PreparedNetworkData {
@ -84,40 +84,69 @@ fn casper_testnet_accounts() -> Vec<AccountId> {
fn casper_testnet_evm_accounts() -> Vec<(AccountId, u128, u8)> {
vec![
// 01c928771aea942a1e7ac06adf2b73dfbc9a25d9eaa516e3673116af7f345198
(get_account_id_from_seed::<sr25519::Public>("1A69d2D5568D1878023EeB121a73d33B9116A760"), 1337 * CSPR, 1),
(
get_account_id_from_seed::<sr25519::Public>("1A69d2D5568D1878023EeB121a73d33B9116A760"),
1337 * CSPR,
1,
),
// b19a435901872f817185f7234a1484eae837613f9d10cf21927a23c2d8cb9139
(get_account_id_from_seed::<sr25519::Public>("2f86cfBED3fbc1eCf2989B9aE5fc019a837A9C12"), 1337 * CSPR, 2),
(
get_account_id_from_seed::<sr25519::Public>("2f86cfBED3fbc1eCf2989B9aE5fc019a837A9C12"),
1337 * CSPR,
2,
),
// d3baf57b74d65719b2dc33f5a464176022d0cc5edbca002234229f3e733875fc
(get_account_id_from_seed::<sr25519::Public>("e83f67361Ac74D42A48E2DAfb6706eb047D8218D"), 69 * CSPR, 3),
(
get_account_id_from_seed::<sr25519::Public>("e83f67361Ac74D42A48E2DAfb6706eb047D8218D"),
69 * CSPR,
3,
),
// c4683d566436af6b58b4a59c8f501319226e85b21869bf93d5eeb4596d4791d4
(get_account_id_from_seed::<sr25519::Public>("827ee4ad9b259b6fa1390ed60921508c78befd63"), 69 * CSPR, 4),
(
get_account_id_from_seed::<sr25519::Public>("827ee4ad9b259b6fa1390ed60921508c78befd63"),
69 * CSPR,
4,
),
]
}
fn casper_testnet_evm_networks() -> Vec<(u32, Vec<u8>)> {
vec![
(1, PreparedNetworkData {
(
1,
PreparedNetworkData {
chain_name: "ethereum-mainnet".into(),
default_endpoint: "https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7/".into(),
default_endpoint:
"https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7/".into(),
finality_delay: Some(40),
release_delay: Some(80),
network_type: Default::default(),
gatekeeper: "0x4d224452801aced8b2f0aebe155379bb5d594381".into(),
topic_name: "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef".into(),
topic_name: "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
.into(),
incoming_fee: 0,
outgoing_fee: 0,
}.encode()),
(56, PreparedNetworkData {
}
.encode(),
),
(
56,
PreparedNetworkData {
chain_name: "bnb-mainnet".into(),
default_endpoint: "https://bsc-mainnet.core.chainstack.com/35848e183f3e3303c8cfeacbea831cab/".into(),
default_endpoint:
"https://bsc-mainnet.core.chainstack.com/35848e183f3e3303c8cfeacbea831cab/"
.into(),
finality_delay: Some(20),
release_delay: Some(40),
network_type: Default::default(),
gatekeeper: "0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82".into(),
topic_name: "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef".into(),
topic_name: "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
.into(),
incoming_fee: 0,
outgoing_fee: 0,
}.encode())
}
.encode(),
),
]
}
@ -127,7 +156,12 @@ fn casper_session_keys(
authority_discovery: AuthorityDiscoveryId,
slow_clap: SlowClapId,
) -> SessionKeys {
SessionKeys { babe, grandpa, authority_discovery, slow_clap }
SessionKeys {
babe,
grandpa,
authority_discovery,
slow_clap,
}
}
fn testnet_config_genesis(
@ -143,8 +177,7 @@ fn testnet_config_genesis(
ghost_accounts: Option<Vec<(AccountId, u128, u8)>>,
evm_networks: Option<Vec<(u32, Vec<u8>)>>,
) -> serde_json::Value {
let endowed_accounts: Vec<AccountId> =
endowed_accounts.unwrap_or_else(casper_testnet_accounts);
let endowed_accounts: Vec<AccountId> = endowed_accounts.unwrap_or_else(casper_testnet_accounts);
let ghost_accounts: Vec<(AccountId, u128, u8)> =
ghost_accounts.unwrap_or_else(casper_testnet_evm_accounts);
@ -218,7 +251,9 @@ fn testnet_config_genesis(
fn casper_development_config_genesis() -> serde_json::Value {
testnet_config_genesis(
vec![get_authority_keys_from_seed("Alice")],
None, None, None,
None,
None,
None,
)
}
@ -229,7 +264,9 @@ fn casper_local_config_genesis() -> serde_json::Value {
get_authority_keys_from_seed("Alice"),
get_authority_keys_from_seed("Bob"),
],
None, None, None,
None,
None,
None,
)
}
@ -240,9 +277,11 @@ pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option<sp_std::vec::Vec<
Ok("local_testnet") => casper_local_config_genesis(),
_ => return None,
};
Some(serde_json::to_string(&patch)
Some(
serde_json::to_string(&patch)
.expect("serialization to json is expected to work; qed")
.into_bytes())
.into_bytes(),
)
}
/// Returns a list of identifiers for available builtin `RuntimeGenesisConfig` presets.

View File

@ -1,8 +1,5 @@
use super::*;
use frame_support::{
dispatch::DispatchResultWithPostInfo,
traits::PrivilegeCmp,
};
use frame_support::{dispatch::DispatchResultWithPostInfo, traits::PrivilegeCmp};
use pallet_alliance::{ProposalIndex, ProposalProvider};
use sp_runtime::DispatchError;
use sp_std::{cmp::Ordering, marker::PhantomData};
@ -14,7 +11,8 @@ type HashOf<T> = <T as frame_system::Config>::Hash;
/// Proposal provider for alliance pallet.
/// Adapter from collective pallet to alliance proposal provider trait.
pub struct AllianceProposalProvider<T, I = ()>(PhantomData<(T, I)>);
impl <T, I> ProposalProvider<AccountIdOf<T>, HashOf<T>, ProposalOf<T, I>> for AllianceProposalProvider<T, I>
impl<T, I> ProposalProvider<AccountIdOf<T>, HashOf<T>, ProposalOf<T, I>>
for AllianceProposalProvider<T, I>
where
T: pallet_collective::Config<I> + frame_system::Config,
I: 'static,
@ -25,7 +23,12 @@ where
proposal: Box<ProposalOf<T, I>>,
length_bound: u32,
) -> Result<(u32, u32), DispatchError> {
pallet_collective::Pallet::<T, I>::do_propose_proposed(who, threshold, proposal, length_bound)
pallet_collective::Pallet::<T, I>::do_propose_proposed(
who,
threshold,
proposal,
length_bound,
)
}
fn vote_proposal(
@ -61,7 +64,7 @@ pub struct EqualOrGreatestRootCmp;
impl PrivilegeCmp<OriginCaller> for EqualOrGreatestRootCmp {
fn cmp_privilege(left: &OriginCaller, right: &OriginCaller) -> Option<Ordering> {
if left == right {
return Some(Ordering::Equal)
return Some(Ordering::Equal);
}
match (left, right) {

309
runtime/casper/src/lib.rs Executable file → Normal file
View File

@ -1,63 +1,59 @@
#![cfg_attr(not(feature = "std"), no_std)]
// `construct_runtime!` does a lot of recursion and requires us to increase
// the limit to 256
#![recursion_limit = "256"]
use frame_system::{EnsureRoot, EnsureRootWithSuccess};
use runtime_common::{
impls::DealWithFees, BlockHashCount, BlockLength, CurrencyToVote,
SlowAdjustingFeeUpdate, impl_runtime_weights, prod_or_fast,
};
use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
use frame_election_provider_support::{
generate_solution_type, onchain, SequentialPhragmen,
bounds::ElectionBoundsBuilder,
bounds::ElectionBoundsBuilder, generate_solution_type, onchain, SequentialPhragmen,
};
use frame_support::{
construct_runtime, parameter_types,
construct_runtime,
genesis_builder_helper::{build_state, get_preset},
parameter_types,
traits::{
fungible::HoldConsideration,
tokens::UnityAssetBalanceConversion,
ConstU128, ConstU32, EitherOf, EitherOfDiverse, InstanceFilter,
KeyOwnerProofSystem, LinearStoragePrice, WithdrawReasons,
fungible::HoldConsideration, tokens::UnityAssetBalanceConversion, ConstU128, ConstU32,
EitherOf, EitherOfDiverse, InstanceFilter, KeyOwnerProofSystem, LinearStoragePrice,
WithdrawReasons,
},
weights::ConstantMultiplier, PalletId
weights::ConstantMultiplier,
PalletId,
};
use frame_system::{EnsureRoot, EnsureRootWithSuccess};
use runtime_common::{
impl_runtime_weights, impls::DealWithFees, prod_or_fast, BlockHashCount, BlockLength,
CurrencyToVote, SlowAdjustingFeeUpdate,
};
use frame_support::traits::tokens::pay::PayFromAccount;
#[cfg(feature = "runtime-benchmarks")]
use runtime_common::benchmarking::BenchmarkTreasuryHelper;
use frame_support::traits::tokens::pay::PayFromAccount;
use pallet_transaction_payment::FungibleAdapter;
use codec::{Decode, Encode, MaxEncodedLen};
use ghost_slow_clap::sr25519::AuthorityId as SlowClapId;
use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId};
use pallet_identity::legacy::IdentityInfo;
use ghost_slow_clap::sr25519::AuthorityId as SlowClapId;
use pallet_session::historical as session_historical;
use pallet_transaction_payment::FungibleAdapter;
use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo};
use codec::{Decode, Encode, MaxEncodedLen};
use primitives::{
AccountId, AccountIndex, Balance, BlockNumber, Hash, Moment, Nonce,
Signature, ReserveIdentifier,
AccountId, AccountIndex, Balance, BlockNumber, Hash, Moment, Nonce, ReserveIdentifier,
Signature,
};
use sp_core::OpaqueMetadata;
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys, FixedU128,
curve::PiecewiseLinear,
traits::{
AccountIdLookup, BlakeTwo256, Block as BlockT, Extrinsic as ExtrinsicT,
OpaqueKeys, SaturatedConversion, Verify, IdentityLookup, ConvertInto,
ConstU16,
},
transaction_validity::{
TransactionPriority, TransactionSource, TransactionValidity,
},
ApplyExtrinsicResult, KeyTypeId, Perbill, Percent, Permill,
RuntimeDebug,
};
use sp_genesis_builder::PresetId;
use sp_runtime::{
create_runtime_str,
curve::PiecewiseLinear,
generic, impl_opaque_keys,
traits::{
AccountIdLookup, BlakeTwo256, Block as BlockT, ConstU16, ConvertInto,
Extrinsic as ExtrinsicT, IdentityLookup, OpaqueKeys, SaturatedConversion, Verify,
},
transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity},
ApplyExtrinsicResult, FixedU128, KeyTypeId, Perbill, Percent, Permill, RuntimeDebug,
};
use sp_std::prelude::*;
#[cfg(any(feature = "std", test))]
use sp_version::NativeVersion;
@ -75,20 +71,20 @@ pub use pallet_timestamp::Call as TimestampCall;
pub use sp_runtime::BuildStorage;
/// Constant values used within the runtime.
use casper_runtime_constants::{currency::*, time::*, fee::*};
use casper_runtime_constants::{currency::*, fee::*, time::*};
mod weights;
mod bag_thresholds;
mod impls;
mod genesis_config_presets;
mod impls;
mod weights;
pub use impls::{AllianceProposalProvider, EqualOrGreatestRootCmp};
// Governance configuration.
pub mod cult;
use cult::{
pallet_cult_origins, CultCollectiveInstance, CultTreasurySpender,
Geniuses, Degens, Zombies, Skeletons, Ghosts,
pallet_cult_origins, CultCollectiveInstance, CultTreasurySpender, Degens, Geniuses, Ghosts,
Skeletons, Zombies,
};
pub const LOG_TARGET: &str = "runtime::casper";
@ -122,7 +118,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_name: create_runtime_str!("casper-svengali"),
authoring_version: 0,
spec_version: 1,
impl_version : 0,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
state_version: 0,
@ -422,13 +418,15 @@ impl pallet_election_provider_multi_phase::Config for Runtime {
type SignedMaxSubmissions = SignedMaxSubmissions;
type SignedMaxRefunds = SignedMaxRefunds;
type SignedRewardBase = SignedRewardBase;
type SignedDepositBase = GeometricDepositBase<Balance, SignedFixedDeposit, SignedDepositIncreaseFactor>;
type SignedDepositBase =
GeometricDepositBase<Balance, SignedFixedDeposit, SignedDepositIncreaseFactor>;
type SignedDepositByte = SignedDepositByte;
type SignedDepositWeight = ();
type SignedMaxWeight = <Self::MinerConfig as pallet_election_provider_multi_phase::MinerConfig>::MaxWeight;
type SignedMaxWeight =
<Self::MinerConfig as pallet_election_provider_multi_phase::MinerConfig>::MaxWeight;
type MinerConfig = Self;
type SlashHandler = ();
type RewardHandler= ();
type RewardHandler = ();
type BetterSignedThreshold = ();
type OffchainRepeat = OffchainRepeat;
type MinerTxPriority = NposSolutionPriority;
@ -449,10 +447,7 @@ impl pallet_election_provider_multi_phase::Config for Runtime {
(),
>;
type BenchmarkingConfig = runtime_common::elections::BenchmarkConfig;
type ForceOrigin = EitherOf<
EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>,
Zombies,
>;
type ForceOrigin = EitherOf<EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>, Zombies>;
type MaxWinners = MaxActiveValidators;
type ElectionBounds = ElectionBounds;
type WeightInfo = weights::pallet_election_provider_multi_phase::WeightInfo<Runtime>;
@ -492,6 +487,8 @@ parameter_types! {
pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17);
pub const MaxNominations: u32 =
<NposCompactSolution16 as frame_election_provider_support::NposSolution>::LIMIT as u32;
pub const StakingHistoryDepth: u32 = 84;
pub const MaxUnlockingChunks: u32 = 32;
}
impl pallet_staking::Config for Runtime {
@ -506,12 +503,9 @@ impl pallet_staking::Config for Runtime {
type SessionsPerEra = SessionsPerEra;
type BondingDuration = BondingDuration;
type SlashDeferDuration = SlashDeferDuration;
type AdminOrigin = EitherOf<
EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>,
Skeletons,
>;
type AdminOrigin = EitherOf<EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>, Skeletons>;
type SessionInterface = Self;
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type EraPayout = ghost_networks::BridgedInflationCurve<RewardCurve, Self>;
type MaxExposurePageSize = MaxExposurePageSize;
type DisablingStrategy = pallet_staking::UpToLimitDisablingStrategy;
type NextNewSession = Session;
@ -520,8 +514,8 @@ impl pallet_staking::Config for Runtime {
type VoterList = VoterList;
type TargetList = UseValidatorsMap<Self>;
type NominationsQuota = pallet_staking::FixedNominationsQuota<{ MaxNominations::get() }>;
type MaxUnlockingChunks = frame_support::traits::ConstU32<32>;
type HistoryDepth = frame_support::traits::ConstU32<84>;
type MaxUnlockingChunks = MaxUnlockingChunks;
type HistoryDepth = StakingHistoryDepth;
type MaxControllersInDeprecationBatch = ConstU32<5314>;
type BenchmarkingConfig = runtime_common::StakingBenchmarkingConfig;
type EventListeners = NominationPools;
@ -533,10 +527,7 @@ impl pallet_fast_unstake::Config for Runtime {
type Currency = Balances;
type BatchSize = frame_support::traits::ConstU32<16>;
type Deposit = ConstU128<{ STRH }>;
type ControlOrigin = EitherOf<
EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>,
Zombies,
>;
type ControlOrigin = EitherOf<EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>, Zombies>;
type Staking = Staking;
type MaxErasToCheckPerBlock = ConstU32<1>;
type WeightInfo = weights::pallet_fast_unstake::WeightInfo<Runtime>;
@ -597,10 +588,7 @@ impl pallet_treasury::Config for Runtime {
type ApproveOrigin = frame_support::traits::NeverEnsureOrigin<Balance>;
#[cfg(feature = "runtime-benchmarks")]
type ApproveOrigin = EnsureRoot<Self::AccountId>;
type RejectOrigin = EitherOf<
EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>,
Degens,
>;
type RejectOrigin = EitherOf<EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>, Degens>;
type RuntimeEvent = RuntimeEvent;
type OnSlash = Treasury;
@ -623,10 +611,7 @@ impl pallet_treasury::Config for Runtime {
type MaxApprovals = MaxApprovals;
type WeightInfo = ();
type SpendOrigin = EitherOf<
EnsureRootWithSuccess<AccountId, MaxBalance>,
CultTreasurySpender
>;
type SpendOrigin = EitherOf<EnsureRootWithSuccess<AccountId, MaxBalance>, CultTreasurySpender>;
type AssetKind = ();
type Beneficiary = AccountId;
@ -706,8 +691,7 @@ impl pallet_grandpa::Config for Runtime {
type MaxNominators = MaxNominators;
type MaxSetIdSessionEntries = MaxSetIdSessionEntries;
type KeyOwnerProof =
<Historical as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;
type KeyOwnerProof = <Historical as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;
type EquivocationReportSystem =
pallet_grandpa::EquivocationReportSystem<Self, Offences, Historical, ReportLongevity>;
@ -724,13 +708,17 @@ where
public: <Signature as Verify>::Signer,
account: AccountId,
nonce: <Runtime as frame_system::Config>::Nonce,
) -> Option<(RuntimeCall, <UncheckedExtrinsic as ExtrinsicT>::SignaturePayload)> {
) -> Option<(
RuntimeCall,
<UncheckedExtrinsic as ExtrinsicT>::SignaturePayload,
)> {
use sp_runtime::traits::StaticLookup;
// take the biggest period possible
let period = BlockHashCount::get()
.checked_next_power_of_two()
.map(|c| c / 2).unwrap_or(2) as u64;
.map(|c| c / 2)
.unwrap_or(2) as u64;
let current_block = System::block_number()
.saturated_into::<u64>()
@ -744,9 +732,10 @@ where
frame_system::CheckSpecVersion::<Runtime>::new(),
frame_system::CheckTxVersion::<Runtime>::new(),
frame_system::CheckGenesis::<Runtime>::new(),
frame_system::CheckMortality::<Runtime>::from(
generic::Era::mortal(period, current_block),
),
frame_system::CheckMortality::<Runtime>::from(generic::Era::mortal(
period,
current_block,
)),
frame_system::CheckNonce::<Runtime>::from(nonce),
frame_system::CheckWeight::<Runtime>::new(),
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip),
@ -828,8 +817,17 @@ parameter_types! {
/// The type used to represent the kinds of proxying allowed.
#[derive(
Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode,
Decode, RuntimeDebug, MaxEncodedLen, scale_info::TypeInfo,
Copy,
Clone,
Eq,
PartialEq,
Ord,
PartialOrd,
Encode,
Decode,
RuntimeDebug,
MaxEncodedLen,
scale_info::TypeInfo,
)]
pub enum ProxyType {
Any = 0,
@ -854,42 +852,40 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
ProxyType::NonTransfer => matches!(c, RuntimeCall::Balances { .. }),
ProxyType::Governance => matches!(
c,
RuntimeCall::Bounties { .. } |
RuntimeCall::Utility { .. } |
RuntimeCall::ChildBounties { .. } |
RuntimeCall::CultReferenda { .. } |
RuntimeCall::CultCollective { .. } |
RuntimeCall::Whitelist { .. } |
RuntimeCall::AllianceMotion { .. } |
RuntimeCall::Alliance { .. } |
RuntimeCall::Multisig { .. }
RuntimeCall::Bounties { .. }
| RuntimeCall::Utility { .. }
| RuntimeCall::ChildBounties { .. }
| RuntimeCall::CultReferenda { .. }
| RuntimeCall::CultCollective { .. }
| RuntimeCall::Whitelist { .. }
| RuntimeCall::AllianceMotion { .. }
| RuntimeCall::Alliance { .. }
| RuntimeCall::Multisig { .. }
),
ProxyType::Staking => matches!(
c,
RuntimeCall::Staking { .. } |
RuntimeCall::Session { .. } |
RuntimeCall::Utility { .. } |
RuntimeCall::FastUnstake { .. } |
RuntimeCall::VoterList { .. } |
RuntimeCall::NominationPools { .. }
RuntimeCall::Staking { .. }
| RuntimeCall::Session { .. }
| RuntimeCall::Utility { .. }
| RuntimeCall::FastUnstake { .. }
| RuntimeCall::VoterList { .. }
| RuntimeCall::NominationPools { .. }
),
ProxyType::IdentityJudgement => matches!(
c,
RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) |
RuntimeCall::Utility { .. }
RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. })
| RuntimeCall::Utility { .. }
),
ProxyType::CancelProxy => matches!(
c,
RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) |
RuntimeCall::Utility { .. } |
RuntimeCall::Multisig { .. }
RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. })
| RuntimeCall::Utility { .. }
| RuntimeCall::Multisig { .. }
),
ProxyType::NominationPools => matches!(
c,
RuntimeCall::NominationPools { .. } |
RuntimeCall::Utility { .. }
RuntimeCall::NominationPools { .. } | RuntimeCall::Utility { .. }
),
}
}
@ -938,10 +934,7 @@ impl pallet_nomination_pools::Config for Runtime {
type MaxUnbonding = <Self as pallet_staking::Config>::MaxUnlockingChunks;
type PalletId = PoolsPalletId;
type MaxPointsToBalance = MaxPointsToBalance;
type AdminOrigin = EitherOf<
EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>,
Zombies,
>;
type AdminOrigin = EitherOf<EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>, Zombies>;
type WeightInfo = weights::pallet_nomination_pools::WeightInfo<Runtime>;
}
@ -1035,19 +1028,12 @@ impl pallet_alliance::Config for Runtime {
impl ghost_networks::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type NetworkId = u64;
type Currency = Balances;
type RegisterOrigin = EitherOf<
EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>,
Ghosts,
>;
type UpdateOrigin = EitherOf<
EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>,
Zombies,
>;
type RemoveOrigin = EitherOf<
EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>,
Skeletons,
>;
type RegisterOrigin = EitherOf<EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>, Ghosts>;
type UpdateOrigin = EitherOf<EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>, Zombies>;
type RemoveOrigin =
EitherOf<EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>, Skeletons>;
type WeightInfo = weights::ghost_networks::WeightInfo<Runtime>;
}
@ -1058,7 +1044,6 @@ parameter_types! {
pub VestingBlocks: u32 = 10 * WEEKS;
}
impl ghost_claims::Config<CultCollectiveInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type VestingSchedule = Vesting;
@ -1073,14 +1058,13 @@ impl ghost_claims::Config<CultCollectiveInstance> for Runtime {
}
parameter_types! {
// maximum number of claps in one tx
pub MaxNumberOfClaps: u32 = 5;
// will be used in `Perbill::from_percent()`
pub ApplauseThreshold: u32 = 70;
pub const ApplauseThreshold: u32 = 70;
// will be used in `Perbill::from_percent()`
pub OffenceThreshold: u32 = 40;
pub const SlowClapUnsignedPriority: TransactionPriority =
TransactionPriority::max_value();
pub const OffenceThreshold: u32 = 40;
pub const SlowClapUnsignedPriority: TransactionPriority = TransactionPriority::MAX;
pub const SlowClapHistoryDepth: sp_staking::SessionIndex =
StakingHistoryDepth::get() * SessionsPerEra::get();
}
impl ghost_slow_clap::Config for Runtime {
@ -1095,17 +1079,20 @@ impl ghost_slow_clap::Config for Runtime {
type ReportUnresponsiveness = Offences;
type MaxAuthorities = MaxAuthorities;
type MaxNumberOfClaps = MaxNumberOfClaps;
type ApplauseThreshold = ApplauseThreshold;
type MaxAuthorityInfoInSession = MaxAuthorities;
type OffenceThreshold = OffenceThreshold;
type UnsignedPriority = SlowClapUnsignedPriority;
type TreasuryPalletId = TreasuryPalletId;
type HistoryDepth = SlowClapHistoryDepth;
type WeightInfo = weights::ghost_slow_clap::WeightInfo<Runtime>;
}
impl ghost_sudo::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type WeightInfo = weights::ghost_sudo::WeightInfo<Runtime>;
}
construct_runtime! {
pub enum Runtime
{
@ -1133,6 +1120,7 @@ construct_runtime! {
Session: pallet_session = 9,
Grandpa: pallet_grandpa = 11,
AuthorityDiscovery: pallet_authority_discovery = 12,
GhostSudo: ghost_sudo = 13,
// Governance stuff.
Treasury: pallet_treasury = 19,
@ -1261,6 +1249,7 @@ mod benches {
[ghost_networks, GhostNetworks]
[ghost_claims, GhostClaims]
[ghost_slow_clap, GhostSlowClaps]
[ghost_sudo, GhostSudo]
);
}
@ -1567,6 +1556,7 @@ sp_api::impl_runtime_apis! {
(list, storage_info)
}
#[allow(non_local_definitions)]
fn dispatch_benchmark(
config: frame_benchmarking::BenchmarkConfig,
) -> Result<
@ -1706,7 +1696,10 @@ mod test_fees {
test_with_multiplier(Multiplier::saturating_from_rational(1u128, 1_00u128));
test_with_multiplier(Multiplier::saturating_from_rational(1u128, 1_000u128));
test_with_multiplier(Multiplier::saturating_from_rational(1u128, 1_000_000u128));
test_with_multiplier(Multiplier::saturating_from_rational(1u128, 1_000_000_000u128));
test_with_multiplier(Multiplier::saturating_from_rational(
1u128,
1_000_000_000u128,
));
}
#[test]
@ -1728,14 +1721,21 @@ mod test_fees {
};
let mut active = target_voters;
while weight_with(active).all_lte(OffchainSolutionWeightLimit::get()) ||
active == target_voters
while weight_with(active).all_lte(OffchainSolutionWeightLimit::get())
|| active == target_voters
{
active += 1;
}
println!("can support {} nominators to yield a weight of {}", active, weight_with(active));
assert!(active > target_voters, "we need to reevaluate the weight of the election system");
println!(
"can support {} nominators to yield a weight of {}",
active,
weight_with(active)
);
assert!(
active > target_voters,
"we need to reevaluate the weight of the election system"
);
}
#[test]
@ -1764,15 +1764,25 @@ mod test {
.collect();
// Block number
assert!(whitelist.contains("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac"));
assert!(
whitelist.contains("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac")
);
// Total issuance
assert!(whitelist.contains("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80"));
assert!(
whitelist.contains("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80")
);
// Execution phase
assert!(whitelist.contains("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a"));
assert!(
whitelist.contains("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a")
);
// Event count
assert!(whitelist.contains("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850"));
assert!(
whitelist.contains("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850")
);
// System events
assert!(whitelist.contains("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7"));
assert!(
whitelist.contains("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7")
);
}
#[test]
@ -1809,13 +1819,21 @@ mod multiplier_tests {
#[test]
fn multiplier_can_grow_from_zero() {
let minimum_multiplier = MinimumMultiplier::get();
let target = TargetBlockFullness::get() *
BlockWeights::get().get(DispatchClass::Normal).max_total.unwrap();
let target = TargetBlockFullness::get()
* BlockWeights::get()
.get(DispatchClass::Normal)
.max_total
.unwrap();
// if the min is too small, then this will not change, and we are doomed forever.
// the weight is 1/100th bigger than target.
run_with_system_weight(target.saturating_mul(101) / 100, || {
let next = SlowAdjustingFeeUpdate::<Runtime>::convert(minimum_multiplier);
assert!(next > minimum_multiplier, "{:?} !>= {:?}", next, minimum_multiplier);
assert!(
next > minimum_multiplier,
"{:?} !>= {:?}",
next,
minimum_multiplier
);
})
}
@ -1828,7 +1846,10 @@ mod multiplier_tests {
<Runtime as pallet_fast_unstake::Config>::BatchSize::get(),
)
.ref_time() as f32;
println!("ratio of block weight for full batch fast-unstake {}", on_idle / block_time);
println!(
"ratio of block weight for full batch fast-unstake {}",
on_idle / block_time
);
assert!(on_idle / block_time <= 0.5f32)
}
@ -1838,12 +1859,18 @@ mod multiplier_tests {
// assume the multiplier is initially set to its minimum. We update it with values twice the
//target (target is 25%, thus 50%) and we see at which point it reaches 1.
let mut multiplier = MinimumMultiplier::get();
let block_weight = BlockWeights::get().get(DispatchClass::Normal).max_total.unwrap();
let block_weight = BlockWeights::get()
.get(DispatchClass::Normal)
.max_total
.unwrap();
let mut blocks = 0;
let mut fees_paid = 0;
frame_system::Pallet::<Runtime>::set_block_consumed_resources(Weight::MAX, 0);
let info = DispatchInfo { weight: Weight::MAX, ..Default::default() };
let info = DispatchInfo {
weight: Weight::MAX,
..Default::default()
};
let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::default()
.build_storage::<Runtime>()

View File

@ -16,7 +16,7 @@
//! Autogenerated weights for `ghost_networks`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
//! DATE: 2024-08-01, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2025-07-29, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `ghostown`, CPU: `Intel(R) Core(TM) i3-2310M CPU @ 2.10GHz`
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("casper-dev")`, DB CACHE: 1024
@ -28,7 +28,7 @@
// --chain=casper-dev
// --steps=50
// --repeat=20
// --pallet=ghost_networks
// --pallet=ghost-networks
// --extrinsic=*
// --wasm-execution=compiled
// --heap-pages=4096
@ -50,30 +50,31 @@ impl<T: frame_system::Config> ghost_networks::WeightInfo for WeightInfo<T> {
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// The range of component `i` is `[1, 20]`.
/// The range of component `j` is `[1, 150]`.
fn register_network(i: u32, j: u32, ) -> Weight {
/// The range of component `k` is `[1, 20]`.
fn register_network(_i: u32, _j: u32, k: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `109`
// Estimated: `3574`
// Minimum execution time: 44_464_000 picoseconds.
Weight::from_parts(44_802_179, 0)
// Minimum execution time: 46_023_000 picoseconds.
Weight::from_parts(97_871_287, 0)
.saturating_add(Weight::from_parts(0, 3574))
// Standard Error: 11_381
.saturating_add(Weight::from_parts(42_872, 0).saturating_mul(i.into()))
// Standard Error: 1_492
.saturating_add(Weight::from_parts(8_794, 0).saturating_mul(j.into()))
// Standard Error: 94_524
.saturating_add(Weight::from_parts(940_486, 0).saturating_mul(k.into()))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `GhostNetworks::Networks` (r:1 w:1)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// The range of component `n` is `[1, 20]`.
fn update_network_name(_n: u32, ) -> Weight {
fn update_network_name(n: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `295`
// Estimated: `3760`
// Minimum execution time: 50_224_000 picoseconds.
Weight::from_parts(54_405_362, 0)
.saturating_add(Weight::from_parts(0, 3760))
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 49_906_000 picoseconds.
Weight::from_parts(55_537_587, 0)
.saturating_add(Weight::from_parts(0, 3767))
// Standard Error: 87_704
.saturating_add(Weight::from_parts(92_366, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
@ -82,13 +83,13 @@ impl<T: frame_system::Config> ghost_networks::WeightInfo for WeightInfo<T> {
/// The range of component `n` is `[1, 150]`.
fn update_network_endpoint(n: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `295`
// Estimated: `3760`
// Minimum execution time: 50_598_000 picoseconds.
Weight::from_parts(54_951_352, 0)
.saturating_add(Weight::from_parts(0, 3760))
// Standard Error: 10_596
.saturating_add(Weight::from_parts(11_691, 0).saturating_mul(n.into()))
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 50_556_000 picoseconds.
Weight::from_parts(57_726_674, 0)
.saturating_add(Weight::from_parts(0, 3767))
// Standard Error: 12_261
.saturating_add(Weight::from_parts(274, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
@ -96,23 +97,35 @@ impl<T: frame_system::Config> ghost_networks::WeightInfo for WeightInfo<T> {
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn update_network_finality_delay() -> Weight {
// Proof Size summary in bytes:
// Measured: `295`
// Estimated: `3760`
// Minimum execution time: 49_089_000 picoseconds.
Weight::from_parts(50_797_000, 0)
.saturating_add(Weight::from_parts(0, 3760))
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 49_406_000 picoseconds.
Weight::from_parts(51_256_000, 0)
.saturating_add(Weight::from_parts(0, 3767))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `GhostNetworks::Networks` (r:1 w:1)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn update_network_release_delay() -> Weight {
fn update_network_rate_limit_delay() -> Weight {
// Proof Size summary in bytes:
// Measured: `295`
// Estimated: `3760`
// Minimum execution time: 49_606_000 picoseconds.
Weight::from_parts(50_371_000, 0)
.saturating_add(Weight::from_parts(0, 3760))
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 49_572_000 picoseconds.
Weight::from_parts(52_584_000, 0)
.saturating_add(Weight::from_parts(0, 3767))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `GhostNetworks::Networks` (r:1 w:1)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn update_network_block_distance() -> Weight {
// Proof Size summary in bytes:
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 48_880_000 picoseconds.
Weight::from_parts(50_596_000, 0)
.saturating_add(Weight::from_parts(0, 3767))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
@ -120,11 +133,11 @@ impl<T: frame_system::Config> ghost_networks::WeightInfo for WeightInfo<T> {
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn update_network_type() -> Weight {
// Proof Size summary in bytes:
// Measured: `295`
// Estimated: `3760`
// Minimum execution time: 48_135_000 picoseconds.
Weight::from_parts(48_619_000, 0)
.saturating_add(Weight::from_parts(0, 3760))
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 48_282_000 picoseconds.
Weight::from_parts(49_137_000, 0)
.saturating_add(Weight::from_parts(0, 3767))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
@ -132,11 +145,11 @@ impl<T: frame_system::Config> ghost_networks::WeightInfo for WeightInfo<T> {
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn update_network_gatekeeper() -> Weight {
// Proof Size summary in bytes:
// Measured: `295`
// Estimated: `3760`
// Minimum execution time: 50_027_000 picoseconds.
Weight::from_parts(51_212_000, 0)
.saturating_add(Weight::from_parts(0, 3760))
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 50_853_000 picoseconds.
Weight::from_parts(51_982_000, 0)
.saturating_add(Weight::from_parts(0, 3767))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
@ -144,11 +157,11 @@ impl<T: frame_system::Config> ghost_networks::WeightInfo for WeightInfo<T> {
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn update_network_topic_name() -> Weight {
// Proof Size summary in bytes:
// Measured: `295`
// Estimated: `3760`
// Minimum execution time: 50_686_000 picoseconds.
Weight::from_parts(52_276_000, 0)
.saturating_add(Weight::from_parts(0, 3760))
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 50_343_000 picoseconds.
Weight::from_parts(52_380_000, 0)
.saturating_add(Weight::from_parts(0, 3767))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
@ -156,11 +169,11 @@ impl<T: frame_system::Config> ghost_networks::WeightInfo for WeightInfo<T> {
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn update_incoming_network_fee() -> Weight {
// Proof Size summary in bytes:
// Measured: `295`
// Estimated: `3760`
// Minimum execution time: 48_485_000 picoseconds.
Weight::from_parts(49_672_000, 0)
.saturating_add(Weight::from_parts(0, 3760))
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 49_393_000 picoseconds.
Weight::from_parts(80_966_000, 0)
.saturating_add(Weight::from_parts(0, 3767))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
@ -168,11 +181,11 @@ impl<T: frame_system::Config> ghost_networks::WeightInfo for WeightInfo<T> {
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn update_outgoing_network_fee() -> Weight {
// Proof Size summary in bytes:
// Measured: `295`
// Estimated: `3760`
// Minimum execution time: 48_926_000 picoseconds.
Weight::from_parts(49_482_000, 0)
.saturating_add(Weight::from_parts(0, 3760))
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 49_579_000 picoseconds.
Weight::from_parts(51_126_000, 0)
.saturating_add(Weight::from_parts(0, 3767))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
@ -180,11 +193,11 @@ impl<T: frame_system::Config> ghost_networks::WeightInfo for WeightInfo<T> {
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn remove_network() -> Weight {
// Proof Size summary in bytes:
// Measured: `295`
// Estimated: `3760`
// Minimum execution time: 45_163_000 picoseconds.
Weight::from_parts(45_822_000, 0)
.saturating_add(Weight::from_parts(0, 3760))
// Measured: `302`
// Estimated: `3767`
// Minimum execution time: 44_634_000 picoseconds.
Weight::from_parts(45_815_000, 0)
.saturating_add(Weight::from_parts(0, 3767))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}

View File

@ -16,7 +16,7 @@
//! Autogenerated weights for `ghost_slow_clap`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
//! DATE: 2024-08-02, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2025-06-19, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `ghostown`, CPU: `Intel(R) Core(TM) i3-2310M CPU @ 2.10GHz`
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("casper-dev")`, DB CACHE: 1024
@ -47,79 +47,61 @@ use core::marker::PhantomData;
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> ghost_slow_clap::WeightInfo for WeightInfo<T> {
/// Storage: `GhostSlowClaps::Authorities` (r:1 w:0)
/// Proof: `GhostSlowClaps::Authorities` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `GhostSlowClaps::AuthorityInfoInSession` (r:1 w:0)
/// Proof: `GhostSlowClaps::AuthorityInfoInSession` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostSlowClaps::ApplausesForTransaction` (r:1 w:0)
/// Proof: `GhostSlowClaps::Authorities` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostSlowClaps::ReceivedClaps` (r:1 w:1)
/// Proof: `GhostSlowClaps::ReceivedClaps` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostSlowClaps::ClapsInSession` (r:1 w:1)
/// Proof: `GhostSlowClaps::ClapsInSession` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostSlowClaps::ApplausesForTransaction` (r:1 w:1)
/// Proof: `GhostSlowClaps::ApplausesForTransaction` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostNetworks::NullifyNeeded` (r:1 w:0)
/// Proof: `GhostNetworks::NullifyNeeded` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `GhostNetworks::Networks` (r:1 w:0)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostNetworks::GatekeeperAmount` (r:1 w:1)
/// Proof: `GhostNetworks::GatekeeperAmount` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostNetworks::BridgedImbalance` (r:1 w:1)
/// Proof: `GhostNetworks::BridgedImbalance` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `GhostNetworks::AccumulatedCommission` (r:1 w:1)
/// Proof: `GhostNetworks::AccumulatedCommission` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `System::Account` (r:1 w:1)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
fn slow_clap() -> Weight {
// Proof Size summary in bytes:
// Measured: `355`
// Estimated: `3820`
// Minimum execution time: 213_817_000 picoseconds.
Weight::from_parts(216_977_000, 0)
.saturating_add(Weight::from_parts(0, 3820))
.saturating_add(T::DbWeight::get().reads(10))
.saturating_add(T::DbWeight::get().writes(7))
}
/// Storage: `GhostSlowClaps::ReceivedClaps` (r:1 w:0)
/// Proof: `GhostSlowClaps::ReceivedClaps` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// The range of component `k` is `[1, 100]`.
/// The range of component `j` is `[1, 20]`.
fn slow_clap(k: u32, j: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `372 + j * (19 ±0)`
// Estimated: `3853 + j * (19 ±0)`
// Minimum execution time: 95_459_000 picoseconds.
Weight::from_parts(96_224_000, 0)
.saturating_add(Weight::from_parts(0, 3853))
// Standard Error: 152_014
.saturating_add(Weight::from_parts(32_092_278, 0).saturating_mul(k.into()))
// Standard Error: 761_228
.saturating_add(Weight::from_parts(22_412_712, 0).saturating_mul(j.into()))
.saturating_add(T::DbWeight::get().reads(4))
.saturating_add(Weight::from_parts(0, 19).saturating_mul(j.into()))
}
/// Storage: `GhostSlowClaps::CurrentCompanionId` (r:1 w:1)
/// Proof: `GhostSlowClaps::CurrentCompanionId` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `GhostSlowClaps::Authorities` (r:1 w:0)
/// Proof: `GhostSlowClaps::Authorities` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostSlowClaps::ApplausesForTransaction` (r:1 w:1)
/// Proof: `GhostSlowClaps::ApplausesForTransaction` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostNetworks::NullifyNeeded` (r:1 w:0)
/// Proof: `GhostNetworks::NullifyNeeded` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `GhostNetworks::Networks` (r:1 w:0)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostSlowClaps::Companions` (r:0 w:1)
/// Proof: `GhostSlowClaps::Companions` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostSlowClaps::CompanionDetails` (r:0 w:1)
/// Proof: `GhostSlowClaps::CompanionDetails` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn propose_companion() -> Weight {
/// Storage: `GhostNetworks::GatekeeperAmount` (r:1 w:1)
/// Proof: `GhostNetworks::GatekeeperAmount` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostNetworks::BridgedImbalance` (r:1 w:1)
/// Proof: `GhostNetworks::BridgedImbalance` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `GhostNetworks::AccumulatedCommission` (r:1 w:1)
/// Proof: `GhostNetworks::AccumulatedCommission` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `System::Account` (r:1 w:1)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
fn self_applause() -> Weight {
// Proof Size summary in bytes:
// Measured: `634`
// Estimated: `4099`
// Minimum execution time: 167_770_000 picoseconds.
Weight::from_parts(168_826_000, 0)
.saturating_add(Weight::from_parts(0, 4099))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(3))
}
/// Storage: `GhostSlowClaps::Companions` (r:1 w:0)
/// Proof: `GhostSlowClaps::Companions` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostNetworks::Networks` (r:1 w:0)
/// Proof: `GhostNetworks::Networks` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostSlowClaps::CompanionDetails` (r:1 w:0)
/// Proof: `GhostSlowClaps::CompanionDetails` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostSlowClaps::ReleaseBlocks` (r:0 w:1)
/// Proof: `GhostSlowClaps::ReleaseBlocks` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn release_companion() -> Weight {
// Proof Size summary in bytes:
// Measured: `839`
// Estimated: `4304`
// Minimum execution time: 82_884_000 picoseconds.
Weight::from_parts(84_135_000, 0)
.saturating_add(Weight::from_parts(0, 4304))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `GhostSlowClaps::ReleaseBlocks` (r:1 w:0)
/// Proof: `GhostSlowClaps::ReleaseBlocks` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostSlowClaps::Companions` (r:1 w:1)
/// Proof: `GhostSlowClaps::Companions` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `GhostSlowClaps::CompanionDetails` (r:1 w:1)
/// Proof: `GhostSlowClaps::CompanionDetails` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn kill_companion() -> Weight {
// Proof Size summary in bytes:
// Measured: `514`
// Estimated: `3979`
// Minimum execution time: 152_418_000 picoseconds.
Weight::from_parts(153_436_000, 0)
.saturating_add(Weight::from_parts(0, 3979))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(2))
// Measured: `655`
// Estimated: `4120`
// Minimum execution time: 210_676_000 picoseconds.
Weight::from_parts(212_905_000, 0)
.saturating_add(Weight::from_parts(0, 4120))
.saturating_add(T::DbWeight::get().reads(9))
.saturating_add(T::DbWeight::get().writes(5))
}
}

View File

@ -0,0 +1,95 @@
// This file is part of Ghost Network.
// Ghost Network is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Ghost Network is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Ghost Network. If not, see <http://www.gnu.org/licenses/>.
//! Autogenerated weights for `ghost_sudo`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
//! DATE: 2025-07-28, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `ghostown`, CPU: `Intel(R) Core(TM) i3-2310M CPU @ 2.10GHz`
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("casper-dev")`, DB CACHE: 1024
// Executed Command:
// ./target/release/ghost
// benchmark
// pallet
// --chain=casper-dev
// --steps=50
// --repeat=20
// --pallet=ghost-sudo
// --extrinsic=*
// --wasm-execution=compiled
// --heap-pages=4096
// --header=./file_header.txt
// --output=./runtime/casper/src/weights/ghost_sudo.rs
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(missing_docs)]
use frame_support::{traits::Get, weights::Weight};
use core::marker::PhantomData;
/// Weight functions for `ghost_sudo`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> ghost_sudo::WeightInfo for WeightInfo<T> {
/// Storage: `GhostSudo::Key` (r:1 w:1)
/// Proof: `GhostSudo::Key` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
fn set_key() -> Weight {
// Proof Size summary in bytes:
// Measured: `165`
// Estimated: `1517`
// Minimum execution time: 40_014_000 picoseconds.
Weight::from_parts(40_856_000, 0)
.saturating_add(Weight::from_parts(0, 1517))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `GhostSudo::Key` (r:1 w:0)
/// Proof: `GhostSudo::Key` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
fn sudo() -> Weight {
// Proof Size summary in bytes:
// Measured: `165`
// Estimated: `1517`
// Minimum execution time: 44_086_000 picoseconds.
Weight::from_parts(45_920_000, 0)
.saturating_add(Weight::from_parts(0, 1517))
.saturating_add(T::DbWeight::get().reads(1))
}
/// Storage: `GhostSudo::Key` (r:1 w:0)
/// Proof: `GhostSudo::Key` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
fn sudo_as() -> Weight {
// Proof Size summary in bytes:
// Measured: `165`
// Estimated: `1517`
// Minimum execution time: 44_106_000 picoseconds.
Weight::from_parts(44_650_000, 0)
.saturating_add(Weight::from_parts(0, 1517))
.saturating_add(T::DbWeight::get().reads(1))
}
/// Storage: `GhostSudo::Key` (r:1 w:1)
/// Proof: `GhostSudo::Key` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`)
fn remove_key() -> Weight {
// Proof Size summary in bytes:
// Measured: `165`
// Estimated: `1517`
// Minimum execution time: 36_416_000 picoseconds.
Weight::from_parts(37_373_000, 0)
.saturating_add(Weight::from_parts(0, 1517))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
}

View File

@ -3,6 +3,7 @@ pub mod frame_system;
pub mod ghost_claims;
pub mod ghost_networks;
pub mod ghost_slow_clap;
pub mod ghost_sudo;
pub mod pallet_alliance;
pub mod pallet_bags_list;
pub mod pallet_balances;
@ -17,7 +18,7 @@ pub mod pallet_nomination_pools;
pub mod pallet_preimage;
pub mod pallet_proxy;
pub mod pallet_ranked_collective;
// pub mod pallet_referenda;
pub mod pallet_referenda;
pub mod pallet_salary;
pub mod pallet_scheduler;
pub mod pallet_session;

2
runtime/common/Cargo.toml Executable file → Normal file
View File

@ -1,6 +1,6 @@
[package]
name = "ghost-runtime-common"
version = "0.4.2"
version = "0.4.3"
authors.workspace = true
edition.workspace = true
homepage.workspace = true

View File

@ -1,11 +1,13 @@
use primitives::{AccountId, Balance};
use pallet_treasury::ArgumentsFactory;
use sp_core::crypto::FromEntropy;
use frame_support::traits::tokens::{Pay, PaymentStatus};
use pallet_treasury::ArgumentsFactory;
use primitives::{AccountId, Balance};
use sp_core::crypto::FromEntropy;
pub struct BenchmarkTreasuryHelper;
impl ArgumentsFactory<(), AccountId> for BenchmarkTreasuryHelper {
fn create_asset_kind(_seed: u32) -> () { () }
fn create_asset_kind(_seed: u32) -> () {
()
}
fn create_beneficiary(seed: [u8; 32]) -> AccountId {
AccountId::from_entropy(&mut seed.as_slice()).unwrap()
}
@ -19,8 +21,16 @@ impl Pay for BenchmarkTreasuryPaymaster {
type AssetKind = ();
type Error = ();
fn pay(_: &Self::Beneficiary, _: Self::AssetKind, _: Self::Balance) -> Result<Self::Id, Self::Error> { Ok(()) }
fn check_payment(_: Self::Id) -> PaymentStatus { PaymentStatus::Success }
fn pay(
_: &Self::Beneficiary,
_: Self::AssetKind,
_: Self::Balance,
) -> Result<Self::Id, Self::Error> {
Ok(())
}
fn check_payment(_: Self::Id) -> PaymentStatus {
PaymentStatus::Success
}
fn ensure_successful(_: &Self::Beneficiary, _: Self::AssetKind, _: Self::Balance) {}
fn ensure_concluded(_: Self::Id) {}
}

39
runtime/common/src/impls.rs Executable file → Normal file
View File

@ -55,7 +55,7 @@ mod tests {
parameter_types,
traits::{
tokens::{PayFromAccount, UnityAssetBalanceConversion},
ConstU32, FindAuthor
ConstU32, FindAuthor,
},
weights::Weight,
PalletId,
@ -65,7 +65,7 @@ mod tests {
use sp_core::{ConstU64, H256};
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
Perbill, BuildStorage,
BuildStorage, Perbill,
};
type Block = frame_system::mocking::MockingBlock<Test>;
@ -172,7 +172,10 @@ mod tests {
pub struct OneAuthor;
impl FindAuthor<AccountId> for OneAuthor {
fn find_author<'a, I>(_: I) -> Option<AccountId> where I: 'a {
fn find_author<'a, I>(_: I) -> Option<AccountId>
where
I: 'a,
{
Some(TEST_ACCOUNT)
}
}
@ -185,7 +188,9 @@ mod tests {
}
pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
let mut t = frame_system::GenesisConfig::default()
.build_storage::<Test>()
.unwrap();
// We use default for brevity, but you can configure as desired if needed.
pallet_balances::GenesisConfig::<Test>::default()
.assimilate_storage(&mut t)
@ -196,8 +201,14 @@ mod tests {
#[test]
fn test_fees_and_tips_split() {
new_test_ext().execute_with(|| {
let fee = <paller_balances::Pallet<Test> as frame_support::traits::fungible::Balanced<AccountId>>::issue(10);
let tip = <paller_balances::Pallet<Test> as frame_support::traits::fungible::Balanced<AccountId>>::issue(20);
let fee =
<paller_balances::Pallet<Test> as frame_support::traits::fungible::Balanced<
AccountId,
>>::issue(10);
let tip =
<paller_balances::Pallet<Test> as frame_support::traits::fungible::Balanced<
AccountId,
>>::issue(20);
assert_eq!(Balances::free_balance(Treasury::account_id()), 0);
assert_eq!(Balances::free_balance(TEST_ACCOUNT), 0);
@ -242,11 +253,23 @@ mod tests {
#[test]
fn era_payout_should_give_sensible_results() {
assert_eq!(
era_payout(75, 100, Perquintill::from_percent(10), Perquintill::one(), 0, ),
era_payout(
75,
100,
Perquintill::from_percent(10),
Perquintill::one(),
0,
),
(10, 0)
);
assert_eq!(
era_payout(80, 100, Perquintill::from_percent(10), Perquintill::one(), 0, ),
era_payout(
80,
100,
Perquintill::from_percent(10),
Perquintill::one(),
0,
),
(6, 4)
);
}

13
runtime/common/src/lib.rs Executable file → Normal file
View File

@ -1,7 +1,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
pub mod impls;
pub mod elections;
pub mod impls;
#[cfg(feature = "try-runtime")]
pub mod elections;
@ -10,7 +10,8 @@ pub mod elections;
pub mod benchmarking;
use frame_support::{
parameter_types, traits::ConstU32,
parameter_types,
traits::ConstU32,
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight},
};
use frame_system::limits;
@ -92,8 +93,8 @@ macro_rules! impl_runtime_weights {
use frame_system::limits;
use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment};
pub use runtime_common::{
impl_elections_weights, AVERAGE_ON_INITIALIZE_RATIO,
MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO,
impl_elections_weights, AVERAGE_ON_INITIALIZE_RATIO, MAXIMUM_BLOCK_WEIGHT,
NORMAL_DISPATCH_RATIO,
};
use sp_runtime::{FixedPointNumber, Perquintill};
@ -101,8 +102,7 @@ macro_rules! impl_runtime_weights {
// Expose the weight from the runtime constants module.
pub use $runtime::weights::{
BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight,
ParityDbWeight,
BlockExecutionWeight, ExtrinsicBaseWeight, ParityDbWeight, RocksDbWeight,
};
parameter_types! {
@ -129,7 +129,6 @@ macro_rules! impl_runtime_weights {
};
}
/// The type used for currency conversion.
///
/// This must be only be used as long as the balance type is `u128`.

View File

@ -4,7 +4,7 @@ use frame_support::{
};
use pallet_fast_unstake::{Pallet as FastUnstake, *};
use pallet_staking::*;
use sp_std::{collections::btree_set::BTreeSet, prelude:*};
use sp_std::{collections::btree_set::BTreeSet, prelude::*};
/// Register all inactive nominators for fast unstake, and progress until they
/// have all benn processed.
@ -16,7 +16,9 @@ where
let mut unstaked_err = 0;
let mut unstaked_slashed = 0;
let all_stakers = Ledger::<T>::iter().map(|(ctrl, l)| (ctrl, l.stash)).collect::<BTreeSet<_>>();
let all_stakers = Ledger::<T>::iter()
.map(|(ctrl, l)| (ctrl, l.stash))
.collect::<BTreeSet<_>>();
let mut all_exposed = BTreeSet::new();
ErasStakers::<T>::iter().for_each(|(_, val, expo)| {
all_exposed.insert(val);
@ -70,15 +72,16 @@ where
maybe_fast_unstake_event
})
.for_each(|e: pallet_fast_unstake::Event<T>| match e {
pallet_fast_unstake::Event<T>::Unstaked { result, .. } =>
pallet_fast_unstake::Event::<T>::Unstaked { result, .. } => {
if result.is_ok() {
unstaked_ok += 1;
} else {
unstaked_err += 1;
},
}
}
pallet_fast_unstake::Event::<T>::Slashed { .. } => unstaked_slashed += 1,
pallet_fast_unstake::Event::<T>::InternalError { .. } => unreachable!(),
_ => {},
_ => {}
});
if now % 100u32.into() == sp_runtime::traits::Zero::zero() {

0
runtime/common/src/weights/block_weights.rs Executable file → Normal file
View File

0
runtime/common/src/weights/extrinsic.rs Executable file → Normal file
View File

0
runtime/common/src/weights/mod.rs Executable file → Normal file
View File

View File

@ -2,6 +2,7 @@
set -Ee
HARD_RESET=false
CHECK_KEYS=false
INSERT_KEYS=false
UNIT_FILE=false
@ -79,6 +80,32 @@ extract_seed() {
echo $seed
}
downgrade_compiler_if_needed() {
# TODO: uncomment later
# echo "[+] fetching the latest ghost-node source code"
# git switch main
# git pull origin main
# 1.83.0 works fine, tested with:
# ...
# 1.87.0 throws errors during compilation
# 1.88.0 throws errors during compilation
LATEST_TESTED_VERSION=83
cargo_version=$(cargo --version | cut -d'.' -f2)
if [ "$cargo_version" -gt "$LATEST_TESTED_VERSION" ]; then
echo "[+] downgrading rustc compiler version to 1.83.0"
rustup default 1.83.0
toolchain_name=$(rustup show | grep default | head -n 1 | cut -d' ' -f1)
rustup target add wasm32-unknown-unknown --toolchain $toolchain_name
rustup component add rust-src --toolchain $toolchain_name
cd $PROJECT_FOLDER
echo "[+] clean build cache..."
cargo clean
else
echo "[+] rustc compiler version is compatible"
fi
}
help() {
echo -e "Ghost Node Build automation tool. Helper for Ghost Node environment preparation.\n"
echo -e "With no OPTION nothing will happen, possible OPTION:\n"
@ -96,6 +123,7 @@ help() {
echo -e "-s, --base-path\n\tPath to the folder with chain database ('/var/lib/ghost' is default)."
echo -e "-c, --specification-path\n\tPath to specification ('/etc/ghost' is default)."
echo -e "-n, --specification-name\n\tSpecification name to be used ('casper' is default)."
echo -e "--hard-reset-i-know-what-im-doing\n\tWill completely remove ledger along with associated session keys."
echo -e "-h, --help\n\tPrints help information."
}
@ -163,6 +191,9 @@ while [ $# -gt 0 ]; do
if [[ "$1" != *=* ]]; then shift; fi
SPECIFICATION_NAME="${1#*=}"
;;
--hard-reset-i-know-what-im-doing)
HARD_RESET=true
;;
--help|-h)
help
exit 0
@ -175,6 +206,51 @@ while [ $# -gt 0 ]; do
shift
done
if [[ $HARD_RESET = true ]]; then
echo -e "\n"
echo "WARNING!!! THIS ACTION WILL COMPLETELY PURGE THE LEDGER AND REBUILD THE NODE USING THE LATEST"
echo "REPOSITORY VERSION. NOTE THAT THE VALIDATION PROCESS WILL BE LOST BECAUSE SESSION OF KEYS."
echo "THERE ARE TWO SCENARIOS IN WHICH YOU MIGHT NEED TO PROCEED:"
echo -e "\t- A new version of the network hsa been released, and a restart is neccessary"
echo -e "\t- There is a critical issue, and you require a hard reset of the node in a single command"
echo -e "\n"
if prompt "[?] do you understand all risks?"; then
echo "[+] you were warned, I hope you know what you're doing"
else
echo "[-] aborting hard reset"
exit 1
fi
downgrade_compiler_if_needed
echo "[+] trying to stop current ghost-node"
sudo systemctl stop ghost-node
echo "[+] trying to remove locally stored ledger"
sudo rm -rf "$BASE_PATH/chains/casper_staging_testnet"
cd $PROJECT_FOLDER
git pull origin main
echo "[+] starting build in 3 seconds..."
sleep 3
cargo build --release
printf "[?] are you ready to continue?"
read anything
cd $PROJECT_FOLDER
echo "[+] trying to copy executable to '$EXECUTABLE_PATH'"
sudo cp target/$TARGET/ghost $EXECUTABLE_PATH
cp service/chain-specs/$SPECIFICATION_NAME.json $SPECIFICATION_PATH
echo "[+] ghost executable copied in '$EXECUTABLE_PATH' from '$TARGET'"
echo "[+] specification '$SPECIFICATION_NAME.json' copied to '$SPECIFICATION_PATH'"
echo "[+] starting ghost-node"
sudo systemctl start ghost-node
exit 0
fi
if [[ $SET_ENVIRONMENT = true ]]; then
echo -e "\n"
echo "WARNING!!! THIS IS HIGHLY EXPERIMENTAL FLAG, USE IT ONLY ON YOUR"
@ -253,16 +329,15 @@ if [[ $SET_ENVIRONMENT = true ]]; then
if prompt "[?] setup the rust environment (e.g. WASM support)?"; then
rustup default stable
rustup update
rustup target add wasm32-unknown-unknown
rustup component add rust-src
downgrade_compiler_if_needed
fi
fi
if [[ ! -z $RELEASE ]]; then
downgrade_compiler_if_needed
if prompt "[?] 'cargo build $RELEASE $FEATURES' is what you want?"; then
cd $PROJECT_FOLDER
echo "[+] Starting build in 3 seconds..."
echo "[+] starting build in 3 seconds..."
sleep 3
cargo build $RELEASE $FEATURES
fi
@ -347,7 +422,6 @@ if [[ $ARGUMENTS = true ]]; then
CLI_ARGS+=("--public-addr=$public_addr")
fi
# default for now
CLI_ARGS+=("--telemetry-url='wss://telemetry.ghostchain.io/submit/ 9'")
CLI_ARGS+=("--base-path=$BASE_PATH")

0
service/Cargo.toml Executable file → Normal file
View File

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,7 @@
use keyring::Sr25519Keyring;
use primitives::AccountId;
use sc_client_api::UsageProvider;
use sp_runtime::OpaqueExtrinsic;
use keyring::Sr25519Keyring;
use crate::*;
@ -21,27 +21,41 @@ macro_rules! identify_chain {
{
use ghost_runtime as runtime;
let call = $generic_code;
Ok(ghost_sign_call(call, $nonce, $current_block, $period, $genesis, $signer))
Ok(ghost_sign_call(
call,
$nonce,
$current_block,
$period,
$genesis,
$signer,
))
}
#[cfg(not(feature = "ghost-native"))]
{
Err("`ghost-native` feature not enabled")
}
},
}
Chain::Casper => {
#[cfg(feature = "casper-native")]
{
use casper_runtime as runtime;
let call = $generic_code;
Ok(casper_sign_call(call, $nonce, $current_block, $period, $genesis, $signer))
Ok(casper_sign_call(
call,
$nonce,
$current_block,
$period,
$genesis,
$signer,
))
}
#[cfg(not(feature = "casper-native"))]
{
Err("`casper-native` feature not enabled")
}
},
}
Chain::Unknown => {
let _ = $nonce;
let _ = $current_block;
@ -50,7 +64,7 @@ macro_rules! identify_chain {
let _ = $signer;
Err("Unknown chain")
},
}
}
};
}
@ -105,7 +119,11 @@ pub struct TransferKeepAliveBuilder {
impl TransferKeepAliveBuilder {
pub fn new(client: Arc<FullClient>, dest: AccountId, chain: Chain) -> Self {
Self { client, dest, chain }
Self {
client,
dest,
chain,
}
}
}
@ -159,10 +177,9 @@ fn casper_sign_call(
frame_system::CheckSpecVersion::<casper_runtime::Runtime>::new(),
frame_system::CheckTxVersion::<casper_runtime::Runtime>::new(),
frame_system::CheckGenesis::<casper_runtime::Runtime>::new(),
frame_system::CheckMortality::<casper_runtime::Runtime>::from(sp_runtime::generic::Era::mortal(
period,
current_block,
)),
frame_system::CheckMortality::<casper_runtime::Runtime>::from(
sp_runtime::generic::Era::mortal(period, current_block),
),
frame_system::CheckNonce::<casper_runtime::Runtime>::from(nonce),
frame_system::CheckWeight::<casper_runtime::Runtime>::new(),
pallet_transaction_payment::ChargeTransactionPayment::<casper_runtime::Runtime>::from(0),
@ -189,7 +206,8 @@ fn casper_sign_call(
sp_runtime::AccountId32::from(acc.public()).into(),
primitives::Signature::Sr25519(signature),
extra,
).into()
)
.into()
}
pub fn benchmark_inherent_data() -> std::result::Result<inherents::InherentData, inherents::Error> {

434
service/src/chain_spec.rs Executable file → Normal file
View File

@ -2,13 +2,13 @@
use codec::Encode;
use ghost_slow_clap::sr25519::AuthorityId as SlowClapId;
use primitives::{AccountId, AccountPublic};
use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
use grandpa_primitives::AuthorityId as GrandpaId;
use babe_primitives::AuthorityId as BabeId;
use ghost_slow_clap::sr25519::AuthorityId as SlowClapId;
use grandpa_primitives::AuthorityId as GrandpaId;
#[cfg(feature = "casper-native")]
use pallet_staking::Forcing;
use primitives::{AccountId, AccountPublic};
#[cfg(feature = "casper-native")]
use casper_runtime as casper;
@ -76,7 +76,6 @@ fn casper_session_keys(
}
}
pub fn casper_chain_spec_properties() -> serde_json::map::Map<String, serde_json::Value> {
serde_json::json!({
"ss58Format": 1996,
@ -161,42 +160,59 @@ fn casper_testnet_accounts() -> Vec<AccountId> {
fn casper_testnet_evm_accounts() -> Vec<(AccountId, u128, u8)> {
vec![
// 01c928771aea942a1e7ac06adf2b73dfbc9a25d9eaa516e3673116af7f345198
(get_account_id_from_seed::<sr25519::Public>("1A69d2D5568D1878023EeB121a73d33B9116A760"), 1337 * CSPR, 1),
(
get_account_id_from_seed::<sr25519::Public>("1A69d2D5568D1878023EeB121a73d33B9116A760"),
1337 * CSPR,
1,
),
// b19a435901872f817185f7234a1484eae837613f9d10cf21927a23c2d8cb9139
(get_account_id_from_seed::<sr25519::Public>("2f86cfBED3fbc1eCf2989B9aE5fc019a837A9C12"), 1337 * CSPR, 2),
(
get_account_id_from_seed::<sr25519::Public>("2f86cfBED3fbc1eCf2989B9aE5fc019a837A9C12"),
1337 * CSPR,
2,
),
// d3baf57b74d65719b2dc33f5a464176022d0cc5edbca002234229f3e733875fc
(get_account_id_from_seed::<sr25519::Public>("e83f67361Ac74D42A48E2DAfb6706eb047D8218D"), 69 * CSPR, 3),
(
get_account_id_from_seed::<sr25519::Public>("e83f67361Ac74D42A48E2DAfb6706eb047D8218D"),
69 * CSPR,
3,
),
// c4683d566436af6b58b4a59c8f501319226e85b21869bf93d5eeb4596d4791d4
(get_account_id_from_seed::<sr25519::Public>("827ee4ad9b259b6fa1390ed60921508c78befd63"), 69 * CSPR, 4),
(
get_account_id_from_seed::<sr25519::Public>("827ee4ad9b259b6fa1390ed60921508c78befd63"),
69 * CSPR,
4,
),
]
}
#[cfg(feature = "casper-native")]
fn casper_testnet_evm_networks() -> Vec<(u32, Vec<u8>)> {
vec![
(1, ghost_networks::NetworkData {
chain_name: "ethereum-mainnet".into(),
default_endpoint: "https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7/".into(),
finality_delay: Some(40u64),
release_delay: Some(80u64),
vec![(
11155111,
ghost_networks::NetworkData {
chain_name: "sepolia-ethereum-testnet".into(),
default_endpoints: vec![
"https://sepolia.drpc.org".into(),
"https://sepolia.gateway.tenderly.co".into(),
"https://api.zan.top/eth-sepolia".into(),
"https://rpc.sepolia.ethpandaops.io".into(),
"https://ethereum-sepolia-rpc.publicnode.com".into(),
"https://1rpc.io/sepolia".into(),
"https://0xrpc.io/sep".into(),
"https://eth-sepolia.api.onfinality.io/public".into(),
],
finality_delay: 69u64,
rate_limit_delay: 5_000u64,
block_distance: 20u64,
network_type: ghost_networks::NetworkType::Evm,
gatekeeper: "0x4d224452801aced8b2f0aebe155379bb5d594381".into(),
topic_name: "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef".into(),
incoming_fee: 0u32,
gatekeeper: "0xc85129A097773B7F8970a7364c928C05f265E6A1".into(),
topic_name: "0x7ab52ec05c331e6257a3d705d6bea6e4c27277351764ad139209e06b203811a6".into(),
incoming_fee: 69_000_000u32,
outgoing_fee: 0u32,
}.encode()),
(56, ghost_networks::NetworkData {
chain_name: "bnb-mainnet".into(),
default_endpoint: "https://bsc-mainnet.core.chainstack.com/35848e183f3e3303c8cfeacbea831cab/".into(),
finality_delay: Some(20u64),
release_delay: Some(40u64),
network_type: ghost_networks::NetworkType::Evm,
gatekeeper: "0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82".into(),
topic_name: "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef".into(),
incoming_fee: 0u32,
outgoing_fee: 0u32,
}.encode())
]
}
.encode(),
)]
}
/// Helper function to create casper `GenesisConfig` for testing
@ -214,14 +230,11 @@ pub fn testnet_config_genesis(
ghost_accounts: Option<Vec<(AccountId, u128, u8)>>,
evm_networks: Option<Vec<(u32, Vec<u8>)>>,
) -> serde_json::Value {
let endowed_accounts: Vec<AccountId> = endowed_accounts
.unwrap_or_else(casper_testnet_accounts);
let endowed_accounts: Vec<AccountId> = endowed_accounts.unwrap_or_else(casper_testnet_accounts);
let ghost_accounts: Vec<(AccountId, u128, u8)> = ghost_accounts
.unwrap_or_default();
let ghost_accounts: Vec<(AccountId, u128, u8)> = ghost_accounts.unwrap_or_default();
let evm_networks: Vec<(u32, Vec<u8>)> = evm_networks
.unwrap_or_default();
let evm_networks: Vec<(u32, Vec<u8>)> = evm_networks.unwrap_or_default();
const ENDOWMENT: u128 = 1_000 * CSPR;
const STASH: u128 = 500 * CSPR;
@ -270,6 +283,11 @@ pub fn testnet_config_genesis(
"babe": {
"epochConfig": Some(casper::BABE_GENESIS_EPOCH_CONFIG),
},
"ghostSudo": {
"key": endowed_accounts
.first()
.cloned(),
},
"ghostNetworks": {
"networks": evm_networks,
},
@ -288,148 +306,6 @@ fn casper_staging_config_genesis() -> serde_json::Value {
use hex_literal::hex;
use sp_core::crypto::UncheckedInto;
// Endowments for the whales from previous testnet.
let whales_endowments = [
// sfHXFVNvLVp8uSZauMyMijqXfoods8kkkik2MKnmr5MTdsweh
(hex!["a8ab31b36aae0dc29d2b92714cee75ee2784037c6f150d759d9aa757ab5a4666"].into(), 25 * CSPR),
// sfEtW9ijdwbU17oderTmwseMV84c7c9Xi1JW7T94rBbYKMMZq
(hex!["342c0035531136ff50d8488eb4d4772dfd10e565f6a5d28c7298b354d33f2dfe"].into(), 14 * CSPR),
// sfJtE2J5yVQBHdzwmXhzTwQZLtS853MFkUVYv5AfnB7TEVp2E
(hex!["e4e6a493d23633bf72b16ead89ab1451611b08311a9a49cc874a92e6ac4f5b1d"].into(), 31 * CSPR),
// sfFf48EnVLjD4wMecZh7meP5RWwYXZr54QiW2xQyPKPjxsxNo
(hex!["56266f27a02869f9498a113cbd4d1507ae5f4b8c91a6b8ccecda3331c21fd67f"].into(), 6 * CSPR),
// sfHxHVmMKZfUUzXRzKrV3oXSSynG1uAJ7c6dhFSq4CwE8qLn3
(hex!["bbc31594a2338e91c248aba474d892f41811a072c7e7c692fcae07fdb398b89f"].into(), 3 * CSPR),
// sfGvSkgfv99AndiEuhmL6t49ekbb2og2aYVRisAeNMPHueACW
(hex!["8e1f85cc6bb89182bc473859287b82fc2b9c89f461431090c2246a1a8d92d911"].into(), 14 * CSPR),
// sfHfByscdWfjzQNXc5g2q2ScMhop5pr5TiqiZosKxtMit1bRy
(hex!["aeb95893ab118bf02f5cd80ebab71ba58490c645e4302773fdc90b659f5c5e22"].into(), 11 * CSPR),
// sfGh1jtdTwWEco2N6cymxKgaoAJwYFMj2K2tdEbuML5LjUprc
(hex!["83e120fa3994efedc51092a8d90882803997f39f552a37699e3acb06c1f8158d"].into(), 28 * CSPR),
// sfJHvJDgdKdo1ZFXB146jhKVgngDrDeKTKF3GV5Eyvg1tJqTq
(hex!["cabca1450cbdc5769fa8f7b80d5bfd00df35b65613d8694e02517c9415fc5462"].into(), 12 * CSPR),
// sfE4SvLvh66FSThDnrTx5Qf5vHNCmBkrAJy8Zt8pMPN8h6dzw
(hex!["0f85589e37f3c0859ba7c055dec527a63796d6285b73cf8bd4657da052ff893c"].into(), 2 * CSPR),
// sfHJF1dYfzCpjJ8QHRBexNMfvSfsJvE75eCzgosrB6PwFXmpz
(hex!["9ebf64b6bc73baf1428da1cfcf36fde9695be0a56a855ddabb5612a70b10e447"].into(), 6 * CSPR),
// sfEEixqLWYct7au1PWkQAKbyso5VQhrgXQ2RXVW5TjcBm3vZ6
(hex!["175bce3674e24ec942112d91df594ba551b329ae7183b0faaef79fa051a85948"].into(), 21 * CSPR),
// sfH5nCFu2wNXnfD1Fic1weyLHncxHb7qpa8yXXQuNbQRUm9HH
(hex!["953e2cdbf7a66e34c50c51d199ad8970b1b2233da5604eb79a1de8d277c03061"].into(), 10 * CSPR),
// sfJnVLd4PMfoABtQiPmifeqkpQQKoV4wbXyAzhXKdSDHfi1bY
(hex!["e086ba892126243d6ef1c2b9132790e4455a3b1271baac8033306d55c8473af4"].into(), 30 * CSPR),
// sfECamJamifU5XyHH27ekuWY3MHAwj1z3rDcV2rpWdeGdAe2Y
(hex!["15b9b710a589968804e6e00f2ccb576ded431627a733b7f9fa0845f59e73f5cc"].into(), 31 * CSPR),
// sfEAhZrKxxChBR5SHQML6gNDJCK2FTMnRZZ2s2KVCFRxqFFTG
(hex!["144a1fa97fdba679efd2a36696a0d40f585b649143bb7da5cbd7458ea4a0f674"].into(), 2 * CSPR),
// sfDrDchmoxEfzyyPFWGX2fekP4mic99D6inhPnRvwokRZCbv5
(hex!["06319d9539108995233c48032bda04d50115fe829a2c4b5b23e54a4d17188606"].into(), 14 * CSPR),
// sfEb6NRc4ZbcuWUGJAnBkvEoacoXLbHZSM1asLpHiXqeY6YkE
(hex!["26e4c66dab5d9df3cb196ce320314e2565489f7d56b9868299a68cc4a1b4c917"].into(), 24 * CSPR),
// sfHfQMwpzNaA3D1uRGrzNPwZDeFbdXQDBJMay1oFDmD7C2RLn
(hex!["aee305cf2e015ef860c96815bb34ff9ac7df36db95f0587b6ded75218ae0d526"].into(), 22 * CSPR),
// sfKPnkuxV9u7AEk6bqU4i83NpAeG5w6VjcXYER5yfoojkkcN4
(hex!["fb72f46bd61ce821d12f5bdd6dc587afe5ae5821632b7e4b09464ea9e04111e3"].into(), 4 * CSPR),
// sfJGyU6k2gPVhmQJvgtY3iaVsakKQuD56jdgKZTGRLwjkHcbQ
(hex!["ca040e9167e0e7675ea2163506706cb7883a601a9ece1ba702fd253446f69e5d"].into(), 19 * CSPR),
// sfF8tAs7Z9R3GU8AnWgHEubxbwGt4zk7V6gSBeJJSqvt1xs8e
(hex!["3f238fbe70fdf9df12ed42416be91fa556802e7be7ea43c4de33314f5fb2da53"].into(), 22 * CSPR),
// sfHtQ3XxjAc3fbr4rxnx5P5ejV7LPXnN8nXwxevJ5MZwPJFCa
(hex!["b8cc24f449bd14c9903431b710842e1398a83d2ced33c5ea8fa4b75461db2f1f"].into(), 28 * CSPR),
// sfG5KDhmeKs6jXC2Jt1otffwHQyLR58dMGHwJCizUJHr4a7pU
(hex!["68a722b719350846a1f5a83143e01fdf18422d0d3d489877510062498ba74e5b"].into(), 17 * CSPR),
// sfH28MB4HFrE8YmtAcj95oTyMsQ9GgYWqxVtisWPqV5SwSMVS
(hex!["9275098141352f7e4fb3a4be9b2e50269947b7f54ecf2a493454955dd327274a"].into(), 28 * CSPR),
// sfEBNrjumQ8GLJTxeu3HvUDqHki3UxHCoSzg1x8SDJkfWfhWc
(hex!["14ce63bf285ad88594a93af2f1b8fd822c4db73030ae0783836083201876cb71"].into(), 14 * CSPR),
// sfFMYowKRoik3N9tYoSaPZ4vGPaPrDaezXiTVGZUBGWEwSKWQ
(hex!["48cc93d26f56df01cbd642e2d6eca745a9e2b84616e7f3b405411963c9aefa2f"].into(), 11 * CSPR),
// sfHPg4uVcq3s3TnfqHcsT6nEmeKJuNiJCW2eHk8Uk5aRfS7jr
(hex!["a2e3f7cfc7d8b7992a17b7aa8a85b47f1e0d254f3f0b760764f79af5a8349b33"].into(), 22 * CSPR),
// sfFo97CYcVqhjeiQiu6umcDggkNRWNjNu3XA6pU67F2C4Zs7g
(hex!["5c512b2cdb7da57ac056d6573ae3d1ae027bcec1b3b3d4dd79dc50160b24101b"].into(), 3 * CSPR),
// sfGxyWHjTMDVfmScYXjRFwXuVLyPj6XB8nzVjeZTLZ8RQkXQU
(hex!["900d88832e0748670c2358f2238bd34aaf49e070aa41aba84d931a0d1fef0978"].into(), 15 * CSPR),
// sfJHHLnAf9kbZz1PL4ESDpEMuAw7GXfFigC9wJD7ZArqRPwVG
(hex!["ca4039b68f9924c12399808da77247f2f45b0a9e397de94a33104c610cd8287f"].into(), 1 * CSPR),
// sfHqoR2AnJgWckgFY4HE2p5SK5gf6mUZGCXV5S3Ck7mnpTWps
(hex!["b6d11481813a6968a1d056794e6f0b85408480c5e8a6056769fbec9b5424314d"].into(), 18 * CSPR),
// sfJCVDhbVQzg7Y9JTm9mYiowUg2SuGQLLKGPwtstLVgtrcnmu
(hex!["c697fbb0ecf8069a0f88292d0a2097ba24b8c6998d04d21a02d92f6a23a65b43"].into(), 11 * CSPR),
// sfFFc7sBndJG1sZpxXfzti9K4Z7cNNfW8EQtEzsX9B1BWXoBv
(hex!["44443e9670b7f6decd4da7b042b6c9f740bd6b82e564fd51c1453fa442f0192f"].into(), 15 * CSPR),
// sfJbxCLF7tdMQRqzVgTiGyJQ2V2tEJXeC9pmeZqRaH3kNqYFA
(hex!["d87d702b99b8b3d58d8a48e5d750f40338b3a3d43fab09c23c50036226ba5325"].into(), 28 * CSPR),
// sfDrr9Vh9k3hC8JnpN4BG15z5yJPfMhHuPwFsZrd3S62b5U2Y
(hex!["06ac96e99519ae0a38f2475edfda3e432d3ae8d1f889a82e9ded1f1ccc850505"].into(), 15 * CSPR),
// sfJq7W4AboVKNgeG33y2oCE5o6h3eJaG6cyoKwtqjTkjSZXs4
(hex!["e286f428cd368ae7249d4ea76ad17df9350b0dcb437eadbf60053177769fbc5a"].into(), 14 * CSPR),
// sfG8ERVrJaoaJZdxT8tt9ZBRH4y1q9RHkyW1juiQBFjfqNm5s
(hex!["6ae0b990e482c499d93382e6183c0d2f3e8228e603de7c154ffb93e2299f152a"].into(), 14 * CSPR),
// sfG7q2arcyPyzNWrEZRoFvrf6go5PuhwofYVcthR3Mpu8dHgz
(hex!["6a91f855ff00e83c9b03cc222291cd6d098be0318eb60b88e6c167ce9e513a50"].into(), 11 * CSPR),
// sfFoee91wxv2u9LRFxCv9pzpM9L9YWGX2CPZveLFWbntrq6zd
(hex!["5cb4964925c2061492b88ff8daea2804b5770c044946c4ff0ac5a170eab1422c"].into(), 26 * CSPR),
// sfGkHJcQDaqeagPGrpaNFKR1kdRShUZH4Ec8iYMj6kyH8M2Tg
(hex!["865f4233b54d0903f5fdad05b0ec715b0ad9613fc69df18df4a013d3c7d3ab73"].into(), 2 * CSPR),
// sfFXJNrot6ou3UAmcynzSrD1RZnZzyhKM4gdMPfuDLUhCPyDs
(hex!["503c72a0f2c549a62d876dea81aa2e597b88503fa639ab0e9b65db599785f61d"].into(), 26 * CSPR),
// sfJyW71FYeFRb3YSQSVJAEp3CjPpNcUmzkw7riKMSkCiBEAs6
(hex!["e8ed0109c607d78aec9d8aa3575a565e34d65b399a5bd0e0102032d807ea0975"].into(), 5 * CSPR),
// sfKCXSvdcMTWyJDXDdZ2QP88ZsHDiwnGPfDVRPetf6KQfDAKY
(hex!["f2dbb77f0f922e5e92d98de7d43612d2f0b0d503aff20607d6c771fe8ee4a623"].into(), 31 * CSPR),
// sfJjXxYZNuXNirgQFE4MxuJ1w2ekxXHvXtowqUqEN52BNRryW
(hex!["de45cf59f588af5ee252c0ee0c805be8fa1ce172f8a6187d3b63dce1dc9c0b60"].into(), 8 * CSPR),
// sfGZf5wgfaLUq3h3JwHgZ52Fg2P27JYn2tSCgjosp4gL2Mdpx
(hex!["7e44e1ede822621cc9f618480433fe002bb8edde02d2fcd4fcf406409e154e68"].into(), 28 * CSPR),
// sfETREDdpH8vyT6zHEfcF5qdJhNw8iJVFeSfspKHv2BeUGQg5
(hex!["210a4b979e39c3136be105df1974fc036f4fe9b035936c149bdb94a3f4820487"].into(), 6 * CSPR),
// sfHA9NkB5Bb5hgt1f58jf1UminCdrmyu94VGoKB3jo9YRoPjW
(hex!["98927535310e1b910ca19860e1539a15c5dc02df780a66a22f5796cec3768812"].into(), 12 * CSPR),
// sfJeYC8LPe41yBP8WptgSzkYgfM39y3derRV4YeYXkpEysT7b
(hex!["da765f0ad9bedffdc9aa88da6fdacf4afa4463395785b6e03acb0811395a8f5d"].into(), 20 * CSPR),
// sfEu7ZzgjwEuhS1EkebXfkvH3wMyxpSgcvH8btDi6EMqG4goQ
(hex!["34a33af049f4f1b65d518e51f38c7afb0cd973c649588808b2ba0211f4ada535"].into(), 5 * CSPR),
// sfHZx1bZK6aoJKfQ1XQfpRD5VZBXZM1uREGcBsnKJdTZDnDod
(hex!["aaba173e1cd257c1ba67afbed0fbf2c4aadbfac329f129f12c4941b8b6bc5865"].into(), 5 * CSPR),
// sfJHhyq2r19nHEbKbVn3NEWqkDWnK53rU9mpRVPEYh7dqkCwU
(hex!["ca932abf1648393d722ad23c2cd97515a436840d905d3dd2b4d1913989abbc12"].into(), 2 * CSPR),
// sfE8Hv37BNfZfdj6aKC8XuBPQRG6eLRJPuRqEmrCfPGF4F7Ag
(hex!["1274036453f19a410d99cd7a13235422062ff5b0d2dbd608d87ad33b9b7b544c"].into(), 17 * CSPR),
// sfJHHALMCEmBTJHEdHkgMbUt2XMFP4K2AcYPiwgtz429YUqWv
(hex!["ca3f9e8480f200b6afe9661cb96a30259fc88b947c3ab466bd2b8e902a859719"].into(), 2 * CSPR),
// sfKTaDy3Yw6eXz4GFfXLRx9LnDf8qEt4JpqnPJc8bQVAu6kET
(hex!["fe55bea13108c5f9e070689c96d63c40ca79db709bebe921289003e56a1fdf27"].into(), 3 * CSPR),
// sfJ4NLMc92S6gSvQLsxUvhh4zXwde1yHYJCBu2WFjwL1Hxgfh
(hex!["c066d79465a7bd3138c770f52c1ad160272705e98f9b3dacc22bc70f010a1564"].into(), 12 * CSPR),
// sfJcMpW8ESzTzpmftos8MoJ7pUyRbxPabxPHSuigfxQxy8GBR
(hex!["d8ccf65eb5e93fdf7af47e9c6962a6822c7f0e8ed14d84f2bebdae0c5623e62b"].into(), 16 * CSPR),
// sfESZE2fNkkRCR2bSmmKZ5VzmMGHFh8eUdE2isdjne7JGW9AU
(hex!["2061f823e814d8c6b524da2f26ba2bfa048bbce57a1186e560b84c47a162b927"].into(), 1 * CSPR),
// sfFSxdDQWSnuF2zJ3tRv3B9Xxzu8boEkByCSXkq1T1F6vRky5
(hex!["4cecf92b37e6954f086002cf7b6a61ac7d9ba40c83ef963005e3cacfb5c1e13f"].into(), 21 * CSPR),
// sfEivpTTfp6Xh7nHaco1sxXQiy163pT474cS2dj8d8MREaJ2x
(hex!["2cde961358bf934533495f186755eb538a925aaa19ab4bad097f9d23665a9553"].into(), 24 * CSPR),
// sfJHPU8JPeCg35QvgTwZ2iFAwiavxem4McAYtgvTKpePSnUrw
(hex!["ca54d983c77c48c948fa9a6f9261ce2d9c4f20abf6632e28da3ec41d4752d519"].into(), 8 * CSPR),
// sfDyruPst6vv93A1pUYtmNQa95iypWhMw1n4PWDfpP9g1WHTQ
(hex!["0c05daf23268fdae4efd5bc1211f662c63399be10666ad3bdc75f3470a5b3378"].into(), 11 * CSPR),
// sfG5dZrh8trJRWewe1THxhvCTdR1Qq6NDUkoGuQg4VA6iAm2z
(hex!["68e4e6131e6a7aaf5ab2629d2ee721031df2e2a6573701862508fa3dc5765f5c"].into(), 4 * CSPR),
// sfHNVjWNHs6fwPpHmmPj4nJQ7evN35qr9KkJVeiJjmyf3fGxj
(hex!["a1fdef07d92813b10b15914afe763aa16bbf3feca8db73fabf1422cd48e05db0"].into(), 16 * CSPR),
// sfEYCLQnQzp8EYfqqhWmB1mtWNPX9AmVLGiwhVpFVQ5JuuGmu
(hex!["24af1eab02801a2d1afe16c75baa55f930138d58229f02f2840f387241529424"].into(), 18 * CSPR),
// sfDwQQ2Zy16Hx5qnHQbsXw8reMewJ684yUydmTXT7E3Y489se
(hex!["0a2622dc4be5606375d3a47e56e2580636b0057c46ec85bd44e149bff55fb943"].into(), 27 * CSPR),
// sfFMhheEBKGwDcJ9aqpYvVsAAq3tu2tEcVaRd66zfxY8qaShs
(hex!["48ea8240144388abb847a7b2c52f6290aeb77f1b6d8e10cda7d14a2f48b05035"].into(), 3 * CSPR),
// sfE66BLe2b6wM9dWctMnizM7yzadJrzGtTDC64cMTmJxZqGG1
(hex!["10c603d5a51516d1ee97212cf0b79f106332439750673b8605a527ffe1d45c50"].into(), 3 * CSPR),
// sfEiXa1R4CGPDZcdJ7oEnTuwiicA5Dhtny8z7aYhSrbDQNygK
(hex!["2c90529d502a1f3c51fcf487782b4defa09bd0e7470d1d080e44da713058241c"].into(), 24 * CSPR),
];
// Following keys are used in genesis config for testing (casper) chains.
// DO NOT use them in production chains such as ghost.
let endowed_accounts = vec![
@ -437,28 +313,10 @@ fn casper_staging_config_genesis() -> serde_json::Value {
hex!["328d3b7c3046ef7700937d99fb2e98ce2591682c2b5dcf3f562e4da157650237"].into(),
// sfEwRjyvEQcpRQ1qbCZum27nEkTggKEt7DtqxwyYQULt9UuUN
hex!["3666e4e19f87bb8680495f31864ce1f1c69d4178002cc01911aef2cc7313f203"].into(),
// sfHcJxw5cgkvukZZyxcNUMCdbm9e7773orByLrGgAREka81TK
hex!["ac871e8bab00dd56ba3a1c0bd289357203dcaf10010b0b04ad7472870cd22a3c"].into(),
// sfFD7KSRi2aSREJWc9X75sVTN4a5pbPM5VSSJefmPvMuiVbPr
hex!["425ccd7bda4f5c76788ba23bc0381d7a2e496179c93301208c57501c80a4232a"].into(),
// sfH29zyFYtoFj6fSXskAEXG5XyyMCa5YycahJkYMwSUz8CcEU
hex!["927a98dcf8f721103005f168476c24b91d7d10d580f457006a908e10e62c7729"].into(),
// sfHcRoUmrL8GDmWxUcPcZEWVfJbnaXyjWuaBxu5pNtdW5nERK
hex!["ac9e227e30a63ce6eeb55cfbb1fb832aa7e1d3fad2bcb3f663de4a91d744fd50"].into(),
// sfFJuDxqSc3skWaNUQgqmtCDYvcRj9c56urEky7ByD26aXQEW
hex!["46c78fcacffd80abc9cca4917ef8369a37e21a1691ca11e7a3b53f80be745313"].into(),
// sfKNNbANdBuBpA4n1sXwPBhV57HBgV2y3R3YjHz1S1uWKfKAy
hex!["fa5e5a295ec74c3dda81118d9240db1552b28f831838465ae0712e97e78a6728"].into(),
// sfFAdZQQVdbCTA7eWomTrJXe5L8ZcwZRfkyyRkMQZftDqbcMg
hex!["4078ddb1ba1388f768fe6aa40ba9124a72692ecbcc83dc088fa86c735e4dc128"].into(),
// sfFqT8fmF15Ddshio5rnucmqzMxtUoHZVh7qSALSdAaM7Y6zb
hex!["5e1456904c40192cd3a18183df7dffea90d97739830a902cabb702ecdae4f649"].into(),
// sfFzUcPxuourb6JtdiudRkrsbnkxne1KEcpksVMJYGau5BVTG
hex!["64f685baa838323c0ef8c45259a3036b3e2bc54edf6553ce323e25b5e37a3721"].into(),
// sfHLkJNKVyAsVMC4bQQwsm1EMyWgKLQH8FFnZzLC78dYJDqSp
hex!["a0a87a75dba18037aa2e7b8036ce951e8d8356104758e15c9f44e2fd7d1bbc41"].into(),
// sfGCg772bqKp3wH23EQbgSbCQ5Q8BCwmCJ39XjR3xLwq6foYD
hex!["6e4429a8fa85cfe2a60488af446d57e719207831b2579b937325645e110bb666"].into(),
];
let initial_authorities: Vec<(
@ -475,13 +333,17 @@ fn casper_staging_config_genesis() -> serde_json::Value {
// sfFXZmnDVnkQ781J2gbqUpi7K5KgMWMdM4eeii74xxGgKYnNN
hex!["507045c82be367f95408466cd054ca39bfa52697a3ef22809af14cf9de304f02"].into(),
// sfJeojACBa7WiH6tBwikBKAMU2oKmseEBD1GYUYATvfWuLcPa
hex!["daaaaab6a6e574099e24ae9bb75b543610edef9d374fa85a378edb573b47615f"].unchecked_into(),
hex!["daaaaab6a6e574099e24ae9bb75b543610edef9d374fa85a378edb573b47615f"]
.unchecked_into(),
// sfFdtzNxJdeEkgHxvk144rJKxf7wcYvgX5tqfgZRutW9YvAKE
hex!["55446f9a7aa99ced06b317c80ce90d56b84e56526775683af2525969e8da0b64"].unchecked_into(),
hex!["55446f9a7aa99ced06b317c80ce90d56b84e56526775683af2525969e8da0b64"]
.unchecked_into(),
// sfE8gsMYAjAJHk5gyYZN7AW6pfmJ7V9H7xxWto24nmhzCUXaQ
hex!["12c14850562021eb99f58f90ab624fb6cfaf3ac9228a92f8b60115fe6a6af15a"].unchecked_into(),
hex!["12c14850562021eb99f58f90ab624fb6cfaf3ac9228a92f8b60115fe6a6af15a"]
.unchecked_into(),
// sfE3GKSrKZzrZpdapJ2VGRpPor45T4D4i8QBZNumSNGqGv7PX
hex!["0e9e698c7b2bf5ce3861cb4bc4ddf9e200237c282025b093ada850d764d12a35"].unchecked_into(),
hex!["0e9e698c7b2bf5ce3861cb4bc4ddf9e200237c282025b093ada850d764d12a35"]
.unchecked_into(),
),
(
// sfHLqWNC4hMKHhwvPWmWcxZsDPhCTQKgh1Ap7pm3qML5GBTBa
@ -489,27 +351,17 @@ fn casper_staging_config_genesis() -> serde_json::Value {
// sfHLqWNC4hMKHhwvPWmWcxZsDPhCTQKgh1Ap7pm3qML5GBTBa
hex!["a0ba0196e6ee7e6b5b0553035c5cb5c04e9725001b5732839d0529cbc00c9600"].into(),
// sfGA6tPPF8dAc8QpMCMjxitG3j8sXPhkdpm5bwz4UsXAApUiw
hex!["6c4dd88b43e2011cf9a6a73d53446336ac9e04cdd4ca23587df63187ac455e49"].unchecked_into(),
hex!["6c4dd88b43e2011cf9a6a73d53446336ac9e04cdd4ca23587df63187ac455e49"]
.unchecked_into(),
// sfGxQZXFUQH1AXv82rpjiJHFs7YsdEuVGdyvKiS2Tajpvw6Se
hex!["8f9ea20bf4a807a8e710f7559dece86e94672b5b361de157bdaa5c1f37849f8d"].unchecked_into(),
hex!["8f9ea20bf4a807a8e710f7559dece86e94672b5b361de157bdaa5c1f37849f8d"]
.unchecked_into(),
// sfGz2enFUR22cQ5ey61MdtPqbCeEWZA1wsCFFSLGaK7vKnv8C
hex!["90db5ed339a559ed157995a48d781f44c7df972dfba4bc855e4b59fa46438e17"].unchecked_into(),
hex!["90db5ed339a559ed157995a48d781f44c7df972dfba4bc855e4b59fa46438e17"]
.unchecked_into(),
// sfEtwe5BoroNjkdLsvnjnMemUKiw8MS1X4YW8bepbbGvhS4LZ
hex!["3481cdcbcf37a4669c29a78cf9ceb39383a10ef0a18b36b92d149fdd0c24ae00"].unchecked_into(),
),
(
// sfGq75CrCrkcfqNzyyidu3D4jW3AoJSzL5tKKuv1UbS16ezzy
hex!["8a0d0b66e827bf20e79f9a499317e73925ce4f422371067edfab690e43857f13"].into(),
// sfGq75CrCrkcfqNzyyidu3D4jW3AoJSzL5tKKuv1UbS16ezzy
hex!["8a0d0b66e827bf20e79f9a499317e73925ce4f422371067edfab690e43857f13"].into(),
// sfJo2ogBpssRAU9ZPTvuXFZEdmJw9pKsPydLjXe8DypRScjzT
hex!["e0f0a776ecc9fa5e1f22e2fa001fe3fba5aea52b9444bc894b45589d42132475"].unchecked_into(),
// sfHq3EVT1sqY7o5ki3zA6LEdRDfdFc29YaZN3w2Thhz6JD5ZF
hex!["b63c5a0cf342b9b04931bc8ed74d7d0165ab99ab5f8a4514797d4b299a4501fe"].unchecked_into(),
// sfEj3wrDy9EDLCAodyEdQEYxJpNnM8Etaj3RJ5bCBRzdaDced
hex!["2cf69452e9f2a8457119139408884941ed50f590c0fc0f2b044c4d82c69e4245"].unchecked_into(),
// sfE32RmBp1xX4KRTphVGLUJBxLGPN3Dzg9BwCJktxMf3iEwck
hex!["0e6fa6934f9e99fa84874f2ed9318825a0d5443a0ced984acfbd24ece72ba55e"].unchecked_into(),
hex!["3481cdcbcf37a4669c29a78cf9ceb39383a10ef0a18b36b92d149fdd0c24ae00"]
.unchecked_into(),
),
(
// sfG9iWUS7AKBzvqdz3uDZv7f1t79vvSTYL1VxzYPHjhmLnQVn
@ -517,13 +369,17 @@ fn casper_staging_config_genesis() -> serde_json::Value {
// sfG9iWUS7AKBzvqdz3uDZv7f1t79vvSTYL1VxzYPHjhmLnQVn
hex!["6c0283f4c688f0e75ad546c790bbd5961c1a6931543aa589f368f8272c44b758"].into(),
// sfGMUYXSjHgwGBpbGiHFoqT1DdJwZdHk49H5ViaQM7HUnayvZ
hex!["74fa7381a7a74b316afb6793a00387eed9d95d46a69866cbb316b5d9c918af0e"].unchecked_into(),
hex!["74fa7381a7a74b316afb6793a00387eed9d95d46a69866cbb316b5d9c918af0e"]
.unchecked_into(),
// sfEWYhczV6PbmeNXZTcA4LvhpzvCfNMatYoSNKvDphmNaQzqB
hex!["236d2fa03f4ed8cb65de7e514d7540159b328f1c170dd402b094ad7fbf547218"].unchecked_into(),
hex!["236d2fa03f4ed8cb65de7e514d7540159b328f1c170dd402b094ad7fbf547218"]
.unchecked_into(),
// sfDirg32ityDvrjxh4822unhP4qm4S9yTqN99gesN322swn7h
hex!["00946618c353e4c6546b87f9ca1089b846b0ea4658ee8e6d9d1200c24cb5ee27"].unchecked_into(),
hex!["00946618c353e4c6546b87f9ca1089b846b0ea4658ee8e6d9d1200c24cb5ee27"]
.unchecked_into(),
// sfFZgp1Z5diFAZ16swuQD5GojGCsMMFVR19uWnCrppMLuYjRv
hex!["520e74f8c5853ec8577932327ad3247656db25b74c79ad09adb431b271002401"].unchecked_into(),
hex!["520e74f8c5853ec8577932327ad3247656db25b74c79ad09adb431b271002401"]
.unchecked_into(),
),
(
// sfHjtrXFzRmxwjE4rjVxFJXpvVv7furjdymZS7PQRFiANpodz
@ -531,125 +387,17 @@ fn casper_staging_config_genesis() -> serde_json::Value {
// sfHjtrXFzRmxwjE4rjVxFJXpvVv7furjdymZS7PQRFiANpodz
hex!["b24feb55b2cac4b365a9245c2a97525b01bd1a594d2d42b91f6bc38c9c2e6517"].into(),
// sfF5XWwvNPjZEsBz1HWs5Ys5zcE85UHnN1BV8TBBectqFQZRm
hex!["3c944c704cae203619b9e7a5a4b6742736da6a8e76c762291bebdc7652cfec2f"].unchecked_into(),
hex!["3c944c704cae203619b9e7a5a4b6742736da6a8e76c762291bebdc7652cfec2f"]
.unchecked_into(),
// sfDx3gj4wFHg3cK6bopnypHQ6TxW1VgyPsYVbXKhRHtLDLxQb
hex!["0aa3a88f6b777c95c3dfe7e997b76798413f16aa325f34824cae0c9102b281d5"].unchecked_into(),
hex!["0aa3a88f6b777c95c3dfe7e997b76798413f16aa325f34824cae0c9102b281d5"]
.unchecked_into(),
// sfHXZbnZV3YWwnH28q2xumm7stvuC8LweYYxPNuHGonnX7QHL
hex!["a8e828d10cf7b74481b6e746e5532d4740ea8014a0d3d856540a59847f8a6b76"].unchecked_into(),
hex!["a8e828d10cf7b74481b6e746e5532d4740ea8014a0d3d856540a59847f8a6b76"]
.unchecked_into(),
// sfEaHBrBgeMhRTA3WHE9Nbyvn3h7xkhYKi7go4yo81L88o9zJ
hex!["2645f1f6820dd3a917eebbdab033088d8862477c1c14759b218685f9a0893377"].unchecked_into(),
),
(
// sfFFYKBEwmJAQEJR73Q4Gfs1sH1c8wyuBGnHc1UdzWucAYrKC
hex!["44376f8fa786be1f16fcb45232cfb07300cea845b2fc6e30dde61952de3e5e33"].into(),
// sfFFYKBEwmJAQEJR73Q4Gfs1sH1c8wyuBGnHc1UdzWucAYrKC
hex!["44376f8fa786be1f16fcb45232cfb07300cea845b2fc6e30dde61952de3e5e33"].into(),
// sfK4K5bS7M6bHeKHoGec9bw1PMngNyzhTx9YZq6hkqibos4LJ
hex!["ec981eb1ef1ddbc8ded2db16198cb03667b4b39a8ea58f28ad469ddfaf256161"].unchecked_into(),
// sfECakKMW2xf5dK8Ut55tnwadoKTNGKdRLh5E7dYRmV6sW812
hex!["15b9a867891cf449584b108e512d60b945b1a065bec1703c4c5709ee5093c03d"].unchecked_into(),
// sfErEin4Ljy11VGnYtTYJZ9LLcDP4fvsKV6f9LXYRwRXtrNqa
hex!["3271915dc67eba8ad2759a30c2537702f4fbf45647cba565e3a464ab75b91f05"].unchecked_into(),
// sfGD5sHSa1h8NGpUD29ZogBJW6fatg8Sg6Pzg9Q7RPUm24Mkr
hex!["6e9426dc78fba9eeb264dcab98be86daf3d8cf510ecfb2acddec370295ff8176"].unchecked_into(),
),
(
// sfFPZZNrhDuY9MKJCBHyBCkgJecgDqPJBPSjA37be4czdX6t3
hex!["4a5596e97c602e7846d54fae81dcdc5a553b7422231e32f9567ac30a6b7c743a"].into(),
// sfFPZZNrhDuY9MKJCBHyBCkgJecgDqPJBPSjA37be4czdX6t3
hex!["4a5596e97c602e7846d54fae81dcdc5a553b7422231e32f9567ac30a6b7c743a"].into(),
// sfJP8aW6eSUs14AfUG6ZDFFjtyJxDed5Ubk1CFh7dNmL69rbx
hex!["ceb63298b1b7a1277fddf6eee735dbbf9921fd5ebaac0132eee1963e22cf5935"].unchecked_into(),
// sfH6jAeHqDpwtYGv9KJWNJ8aom8ivSvVztRSwAHw4bXd1isoP
hex!["95f73a6271b517f2016fa91411bdeeb990158066c95f106a79697446ba9f78b4"].unchecked_into(),
// sfEXSdKyx6uQBzgR3a7oH53XSCLrjUM2B7fbcvUvm21b5J6Uf
hex!["241bfc05caa2d3e53e671df7261599c13f069a37f6cc4be10b5d49502c3a1e1c"].unchecked_into(),
// sfGXqJTwJTkh3bwhECju7XCdgvJXYJZUtYSEJ2PbfpXGak42s
hex!["7ce0c80ee65fb00e229d8c8fa5484144eca3d45d733165fbffcdb4de24c14951"].unchecked_into(),
),
(
// sfESE7VifnknxVe71z3zsqC3xiirXyzHurKjdQoD537WpwJjW
hex!["2021a16182e3af39a79d20021a1b8755d589c04292d361d6b387411f7e975602"].into(),
// sfESE7VifnknxVe71z3zsqC3xiirXyzHurKjdQoD537WpwJjW
hex!["2021a16182e3af39a79d20021a1b8755d589c04292d361d6b387411f7e975602"].into(),
// sfFzQmYYckD8XLV7XGU1pJAyt1K3foCpPumpKBqdb5sJGHXrc
hex!["64e9968f3af2e1a86ee8d4be9ad77a1d66f50138527988bf93ede25baaf2e671"].unchecked_into(),
// sfFHjCLzWetvQJQzNwxeWcrkHmnPS1mVz7gT63yiRdvxFZ9T8
hex!["45e28f333bf0d4a9956ae20341cd07db8d471c4b482ed15d5cf7edd70201670d"].unchecked_into(),
// sfHJAk4HiVuMjXqaXoFEKTCF6938Lta7qd9w3zbyyuWCs1T5L
hex!["9eb1063afcaf568e7a62458ef33237a41ca500c89e084f7a5dd75bf5d89b105a"].unchecked_into(),
// sfEm2SME5H6GiezhYokZWmrZLMTUNFbLV7xwgKrMXz3NwppKb
hex!["2e77fde21162d1f21ca371846d70c3b75931329074101ee668e614336d25c120"].unchecked_into(),
),
(
// sfHpvEbP79MrDMVw4GhTvgLSU987ZSJ21VAsDWiJdgjG3ijse
hex!["b624cb291f7464773f3b449ee2252165f3934ace08b1e10611a53e174766fc73"].into(),
// sfHpvEbP79MrDMVw4GhTvgLSU987ZSJ21VAsDWiJdgjG3ijse
hex!["b624cb291f7464773f3b449ee2252165f3934ace08b1e10611a53e174766fc73"].into(),
// sfJHYLgjoHotvKi46URmtaVoG4p54SPE2ASTrauym99WxFcAn
hex!["ca72b6ea2c83f9e429479bf51c324ea90cbf01e08d2850ced2590c8796cfe222"].unchecked_into(),
// sfFVPqgCsDQe3k4qhGmUH4UoZaxsGb9majPgoH3WaYCZjFhTf
hex!["4ec8584ca9da16d8c60e1770e98fbca8bec648e13c69601e3dfdc1330bf1f999"].unchecked_into(),
// sfJ6nxM1SvcdbV2Gmf8WKkPKeX6rRYaEmSj7V9r64799acqHV
hex!["c2403683be24a92ae8489e28fb502e2bab16d815c4f6c865c50ffb34430a8d7c"].unchecked_into(),
// sfK1sQY3GL8waX2htW9EaBo9MjWGuy4VGeiUfP4NCq5tCjt37
hex!["eabb3463e300f357b9886683d5a240a395f6bd41182057f03b0e9697a8b3465e"].unchecked_into(),
),
(
// sfJeU4TBQyuGxfsCqNDPax1TcfAseEmBDPqx5YEm7kXUvnnPa
hex!["da6875e9df9a7894e065ef5befcde567dec4dc2c0b73a6ad5514dcca26a90702"].into(),
// sfJeU4TBQyuGxfsCqNDPax1TcfAseEmBDPqx5YEm7kXUvnnPa
hex!["da6875e9df9a7894e065ef5befcde567dec4dc2c0b73a6ad5514dcca26a90702"].into(),
// sfGbxmQAD2jbktjRkq6NsJxHKHWnkdtvoR14fFPAX85t148ej
hex!["8006e3f6e3d92c4c5f2e2f001452e4993e6d5c2b1136f2ae6060c6e9c9523b4a"].unchecked_into(),
// sfGm1jJagueW5dCng6xKCDx3FX2JohtsYMuNjf2tJGXN5ePUL
hex!["86ee138c9e7e67c1c2e157c0ba888761a122d8b9aa6a8653e886ac329e34255d"].unchecked_into(),
// sfEB68auUQmSCK8M3Zr7WuzRSipj9sQ5ykfDmvLmT8FDY5bg6
hex!["1496150847d512e0491899eba72ee36f76b882ae29fccf18201fd9fbd5bfd300"].unchecked_into(),
// sfHZqUptNXpRNGPHKn2Tfv8K1RjFGJ9XCdSw41nPAw9ZXM37T
hex!["aaa41b6ade4c30b5792aa6e5604c444e424900ddf649b23eed4bd0d7f5d3a34f"].unchecked_into(),
),
(
// sfFBEdrB1J7jLJKQp3fABEiHkwec1gCgGeTxMVyVm4UjWwvRs
hex!["40eef1c6c8d8242ccbd3f03144bd4ea1a7374cbd8219e2849d3a3ee78f1da045"].into(),
// sfFBEdrB1J7jLJKQp3fABEiHkwec1gCgGeTxMVyVm4UjWwvRs
hex!["40eef1c6c8d8242ccbd3f03144bd4ea1a7374cbd8219e2849d3a3ee78f1da045"].into(),
// sfF2FRJSuQSCidfbpu8DwpsHwezCcBJcZfh7Pds5vqtEF3Rbw
hex!["3a145fb664353e473f1937058c881b14ed150285f3cec1aff348c5209d56d96d"].unchecked_into(),
// sfDysi9h3PJoA5BGeJ2vfAkx3wXS9oK7yTDUyuJG2CRMJvXnh
hex!["0c0891a518270014530061bd217606269686abdf3c1d237a3c6a3db308fc2d0d"].unchecked_into(),
// sfGsyqzBAT7a9oBGdDBykyRwF95wRBL4yaGs4QFWznXHw5xsF
hex!["8c3e730f6e6ecfb96581091e71556175384f077bee31b0199f13321df018427d"].unchecked_into(),
// sfJP7W9aZe2F6G5w7xZtHhzSUCg86SvUcur4GPm2LMs7N2f5w
hex!["ceb294227950d177b63e6c1d10a66131f5da3792428b03f5b83be84a33db215f"].unchecked_into(),
),
(
// sfFCsSaJrPqkCZMdkm7WoyHP7w3UbNaC3aCHQfWbUaLbDqfdR
hex!["422e16b0c58f03af378d1638fe56127f337abf1d1a4a740c3371714616abd43d"].into(),
// sfFCsSaJrPqkCZMdkm7WoyHP7w3UbNaC3aCHQfWbUaLbDqfdR
hex!["422e16b0c58f03af378d1638fe56127f337abf1d1a4a740c3371714616abd43d"].into(),
// sfGShS9zKf8nzDr71qPv9LZJtK1LCMxPV4QUMYG8jvZhVe9pS
hex!["78f612068566eb6cc5cb5d9f1fda92c5dc3e3888eb61eb1af27af6855365ba3c"].unchecked_into(),
// sfJg5cPBkyrcu7zZaKaUkjp2vDVGfpGNjjT1sn8fS6qjv9mDU
hex!["dba3613933d60ca248ee024deac42bc9c8c2d9fe8734b6052cd9a148978cbedb"].unchecked_into(),
// sfFav2ALRGkJtmEHEpz2LiRmshGPzn4aWdAZeFUyKA56LqDDF
hex!["52fe2b63b03a0d439923967278442418a2d1f0d250bcab26f85f12ea212cbd3e"].unchecked_into(),
// sfDmN4zoicQ54R5MmSpCf9ojg8zE2eD3x39pnba412oDivkBc
hex!["027dd852bf20bef53545afd1e08bf8760abb6b1af1df6c17e73f4cf88210ee46"].unchecked_into(),
),
(
// sfF2fiFe2PteoYe286cZNJpxaT1omCPuTgwHjB1Z8tqjsLxRn
hex!["3a6626211a2dd35683fd7cb5f2f343d75f2b698d6c48c2d6eb1cdbe116e32315"].into(),
// sfF2fiFe2PteoYe286cZNJpxaT1omCPuTgwHjB1Z8tqjsLxRn
hex!["3a6626211a2dd35683fd7cb5f2f343d75f2b698d6c48c2d6eb1cdbe116e32315"].into(),
// sfG9m1LEV1sjUwyLwp1UQPUGnuMGF1oaCjSC4PVx9q4zgJRMr
hex!["6c0aec49974aaff08ff962a2d8d7857227d027ed27a272cbc4acaa1ee937db0f"].unchecked_into(),
// sfH3JwHTbimvG3SZLd5d8Ad8Ztvgb8NVSwxxzxYfArpXVYqFD
hex!["935becdfb2e0d4fcd46ba82e680cfc447180de6b85ec42d17f1396a520b0c04f"].unchecked_into(),
// sfGkKjBX5UdujuTrbxyepUzdU4Jew7DvgNs1UUM2HBLj4xNM5
hex!["86676ad3cd2d970b86dee2f25d4318f9bba40455111f16300e114e7f00c58706"].unchecked_into(),
// sfDisU5wryao4kcd4WuHyZZB6LfJrDuoQoU14cTiiJqD7Whoc
hex!["009712519ba7dad1c682c871b94573ccaba8b7d530f7194fb16bf553fd7ae67d"].unchecked_into(),
hex!["2645f1f6820dd3a917eebbdab033088d8862477c1c14759b218685f9a0893377"]
.unchecked_into(),
),
];
@ -665,7 +413,6 @@ fn casper_staging_config_genesis() -> serde_json::Value {
.iter()
.map(|k: &AccountId| (k.clone(), ENDOWMENT))
.chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH)))
.chain(whales_endowments)
.collect::<Vec<_>>(),
},
"session": {
@ -707,6 +454,11 @@ fn casper_staging_config_genesis() -> serde_json::Value {
"babe": {
"epochConfig": Some(casper::BABE_GENESIS_EPOCH_CONFIG),
},
"ghostSudo": {
"key": endowed_accounts
.first()
.cloned(),
},
"ghostNetworks": {
"networks": evm_networks,
},
@ -726,7 +478,9 @@ fn casper_staging_config_genesis() -> serde_json::Value {
fn casper_development_config_genesis() -> serde_json::Value {
testnet_config_genesis(
vec![get_authority_keys_from_seed("Alice")],
None, None, None,
None,
None,
None,
)
}

160
service/src/lib.rs Executable file → Normal file
View File

@ -7,15 +7,15 @@ pub mod chain_spec;
use {
grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider},
sc_client_api::BlockBackend,
tx_pool_api::OffchainTransactionPoolFactory,
sp_blockchain::HeaderBackend,
sc_service::{KeystoreContainer, RpcHandlers},
sp_blockchain::HeaderBackend,
telemetry::{Telemetry, TelemetryWorkerHandle},
tx_pool_api::OffchainTransactionPoolFactory,
};
use sc_executor::{HeapAllocStrategy, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY};
use std::{sync::Arc, time::Duration};
use telemetry::TelemetryWorker;
use sc_executor::{HeapAllocStrategy, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY};
pub use chain_spec::GenericChainSpec;
pub use consensus_common::{Proposal, SelectChain};
@ -23,27 +23,23 @@ pub use primitives::{Block, BlockId, BlockNumber, Hash};
pub use sc_client_api::{Backend, CallExecutor};
pub use sc_consensus::BlockImport;
pub use sc_executor::NativeExecutionDispatch;
pub use sp_api::{ApiRef, ConstructRuntimeApi, Core as CoreApi, ProvideRuntimeApi};
pub use sc_service::{
config::{DatabaseSource, PrometheusConfig},
ChainSpec, Configuration, Error as SubstrateServiceError, PruningMode, Role,
RuntimeGenesis, TFullBackend, TFullCallExecutor, TFullClient, TaskManager,
TransactionPoolOptions,
ChainSpec, Configuration, Error as SubstrateServiceError, PruningMode, Role, RuntimeGenesis,
TFullBackend, TFullCallExecutor, TFullClient, TaskManager, TransactionPoolOptions,
};
pub use sp_api::{ApiRef, ConstructRuntimeApi, Core as CoreApi, ProvideRuntimeApi};
pub use sp_runtime::{
generic,
traits::{
self as runtime_traits, BlakeTwo256, Block as BlockT, Header as HeaderT,
NumberFor,
},
traits::{self as runtime_traits, BlakeTwo256, Block as BlockT, Header as HeaderT, NumberFor},
};
#[cfg(feature = "casper-native")]
use casper_runtime::RuntimeApi;
#[cfg(feature = "casper-native")]
pub use chain_spec::CasperChainSpec;
#[cfg(feature = "casper-native")]
pub use {casper_runtime, casper_runtime_constants};
#[cfg(feature = "casper-native")]
use casper_runtime::RuntimeApi;
#[cfg(feature = "full-node")]
pub type FullBackend = sc_service::TFullBackend<Block>;
@ -177,9 +173,13 @@ impl IdentifyVariant for Box<dyn ChainSpec> {
}
fn identify_chain(&self) -> Chain {
if self.is_ghost() { Chain::Ghost }
else if self.is_casper() { Chain::Casper }
else { Chain::Unknown }
if self.is_ghost() {
Chain::Ghost
} else if self.is_casper() {
Chain::Casper
} else {
Chain::Unknown
}
}
}
@ -222,7 +222,9 @@ fn new_partial_basics(
let heap_pages = config
.default_heap_pages
.map_or(DEFAULT_HEAP_ALLOC_STRATEGY, |h| HeapAllocStrategy::Static { extra_pages: h as _ });
.map_or(DEFAULT_HEAP_ALLOC_STRATEGY, |h| HeapAllocStrategy::Static {
extra_pages: h as _,
});
let executor = WasmExecutor::builder()
.with_execution_method(config.wasm_method)
@ -251,13 +253,25 @@ fn new_partial_basics(
telemetry
});
Ok(Basics { task_manager, client, backend, keystore_container, telemetry })
Ok(Basics {
task_manager,
client,
backend,
keystore_container,
telemetry,
})
}
#[cfg(feature = "full-node")]
fn new_partial<ChainSelection>(
config: &mut Configuration,
Basics { task_manager, backend, client, keystore_container, telemetry }: Basics,
Basics {
task_manager,
backend,
client,
keystore_container,
telemetry,
}: Basics,
select_chain: ChainSelection,
) -> Result<
sc_service::PartialComponents<
@ -272,11 +286,7 @@ fn new_partial<ChainSelection>(
ghost_rpc::SubscriptionTaskExecutor,
) -> Result<ghost_rpc::RpcExtension, SubstrateServiceError>,
(
babe::BabeBlockImport<
Block,
FullClient,
FullGrandpaBlockImport<ChainSelection>,
>,
babe::BabeBlockImport<Block, FullClient, FullGrandpaBlockImport<ChainSelection>>,
grandpa::LinkHalf<Block, FullClient, ChainSelection>,
babe::BabeLink<Block>,
),
@ -297,8 +307,7 @@ where
client.clone(),
);
let (grandpa_block_import, grandpa_link) =
grandpa::block_import(
let (grandpa_block_import, grandpa_link) = grandpa::block_import(
client.clone(),
GRANDPA_JUSTIFICATION_PERIOD,
&(client.clone() as Arc<_>),
@ -312,8 +321,7 @@ where
babe::block_import(babe_config.clone(), grandpa_block_import, client.clone())?;
let slot_duration = babe_link.config().slot_duration();
let (import_queue, babe_worker_handle) =
babe::import_queue(babe::ImportQueueParams {
let (import_queue, babe_worker_handle) = babe::import_queue(babe::ImportQueueParams {
link: babe_link.clone(),
block_import: block_import.clone(),
justification_import: Some(Box::new(justification_import)),
@ -353,10 +361,9 @@ where
let chain_spec = config.chain_spec.cloned_box();
let backend = backend.clone();
move |
deny_unsafe,
subscription_executor: ghost_rpc::SubscriptionTaskExecutor,
| -> Result<ghost_rpc::RpcExtension, sc_service::Error> {
move |deny_unsafe,
subscription_executor: ghost_rpc::SubscriptionTaskExecutor|
-> Result<ghost_rpc::RpcExtension, sc_service::Error> {
let deps = ghost_rpc::FullDeps {
client: client.clone(),
pool: transaction_pool.clone(),
@ -428,8 +435,7 @@ pub fn new_full<Network: sc_network::NetworkBackend<Block, <Block as BlockT>::Ha
let backoff_authoring_blocks = if !force_authoring_backoff {
None
} else {
let mut backoff =
sc_consensus_slots::BackoffAuthoringOnFinalizedHeadLagging::default();
let mut backoff = sc_consensus_slots::BackoffAuthoringOnFinalizedHeadLagging::default();
if config.chain_spec.is_dev() {
backoff.max_interval = 10;
@ -446,7 +452,14 @@ pub fn new_full<Network: sc_network::NetworkBackend<Block, <Block as BlockT>::Ha
let prometheus_registry = config.prometheus_registry().cloned();
let select_chain = sc_consensus::LongestChain::new(basics.backend.clone());
let sc_service::PartialComponents::<_, _, sc_consensus::LongestChain<FullBackend, Block>, _, _, _,> {
let sc_service::PartialComponents::<
_,
_,
sc_consensus::LongestChain<FullBackend, Block>,
_,
_,
_,
> {
client,
backend,
mut task_manager,
@ -454,12 +467,7 @@ pub fn new_full<Network: sc_network::NetworkBackend<Block, <Block as BlockT>::Ha
select_chain,
import_queue,
transaction_pool,
other: (
rpc_extensions_builder,
import_setup,
rpc_setup,
mut telemetry,
),
other: (rpc_extensions_builder, import_setup, rpc_setup, mut telemetry),
} = new_partial::<sc_consensus::LongestChain<FullBackend, Block>>(
&mut config,
basics,
@ -476,7 +484,11 @@ pub fn new_full<Network: sc_network::NetworkBackend<Block, <Block as BlockT>::Ha
let mut net_config =
sc_network::config::FullNetworkConfiguration::<_, _, Network>::new(&config.network);
let genesis_hash = client.block_hash(0).ok().flatten().expect("Genesis block exists; qed");
let genesis_hash = client
.block_hash(0)
.ok()
.flatten()
.expect("Genesis block exists; qed");
let peer_store_handle = net_config.peer_store_handle();
let grandpa_protocol_name = grandpa::protocol_standard_name(&genesis_hash, &config.chain_spec);
@ -554,8 +566,8 @@ pub fn new_full<Network: sc_network::NetworkBackend<Block, <Block as BlockT>::Ha
"⚠️ The hardware does not meet the minimal requirements {} for role 'Authority'",
err
);
},
_ => {},
}
_ => {}
}
if let Some(ref mut telemetry) = telemetry {
@ -563,10 +575,7 @@ pub fn new_full<Network: sc_network::NetworkBackend<Block, <Block as BlockT>::Ha
task_manager.spawn_handle().spawn(
"telemetry_hwbench",
None,
sc_sysinfo::initialize_hwbench_telemetry(
telemetry_handle,
hwbench,
),
sc_sysinfo::initialize_hwbench_telemetry(telemetry_handle, hwbench),
);
}
}
@ -580,7 +589,9 @@ pub fn new_full<Network: sc_network::NetworkBackend<Block, <Block as BlockT>::Ha
let authority_discovery_role =
sc_authority_discovery::Role::PublishAndDiscover(keystore_container.keystore());
let dht_event_stream =
network.event_stream("authority-discovery").filter_map(|e| async move {
network
.event_stream("authority-discovery")
.filter_map(|e| async move {
match e {
Event::Dht(e) => Some(e),
_ => None,
@ -597,7 +608,7 @@ pub fn new_full<Network: sc_network::NetworkBackend<Block, <Block as BlockT>::Ha
Arc::new(network.clone()),
Box::pin(dht_event_stream),
authority_discovery_role,
prometheus_registry.clone()
prometheus_registry.clone(),
);
task_manager.spawn_handle().spawn(
@ -625,8 +636,7 @@ pub fn new_full<Network: sc_network::NetworkBackend<Block, <Block as BlockT>::Ha
env: proposer,
sync_oracle: sync_service.clone(),
justification_sync_link: sync_service.clone(),
create_inherent_data_providers: move |_, ()| {
async move {
create_inherent_data_providers: move |_, ()| async move {
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();
let slot =
babe_primitives::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
@ -634,7 +644,6 @@ pub fn new_full<Network: sc_network::NetworkBackend<Block, <Block as BlockT>::Ha
slot_duration,
);
Ok((slot, timestamp))
}
},
force_authoring,
backoff_authoring_blocks,
@ -646,7 +655,9 @@ pub fn new_full<Network: sc_network::NetworkBackend<Block, <Block as BlockT>::Ha
let babe = babe::start_babe(babe_config)?;
task_manager.spawn_essential_handle().spawn_blocking("babe", None, babe);
task_manager
.spawn_essential_handle()
.spawn_blocking("babe", None, babe);
}
let keystore_opt = if role.is_authority() {
@ -711,8 +722,17 @@ macro_rules! chain_ops {
let chain_selection = sc_consensus::LongestChain::new(basics.backend.clone());
let sc_service::PartialComponents { client, backend, import_queue, task_manager, .. } =
new_partial::<sc_consensus::LongestChain<FullBackend, Block>>(&mut config, basics, chain_selection)?;
let sc_service::PartialComponents {
client,
backend,
import_queue,
task_manager,
..
} = new_partial::<sc_consensus::LongestChain<FullBackend, Block>>(
&mut config,
basics,
chain_selection,
)?;
Ok((client, backend, import_queue, task_manager))
}};
}
@ -720,22 +740,28 @@ macro_rules! chain_ops {
#[cfg(feature = "full-node")]
pub fn new_chain_ops(
config: &mut Configuration,
) -> Result<(Arc<FullClient>, Arc<FullBackend>, sc_consensus::BasicQueue<Block>, TaskManager), Error>
{
) -> Result<
(
Arc<FullClient>,
Arc<FullBackend>,
sc_consensus::BasicQueue<Block>,
TaskManager,
),
Error,
> {
config.keystore = sc_service::config::KeystoreConfig::InMemory;
chain_ops!(config, None)
}
#[cfg(feature = "full-node")]
pub fn build_full(
config: Configuration,
params: NewFullParams,
) -> Result<NewFull, Error> {
pub fn build_full(config: Configuration, params: NewFullParams) -> Result<NewFull, Error> {
match config.network.network_backend {
sc_network::config::NetworkBackendType::Libp2p =>
new_full::<sc_network::NetworkWorker<Block, Hash>>(config, params),
sc_network::config::NetworkBackendType::Litep2p =>
new_full::<sc_network::Litep2pNetworkBackend>(config, params),
sc_network::config::NetworkBackendType::Libp2p => {
new_full::<sc_network::NetworkWorker<Block, Hash>>(config, params)
}
sc_network::config::NetworkBackendType::Litep2p => {
new_full::<sc_network::Litep2pNetworkBackend>(config, params)
}
}
}
@ -750,7 +776,7 @@ pub fn revert_backend(
let revertible = blocks.min(best_number - finalized);
if revertible == 0 {
return Ok(())
return Ok(());
}
babe::revert(client.clone(), backend, blocks)?;

View File

@ -1,200 +0,0 @@
### TEMPLATE ###
Local identity : ./PATH_TO_GHOST/ghost key inspect-node-key --bin --file PATH_TO_NODE_KEY
Public key (hex) wallet : ./PATH_TO_GHOST/ghost key inspect $(cat PATH_TO_WALLET_KEY)
==================================================================================================================
Public key (hex) for stash : ./PATH_TO_GHOST/ghost key inspect --scheme=sr25519 $(cat PATH_TO_STASH_KEY)
Public key (hex) for audi : ./PATH_TO_GHOST/ghost key inspect --scheme=sr25519 "$(cat PATH_TO_SESSION_KEY)//audi"
Public key (hex) for babe : ./PATH_TO_GHOST/ghost key inspect --scheme=sr25519 "$(cat PATH_TO_SESSION_KEY)//babe"
Public key (hex) for slow : ./PATH_TO_GHOST/ghost key inspect --scheme=sr25519 "$(cat PATH_TO_SESSION_KEY)//slow"
Public key (hex) for gran : ./PATH_TO_GHOST/ghost key inspect --scheme=ed25519 "$(cat PATH_TO_SESSION_KEY)//gran"
### str3tch aka Pierre ###
Local identity : 12D3KooWFMiBom4mrJ57CaJZBxKWD1eDLYUyWLZzcjTaQW5crcNQ
Public key (hex) wallet : 0x328d3b7c3046ef7700937d99fb2e98ce2591682c2b5dcf3f562e4da157650237
===============================================================================================
Public key (hex) for stash : 0x507045c82be367f95408466cd054ca39bfa52697a3ef22809af14cf9de304f02
Public key (hex) for audi : 0x12c14850562021eb99f58f90ab624fb6cfaf3ac9228a92f8b60115fe6a6af15a
Public key (hex) for babe : 0xdaaaaab6a6e574099e24ae9bb75b543610edef9d374fa85a378edb573b47615f
Public key (hex) for slow : 0x0e9e698c7b2bf5ce3861cb4bc4ddf9e200237c282025b093ada850d764d12a35
Public key (hex) for gran : 0x55446f9a7aa99ced06b317c80ce90d56b84e56526775683af2525969e8da0b64
### ghost_7 ###
Local identity : 12D3KooWNZYbA3Ty1h8BqfMjzKVeJ83UTJxKUXj9zqnSirJZ51KR
Public key (hex) wallet : 0x3666e4e19f87bb8680495f31864ce1f1c69d4178002cc01911aef2cc7313f203
===============================================================================================
Public key (hex) for stash : 0xa0ba0196e6ee7e6b5b0553035c5cb5c04e9725001b5732839d0529cbc00c9600
Public key (hex) for audi : 0x90db5ed339a559ed157995a48d781f44c7df972dfba4bc855e4b59fa46438e17
Public key (hex) for babe : 0x6c4dd88b43e2011cf9a6a73d53446336ac9e04cdd4ca23587df63187ac455e49
Public key (hex) for slow : 0x3481cdcbcf37a4669c29a78cf9ceb39383a10ef0a18b36b92d149fdd0c24ae00
Public key (hex) for gran : 0x8f9ea20bf4a807a8e710f7559dece86e94672b5b361de157bdaa5c1f37849f8d
### Neptune ###
Local identity : 12D3KooWF9SWxz9dmy6vfndQhoxqCa7PESaoFWEiF8Jkqh4xKDRf
Public key (hex) wallet : 0xac871e8bab00dd56ba3a1c0bd289357203dcaf10010b0b04ad7472870cd22a3c
===============================================================================================
Public key (hex) for stash : 0x8a0d0b66e827bf20e79f9a499317e73925ce4f422371067edfab690e43857f13
Public key (hex) for audi : 0x2cf69452e9f2a8457119139408884941ed50f590c0fc0f2b044c4d82c69e4245
Public key (hex) for babe : 0xe0f0a776ecc9fa5e1f22e2fa001fe3fba5aea52b9444bc894b45589d42132475
Public key (hex) for slow : 0x0e6fa6934f9e99fa84874f2ed9318825a0d5443a0ced984acfbd24ece72ba55e
Public key (hex) for gran : 0xb63c5a0cf342b9b04931bc8ed74d7d0165ab99ab5f8a4514797d4b299a4501fe
### Neptune 2 ###
Local identity : 12D3KooWPQXpz8UM9uBsB7pcv12pLCLbYdk8W3SHrZBgiju2fbAs
Public key (hex) wallet : 0x425ccd7bda4f5c76788ba23bc0381d7a2e496179c93301208c57501c80a4232a
===============================================================================================
Public key (hex) for stash : 0x6c0283f4c688f0e75ad546c790bbd5961c1a6931543aa589f368f8272c44b758
Public key (hex) for audi : 0x00946618c353e4c6546b87f9ca1089b846b0ea4658ee8e6d9d1200c24cb5ee27
Public key (hex) for babe : 0x74fa7381a7a74b316afb6793a00387eed9d95d46a69866cbb316b5d9c918af0e
Public key (hex) for slow : 0x520e74f8c5853ec8577932327ad3247656db25b74c79ad09adb431b271002401
Public key (hex) for gran : 0x236d2fa03f4ed8cb65de7e514d7540159b328f1c170dd402b094ad7fbf547218
### Doctor K ###
Local identity : 12D3KooWP3h5dSdqcpvsCr7fp1jyfqDj291QDZ68a4gY6VQ8T1nW
Public key (hex) wallet : 0x927a98dcf8f721103005f168476c24b91d7d10d580f457006a908e10e62c7729
===============================================================================================
Public key (hex) for stash : 0xb24feb55b2cac4b365a9245c2a97525b01bd1a594d2d42b91f6bc38c9c2e6517
Public key (hex) for audi : 0xa8e828d10cf7b74481b6e746e5532d4740ea8014a0d3d856540a59847f8a6b76
Public key (hex) for babe : 0x3c944c704cae203619b9e7a5a4b6742736da6a8e76c762291bebdc7652cfec2f
Public key (hex) for slow : 0x2645f1f6820dd3a917eebbdab033088d8862477c1c14759b218685f9a0893377
Public key (hex) for gran : 0x0aa3a88f6b777c95c3dfe7e997b76798413f16aa325f34824cae0c9102b281d5
### starman ###
Local identity : 12D3KooWMikWyNweALKadEN8KMEhLs5JnNqCBecydAtP8d5UzVgs
Public key (hex) wallet : 0xac9e227e30a63ce6eeb55cfbb1fb832aa7e1d3fad2bcb3f663de4a91d744fd50
===============================================================================================
Public key (hex) for stash : 0x44376f8fa786be1f16fcb45232cfb07300cea845b2fc6e30dde61952de3e5e33
Public key (hex) for audi : 0x3271915dc67eba8ad2759a30c2537702f4fbf45647cba565e3a464ab75b91f05
Public key (hex) for babe : 0xec981eb1ef1ddbc8ded2db16198cb03667b4b39a8ea58f28ad469ddfaf256161
Public key (hex) for slow : 0x6e9426dc78fba9eeb264dcab98be86daf3d8cf510ecfb2acddec370295ff8176
Public key (hex) for gran : 0x15b9a867891cf449584b108e512d60b945b1a065bec1703c4c5709ee5093c03d
### IBN ###
Local identity : 12D3KooWQtgCKVcoSkbAcxXdXQFQBpHkriaeXkdMeLUyddjVugwD
Public key (hex) wallet : 0x5ebcc2d213e482d00e2a27e2031abda6ecbe49eb30709113c6142aa4d7395134
===============================================================================================
Public key (hex) for stash : 0x42dbb785808c7b22eb3a57605b4676e370620c79d768a9e8f1f93ad3137b751c
Public key (hex) for audi : 0xe28dd330cc0daee36806b6b9209547fd65a6916f6e3cc3c2647417ff67bcb065
Public key (hex) for babe : 0x56bde237ae958813482ec69ac5734f64c271c7c5b3d1af45daa4d4d43c051e34
Public key (hex) for slow : 0x5eff55ed5111e7430d0acb23aee45e04d389f4d3f72019cda302bb2176485578
Public key (hex) for gran : 0x03562f5fa0b39c4f85b8692be4aa2447203b8ba5a95f9ba3d1e43d52ba8d1254
### My Submission for Genesis Code - youaresparta ###
Local identity : 12D3KooWSHS1YCJvxck3Dcpk92ZiEW5ZrhTDrGQMHhjEErTxCxzZ
Public key (hex) wallet : 0xea1c01ff56725c6fdd62efaa119b704a2f467fd21d20a3c2117668bfeba02e76
===============================================================================================
Public key (hex) for stash : 0x909ab2271d3fc8df9e8556232a29eea7cf1cfdf8c89603a602779daa6484f011
Public key (hex) for audi : 0x0eef8f5d5d3bf5b5986bdd76ee6feba013171ab6c76bd38b3aa556e7fad4ea6c
Public key (hex) for babe : 0x00623f9d2ca673af3ec6d5c0077a7314c0fa92ec5fa853015b189daa12a2e02a
Public key (hex) for slow : 0x9ef7278866ed6015bd3055e3ef2cc77c62e796667f250a42d832846534a16743
Public key (hex) for gran : 0x47acf609aefff57c8b3680d862df19f11a9d5970e0e9be3606781f430790e94c
### Kitsune1 ###
Local identity : 12D3KooWR5JJQ9mALPpnSxfZm5M23AByitSfxpei9ZDghU1NLNeW
Public key (hex) wallet : 0x46c78fcacffd80abc9cca4917ef8369a37e21a1691ca11e7a3b53f80be745313
===============================================================================================
Public key (hex) for stash : 0x4a5596e97c602e7846d54fae81dcdc5a553b7422231e32f9567ac30a6b7c743a
Public key (hex) for audi : 0x241bfc05caa2d3e53e671df7261599c13f069a37f6cc4be10b5d49502c3a1e1c
Public key (hex) for babe : 0xceb63298b1b7a1277fddf6eee735dbbf9921fd5ebaac0132eee1963e22cf5935
Public key (hex) for slow : 0x7ce0c80ee65fb00e229d8c8fa5484144eca3d45d733165fbffcdb4de24c14951
Public key (hex) for gran : 0x95f73a6271b517f2016fa91411bdeeb990158066c95f106a79697446ba9f78b4
### mridkwya ###
Local identity : 12D3KooWQHiwqRokC3BmDrZ9LszxwFj7vjJ2adJDZPVQvRJXSA42
Public key (hex) wallet : 0xaaba173e1cd257c1ba67afbed0fbf2c4aadbfac329f129f12c4941b8b6bc5865
===============================================================================================
Public key (hex) for stash : 0x56bbe4fddb35ccdfbc59fad45f011c0bd0869fe42b34396804c060dc963bf866
Public key (hex) for audi : 0x5ce0221a8ee8b7e093ef9ca48f08b890d65c6ef98185010c5013d7a0e108452d
Public key (hex) for babe : 0x50fd46be1d746a5d355018615bacef98ac280dbed490ef2a26c1aefd06ec4f1c
Public key (hex) for slow : 0x46735b00d80e2e32c4eb652729c791d32f83f5f423a3d963c3c226ab0d131129
Public key (hex) for gran : 0x210a4b979e39c3136be105df1974fc036f4fe9b035936c149bdb94a3f4820487
### ajruecker (scientio) ###
Local identity : 12D3KooWEiC9wp3rHF8JcDiadqtwdWvtUXLBbZhKuao1SwPy2m52
Public key (hex) wallet : 0xfa5e5a295ec74c3dda81118d9240db1552b28f831838465ae0712e97e78a6728
===============================================================================================
Public key (hex) for stash : 0x2021a16182e3af39a79d20021a1b8755d589c04292d361d6b387411f7e975602
Public key (hex) for audi : 0x9eb1063afcaf568e7a62458ef33237a41ca500c89e084f7a5dd75bf5d89b105a
Public key (hex) for babe : 0x64e9968f3af2e1a86ee8d4be9ad77a1d66f50138527988bf93ede25baaf2e671
Public key (hex) for slow : 0x2e77fde21162d1f21ca371846d70c3b75931329074101ee668e614336d25c120
Public key (hex) for gran : 0x45e28f333bf0d4a9956ae20341cd07db8d471c4b482ed15d5cf7edd70201670d
### Kitsune_2 ###
Local identity : 12D3KooWDs4i6VoK4dpwGSUVtZENzSmsbQk3tF63gYT745x7eAb2
Public key (hex) wallet : 0x4078ddb1ba1388f768fe6aa40ba9124a72692ecbcc83dc088fa86c735e4dc128
===============================================================================================
Public key (hex) for stash : 0xb624cb291f7464773f3b449ee2252165f3934ace08b1e10611a53e174766fc73
Public key (hex) for audi : 0xc2403683be24a92ae8489e28fb502e2bab16d815c4f6c865c50ffb34430a8d7c
Public key (hex) for babe : 0xca72b6ea2c83f9e429479bf51c324ea90cbf01e08d2850ced2590c8796cfe222
Public key (hex) for slow : 0xeabb3463e300f357b9886683d5a240a395f6bd41182057f03b0e9697a8b3465e
Public key (hex) for gran : 0x4ec8584ca9da16d8c60e1770e98fbca8bec648e13c69601e3dfdc1330bf1f999
### Proxmio ###
Local identity : 12D3KooWHZDmyvNFF31PCVVrwDSmUPyC7kgvfpC6wTTDevFcX4dH
Public key (hex) wallet : 0x5e1456904c40192cd3a18183df7dffea90d97739830a902cabb702ecdae4f649
===============================================================================================
Public key (hex) for stash : 0xda6875e9df9a7894e065ef5befcde567dec4dc2c0b73a6ad5514dcca26a90702
Public key (hex) for audi : 0x1496150847d512e0491899eba72ee36f76b882ae29fccf18201fd9fbd5bfd300
Public key (hex) for babe : 0x8006e3f6e3d92c4c5f2e2f001452e4993e6d5c2b1136f2ae6060c6e9c9523b4a
Public key (hex) for slow : 0xaaa41b6ade4c30b5792aa6e5604c444e424900ddf649b23eed4bd0d7f5d3a34f
Public key (hex) for gran : 0x86ee138c9e7e67c1c2e157c0ba888761a122d8b9aa6a8653e886ac329e34255d
### Zoom ###
Local identity : 12D3KooWLxCLSGuDVHePoXEuyBVFfRPzYXiSVngpYSTVDEwxX49S
Public key (hex) wallet : 0xfc00ebab85e7271d8436b9258a4b80700f655810af632b3647109965f8b8e639
===============================================================================================
Public key (hex) for stash : 0x1040c71fc62c08d520f04bff23814cf9a19673e385142f7ea910c7fbaa910e06
Public key (hex) for audi : 0x60a07df1236d676011eb5a49c2e01a04f734a05599e0df51208899bfd746a23e
Public key (hex) for babe : 0xf425e0965fc1b6593288a5d100396028217f5931f1bdebaf491358485dfa7f29
Public key (hex) for slow : 0x10559a32c870d6087db5367f31c6828d5615effa8f0334362ec444666908ba59
Public key (hex) for gran : 0x489b5c32c26dbb04ebaa41695d043934120cdb5794ecb9c51748a9e0edfb9286
### Tyrone-Overit ###
Local identity : 12D3KooWReS7ezsKuuttK4FuGqCJycH9bJEccsBhKb4YuDMhaVZ
Public key (hex) wallet : 0x50c8a6b85ae6c3aebf402dbc98f0f09dad4758d37d63f3e39e4d9127eece9360
===============================================================================================
Public key (hex) for stash : 0xfa6bad513351346342177594080c851e5ac91ebebe708cf368a1044972582f53
Public key (hex) for audi : 0x528860f091ca1634af2919472880b93f1788532c2d6779ef940a900c5abc1a26
Public key (hex) for babe : 0xc2ee8058909f4880a068190a9cff3b9fa570cdec110334f174b16d9e7d720056
Public key (hex) for slow : 0x1ee11e06d7a61e49d61636d1be7c2a58ba26dd87110806ce8573b973f5f6892a
Public key (hex) for gran : 0x635308cf5fae9b94271b09a4987064319d57c93abea88671841a84e41be5a83f
### My Submission for Genesis Code - Satoshi ###
Local identity : 12D3KooWPvdyWvTrTpkBKoGZ8KBMjEumrSwWHThoTNg416mVakWJ
Public key (hex) wallet : 0x80932904b805be74fa163be7474390633c96f319163f7466adf9844e9b4fa038
===============================================================================================
Public key (hex) for stash : 0x7291cffd9a948e4a8f7ea9015faae5c9f2384821c34e831d5afaec3284a7c563
Public key (hex) for audi : 0x9a4a2cfc28b9196eea423b6177252f7598e93c5e40396a91d214e0bc6c4aca73
Public key (hex) for babe : 0xfa517486ef74d8cedbabc8fe4470b3e79c9afd44fca7e5c639e1612c026d2c3d
Public key (hex) for slow : 0x58a9b312e847a5bdd1d92d603c07fc3fb5af8d241c482c41e5a30db6240a4779
Public key (hex) for gran : 0xffd30acb4b7b4563585618fa0e35f0d64a512387fabe6db931e726e44d0e6726
### Youconnect ###
Local identity : 12D3KooWJXBYA7cUQLLenEfT7hmCjBJ6fyikDy8YhNz4aLfwbBC8
Public key (hex) wallet : 0x6e4429a8fa85cfe2a60488af446d57e719207831b2579b937325645e110bb666
===============================================================================================
Public key (hex) for stash : 0x3a6626211a2dd35683fd7cb5f2f343d75f2b698d6c48c2d6eb1cdbe116e32315
Public key (hex) for audi : 0x86676ad3cd2d970b86dee2f25d4318f9bba40455111f16300e114e7f00c58706
Public key (hex) for babe : 0x6c0aec49974aaff08ff962a2d8d7857227d027ed27a272cbc4acaa1ee937db0f
Public key (hex) for slow : 0x009712519ba7dad1c682c871b94573ccaba8b7d530f7194fb16bf553fd7ae67d
Public key (hex) for gran : 0x935becdfb2e0d4fcd46ba82e680cfc447180de6b85ec42d17f1396a520b0c04f
### pietro0hz ###
Local identity : 12D3KooWEcJAQHs59gD3hDWU5UXxc9nNQcS6dPe3cnFtL8bBuEnw
Public key (hex) wallet : 0x3aed46c45d1db596ba68c171f58cd0c34178c410ec2485dc9ecaa52f1af75320
===============================================================================================
Public key (hex) for stash : 0x445208ab2cd2f9169f1a011bc9d53dd6bc11b139b27caef3bbb1342609931738
Public key (hex) for audi : 0x9a12223615fe9cb2967c2b19eb2a4571dcb38a6e059b746c68d58cd00d408b17
Public key (hex) for babe : 0x90be1b9c74b38458219433533456b85100727a7f7d5718f0f5aa2145583d4e09
Public key (hex) for slow : 0xc051db0753ad038264d823a71e5c5552e456231b9a1c4e1e7584c6d1c854d44b
Public key (hex) for gran : 0x6453e432623c915705afc09e0da19b05b58005d4269838b643f11f5df7524b02
### Fujisan-1 ###
Local identity : 12D3KooWDWU21S6yxDapSnKAS3JnhaQBkT4iNTNQ8NpB4QgNUzxr
Public key (hex) wallet : 0xe0a13fb6efe591216ca3f2c5a495b9653a5255d0344b17cf02584c40b5b57043
===============================================================================================
Public key (hex) for stash : 0xa00bd3284a6824ad7f757d98a2646c055126c5dd6450be383760b4f6c0193e40
Public key (hex) for audi : 0x3680593818dfa5ed287de4320f730ae22f2a9c05ebebfad931322411ec508961
Public key (hex) for babe : 0x3477d5cb7f3dffb8d76a33f32bcbcb5669f992d56ab222cfa0ab496b5b8bff12
Public key (hex) for slow : 0x1cf9b6843abd08eee9f99c5db2c9546fa72ef603a5db0e3c9372e63ec6bb6a06
Public key (hex) for gran : 0x3a539da581ced44fe567f9dee8a037fbd6cbe5027afe0c1099e3df0a621f030a

0
src/main.rs Executable file → Normal file
View File

17
tests/benchmark_block.rs Executable file → Normal file
View File

@ -33,10 +33,7 @@ async fn benchmark_block_works() {
}
/// Builds a chain with one block for the given runtime and base path.
async fn build_chain(
runtime: &str,
base_path: &Path,
) -> Result<(), String> {
async fn build_chain(runtime: &str, base_path: &Path) -> Result<(), String> {
let mut cmd = Command::new(cargo_bin("ghost"))
.stdout(process::Stdio::piped())
.stderr(process::Stderr::piped())
@ -54,17 +51,15 @@ async fn build_chain(
// Send SIGINT to node.
kill(Pid::from_raw(cmd.id().try_into().unwrap()), SIGINT).unwrap();
// Wait for the node to handle it and exit.
assert!(common::wait_for(&mut cmd, 30).map(|x| x.success()).unwrap_or_default());
assert!(common::wait_for(&mut cmd, 30)
.map(|x| x.success())
.unwrap_or_default());
ok.map_err(|e| format!("Node dod not build the chain: {:?}", e))
}
/// Benchmarks the given block with the wasm executor.
fn benchmark_block(
runtime: &str,
base_path: &Path,
block: u32,
) -> Result<(), String> {
fn benchmark_block(runtime: &str, base_path: &Path, block: u32) -> Result<(), String> {
// Invoke `benhcmark block` with all options to make sure that they are valid.
let status = Command::new(carg_bin("ghost"))
.args(["benchmark", "block", "--chain", runtime])
@ -77,7 +72,7 @@ fn benchmark_block(
.map_err(|e| format!("command failed: {:?}", e))?;
if !status.success() {
return Err("Command failed".into())
return Err("Command failed".into());
}
Ok(())

20
tests/benchmark_extrinsic.rs Executable file → Normal file
View File

@ -3,10 +3,7 @@ use std::{process::Command, result::Result};
static RUNTIMES: [&str; 2] = ["ghost", "casper"];
static EXTRINSIC: [(&str, &str); 2] = [
("system", "remark"),
("balances", "transfer_keep_alive"),
];
static EXTRINSIC: [(&str, &str); 2] = [("system", "remark"), ("balances", "transfer_keep_alive")];
/// `becnhamrk extrinsic` works for all dev runtimes and some extrinsics.
#[test]
@ -25,22 +22,19 @@ fn benchmark_extrinsic_rejects_non_dev_runtimes() {
for runtime in RUNTIMES {
assert!(benchmark_extrinsic(runtime, "system", "remark").is_err());
}
}o
fn benchmark_extrinsic(
runtime: &str,
pallet: &str,
extrinsic: &str,
) -> Result<(), String> {
}
fn benchmark_extrinsic(runtime: &str, pallet: &str, extrinsic: &str) -> Result<(), String> {
let status = Command::new(cargo_bin("ghost"))
.args(["benchmark", "extrinsic", "--chain", runtime)]
.args(["--pallet", pallet, "--extrinsic", extrinsic)]
.args(["benchmark", "extrinsic", "--chain", runtime])
.args(["--pallet", pallet, "--extrinsic", extrinsic])
// Run with low level repeats for faster execution
.args(["--repeat=1", "--warmup=1", "--max-ext-per-block=1"])
.status()
.map_err(|e| format!("command failed: {:?}", e))?;
if !status.success() {
return Err("Command failed".into())
return Err("Command failed".into());
}
Ok(())

2
tests/benchmark_overhead.rs Executable file → Normal file
View File

@ -40,7 +40,7 @@ fn becnhamrk_overhead(runtime: String) -> Result<(), String> {
.map_err(|e| format!("command failed: {:?}", e))?;
if !status.success() {
return Err("Command failed".into())
return Err("Command failed".into());
}
// Weight files have been created.

0
tests/benchmark_storage_works.rs Executable file → Normal file
View File

9
tests/common.rs Executable file → Normal file
View File

@ -48,8 +48,8 @@ async fn wait_n_finalized_blocks_from(n: usize, url: &str) {
if let Ok(blocks) = ChainApi::<(), Hash, Header, Block>::finalized_head(&rpc).await {
build_blocks.insert(block);
if (build_blocks.len() > n {
break
if build_blocks.len() > n {
break;
}
};
interval.tick().await;
@ -80,7 +80,10 @@ pub fn find_ws_url_from_output(read: impl Read + Send) -> (String, String) {
Some(format!("ws://{}", sock_addr))
})
.unwrap_or_else(|| {
panic!("Could not find WebSocket address in process output:\n{}", &data)
panic!(
"Could not find WebSocket address in process output:\n{}",
&data
)
});
(ws_url, data)

0
tests/invalid_order_arguments.rs Executable file → Normal file
View File

4
tests/purge_chain_works.rs Executable file → Normal file
View File

@ -38,7 +38,9 @@ async fn purge_chain_rocksdb_works() {
// Send SIGINT to node
kill(Pid::from_raw(cmd.id().try_into().unwrap()), SIGINT).unwrap();
// Wait for the node to handle it and exit.
assert!(common::wait_for(&mut cmd, 30).map(|x| x.success()).unwrap_or_default());
assert!(common::wait_for(&mut cmd, 30)
.map(|x| x.success())
.unwrap_or_default());
assert!(tmpdir.path().join("chains/dev").exists());
assert!(tmpdir.path().join("chains/dev/db/full").exists());

9
tests/running_the_node_and_interrupt.rs Executable file → Normal file
View File

@ -13,7 +13,7 @@ async fn running_the_node_works_and_can_be_interrupted() {
use nix::{
sys::signal::{
kill,
Signal::{self, SIGINT, SIGTERM,},
Signal::{self, SIGINT, SIGTERM},
},
unistd::Pid,
};
@ -33,11 +33,14 @@ async fn running_the_node_works_and_can_be_interrupted() {
let (ws_url, _) = common::find_ws_url_from_output(cmd.stderr.take().unwrap());
// Let produce three blocks.
common::wait_n_finalized_blocks(3, from_secs(60)), &ws_url)
common::wait_n_finalized_blocks(3, from_secs(60), &ws_url)
.await
.unwrap();
assert!(cmd.try_wait().unwrap().is_none(), "the process should still be running");
assert!(
cmd.try_wait().unwrap().is_none(),
"the process should still be running"
);
kill(Pid::from_raw(cmd.id().try_into().unwrap()), signal).unwrap();
assert_eq!(
common::wait_for(&mut cmd, 30).map(|x| x.success()),

View File

@ -1,6 +1,6 @@
[package]
name = "ghost-remote-ext-tests-bags-list"
version = "1.0.0"
version = "1.0.1"
description = "Integration test that use state from live chains via remote externalities."
license.workspace = true
authors.workspace = true

Some files were not shown because too many files have changed in this diff Show More