Skip to content

Commit

Permalink
Merge branch 'ab/st' into ma/stake-table-update-script
Browse files Browse the repository at this point in the history
  • Loading branch information
imabdulbasit authored Dec 18, 2024
2 parents 7b718a9 + a04ace9 commit 014da42
Show file tree
Hide file tree
Showing 8 changed files with 341 additions and 149 deletions.
363 changes: 250 additions & 113 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,19 @@ opt-level = 3
opt-level = 3
[profile.test.package.diff-test-hotshot]
opt-level = 3

[patch.'https://github.com/EspressoSystems/hotshot.git']
hotshot = { git = 'https://github.com/EspressoSystems/HotShot//', branch = 'lr/double-quorum' }
hotshot-builder-api = { git = 'https://github.com/EspressoSystems/hotshot//', branch = 'lr/double-quorum' }
hotshot-orchestrator ={ git = 'https://github.com/EspressoSystems/hotshot//', branch = 'lr/double-quorum' }
hotshot-stake-table = { git = 'https://github.com/EspressoSystems/hotshot//', branch = 'lr/double-quorum' }
hotshot-task = { git = 'https://github.com/EspressoSystems/hotshot//', branch = 'lr/double-quorum' }
hotshot-task-impls = { git = 'https://github.com/EspressoSystems/hotshot//', branch = 'lr/double-quorum' }
hotshot-testing = { git = 'https://github.com/EspressoSystems/hotshot//', branch = 'lr/double-quorum' }
hotshot-types ={ git = 'https://github.com/EspressoSystems/hotshot//', branch = 'lr/double-quorum' }
libp2p-networking = { git = "https://github.com/EspressoSystems/hotshot//", branch = 'lr/double-quorum' }
hotshot-example-types = { git = "https://github.com/EspressoSystems/hotshot//", branch = 'lr/double-quorum' }
utils = { git = "https://github.com/EspressoSystems/hotshot//", branch = 'lr/double-quorum' }

# patch
# https://github.com/rust-lang/cargo/issues/5478
33 changes: 33 additions & 0 deletions data/genesis/demo-epoch.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
base_version = "0.2"
upgrade_version = "0.3"

[stake_table]
capacity = 10

[chain_config]
chain_id = 999999999
base_fee = '0 wei'
max_block_size = '1mb'
fee_recipient = '0x0000000000000000000000000000000000000000'
fee_contract = '0xa15bb66138824a1c7167f5e85b957d04dd34e468'

[header]
timestamp = "1970-01-01T00:00:00Z"

[l1_finalized]
number = 0

[[upgrade]]
version = "0.99"
start_proposing_view = 10
stop_proposing_view = 60

