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

test marketplace upgrade #1927

Merged
merged 11 commits into from
Sep 11, 2024
126 changes: 90 additions & 36 deletions sequencer/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1069,16 +1069,16 @@ mod api_tests {

#[cfg(test)]
mod test {
use std::time::Duration;
use std::{collections::BTreeMap, time::Duration};

use async_std::task::sleep;
use committable::{Commitment, Committable};

use espresso_types::{
mock::MockStateCatchup,
v0_1::{UpgradeMode, ViewBasedUpgrade},
FeeAccount, FeeAmount, Header, MockSequencerVersions, TimeBasedUpgrade, Timestamp, Upgrade,
UpgradeType, ValidatedState,
FeeAccount, FeeAmount, Header, MockSequencerVersions, SequencerVersions, TimeBasedUpgrade,
Timestamp, Upgrade, UpgradeType, ValidatedState,
};
use ethers::utils::Anvil;
use futures::{
Expand All @@ -1105,7 +1105,7 @@ mod test {
};
use tide_disco::{app::AppHealth, error::ServerError, healthcheck::HealthStatus};
use time::OffsetDateTime;
use vbs::version::{StaticVersion, StaticVersionType};
use vbs::version::{StaticVersion, StaticVersionType, Version};

use self::{
data_source::{testing::TestableSequencerDataSource, PublicHotShotConfig},
Expand Down Expand Up @@ -1465,50 +1465,105 @@ mod test {
async fn test_fee_upgrade_view_based() {
setup_test();

test_fee_upgrade_helper(UpgradeMode::View(ViewBasedUpgrade {
let mut upgrades = std::collections::BTreeMap::new();
type MySequencerVersions = SequencerVersions<StaticVersion<0, 1>, StaticVersion<0, 2>>;

let mode = UpgradeMode::View(ViewBasedUpgrade {
start_voting_view: None,
stop_voting_view: None,
start_proposing_view: 1,
stop_proposing_view: 10,
}))
.await;
});

let upgrade_type = UpgradeType::Fee {
chain_config: ChainConfig {
max_block_size: 300.into(),
base_fee: 1.into(),
..Default::default()
},
};

upgrades.insert(
<MySequencerVersions as Versions>::Upgrade::VERSION,
Upgrade { mode, upgrade_type },
);
test_upgrade_helper::<MySequencerVersions>(upgrades, MySequencerVersions::new()).await;
}

#[async_std::test]
async fn test_fee_upgrade_time_based() {
setup_test();

let now = OffsetDateTime::now_utc().unix_timestamp() as u64;
test_fee_upgrade_helper(UpgradeMode::Time(TimeBasedUpgrade {

let mut upgrades = std::collections::BTreeMap::new();
type MySequencerVersions = SequencerVersions<StaticVersion<0, 1>, StaticVersion<0, 2>>;

let mode = 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,
}))
.await;
});

let upgrade_type = UpgradeType::Fee {
chain_config: ChainConfig {
max_block_size: 300.into(),
base_fee: 1.into(),
..Default::default()
},
};

upgrades.insert(
<MySequencerVersions as Versions>::Upgrade::VERSION,
Upgrade { mode, upgrade_type },
);
test_upgrade_helper::<MySequencerVersions>(upgrades, MySequencerVersions::new()).await;
}

async fn test_fee_upgrade_helper(mode: UpgradeMode) {
let port = pick_unused_port().expect("No ports free");
let anvil = Anvil::new().spawn();
let l1 = anvil.endpoint().parse().unwrap();
#[async_std::test]
async fn test_marketplace_upgrade_view_based() {
setup_test();

let chain_config_upgrade = ChainConfig {
max_block_size: 300.into(),
base_fee: 1.into(),
..Default::default()
};
let mut upgrades = std::collections::BTreeMap::new();
type MySequencerVersions = SequencerVersions<StaticVersion<0, 2>, StaticVersion<0, 3>>;

upgrades.insert(
StaticVersion::<0, 2>::version(),
Upgrade {
mode,
upgrade_type: UpgradeType::Fee {
chain_config: chain_config_upgrade,
},
let mode = UpgradeMode::View(ViewBasedUpgrade {
start_voting_view: None,
stop_voting_view: None,
start_proposing_view: 1,
stop_proposing_view: 10,
});

let upgrade_type = UpgradeType::Marketplace {
chain_config: ChainConfig {
max_block_size: 400.into(),
base_fee: 2.into(),
bid_recipient: Some(Default::default()),
..Default::default()
},
};

upgrades.insert(
<MySequencerVersions as Versions>::Upgrade::VERSION,
Upgrade { mode, upgrade_type },
);
test_upgrade_helper::<MySequencerVersions>(upgrades, MySequencerVersions::new()).await;
}

async fn test_upgrade_helper<MockSeqVersions: Versions>(
upgrades: BTreeMap<Version, Upgrade>,
bind_version: MockSeqVersions,
) {
let port = pick_unused_port().expect("No ports free");
let anvil = Anvil::new().spawn();
let l1 = anvil.endpoint().parse().unwrap();

let chain_config_upgrade = upgrades
.get(&<MockSeqVersions as Versions>::Upgrade::VERSION)
.unwrap()
.upgrade_type
.data();

const NUM_NODES: usize = 5;
let config = TestNetworkConfigBuilder::<NUM_NODES, _, _>::with_num_nodes()
Expand All @@ -1534,7 +1589,7 @@ mod test {
)
.build();

let mut network = TestNetwork::new(config, MockSequencerVersions::new()).await;
let mut network = TestNetwork::new(config, bind_version).await;

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

Expand All @@ -1543,15 +1598,12 @@ mod test {
// voting and finally the actual upgrade.
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,
<MockSequencerVersions as Versions>::Upgrade::VERSION
);
dbg!(&new_version);
assert_eq!(new_version, <MockSeqVersions as Versions>::Upgrade::VERSION);
break upgrade.new_version_first_view;
}
_ => continue,
Expand All @@ -1566,9 +1618,10 @@ mod test {
// 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.
// >= to view. Especially when using Anvil, there should be little
// difference. As a possible alternative we might loop on
// hotshot events here again and pull the view number off
// the event.
let height = client
.get::<ViewNumber>("status/block-height")
.send()
Expand All @@ -1589,7 +1642,8 @@ mod test {

// ChainConfigs will eventually be resolved
if let Some(configs) = configs {
if height >= new_version_first_view {
dbg!(height, new_version_first_view);
if height > new_version_first_view {
for config in configs {
assert_eq!(config, chain_config_upgrade);
}
Expand Down
13 changes: 5 additions & 8 deletions sequencer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,18 +641,15 @@ pub mod testing {
}

pub fn upgrades(mut self, upgrades: BTreeMap<Version, Upgrade>) -> Self {
for key in upgrades.keys() {
imabdulbasit marked this conversation as resolved.
Show resolved Hide resolved
let upgrade = upgrades.get(key).unwrap();
upgrade.set_hotshot_config_parameters(&mut self.config)
}
self.upgrades = upgrades;
self
}

pub fn build(mut self) -> TestConfig<NUM_NODES> {
if let Some(upgrade) = self
.upgrades
.get(&<MockSequencerVersions as Versions>::Upgrade::VERSION)
{
upgrade.set_hotshot_config_parameters(&mut self.config)
}

pub fn build(self) -> TestConfig<NUM_NODES> {
TestConfig {
config: self.config,
priv_keys: self.priv_keys,
Expand Down
11 changes: 11 additions & 0 deletions types/src/v0/v0_1/instance_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ pub enum UpgradeType {
Marketplace { chain_config: ChainConfig },
}

impl UpgradeType {
/// Get the upgrade data from `UpgradeType`. As of this writing,
/// we are only concerned w/ `ChainConfig`.
pub fn data(&self) -> ChainConfig {
match self {
UpgradeType::Fee { chain_config } => *chain_config,
UpgradeType::Marketplace { chain_config } => *chain_config,
}
}
}

/// Represents an upgrade based on time (unix timestamp).
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub struct TimeBasedUpgrade {
Expand Down
Loading