Skip to content

Commit

Permalink
fee upgrade test fix (#1889)
Browse files Browse the repository at this point in the history
Fixes the bug where test_fee_upgrade_view_based would never fail. It also attempts to make the logic more easy to follow (in order to make it easier to spot bugs).

---------

Co-authored-by: tbro <[email protected]>
  • Loading branch information
tbro and tbro authored Aug 22, 2024
1 parent ea662d0 commit bd1478a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
50 changes: 32 additions & 18 deletions sequencer/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1479,8 +1479,6 @@ mod test {
},
);

let stop_voting_view = u64::MAX;

const NUM_NODES: usize = 5;
let config = TestNetworkConfigBuilder::<NUM_NODES, _, _>::with_num_nodes()
.api_config(
Expand Down Expand Up @@ -1508,7 +1506,11 @@ mod test {
let mut network = TestNetwork::new(config, MockSequencerVersions::new()).await;

let mut events = network.server.event_stream().await;
loop {

// First loop to get an `UpgradeProposal`. Note that the
// actual upgrade will take several subsequent views for
// voting and finally the actual upgrade.
let new_version_first_view = loop {
let event = events.next().await.unwrap();

match event.event {
Expand All @@ -1519,42 +1521,54 @@ mod test {
new_version,
<MockSequencerVersions as Versions>::Upgrade::VERSION
);
break;
break upgrade.new_version_first_view;
}
_ => continue,
}
}
};

let client: Client<ServerError, SequencerApiVersion> =
Client::new(format!("http://localhost:{port}").parse().unwrap());
client.connect(None).await;
tracing::info!(port, "server running");

'outer: loop {
// Loop to wait on the upgrade itself.
loop {
// Get height as a proxy for view number. Height is always
// >= to view, especially using anvil. As a possible
// alternative we might loop on hotshot events here again
// and pull the view number off the event.
let height = client
.get::<usize>("status/block-height")
.get::<ViewNumber>("status/block-height")
.send()
.await
.unwrap();

for peer in &network.peers {
let state = peer.consensus().read().await.decided_state().await;
let states: Vec<_> = network
.peers
.iter()
.map(|peer| async { peer.consensus().read().await.decided_state().await })
.collect();

match state.chain_config.resolve() {
Some(cf) => {
if cf != chain_config_upgrade && height as u64 > stop_voting_view {
panic!("failed to upgrade chain config");
}
let configs: Option<Vec<ChainConfig>> = join_all(states)
.await
.iter()
.map(|state| state.chain_config.resolve())
.collect();

// ChainConfigs will eventually be resolved
if let Some(configs) = configs {
if height >= new_version_first_view {
for config in configs {
assert_eq!(config, chain_config_upgrade);
}
None => continue 'outer,
break; // if assertion did not panic, we need to exit the loop
}
}

break;
sleep(Duration::from_millis(200)).await;
}

network.server.shut_down().await;
drop(network);
}

#[async_std::test]
Expand Down
1 change: 0 additions & 1 deletion sequencer/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,6 @@ mod test {
timestamp = "0x123def"
hash = "0x80f5dd11f2bdda2814cb1ad94ef30a47de02cf28ad68c89e104c00c4e51bb7a5"


[[upgrade]]
version = "0.3"
start_proposing_view = 1
Expand Down

0 comments on commit bd1478a

Please sign in to comment.