Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add randomness to pallet-collator-assignment #267

Merged
merged 64 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 59 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
9ea58f4
Add randomness to pallet-collator-assignment
tmpolaczyk Sep 13, 2023
e2d8b30
Mock randomness inherent in tests
tmpolaczyk Sep 14, 2023
b56ad19
Do not shuffle collators if seed is 0
tmpolaczyk Sep 14, 2023
eac5238
Fix benchmarks
tmpolaczyk Sep 14, 2023
72f0755
Merge the functions to add and fill new container chains into one
tmpolaczyk Sep 14, 2023
cb342ff
Shuffle list of container chains as well
tmpolaczyk Sep 14, 2023
d5ad1b5
Add config parameter to force collator rotation
tmpolaczyk Sep 14, 2023
5bd49e3
Rotate collators according to config param
tmpolaczyk Sep 14, 2023
cddb149
WIP tests
tmpolaczyk Sep 18, 2023
7488fb1
Merge remote-tracking branch 'origin/master' into tomasz-shuffle-coll…
tmpolaczyk Sep 20, 2023
8553f9f
Use shuffled order in reorganize_collators function
tmpolaczyk Sep 20, 2023
f864585
Use per-block randomness instead of per-epoch randomness
tmpolaczyk Sep 20, 2023
6b7587c
Dont check collator2002-01 dbpath
tmpolaczyk Sep 22, 2023
a34faff
Fix metrics server not stopping if there are open connections (#270)
tmpolaczyk Sep 21, 2023
d178f8f
debug logs
tmpolaczyk Sep 22, 2023
8966fec
Fix dev_tanssi suite
tmpolaczyk Sep 22, 2023
cf86856
Add zombie_tanssi_rotation test suite
tmpolaczyk Sep 22, 2023
e1f8b31
Merge remote-tracking branch 'origin/master' into tomasz-shuffle-coll…
tmpolaczyk Sep 25, 2023
d211916
Unit test collator assignment rotation
tmpolaczyk Sep 25, 2023
d829db1
Fix warnings in zombienet tests
tmpolaczyk Sep 25, 2023
677ef04
Try to add integration test, fails
tmpolaczyk Sep 25, 2023
3a24a45
Fix integration test by killing storage value
tmpolaczyk Sep 26, 2023
b1cde0f
Merge remote-tracking branch 'origin/master' into tomasz-shuffle-coll…
tmpolaczyk Sep 26, 2023
da3faa8
Rename para-rotation suite to avoid moonwall bug
tmpolaczyk Sep 26, 2023
f1d9f6c
Increase zombienet test timeout
tmpolaczyk Sep 26, 2023
ae44dee
Mix subject with relay randomness, and fix bug all seeds starting with 1
tmpolaczyk Sep 26, 2023
5658cfb
Fix collators rotating 1 block too early
tmpolaczyk Sep 27, 2023
2734f75
Fix zombienet tests
tmpolaczyk Sep 27, 2023
289c355
Merge branch 'tomasz-finality-stream' into tomasz-shuffle-collator-as…
tmpolaczyk Sep 27, 2023
c35632d
Fix mock randomness
tmpolaczyk Sep 27, 2023
d15139f
Fix unused import
tmpolaczyk Sep 27, 2023
ee373d7
WIP tests
tmpolaczyk Sep 27, 2023
30be0c3
Implement zombie_tanssi_rotation test suite
tmpolaczyk Sep 28, 2023
3113ba0
Merge remote-tracking branch 'origin/master' into tomasz-shuffle-coll…
tmpolaczyk Sep 28, 2023
37567ef
Remove fixed random seed, was used for testing
tmpolaczyk Oct 4, 2023
8f9e6a2
Merge remote-tracking branch 'origin/master' into tomasz-shuffle-coll…
tmpolaczyk Oct 4, 2023
608b3aa
Merge remote-tracking branch 'origin/master' into tomasz-shuffle-coll…
tmpolaczyk Oct 9, 2023
1301a67
Fix merge
tmpolaczyk Oct 9, 2023
901b6f6
Fix PR comments
tmpolaczyk Oct 9, 2023
b03e51e
Add event CollatorAssignment::NewPendingAssignment
tmpolaczyk Oct 10, 2023
d97b799
Merge remote-tracking branch 'origin/master' into tomasz-shuffle-coll…
tmpolaczyk Oct 10, 2023
317cf5e
Fix build
tmpolaczyk Oct 10, 2023
9a84aec
Already renamed
tmpolaczyk Oct 11, 2023
53d1180
Merge remote-tracking branch 'origin/master' into tomasz-shuffle-coll…
tmpolaczyk Oct 16, 2023
cf47360
Fix Cargo.toml
tmpolaczyk Oct 16, 2023
4057a44
Fix tests after 1.1.0 upgrade
tmpolaczyk Oct 16, 2023
59b1b07
Make full_rotatio_period configurable, defined in pallet_configuration
tmpolaczyk Oct 16, 2023
9312833
fmt
tmpolaczyk Oct 16, 2023
62ec740
Use fast_or_prod macro to set full_rotation_period = 5 for tests
tmpolaczyk Oct 16, 2023
08714aa
Merge remote-tracking branch 'origin/master' into tomasz-shuffle-coll…
tmpolaczyk Oct 17, 2023
1573957
augment-api
tmpolaczyk Oct 17, 2023
a3b77c9
Fix tests zombie_tanssi_rotation
tmpolaczyk Oct 17, 2023
d0ddd2b
Merge remote-tracking branch 'origin/master' into tomasz-shuffle-coll…
tmpolaczyk Oct 17, 2023
f6bcc37
augment-api
tmpolaczyk Oct 17, 2023
1223f9b
Store randomness from previous relay block in pallet storage
tmpolaczyk Oct 17, 2023
0d6d67f
augment-api
tmpolaczyk Oct 17, 2023
5de5bc6
Fix benchmarks
tmpolaczyk Oct 17, 2023
3992c31
Merge remote-tracking branch 'origin/master' into tomasz-shuffle-coll…
tmpolaczyk Oct 17, 2023
8697c51
Change para-rotation test to rotate every 5 sessions instead of every 1
tmpolaczyk Oct 17, 2023
b554eed
Rewrite migration using get_raw and put_raw
tmpolaczyk Oct 19, 2023
ac80d4b
Rotation period of 0 disables rotation
tmpolaczyk Oct 19, 2023
39db625
Fix byte count in migration
tmpolaczyk Oct 19, 2023
2fa1ca1
Add integration test for migration
tmpolaczyk Oct 19, 2023
3ba2933
Rewrite migration using a less hacky approach
tmpolaczyk Oct 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,61 @@ jobs:
name: logs
path: logs

zombienet-tests-rotation:
runs-on: self-hosted
needs: ["set-tags", "build"]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ needs.set-tags.outputs.git_ref }}

