From c408e5ee32a319e6026660a4e7ca33ad98455b13 Mon Sep 17 00:00:00 2001 From: Abdul Basit <45506001+imabdulbasit@users.noreply.github.com> Date: Wed, 14 Aug 2024 19:12:56 +0500 Subject: [PATCH] add marketplace upgrade type (#1850) * marketplace upgrade type * fix version in toml file * use empty variant for marketplace * rename chainconfig upgrade type to feeupgrade * fix tests and update doc * rename fee_upgrade to fee * remove comment --- data/genesis/demo.toml | 11 ++- doc/upgrades.md | 25 ++++-- sequencer/src/api.rs | 12 +-- sequencer/src/genesis.rs | 117 +++++++++++++++++++++++++--- types/src/v0/impls/header.rs | 24 +++--- types/src/v0/impls/state.rs | 9 +-- types/src/v0/v0_1/instance_state.rs | 6 +- 7 files changed, 154 insertions(+), 50 deletions(-) diff --git a/data/genesis/demo.toml b/data/genesis/demo.toml index 3493200e6..00a6b60ef 100644 --- a/data/genesis/demo.toml +++ b/data/genesis/demo.toml @@ -16,9 +16,18 @@ version = "0.2" start_proposing_view = 5 stop_proposing_view = 15 -[upgrade.chain_config] +[upgrade.fee] + +[upgrade.fee.chain_config] chain_id = 999999999 base_fee = '1 wei' max_block_size = '1mb' fee_recipient = '0x0000000000000000000000000000000000000000' fee_contract = '0xa15bb66138824a1c7167f5e85b957d04dd34e468' + +[[upgrade]] +version = "0.3" +start_proposing_view = 5 +stop_proposing_view = 15 + +[upgrade.marketplace] \ No newline at end of file diff --git a/doc/upgrades.md b/doc/upgrades.md index 75a65dfba..72811804a 100644 --- a/doc/upgrades.md +++ b/doc/upgrades.md @@ -85,25 +85,34 @@ TOML file. For an example with upgrades enabled, refer to [`data/genesis/demo.to ```toml [[upgrade]] version = "0.2" -view = 5 -propose_window = 10 +start_proposing_view = 5 +stop_proposing_view = 15 -[upgrade.chain_config] +[upgrade.fee] + +[upgrade.fee.chain_config] chain_id = 999999999 -base_fee = '2 wei' +base_fee = '1 wei' max_block_size = '1mb' fee_recipient = '0x0000000000000000000000000000000000000000' fee_contract = '0xa15bb66138824a1c7167f5e85b957d04dd34e468' + +[[upgrade]] +version = "0.3" +start_proposing_view = 5 +stop_proposing_view = 15 + +[upgrade.marketplace] ``` In the TOML configuration example above, the `upgrade` section defines an array of tables, each specifying upgrade -parameters: +parameters - **Version:** the new version after an upgrade is successful. -- **View:** Represents the `start_proposing_view` value at which the upgrade is proposed. -- **Propose Window:** Refers to the view window between `start_proposing_view` and `stop_proposing_view`. +- **start_proposing_view:** Represents the `start_proposing_view` value at which the upgrade is proposed. +- **stop_proposing_view:** Refers to the view view after which the node stops proposing an upgrade. -The `upgrade.chain_config` table contains the complete set of chain config parameters, which can be used, for example, +The `upgrade.fee.chain_config` table contains the complete set of chain config parameters, which can be used, for example, to enable protocol fees or modify other parameters. ## Fee upgrade diff --git a/sequencer/src/api.rs b/sequencer/src/api.rs index fc3791943..5f1a2098a 100644 --- a/sequencer/src/api.rs +++ b/sequencer/src/api.rs @@ -1455,10 +1455,10 @@ mod test { } #[async_std::test] - async fn test_chain_config_upgrade_view_based() { + async fn test_fee_upgrade_view_based() { setup_test(); - test_chain_config_upgrade_helper(UpgradeMode::View(ViewBasedUpgrade { + test_fee_upgrade_helper(UpgradeMode::View(ViewBasedUpgrade { start_voting_view: None, stop_voting_view: None, start_proposing_view: 1, @@ -1468,11 +1468,11 @@ mod test { } #[async_std::test] - async fn test_chain_config_upgrade_time_based() { + async fn test_fee_upgrade_time_based() { setup_test(); let now = OffsetDateTime::now_utc().unix_timestamp() as u64; - test_chain_config_upgrade_helper(UpgradeMode::Time(TimeBasedUpgrade { + 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, @@ -1481,7 +1481,7 @@ mod test { .await; } - async fn test_chain_config_upgrade_helper(mode: UpgradeMode) { + 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(); @@ -1497,7 +1497,7 @@ mod test { ::Upgrade::VERSION, Upgrade { mode, - upgrade_type: UpgradeType::ChainConfig { + upgrade_type: UpgradeType::Fee { chain_config: chain_config_upgrade, }, }, diff --git a/sequencer/src/genesis.rs b/sequencer/src/genesis.rs index fc5440cc1..254b746eb 100644 --- a/sequencer/src/genesis.rs +++ b/sequencer/src/genesis.rs @@ -56,10 +56,8 @@ impl Genesis { let upgrades: Vec<&Upgrade> = self.upgrades.values().collect(); for upgrade in upgrades { - match upgrade.upgrade_type { - UpgradeType::ChainConfig { chain_config } => { - base_fee = std::cmp::max(chain_config.base_fee, base_fee); - } + if let UpgradeType::Fee { chain_config } = upgrade.upgrade_type { + base_fee = std::cmp::max(chain_config.base_fee, base_fee); } } @@ -401,7 +399,7 @@ mod test { } #[test] - fn test_genesis_toml_upgrade_view_mode() { + fn test_genesis_toml_fee_upgrade_view_mode() { // without optional fields // with view settings let toml = toml! { @@ -432,7 +430,9 @@ mod test { start_proposing_view = 1 stop_proposing_view = 15 - [upgrade.chain_config] + [upgrade.fee] + + [upgrade.fee.chain_config] chain_id = 12345 max_block_size = 30000 base_fee = 1 @@ -454,7 +454,7 @@ mod test { start_proposing_view: 1, stop_proposing_view: 15, }), - upgrade_type: UpgradeType::ChainConfig { + upgrade_type: UpgradeType::Fee { chain_config: genesis.chain_config, }, }; @@ -463,7 +463,7 @@ mod test { } #[test] - fn test_genesis_toml_upgrade_time_mode() { + fn test_genesis_toml_fee_upgrade_time_mode() { // without optional fields // with time settings let toml = toml! { @@ -494,7 +494,9 @@ mod test { start_proposing_time = "2024-01-01T00:00:00Z" stop_proposing_time = "2024-01-02T00:00:00Z" - [upgrade.chain_config] + [upgrade.fee] + + [upgrade.fee.chain_config] chain_id = 12345 max_block_size = 30000 base_fee = 1 @@ -518,7 +520,7 @@ mod test { stop_proposing_time: Timestamp::from_string("2024-01-02T00:00:00Z".to_string()) .unwrap(), }), - upgrade_type: UpgradeType::ChainConfig { + upgrade_type: UpgradeType::Fee { chain_config: genesis.chain_config, }, }; @@ -527,7 +529,7 @@ mod test { } #[test] - fn test_genesis_toml_upgrade_view_and_time_mode() { + fn test_genesis_toml_fee_upgrade_view_and_time_mode() { // set both time and view parameters // this should err let toml = toml! { @@ -560,7 +562,9 @@ mod test { start_proposing_time = 1 stop_proposing_time = 10 - [upgrade.chain_config] + [upgrade.fee] + + [upgrade.fee.chain_config] chain_id = 12345 max_block_size = 30000 base_fee = 1 @@ -571,4 +575,93 @@ mod test { toml::from_str::(&toml).unwrap_err(); } + + #[test] + fn test_marketplace_upgrade_toml() { + let toml = toml! { + [stake_table] + capacity = 10 + + [chain_config] + chain_id = 12345 + max_block_size = 30000 + base_fee = 1 + fee_recipient = "0x0000000000000000000000000000000000000000" + fee_contract = "0x0000000000000000000000000000000000000000" + + [header] + timestamp = 123456 + + [accounts] + "0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f" = 100000 + "0x0000000000000000000000000000000000000000" = 42 + + [l1_finalized] + number = 64 + timestamp = "0x123def" + hash = "0x80f5dd11f2bdda2814cb1ad94ef30a47de02cf28ad68c89e104c00c4e51bb7a5" + + + [[upgrade]] + version = "0.3" + start_proposing_view = 1 + stop_proposing_view = 10 + + [upgrade.marketplace] + } + .to_string(); + + toml::from_str::(&toml).unwrap(); + } + + #[test] + fn test_marketplace_and_fee_upgrade_toml() { + let toml = toml! { + [stake_table] + capacity = 10 + + [chain_config] + chain_id = 12345 + max_block_size = 30000 + base_fee = 1 + fee_recipient = "0x0000000000000000000000000000000000000000" + fee_contract = "0x0000000000000000000000000000000000000000" + + [header] + timestamp = 123456 + + [accounts] + "0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f" = 100000 + "0x0000000000000000000000000000000000000000" = 42 + + [l1_finalized] + number = 64 + timestamp = "0x123def" + hash = "0x80f5dd11f2bdda2814cb1ad94ef30a47de02cf28ad68c89e104c00c4e51bb7a5" + + [[upgrade]] + version = "0.3" + start_proposing_view = 1 + stop_proposing_view = 10 + + [upgrade.marketplace] + + [[upgrade]] + version = "0.2" + start_proposing_view = 1 + stop_proposing_view = 15 + + [upgrade.fee] + + [upgrade.fee.chain_config] + chain_id = 12345 + max_block_size = 30000 + base_fee = 1 + fee_recipient = "0x0000000000000000000000000000000000000000" + fee_contract = "0x0000000000000000000000000000000000000000" + } + .to_string(); + + toml::from_str::(&toml).unwrap(); + } } diff --git a/types/src/v0/impls/header.rs b/types/src/v0/impls/header.rs index 2a34201c9..ad427d6b2 100644 --- a/types/src/v0/impls/header.rs +++ b/types/src/v0/impls/header.rs @@ -748,13 +748,11 @@ impl BlockHeader for Header { let mut validated_state = parent_state.clone(); let chain_config = if version > instance_state.current_version { - match instance_state - .upgrades - .get(&version) - .map(|upgrade| match upgrade.upgrade_type { - UpgradeType::ChainConfig { chain_config } => chain_config, - }) { - Some(cf) => cf, + match instance_state.upgrades.get(&version) { + Some(upgrade) => match upgrade.upgrade_type { + UpgradeType::Fee { chain_config } => chain_config, + _ => Header::get_chain_config(&validated_state, instance_state).await, + }, None => Header::get_chain_config(&validated_state, instance_state).await, } } else { @@ -867,13 +865,11 @@ impl BlockHeader for Header { let mut validated_state = parent_state.clone(); let chain_config = if version > instance_state.current_version { - match instance_state - .upgrades - .get(&version) - .map(|upgrade| match upgrade.upgrade_type { - UpgradeType::ChainConfig { chain_config } => chain_config, - }) { - Some(cf) => cf, + match instance_state.upgrades.get(&version) { + Some(upgrade) => match upgrade.upgrade_type { + UpgradeType::Fee { chain_config } => chain_config, + _ => Header::get_chain_config(&validated_state, instance_state).await, + }, None => Header::get_chain_config(&validated_state, instance_state).await, } } else { diff --git a/types/src/v0/impls/state.rs b/types/src/v0/impls/state.rs index a38839119..cabaad45f 100644 --- a/types/src/v0/impls/state.rs +++ b/types/src/v0/impls/state.rs @@ -510,10 +510,8 @@ impl ValidatedState { return; }; - match upgrade.upgrade_type { - UpgradeType::ChainConfig { chain_config } => { - self.chain_config = chain_config.into(); - } + if let UpgradeType::Fee { chain_config } = upgrade.upgrade_type { + self.chain_config = chain_config.into(); } } @@ -794,6 +792,7 @@ mod test { use hotshot_types::{traits::signature_key::BuilderSignatureKey, vid::vid_scheme}; use jf_vid::VidScheme; use sequencer_utils::ser::FromStringOrInteger; + use tracing::debug; use super::*; use crate::{ @@ -1065,7 +1064,7 @@ mod test { let metadata = parent.block_header().metadata(); let vid_commitment = parent.payload_commitment(); - dbg!(header.version()); + debug!("{:?}", header.version()); let key_pair = EthKeyPair::random(); let account = key_pair.fee_account(); diff --git a/types/src/v0/v0_1/instance_state.rs b/types/src/v0/v0_1/instance_state.rs index 2d2333fb2..8d381c217 100644 --- a/types/src/v0/v0_1/instance_state.rs +++ b/types/src/v0/v0_1/instance_state.rs @@ -5,12 +5,10 @@ use crate::{v0_3::ChainConfig, Timestamp}; /// Represents the specific type of upgrade. #[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] -#[serde(untagged)] #[serde(rename_all = "snake_case")] pub enum UpgradeType { - // Note: Wrapping this in a tuple variant causes deserialization to fail because - // the 'chain_config' name is also provided in the TOML input. - ChainConfig { chain_config: ChainConfig }, + Fee { chain_config: ChainConfig }, + Marketplace {}, } /// Represents an upgrade based on time (unix timestamp).