Skip to content

Commit

Permalink
fix(lsd-relayblock): take relay block number from validation data (#4371
Browse files Browse the repository at this point in the history
)
  • Loading branch information
RustNinja authored Dec 7, 2023
2 parents 84f8b42 + 5794d43 commit 4ca0559
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion code/parachain/frame/liquid-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1840,7 +1840,9 @@ pub mod pallet {
&offset,
);

EraStartBlock::<T>::put(T::RelayChainValidationDataProvider::current_block_number());
let relay_block_number: BlockNumberFor<T> =
ValidationData::<T>::get().map(|i| i.relay_parent_number).unwrap_or(0).into();
EraStartBlock::<T>::put(relay_block_number);
CurrentEra::<T>::mutate(|e| *e = e.saturating_add(offset));

// ignore error
Expand Down
3 changes: 2 additions & 1 deletion code/parachain/frame/liquid-staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,8 @@ fn test_on_initialize_work() {
LiquidStaking::on_finalize(System::block_number());
System::set_block_number(System::block_number() + 1);
LiquidStaking::on_initialize(System::block_number());
assert_eq!(EraStartBlock::<Test>::get(), total_era_blocknumbers);
let current_era: u64 = CurrentEra::<Test>::get() as u64;
assert_eq!(EraStartBlock::<Test>::get(), total_era_blocknumbers * current_era);
// ValidationDataProvider return relay_parent_number = 100
// total_era_blocknumbers = 10 so the current era is 10
assert_eq!(CurrentEra::<Test>::get(), 10);
Expand Down

0 comments on commit 4ca0559

Please sign in to comment.