- name: Pnpm
uses: pnpm/action-setup@v2
with:
version: 8

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 20.x
cache: "pnpm"

- name: "Download binaries"
uses: actions/[email protected]
with:
name: binaries
path: target/release

- name: "Run zombie test"
run: |
chmod uog+x target/release/tanssi-node
chmod uog+x target/release/container-chain-template-simple-node
chmod uog+x target/release/container-chain-template-frontier-node

cd test
pnpm install

## Run tests

pnpm moonwall test zombie_tanssi_rotation

- name: "Gather zombie logs"
if: failure()
run: |
ls -ltr /tmp
latest_zombie_dir=$(find /tmp -type d -iname "*zombie*" -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" ")
logs_dir="logs"
mkdir -p "$logs_dir"
find "$latest_zombie_dir" -type f -name "*.log" -exec cp {} "$logs_dir" \;

- name: "Upload zombie logs"
if: failure()
uses: actions/[email protected]
with:
name: logs-rotation
path: logs

zombienet-tests-warp-sync:
runs-on: ubuntu-latest
needs: ["set-tags", "build"]
Expand Down
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ cumulus-client-pov-recovery = { git = "https://github.com/moondance-labs/polkado
cumulus-client-service = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-v1.1.0", default-features = false }
cumulus-primitives-parachain-inherent = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-v1.1.0", default-features = false }
cumulus-relay-chain-interface = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-v1.1.0", default-features = false }
cumulus-test-relay-sproof-builder = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-v1.1.0", default-features = false }
xcm-emulator = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-v1.1.0", default-features = false }

# Frontier (wasm)
Expand Down Expand Up @@ -220,6 +221,7 @@ hex-literal = { version = "0.3.4" }
log = { version = "0.4.17", default-features = false }
serde = { version = "1.0.152", default-features = false }
smallvec = "1.10.0"
rand_chacha = { version = "0.3.1", default-features = false }

# General (client)
async-io = "1.3"
Expand Down
6 changes: 4 additions & 2 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
use {
cumulus_primitives_core::ParaId,
dancebox_runtime::{
AccountId, MaintenanceModeConfig, MigrationsConfig, PolkadotXcmConfig, RegistrarConfig,
Signature, SudoConfig,
prod_or_fast, AccountId, MaintenanceModeConfig, MigrationsConfig, PolkadotXcmConfig,
RegistrarConfig, Signature, SudoConfig,
},
nimbus_primitives::NimbusId,
pallet_configuration::HostConfiguration,
Expand Down Expand Up @@ -195,6 +195,7 @@ pub fn development_config(
min_orchestrator_collators: 1u32,
max_orchestrator_collators: 1u32,
collators_per_container: 2u32,
full_rotation_period: prod_or_fast!(24u32, 5u32),
},
..Default::default()
},
Expand Down Expand Up @@ -259,6 +260,7 @@ pub fn local_dancebox_config(
min_orchestrator_collators: 2u32,
max_orchestrator_collators: 5u32,
collators_per_container: 2u32,
full_rotation_period: prod_or_fast!(24u32, 5u32),
},
..Default::default()
},
Expand Down
1 change: 1 addition & 0 deletions pallets/authority-assignment/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ pub fn run_to_block(n: u64) {
let old_block_number = System::block_number();

for x in (old_block_number + 1)..=n {
System::reset_events();
System::set_block_number(x);

if x % SESSION_LEN == 1 {
Expand Down
4 changes: 2 additions & 2 deletions pallets/collator-assignment/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ sp-std = { workspace = true }
tp-collator-assignment = { workspace = true }
tp-traits = { workspace = true }
frame-benchmarking = { workspace = true }
rand = { workspace = true, optional = true }
rand = { workspace = true }
rand_chacha = { workspace = true }

[dev-dependencies]
sp-io = { workspace = true }
Expand All @@ -44,7 +45,6 @@ runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"rand",
"tp-traits/runtime-benchmarks",
]
try-runtime = [ "frame-support/try-runtime" ]
21 changes: 21 additions & 0 deletions pallets/collator-assignment/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ fn invulnerables<T: Config + frame_system::Config>(count: u32, seed: u32) -> Vec
invulnerables
}

fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
let events = frame_system::Pallet::<T>::events();
let system_event: <T as frame_system::Config>::RuntimeEvent = generic_event.into();
// compare to the last event record
let EventRecord { event, .. } = &events[events.len() - 1];
assert_eq!(event, &system_event);
}

#[benchmarks]
mod benchmarks {
use super::*;
Expand Down Expand Up @@ -75,6 +83,9 @@ mod benchmarks {
container_chains: BTreeMap::from_iter(old_container_chains),
};
<CollatorContainerChain<T>>::put(&old_assigned);
// Do not use [0; 32] because that seed will not shuffle the list of collators
let random_seed = [1; 32];
<Randomness<T>>::put(random_seed);

#[block]
{
Expand All @@ -89,6 +100,16 @@ mod benchmarks {
0
);

// Worst case is `full_rotation: false` because it needs to check the previous assignment
assert_last_event::<T>(
Event::NewPendingAssignment {
random_seed,
full_rotation: false,
target_session: T::SessionIndex::from(1u32),
}
.into(),
);

Ok(())
}

Expand Down
Loading
Loading