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

Tb/test marketplace upgrade #1880

Closed
wants to merge 14 commits into from
126 changes: 82 additions & 44 deletions sequencer/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1453,12 +1453,21 @@ mod test {
async fn test_fee_upgrade_view_based() {
setup_test();

test_fee_upgrade_helper(UpgradeMode::View(ViewBasedUpgrade {
start_voting_view: None,
stop_voting_view: None,
start_proposing_view: 1,
stop_proposing_view: 10,
}))
test_upgrade_helper(
UpgradeMode::View(ViewBasedUpgrade {
start_voting_view: None,
stop_voting_view: None,
start_proposing_view: 1,
stop_proposing_view: 10,
}),
UpgradeType::Fee {
chain_config: ChainConfig {
max_block_size: 300.into(),
base_fee: 1.into(),
..Default::default()
},
},
)
.await;
}

Expand All @@ -1467,38 +1476,60 @@ mod test {
setup_test();

let now = OffsetDateTime::now_utc().unix_timestamp() as u64;
test_fee_upgrade_helper(UpgradeMode::Time(TimeBasedUpgrade {
start_proposing_time: Timestamp::from_integer(now).unwrap(),
stop_proposing_time: Timestamp::from_integer(now + 500).unwrap(),
start_voting_time: None,
stop_voting_time: None,
}))
test_upgrade_helper(
UpgradeMode::Time(TimeBasedUpgrade {
start_proposing_time: Timestamp::from_integer(now).unwrap(),
stop_proposing_time: Timestamp::from_integer(now + 500).unwrap(),
start_voting_time: None,
stop_voting_time: None,
}),
UpgradeType::Fee {
chain_config: ChainConfig {
max_block_size: 300.into(),
base_fee: 1.into(),
..Default::default()
},
},
)
.await;
}

async fn test_fee_upgrade_helper(mode: UpgradeMode) {
#[async_std::test]
async fn test_marketplace_upgrade_view_based() {
setup_test();

test_upgrade_helper(
UpgradeMode::View(ViewBasedUpgrade {
start_voting_view: None,
stop_voting_view: None,
start_proposing_view: 1,
stop_proposing_view: 10,
}),
UpgradeType::Marketplace {
chain_config: ChainConfig {
max_block_size: 400.into(),
base_fee: 2.into(),
bid_recipient: Some(FeeAccount::default()),
..Default::default()
},
},
)
.await;
}

async fn test_upgrade_helper(mode: UpgradeMode, upgrade_type: UpgradeType) {
let port = pick_unused_port().expect("No ports free");
let anvil = Anvil::new().spawn();
let l1 = anvil.endpoint().parse().unwrap();

let chain_config_upgrade = ChainConfig {
max_block_size: 300.into(),
base_fee: 1.into(),
..Default::default()
let chain_config_upgrade = match upgrade_type {
UpgradeType::Fee { chain_config } => chain_config,
UpgradeType::Marketplace { chain_config } => chain_config,
};
let mut upgrades = std::collections::BTreeMap::new();

upgrades.insert(
UpgradeVersion::VERSION,
Upgrade {
mode,
upgrade_type: UpgradeType::Fee {
chain_config: chain_config_upgrade,
},
},
);
let mut upgrades = std::collections::BTreeMap::new();

let stop_voting_view = u64::MAX;
upgrades.insert(UpgradeVersion::VERSION, Upgrade { mode, upgrade_type });

const NUM_NODES: usize = 5;
let config = TestNetworkConfigBuilder::<NUM_NODES, _, _>::with_num_nodes()
Expand Down Expand Up @@ -1527,50 +1558,57 @@ mod test {
let mut network = TestNetwork::new(config, BaseVersion::instance()).await;

let mut events = network.server.event_stream().await;
loop {
let new_version_first_view = loop {
let event = events.next().await.unwrap();

match event.event {
EventType::UpgradeProposal { proposal, .. } => {
let upgrade = proposal.data.upgrade_proposal;
let new_version = upgrade.new_version;
assert_eq!(new_version, UpgradeVersion::VERSION);
break;
break upgrade.new_version_first_view;
}
_ => continue,
}
}
};

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

'outer: loop {
loop {
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 {
tbro marked this conversation as resolved.
Show resolved Hide resolved
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
16 changes: 15 additions & 1 deletion sequencer/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,13 +601,20 @@ mod test {
timestamp = "0x123def"
hash = "0x80f5dd11f2bdda2814cb1ad94ef30a47de02cf28ad68c89e104c00c4e51bb7a5"


[[upgrade]]
version = "0.3"
start_proposing_view = 1
stop_proposing_view = 10

[upgrade.marketplace]
[upgrade.marketplace.chain_config]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

marketplace genesis upgrade

chain_id = 12345
max_block_size = 30000
base_fee = 1
fee_recipient = "0x0000000000000000000000000000000000000000"
bid_recipient = "0x0000000000000000000000000000000000000000"
fee_contract = "0x0000000000000000000000000000000000000000"

}
.to_string();

Expand Down Expand Up @@ -645,6 +652,13 @@ mod test {
stop_proposing_view = 10

[upgrade.marketplace]
[upgrade.marketplace.chain_config]
chain_id = 12345
max_block_size = 30000
base_fee = 1
fee_recipient = "0x0000000000000000000000000000000000000000"
bid_recipient = "0x0000000000000000000000000000000000000000"
fee_contract = "0x0000000000000000000000000000000000000000"

[[upgrade]]
version = "0.2"
Expand Down
5 changes: 4 additions & 1 deletion types/src/v0/impls/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,13 @@ impl HasUrls for SolverAuctionResults {
type SurfClient = surf_disco::Client<ServerError, BaseVersion>;

#[derive(Debug, Clone, Eq, PartialEq, Hash)]
/// Auction Results provider holding the Url of the solver in order to fetch auction results.
/// Auction Results provider. holding the Url of the solver in order to fetch auction results.
pub struct SolverAuctionResultsProvider {
/// Url of the solver from which we will fetch auction results.
pub url: Url,
/// Base path of marketplace API
pub marketplace_path: String,
/// Path for fetching `AuctionResults`, relative to `marketplace_path`.
pub results_path: String,
}

Expand Down
2 changes: 1 addition & 1 deletion types/src/v0/v0_1/instance_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{v0_3::ChainConfig, Timestamp};
#[serde(rename_all = "snake_case")]
pub enum UpgradeType {
Fee { chain_config: ChainConfig },
Marketplace {},
Marketplace { chain_config: ChainConfig },
tbro marked this conversation as resolved.
Show resolved Hide resolved
}

/// Represents an upgrade based on time (unix timestamp).
Expand Down
Loading