[upgrade.epoch]
[upgrade.epoch.chain_config]
chain_id = 999999999
max_block_size = '1mb'
base_fee = '1 wei'
fee_recipient = "0x0000000000000000000000000000000000000000"
bid_recipient = "0x0000000000000000000000000000000000000000"
fee_contract = "0xa15bb66138824a1c7167f5e85b957d04dd34e468"
stake_table_contract = "0x8ce361602b935680e8dec218b820ff5056beb7af"
3 changes: 2 additions & 1 deletion sequencer/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2127,7 +2127,8 @@ mod test {
.get(&<MockSeqVersions as Versions>::Upgrade::VERSION)
.unwrap()
.upgrade_type
.data();
.chain_config()
.unwrap();

const NUM_NODES: usize = 5;
let config = TestNetworkConfigBuilder::<NUM_NODES, _, _>::with_num_nodes()
Expand Down
55 changes: 28 additions & 27 deletions sequencer/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use std::{
path::Path,
};

use anyhow::Context;
use anyhow::{Context, Ok};
use espresso_types::{
v0_99::ChainConfig, FeeAccount, FeeAmount, GenesisHeader, L1BlockInfo, L1Client, Timestamp,
Upgrade, UpgradeType,
Upgrade,
};
use ethers::types::H160;
use sequencer_utils::deployer::is_proxy_contract;
Expand Down Expand Up @@ -60,7 +60,7 @@ pub struct Genesis {
pub header: GenesisHeader,
#[serde(rename = "upgrade", with = "upgrade_ser")]
#[serde(default)]
pub upgrades: BTreeMap<Version, Upgrade>,
pub upgrades: BTreeMap<Version, Upgrade>,
}

impl Genesis {
Expand All @@ -70,13 +70,10 @@ impl Genesis {
let upgrades: Vec<&Upgrade> = self.upgrades.values().collect();

for upgrade in upgrades {
match upgrade.upgrade_type {
UpgradeType::Fee { chain_config } => {
base_fee = std::cmp::max(chain_config.base_fee, base_fee);
}
UpgradeType::Marketplace { chain_config } => {
base_fee = std::cmp::max(chain_config.base_fee, base_fee);
}
let chain_config = upgrade.upgrade_type.chain_config();

if let Some(cf) = chain_config {
base_fee = std::cmp::max(cf.base_fee, base_fee);
}
}

Expand All @@ -103,24 +100,28 @@ impl Genesis {

// now iterate over each upgrade type and validate the fee contract if it exists
for (version, upgrade) in &self.upgrades {
match &upgrade.upgrade_type {
UpgradeType::Fee { chain_config } | UpgradeType::Marketplace { chain_config } => {
if let Some(fee_contract_address) = chain_config.fee_contract {
if fee_contract_address == H160::zero() {
anyhow::bail!("Fee contract cannot use the zero address");
} else if !is_proxy_contract(l1.provider(), fee_contract_address)
.await
.context(format!(
"checking if fee contract is a proxy in upgrade {version}",
))?
{
anyhow::bail!("Fee contract's address is not a proxy");
}
} else {
// The Fee Contract address has to be provided for an upgrade so return an error
anyhow::bail!("Fee contract's address for the upgrade is missing");
}
let chain_config = &upgrade.upgrade_type.chain_config();

if chain_config.is_none() {
continue;
}

let chain_config = chain_config.unwrap();

if let Some(fee_contract_address) = chain_config.fee_contract {
if fee_contract_address == H160::zero() {
anyhow::bail!("Fee contract cannot use the zero address");
} else if !is_proxy_contract(l1.provider(), fee_contract_address)
.await
.context(format!(
"checking if fee contract is a proxy in upgrade {version}",
))?
{
anyhow::bail!("Fee contract's address is not a proxy");
}
} else {
// The Fee Contract address has to be provided for an upgrade so return an error
anyhow::bail!("Fee contract's address for the upgrade is missing");
}
}
// TODO: it's optional for the fee contract to be included in a proxy in v1 so no need to panic but revisit this after v1 https://github.com/EspressoSystems/espresso-sequencer/pull/2000#discussion_r1765174702
Expand Down
11 changes: 6 additions & 5 deletions types/src/v0/impls/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,11 +838,12 @@ impl BlockHeader<SeqTypes> for Header {
let mut validated_state = parent_state.clone();

let chain_config = if version >= MarketplaceVersion::version() {
match instance_state.upgrades.get(&version) {
Some(upgrade) => match upgrade.upgrade_type {
UpgradeType::Marketplace { chain_config } => chain_config,
UpgradeType::Fee { chain_config } => chain_config,
},
match instance_state
.upgrades
.get(&version)
.and_then(|u| u.upgrade_type.chain_config())
{
Some(cf) => cf,
None => Header::get_chain_config(&validated_state, instance_state).await?,
}
} else {
Expand Down
1 change: 1 addition & 0 deletions types/src/v0/impls/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,7 @@ impl ValidatedState {
let cf = match upgrade.upgrade_type {
UpgradeType::Fee { chain_config } => chain_config,
UpgradeType::Marketplace { chain_config } => chain_config,
UpgradeType::Epoch { chain_config } => chain_config,
};

self.chain_config = cf.into();
Expand Down
8 changes: 5 additions & 3 deletions types/src/v0/v0_1/instance_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ use crate::{v0_99::ChainConfig, Timestamp};
pub enum UpgradeType {
Fee { chain_config: ChainConfig },
Marketplace { chain_config: ChainConfig },
Epoch { 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 {
pub fn chain_config(&self) -> Option<ChainConfig> {
match self {
UpgradeType::Fee { chain_config } => *chain_config,
UpgradeType::Marketplace { chain_config } => *chain_config,
UpgradeType::Fee { chain_config } => Some(*chain_config),
UpgradeType::Marketplace { chain_config } => Some(*chain_config),
UpgradeType::Epoch { chain_config } => Some(*chain_config),
}
}
}
Expand Down

0 comments on commit 014da42

Please sign in to comment.