Skip to content

Commit c408e5e

Browse files
authored
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
1 parent 06bf72f commit c408e5e

File tree

7 files changed

+154
-50
lines changed

7 files changed

+154
-50
lines changed

data/genesis/demo.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,18 @@ version = "0.2"
1616
start_proposing_view = 5
1717
stop_proposing_view = 15
1818

19-
[upgrade.chain_config]
19+
[upgrade.fee]
20+
21+
[upgrade.fee.chain_config]
2022
chain_id = 999999999
2123
base_fee = '1 wei'
2224
max_block_size = '1mb'
2325
fee_recipient = '0x0000000000000000000000000000000000000000'
2426
fee_contract = '0xa15bb66138824a1c7167f5e85b957d04dd34e468'
27+
28+
[[upgrade]]
29+
version = "0.3"
30+
start_proposing_view = 5
31+
stop_proposing_view = 15
32+
33+
[upgrade.marketplace]

doc/upgrades.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,25 +85,34 @@ TOML file. For an example with upgrades enabled, refer to [`data/genesis/demo.to
8585
```toml
8686
[[upgrade]]
8787
version = "0.2"
88-
view = 5
89-
propose_window = 10
88+
start_proposing_view = 5
89+
stop_proposing_view = 15
9090

91-
[upgrade.chain_config]
91+
[upgrade.fee]
92+
93+
[upgrade.fee.chain_config]
9294
chain_id = 999999999
93-
base_fee = '2 wei'
95+
base_fee = '1 wei'
9496
max_block_size = '1mb'
9597
fee_recipient = '0x0000000000000000000000000000000000000000'
9698
fee_contract = '0xa15bb66138824a1c7167f5e85b957d04dd34e468'
99+
100+
[[upgrade]]
101+
version = "0.3"
102+
start_proposing_view = 5
103+
stop_proposing_view = 15
104+
105+
[upgrade.marketplace]
97106
```
98107

99108
In the TOML configuration example above, the `upgrade` section defines an array of tables, each specifying upgrade
100-
parameters:
109+
parameters
101110

102111
- **Version:** the new version after an upgrade is successful.
103-
- **View:** Represents the `start_proposing_view` value at which the upgrade is proposed.
104-
- **Propose Window:** Refers to the view window between `start_proposing_view` and `stop_proposing_view`.
112+
- **start_proposing_view:** Represents the `start_proposing_view` value at which the upgrade is proposed.
113+
- **stop_proposing_view:** Refers to the view view after which the node stops proposing an upgrade.
105114

106-
The `upgrade.chain_config` table contains the complete set of chain config parameters, which can be used, for example,
115+
The `upgrade.fee.chain_config` table contains the complete set of chain config parameters, which can be used, for example,
107116
to enable protocol fees or modify other parameters.
108117

109118
## Fee upgrade

sequencer/src/api.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,10 +1455,10 @@ mod test {
14551455
}
14561456

14571457
#[async_std::test]
1458-
async fn test_chain_config_upgrade_view_based() {
1458+
async fn test_fee_upgrade_view_based() {
14591459
setup_test();
14601460

1461-
test_chain_config_upgrade_helper(UpgradeMode::View(ViewBasedUpgrade {
1461+
test_fee_upgrade_helper(UpgradeMode::View(ViewBasedUpgrade {
14621462
start_voting_view: None,
14631463
stop_voting_view: None,
14641464
start_proposing_view: 1,
@@ -1468,11 +1468,11 @@ mod test {
14681468
}
14691469

14701470
#[async_std::test]
1471-
async fn test_chain_config_upgrade_time_based() {
1471+
async fn test_fee_upgrade_time_based() {
14721472
setup_test();
14731473

14741474
let now = OffsetDateTime::now_utc().unix_timestamp() as u64;
1475-
test_chain_config_upgrade_helper(UpgradeMode::Time(TimeBasedUpgrade {
1475+
test_fee_upgrade_helper(UpgradeMode::Time(TimeBasedUpgrade {
14761476
start_proposing_time: Timestamp::from_integer(now).unwrap(),
14771477
stop_proposing_time: Timestamp::from_integer(now + 500).unwrap(),
14781478
start_voting_time: None,
@@ -1481,7 +1481,7 @@ mod test {
14811481
.await;
14821482
}
14831483

1484-
async fn test_chain_config_upgrade_helper(mode: UpgradeMode) {
1484+
async fn test_fee_upgrade_helper(mode: UpgradeMode) {
14851485
let port = pick_unused_port().expect("No ports free");
14861486
let anvil = Anvil::new().spawn();
14871487
let l1 = anvil.endpoint().parse().unwrap();
@@ -1497,7 +1497,7 @@ mod test {
14971497
<SeqTypes as NodeType>::Upgrade::VERSION,
14981498
Upgrade {
14991499
mode,
1500-
upgrade_type: UpgradeType::ChainConfig {
1500+
upgrade_type: UpgradeType::Fee {
15011501
chain_config: chain_config_upgrade,
15021502
},
15031503
},

sequencer/src/genesis.rs

Lines changed: 105 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,8 @@ impl Genesis {
5656
let upgrades: Vec<&Upgrade> = self.upgrades.values().collect();
5757

5858
for upgrade in upgrades {
59-
match upgrade.upgrade_type {
60-
UpgradeType::ChainConfig { chain_config } => {
61-
base_fee = std::cmp::max(chain_config.base_fee, base_fee);
62-
}
59+
if let UpgradeType::Fee { chain_config } = upgrade.upgrade_type {
60+
base_fee = std::cmp::max(chain_config.base_fee, base_fee);
6361
}
6462
}
6563

@@ -401,7 +399,7 @@ mod test {
401399
}
402400

403401
#[test]
404-
fn test_genesis_toml_upgrade_view_mode() {
402+
fn test_genesis_toml_fee_upgrade_view_mode() {
405403
// without optional fields
406404
// with view settings
407405
let toml = toml! {
@@ -432,7 +430,9 @@ mod test {
432430
start_proposing_view = 1
433431
stop_proposing_view = 15
434432

435-
[upgrade.chain_config]
433+
[upgrade.fee]
434+
435+
[upgrade.fee.chain_config]
436436
chain_id = 12345
437437
max_block_size = 30000
438438
base_fee = 1
@@ -454,7 +454,7 @@ mod test {
454454
start_proposing_view: 1,
455455
stop_proposing_view: 15,
456456
}),
457-
upgrade_type: UpgradeType::ChainConfig {
457+
upgrade_type: UpgradeType::Fee {
458458
chain_config: genesis.chain_config,
459459
},
460460
};
@@ -463,7 +463,7 @@ mod test {
463463
}
464464

465465
#[test]
466-
fn test_genesis_toml_upgrade_time_mode() {
466+
fn test_genesis_toml_fee_upgrade_time_mode() {
467467
// without optional fields
468468
// with time settings
469469
let toml = toml! {
@@ -494,7 +494,9 @@ mod test {
494494
start_proposing_time = "2024-01-01T00:00:00Z"
495495
stop_proposing_time = "2024-01-02T00:00:00Z"
496496

497-
[upgrade.chain_config]
497+
[upgrade.fee]
498+
499+
[upgrade.fee.chain_config]
498500
chain_id = 12345
499501
max_block_size = 30000
500502
base_fee = 1
@@ -518,7 +520,7 @@ mod test {
518520
stop_proposing_time: Timestamp::from_string("2024-01-02T00:00:00Z".to_string())
519521
.unwrap(),
520522
}),
521-
upgrade_type: UpgradeType::ChainConfig {
523+
upgrade_type: UpgradeType::Fee {
522524
chain_config: genesis.chain_config,
523525
},
524526
};
@@ -527,7 +529,7 @@ mod test {
527529
}
528530

529531
#[test]
530-
fn test_genesis_toml_upgrade_view_and_time_mode() {
532+
fn test_genesis_toml_fee_upgrade_view_and_time_mode() {
531533
// set both time and view parameters
532534
// this should err
533535
let toml = toml! {
@@ -560,7 +562,9 @@ mod test {
560562
start_proposing_time = 1
561563
stop_proposing_time = 10
562564

563-
[upgrade.chain_config]
565+
[upgrade.fee]
566+
567+
[upgrade.fee.chain_config]
564568
chain_id = 12345
565569
max_block_size = 30000
566570
base_fee = 1
@@ -571,4 +575,93 @@ mod test {
571575

572576
toml::from_str::<Genesis>(&toml).unwrap_err();
573577
}
578+
579+
#[test]
580+
fn test_marketplace_upgrade_toml() {
581+
let toml = toml! {
582+
[stake_table]
583+
capacity = 10
584+
585+
[chain_config]
586+
chain_id = 12345
587+
max_block_size = 30000
588+
base_fee = 1
589+
fee_recipient = "0x0000000000000000000000000000000000000000"
590+
fee_contract = "0x0000000000000000000000000000000000000000"
591+
592+
[header]
593+
timestamp = 123456
594+
595+
[accounts]
596+
"0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f" = 100000
597+
"0x0000000000000000000000000000000000000000" = 42
598+
599+
[l1_finalized]
600+
number = 64
601+
timestamp = "0x123def"
602+
hash = "0x80f5dd11f2bdda2814cb1ad94ef30a47de02cf28ad68c89e104c00c4e51bb7a5"
603+
604+
605+
[[upgrade]]
606+
version = "0.3"
607+
start_proposing_view = 1
608+
stop_proposing_view = 10
609+
610+
[upgrade.marketplace]
611+
}
612+
.to_string();
613+
614+
toml::from_str::<Genesis>(&toml).unwrap();
615+
}
616+
617+
#[test]
618+
fn test_marketplace_and_fee_upgrade_toml() {
619+
let toml = toml! {
620+
[stake_table]
621+
capacity = 10
622+
623+
[chain_config]
624+
chain_id = 12345
625+
max_block_size = 30000
626+
base_fee = 1
627+
fee_recipient = "0x0000000000000000000000000000000000000000"
628+
fee_contract = "0x0000000000000000000000000000000000000000"
629+
630+
[header]
631+
timestamp = 123456
632+
633+
[accounts]
634+
"0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f" = 100000
635+
"0x0000000000000000000000000000000000000000" = 42
636+
637+
[l1_finalized]
638+
number = 64
639+
timestamp = "0x123def"
640+
hash = "0x80f5dd11f2bdda2814cb1ad94ef30a47de02cf28ad68c89e104c00c4e51bb7a5"
641+
642+
[[upgrade]]
643+
version = "0.3"
644+
start_proposing_view = 1
645+
stop_proposing_view = 10
646+
647+
[upgrade.marketplace]
648+
649+
[[upgrade]]
650+
version = "0.2"
651+
start_proposing_view = 1
652+
stop_proposing_view = 15
653+
654+
[upgrade.fee]
655+
656+
[upgrade.fee.chain_config]
657+
chain_id = 12345
658+
max_block_size = 30000
659+
base_fee = 1
660+
fee_recipient = "0x0000000000000000000000000000000000000000"
661+
fee_contract = "0x0000000000000000000000000000000000000000"
662+
}
663+
.to_string();
664+
665+
toml::from_str::<Genesis>(&toml).unwrap();
666+
}
574667
}

types/src/v0/impls/header.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -748,13 +748,11 @@ impl BlockHeader<SeqTypes> for Header {
748748
let mut validated_state = parent_state.clone();
749749

750750
let chain_config = if version > instance_state.current_version {
751-
match instance_state
752-
.upgrades
753-
.get(&version)
754-
.map(|upgrade| match upgrade.upgrade_type {
755-
UpgradeType::ChainConfig { chain_config } => chain_config,
756-
}) {
757-
Some(cf) => cf,
751+
match instance_state.upgrades.get(&version) {
752+
Some(upgrade) => match upgrade.upgrade_type {
753+
UpgradeType::Fee { chain_config } => chain_config,
754+
_ => Header::get_chain_config(&validated_state, instance_state).await,
755+
},
758756
None => Header::get_chain_config(&validated_state, instance_state).await,
759757
}
760758
} else {
@@ -867,13 +865,11 @@ impl BlockHeader<SeqTypes> for Header {
867865
let mut validated_state = parent_state.clone();
868866

869867
let chain_config = if version > instance_state.current_version {
870-
match instance_state
871-
.upgrades
872-
.get(&version)
873-
.map(|upgrade| match upgrade.upgrade_type {
874-
UpgradeType::ChainConfig { chain_config } => chain_config,
875-
}) {
876-
Some(cf) => cf,
868+
match instance_state.upgrades.get(&version) {
869+
Some(upgrade) => match upgrade.upgrade_type {
870+
UpgradeType::Fee { chain_config } => chain_config,
871+
_ => Header::get_chain_config(&validated_state, instance_state).await,
872+
},
877873
None => Header::get_chain_config(&validated_state, instance_state).await,
878874
}
879875
} else {

types/src/v0/impls/state.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -510,10 +510,8 @@ impl ValidatedState {
510510
return;
511511
};
512512

513-
match upgrade.upgrade_type {
514-
UpgradeType::ChainConfig { chain_config } => {
515-
self.chain_config = chain_config.into();
516-
}
513+
if let UpgradeType::Fee { chain_config } = upgrade.upgrade_type {
514+
self.chain_config = chain_config.into();
517515
}
518516
}
519517

@@ -794,6 +792,7 @@ mod test {
794792
use hotshot_types::{traits::signature_key::BuilderSignatureKey, vid::vid_scheme};
795793
use jf_vid::VidScheme;
796794
use sequencer_utils::ser::FromStringOrInteger;
795+
use tracing::debug;
797796

798797
use super::*;
799798
use crate::{
@@ -1065,7 +1064,7 @@ mod test {
10651064
let metadata = parent.block_header().metadata();
10661065
let vid_commitment = parent.payload_commitment();
10671066

1068-
dbg!(header.version());
1067+
debug!("{:?}", header.version());
10691068

10701069
let key_pair = EthKeyPair::random();
10711070
let account = key_pair.fee_account();

types/src/v0/v0_1/instance_state.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ use crate::{v0_3::ChainConfig, Timestamp};
55

66
/// Represents the specific type of upgrade.
77
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
8-
#[serde(untagged)]
98
#[serde(rename_all = "snake_case")]
109
pub enum UpgradeType {
11-
// Note: Wrapping this in a tuple variant causes deserialization to fail because
12-
// the 'chain_config' name is also provided in the TOML input.
13-
ChainConfig { chain_config: ChainConfig },
10+
Fee { chain_config: ChainConfig },
11+
Marketplace {},
1412
}
1513

1614
/// Represents an upgrade based on time (unix timestamp).

0 commit comments

Comments
 (0)