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

feat(test): implement missing resharding double signing fork test #12819

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 25 additions & 7 deletions integration-tests/src/test_loop/tests/resharding_v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -926,26 +926,44 @@ fn slow_test_resharding_v3_resharding_block_in_fork() {
.num_validators(0)
.num_rpcs(0)
.num_archivals(0)
.add_loop_action(fork_before_resharding_block(false))
.add_loop_action(fork_before_resharding_block(false, 3))
.build(),
);
}

#[test]
// TODO(resharding): duplicate this test so that in one case resharding is performed on block
// B(height=13) and in another case resharding is performed on block B'(height=13).
// In the current scenario the real resharding happens on block B'. Low priority TODO
// since it's a very rare corner case.
// Scenario:
// Two double signed blocks B(height=15) and B'(height=15) processed in the order B -> B'.
// In this scenario the chain discards the resharding at B' and performs resharding at B.
#[cfg(feature = "test_features")]
fn slow_test_resharding_v3_double_sign_resharding_block() {
fn slow_test_resharding_v3_double_sign_resharding_block_first_fork() {
test_resharding_v3_base(
TestReshardingParametersBuilder::default()
.num_clients(1)
.num_producers(1)
.num_validators(0)
.num_rpcs(0)
.num_archivals(0)
.add_loop_action(fork_before_resharding_block(true))
.add_loop_action(fork_before_resharding_block(true, 1))
.build(),
);
}

#[test]
// Scenario:
// Two double signed blocks B(height=15) and B'(height=15) and a third block C(height=19)
// processed in the order B -> B' -> C.
// In this scenario the chain discards the reshardings at B and B' and performs resharding at C.
#[cfg(feature = "test_features")]
fn slow_test_resharding_v3_double_sign_resharding_block_last_fork() {
test_resharding_v3_base(
TestReshardingParametersBuilder::default()
.num_clients(1)
.num_producers(1)
.num_validators(0)
.num_rpcs(0)
.num_archivals(0)
.add_loop_action(fork_before_resharding_block(true, 3))
.build(),
);
}
Expand Down
7 changes: 5 additions & 2 deletions integration-tests/src/test_loop/utils/resharding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ pub(crate) struct TrackedShardSchedule {

// Returns a callable function that, when invoked inside a test loop iteration, can force the creation of a chain fork.
#[cfg(feature = "test_features")]
pub(crate) fn fork_before_resharding_block(double_signing: bool) -> LoopAction {
pub(crate) fn fork_before_resharding_block(
double_signing: bool,
blocks_produced: near_primitives::types::BlockHeight,
) -> LoopAction {
use near_client::client_actor::AdvProduceBlockHeightSelection;

let (done, succeeded) = LoopAction::shared_success_flag();
Expand Down Expand Up @@ -80,7 +83,7 @@ pub(crate) fn fork_before_resharding_block(double_signing: bool) -> LoopAction {
base_block_height: tip.height - 1,
}
};
client_actor.adv_produce_blocks_on(3, true, height_selection);
client_actor.adv_produce_blocks_on(blocks_produced, true, height_selection);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why move it to an argument?

What exactly does this control? Does it have to be 3 in order to trigger fork at the right place?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's num of block produced

Yes it's a way to change which fork gets finalized. Small number of produced blocks -> discarded, large number -> not discarded

done.set(true);
}
},
Expand Down
Loading