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

add marketplace upgrade type #1850

Merged
merged 9 commits into from
Aug 14, 2024
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
11 changes: 10 additions & 1 deletion data/genesis/demo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
25 changes: 17 additions & 8 deletions doc/upgrades.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions sequencer/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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();
Expand All @@ -1497,7 +1497,7 @@ mod test {
<SeqTypes as NodeType>::Upgrade::VERSION,
Upgrade {
mode,
upgrade_type: UpgradeType::ChainConfig {
upgrade_type: UpgradeType::Fee {
chain_config: chain_config_upgrade,
},
},
Expand Down
117 changes: 105 additions & 12 deletions sequencer/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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! {
Expand Down Expand Up @@ -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
Expand All @@ -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,
},
};
Expand All @@ -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! {
Expand Down Expand Up @@ -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
Expand All @@ -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,
},
};
Expand All @@ -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! {
Expand Down Expand Up @@ -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
Expand All @@ -571,4 +575,93 @@ mod test {

toml::from_str::<Genesis>(&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::<Genesis>(&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::<Genesis>(&toml).unwrap();
}
}
24 changes: 10 additions & 14 deletions types/src/v0/impls/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,13 +748,11 @@ impl BlockHeader<SeqTypes> 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 {
Expand Down Expand Up @@ -867,13 +865,11 @@ impl BlockHeader<SeqTypes> 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 {
Expand Down
9 changes: 4 additions & 5 deletions types/src/v0/impls/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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::{
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 2 additions & 4 deletions types/src/v0/v0_1/instance_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
Loading