From b98ff72f425d825bdf9fe837a48a475c47a1e5f2 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Tue, 10 Dec 2024 19:17:07 -0500 Subject: [PATCH] Fix reshare timing issue --- pallets/propagation/src/lib.rs | 4 ++-- pallets/propagation/src/tests.rs | 2 +- pallets/staking/src/lib.rs | 2 +- pallets/staking/src/tests.rs | 12 +----------- 4 files changed, 5 insertions(+), 15 deletions(-) diff --git a/pallets/propagation/src/lib.rs b/pallets/propagation/src/lib.rs index fcea66d47..372cae8bd 100644 --- a/pallets/propagation/src/lib.rs +++ b/pallets/propagation/src/lib.rs @@ -160,11 +160,11 @@ pub mod pallet { /// Submits a request to do a key refresh on the signers parent key. pub fn post_reshare(block_number: BlockNumberFor) -> Result<(), http::Error> { let reshare_data = pallet_staking_extension::Pallet::::reshare_data(); - if reshare_data.block_number != block_number { + if reshare_data.block_number + sp_runtime::traits::One::one() != block_number { return Ok(()); } - let deadline = sp_io::offchain::timestamp().add(Duration::from_millis(2_000)); + let deadline = sp_io::offchain::timestamp().add(Duration::from_millis(10_000)); let kind = sp_core::offchain::StorageKind::PERSISTENT; let from_local = sp_io::offchain::local_storage_get(kind, b"reshare_validators") .unwrap_or_else(|| b"http://localhost:3001/validator/reshare".to_vec()); diff --git a/pallets/propagation/src/tests.rs b/pallets/propagation/src/tests.rs index 05b597633..0be5f1315 100644 --- a/pallets/propagation/src/tests.rs +++ b/pallets/propagation/src/tests.rs @@ -93,7 +93,7 @@ fn knows_how_to_mock_several_http_calls() { // doesn't trigger no reshare block Propagation::post_reshare(7).unwrap(); pallet_staking_extension::ReshareData::::put(ReshareInfo { - block_number: 7, + block_number: 6, new_signers: vec![1u64.encode()], }); // now triggers diff --git a/pallets/staking/src/lib.rs b/pallets/staking/src/lib.rs index 88bf6cbec..128b7cf4e 100644 --- a/pallets/staking/src/lib.rs +++ b/pallets/staking/src/lib.rs @@ -876,7 +876,7 @@ pub mod pallet { // trigger reshare at next block let current_block_number = >::block_number(); let reshare_info = ReshareInfo { - block_number: current_block_number + sp_runtime::traits::One::one(), + block_number: current_block_number - sp_runtime::traits::One::one(), new_signers, }; diff --git a/pallets/staking/src/tests.rs b/pallets/staking/src/tests.rs index 92125b2a9..9e4fce94e 100644 --- a/pallets/staking/src/tests.rs +++ b/pallets/staking/src/tests.rs @@ -555,11 +555,7 @@ fn it_tests_new_session_handler() { assert_ok!(Staking::new_session_handler(&[1, 5, 6])); // takes signers original (5,6) pops off one and adds in new validator assert_eq!(Staking::next_signers().unwrap().next_signers, vec![6, 1]); - assert_eq!( - Staking::reshare_data().block_number, - 101, - "Check reshare block start at 100 + 1" - ); + assert_eq!(Staking::reshare_data().block_number, 99, "Check reshare block start at 99 + 1"); assert_eq!( Staking::reshare_data().new_signers, vec![1u64.encode()], @@ -571,12 +567,6 @@ fn it_tests_new_session_handler() { "parent key threhsold updated" ); - assert_eq!( - Staking::reshare_data().block_number, - 101, - "Check reshare block start at 100 + 1" - ); - assert_ok!(Staking::new_session_handler(&[6, 5, 3])); // takes 3 and leaves 5 and 6 since already in signer group assert_eq!(Staking::next_signers().unwrap().next_signers, vec![6, 3]);