From f1be76370075bf46a89946db4d7c725745bfb6ad Mon Sep 17 00:00:00 2001 From: tbro Date: Fri, 12 Jul 2024 18:48:38 +0300 Subject: [PATCH] fixes for chain_config v3 * move NodeState and ValidatedState to `impl` * wrap `bid_reciepient` in an `Option` * Implement from `v0_1::ResolvableChainConfig` for `v0_3::ResolvableChainConfig` --- types/src/v0/impls/auction.rs | 18 +++++- .../v0/impls/block/full_payload/payload.rs | 7 ++- types/src/v0/impls/chain_config.rs | 18 +----- types/src/v0/impls/header.rs | 20 ++++--- types/src/v0/impls/instance_state.rs | 39 ++++++++++++- types/src/v0/impls/mod.rs | 4 +- types/src/v0/impls/state.rs | 30 +++++++--- types/src/v0/mod.rs | 8 +-- types/src/v0/traits.rs | 6 +- types/src/v0/v0_1/chain_config.rs | 12 ++++ types/src/v0/v0_1/instance_state.rs | 40 +------------ types/src/v0/v0_1/state.rs | 18 +----- types/src/v0/v0_2/mod.rs | 13 ++--- types/src/v0/v0_3/chain_config.rs | 57 ++++++++++++++++--- types/src/v0/v0_3/mod.rs | 10 ++-- 15 files changed, 177 insertions(+), 123 deletions(-) diff --git a/types/src/v0/impls/auction.rs b/types/src/v0/impls/auction.rs index b14ccb7d99..a251914965 100644 --- a/types/src/v0/impls/auction.rs +++ b/types/src/v0/impls/auction.rs @@ -1,7 +1,7 @@ use crate::{ eth_signature_key::{EthKeyPair, SigningError}, v0_3::{BidTx, BidTxBody, FullNetworkTx}, - FeeAccount, FeeAmount, FeeError, FeeInfo, NamespaceId, ValidatedState, + FeeAccount, FeeAmount, FeeError, FeeInfo, NamespaceId, }; use committable::{Commitment, Committable}; use ethers::types::Signature; @@ -16,6 +16,8 @@ use std::str::FromStr; use thiserror::Error; use url::Url; +use super::state::ValidatedState; + impl FullNetworkTx { pub fn execute( &self, @@ -176,7 +178,12 @@ impl BidTx { let recipient = chain_config.bid_recipient; // Charge the bid amount state - .charge_fee(FeeInfo::new(self.account(), self.amount()), recipient) + .charge_fee( + FeeInfo::new(self.account(), self.amount()), + // TODO This code is only called from v0_3, so should be safe to unwrap, + // but maybe we should guard against the error anyway + recipient.unwrap(), + ) .map_err(ExecutionError::from)?; // TODO are gas and bid funded to same recipient? Possibly @@ -184,7 +191,12 @@ impl BidTx { // fee recipient? // Charge the the gas amount state - .charge_fee(FeeInfo::new(self.account(), self.gas_price()), recipient) + .charge_fee( + FeeInfo::new(self.account(), self.gas_price()), + // TODO This code is only called from v0_3, so should be safe to unwrap, + // but maybe we should guard against the error anyway + recipient.unwrap(), + ) .map_err(ExecutionError::from)?; Ok(()) diff --git a/types/src/v0/impls/block/full_payload/payload.rs b/types/src/v0/impls/block/full_payload/payload.rs index 4785a0b36b..f0678b3e58 100644 --- a/types/src/v0/impls/block/full_payload/payload.rs +++ b/types/src/v0/impls/block/full_payload/payload.rs @@ -12,9 +12,10 @@ use jf_vid::VidScheme; use sha2::Digest; use crate::{ - ChainConfig, Index, Iter, NamespaceId, NodeState, NsIndex, NsPayload, NsPayloadBuilder, - NsPayloadRange, NsTable, NsTableBuilder, Payload, PayloadByteLen, SeqTypes, Transaction, - TxProof, ValidatedState, + v0::impls::{instance_state::NodeState, state::ValidatedState}, + v0_3::ChainConfig, + Index, Iter, NamespaceId, NsIndex, NsPayload, NsPayloadBuilder, NsPayloadRange, NsTable, + NsTableBuilder, Payload, PayloadByteLen, SeqTypes, Transaction, TxProof, }; impl Payload { diff --git a/types/src/v0/impls/chain_config.rs b/types/src/v0/impls/chain_config.rs index 0b01c1170f..0fe7e4d3b7 100644 --- a/types/src/v0/impls/chain_config.rs +++ b/types/src/v0/impls/chain_config.rs @@ -1,5 +1,4 @@ use std::str::FromStr; - use bytesize::ByteSize; use committable::Commitment; use derive_more::From; @@ -10,7 +9,7 @@ use sequencer_utils::{ }; use snafu::Snafu; -use crate::{BlockSize, ChainConfig, ChainId, ResolvableChainConfig}; +use crate::{BlockSize, ChainId}; impl_serde_from_string_or_integer!(ChainId); impl_to_fixed_bytes!(ChainId, U256); @@ -77,19 +76,6 @@ impl FromStringOrInteger for BlockSize { } } -impl Default for ChainConfig { - fn default() -> Self { - Self { - chain_id: U256::from(35353).into(), // arbitrarily chosen chain ID - max_block_size: 10240.into(), - base_fee: 0.into(), - fee_contract: None, - fee_recipient: Default::default(), - bid_recipient: Default::default(), - } - } -} - #[derive(Clone, Debug, From, Snafu)] pub struct ParseSizeError { msg: String, @@ -101,6 +87,8 @@ pub fn parse_size(s: &str) -> Result { #[cfg(test)] mod tests { + use crate::v0_3::{ChainConfig, ResolvableChainConfig}; + use super::*; #[test] diff --git a/types/src/v0/impls/header.rs b/types/src/v0/impls/header.rs index c76e94ee67..3a502e8545 100644 --- a/types/src/v0/impls/header.rs +++ b/types/src/v0/impls/header.rs @@ -28,12 +28,14 @@ use vbs::version::Version; use crate::{ v0::header::{EitherOrVersion, VersionedHeader}, v0_1, v0_2, - v0_3::{self, FullNetworkTx, IterableFeeInfo}, - BlockMerkleCommitment, BlockSize, BuilderSignature, ChainConfig, FeeAccount, FeeAmount, - FeeInfo, FeeMerkleCommitment, Header, L1BlockInfo, L1Snapshot, Leaf, NamespaceId, NodeState, - NsTable, NsTableValidationError, ResolvableChainConfig, SeqTypes, UpgradeType, ValidatedState, + v0_3::{self, ChainConfig, FullNetworkTx, IterableFeeInfo, ResolvableChainConfig}, + BlockMerkleCommitment, BlockSize, BuilderSignature, FeeAccount, FeeAmount, FeeInfo, + FeeMerkleCommitment, Header, L1BlockInfo, L1Snapshot, Leaf, NamespaceId, NsTable, + NsTableValidationError, SeqTypes, UpgradeType, }; +use super::{instance_state::NodeState, state::ValidatedState}; + /// Possible proposal validation failures #[derive(Error, Debug, Eq, PartialEq)] pub enum ProposalValidationError { @@ -542,8 +544,12 @@ impl Header { impl Header { /// A commitment to a ChainConfig or a full ChainConfig. - pub fn chain_config(&self) -> &ResolvableChainConfig { - field!(self.chain_config) + pub fn chain_config(&self) -> v0_3::ResolvableChainConfig { + match self { + Self::V1(fields) => v0_3::ResolvableChainConfig::from(&fields.chain_config), + Self::V2(fields) => v0_3::ResolvableChainConfig::from(&fields.chain_config), + Self::V3(fields) => fields.chain_config, + } } pub fn height(&self) -> u64 { @@ -958,7 +964,7 @@ mod test_headers { use super::*; use crate::{ eth_signature_key::EthKeyPair, v0::impls::instance_state::mock::MockStateCatchup, - validate_proposal, NodeState, + validate_proposal, }; #[derive(Debug, Default)] diff --git a/types/src/v0/impls/instance_state.rs b/types/src/v0/impls/instance_state.rs index c47abcda14..93a952a64a 100644 --- a/types/src/v0/impls/instance_state.rs +++ b/types/src/v0/impls/instance_state.rs @@ -1,12 +1,45 @@ -use std::{collections::BTreeMap, sync::Arc}; - use hotshot_types::traits::{node_implementation::NodeType, states::InstanceState}; +use std::{collections::BTreeMap, sync::Arc}; use vbs::version::{StaticVersionType, Version}; use crate::{ - v0::traits::StateCatchup, ChainConfig, L1Client, NodeState, SeqTypes, Upgrade, ValidatedState, + v0::traits::StateCatchup, v0_3::ChainConfig, GenesisHeader, L1BlockInfo, L1Client, SeqTypes, + Upgrade, }; +use super::state::ValidatedState; + +/// Represents the immutable state of a node. +/// +/// For mutable state, use `ValidatedState`. +#[derive(Debug, Clone)] +pub struct NodeState { + pub node_id: u64, + pub chain_config: crate::v0_3::ChainConfig, + pub l1_client: L1Client, + pub peers: Arc, + pub genesis_header: GenesisHeader, + pub genesis_state: ValidatedState, + pub l1_genesis: Option, + + /// Map containing all planned and executed upgrades. + /// + /// Currently, only one upgrade can be executed at a time. + /// For multiple upgrades, the node needs to be restarted after each upgrade. + /// + /// This field serves as a record for planned and past upgrades, + /// listed in the genesis TOML file. It will be very useful if multiple upgrades + /// are supported in the future. + pub upgrades: BTreeMap, + /// Current version of the sequencer. + /// + /// This version is checked to determine if an upgrade is planned, + /// and which version variant for versioned types + /// to use in functions such as genesis. + /// (example: genesis returns V2 Header if version is 0.2) + pub current_version: Version, +} + impl NodeState { pub fn new( node_id: u64, diff --git a/types/src/v0/impls/mod.rs b/types/src/v0/impls/mod.rs index 91aad85957..8946357aea 100644 --- a/types/src/v0/impls/mod.rs +++ b/types/src/v0/impls/mod.rs @@ -12,5 +12,5 @@ mod transaction; pub use fee_info::FeeError; pub use header::ProposalValidationError; -pub use instance_state::mock; -pub use state::{validate_proposal, BuilderValidationError, StateValidationError}; +pub use instance_state::{mock, NodeState}; +pub use state::{validate_proposal, BuilderValidationError, StateValidationError, ValidatedState}; diff --git a/types/src/v0/impls/state.rs b/types/src/v0/impls/state.rs index aba7b07d94..36e16f4241 100644 --- a/types/src/v0/impls/state.rs +++ b/types/src/v0/impls/state.rs @@ -1,5 +1,3 @@ -use std::ops::Add; - use anyhow::bail; use committable::Committable; use ethers::types::Address; @@ -21,15 +19,20 @@ use jf_merkle_tree::{ }; use jf_vid::VidScheme; use num_traits::CheckedSub; +use serde::{Deserialize, Serialize}; +use std::ops::Add; use thiserror::Error; use vbs::version::Version; -use super::{auction::ExecutionError, fee_info::FeeError, header::ProposalValidationError}; +use super::{ + auction::ExecutionError, fee_info::FeeError, header::ProposalValidationError, + instance_state::NodeState, +}; use crate::{ - v0_3::{FullNetworkTx, IterableFeeInfo}, - BlockMerkleTree, ChainConfig, Delta, FeeAccount, FeeAmount, FeeInfo, FeeMerkleTree, Header, - Leaf, NodeState, NsTableValidationError, PayloadByteLen, ResolvableChainConfig, SeqTypes, - UpgradeType, ValidatedState, BLOCK_MERKLE_TREE_HEIGHT, FEE_MERKLE_TREE_HEIGHT, + v0_3::{ChainConfig, FullNetworkTx, IterableFeeInfo, ResolvableChainConfig}, + BlockMerkleTree, Delta, FeeAccount, FeeAmount, FeeInfo, FeeMerkleTree, Header, Leaf, + NsTableValidationError, PayloadByteLen, SeqTypes, UpgradeType, BLOCK_MERKLE_TREE_HEIGHT, + FEE_MERKLE_TREE_HEIGHT, }; /// Possible builder validation failures @@ -54,6 +57,15 @@ pub enum StateValidationError { impl StateDelta for Delta {} +#[derive(Hash, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] +pub struct ValidatedState { + /// Frontier of Block Merkle Tree + pub block_merkle_tree: BlockMerkleTree, + /// Fee Merkle Tree + pub fee_merkle_tree: FeeMerkleTree, + pub chain_config: ResolvableChainConfig, +} + impl Default for ValidatedState { fn default() -> Self { let block_merkle_tree = @@ -337,7 +349,7 @@ impl ValidatedState { validated_state.apply_upgrade(instance, version); let chain_config = validated_state - .get_chain_config(instance, proposed_header.chain_config()) + .get_chain_config(instance, &proposed_header.chain_config()) .await?; if Some(chain_config) != validated_state.chain_config.resolve() { @@ -627,7 +639,7 @@ impl HotShotState for ValidatedState { Self { fee_merkle_tree, block_merkle_tree, - chain_config: *block_header.chain_config(), + chain_config: block_header.chain_config(), } } /// Construct a genesis validated state. diff --git a/types/src/v0/mod.rs b/types/src/v0/mod.rs index bd9bb77473..45de3c9a98 100644 --- a/types/src/v0/mod.rs +++ b/types/src/v0/mod.rs @@ -20,6 +20,8 @@ pub use impls::{ pub use utils::*; use vbs::version::StaticVersion; +// TODO can we expand this documentation to include not only what this code does but why we need it? + // This is the single source of truth for minor versions supported by this major version. // // It is written as a higher-level macro which takes a macro invocation as an argument and appends @@ -69,7 +71,6 @@ reexport_unchanged_types!( BlockMerkleCommitment, BlockMerkleTree, BuilderSignature, - ChainConfig, ChainId, Delta, FeeAccount, @@ -85,7 +86,6 @@ reexport_unchanged_types!( L1Client, L1Snapshot, NamespaceId, - NodeState, NsIndex, NsIter, NsPayload, @@ -103,7 +103,6 @@ reexport_unchanged_types!( NumTxsUnchecked, Payload, PayloadByteLen, - ResolvableChainConfig, Transaction, TxIndex, TxIter, @@ -114,7 +113,6 @@ reexport_unchanged_types!( TxTableEntriesRange, Upgrade, UpgradeType, - ValidatedState, BlockSize, ); @@ -134,6 +132,7 @@ impl NodeType for SeqTypes { type Membership = GeneralStaticCommittee; type BuilderSignatureKey = FeeAccount; type Base = StaticVersion<0, 1>; + // TODO we could have comments describing the role of these types in upgrades/versioning type Upgrade = StaticVersion<0, 2>; const UPGRADE_HASH: [u8; 32] = [ 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, @@ -148,6 +147,7 @@ pub type PrivKey = ::PrivateKey; pub type NetworkConfig = hotshot_orchestrator::config::NetworkConfig; +use self::impls::{NodeState, ValidatedState}; pub use crate::v0_1::{ BLOCK_MERKLE_TREE_HEIGHT, FEE_MERKLE_TREE_HEIGHT, NS_ID_BYTE_LEN, NS_OFFSET_BYTE_LEN, NUM_NSS_BYTE_LEN, NUM_TXS_BYTE_LEN, TX_OFFSET_BYTE_LEN, diff --git a/types/src/v0/traits.rs b/types/src/v0/traits.rs index ee976453ad..de07e77c01 100644 --- a/types/src/v0/traits.rs +++ b/types/src/v0/traits.rs @@ -22,10 +22,12 @@ use hotshot_types::{ use serde::{de::DeserializeOwned, Serialize}; use crate::{ - AccountQueryData, BackoffParams, BlockMerkleTree, ChainConfig, Event, FeeAccount, - FeeMerkleCommitment, Leaf, NetworkConfig, NodeState, SeqTypes, ValidatedState, + v0::impls::ValidatedState, v0_3::ChainConfig, AccountQueryData, BackoffParams, BlockMerkleTree, + Event, FeeAccount, FeeMerkleCommitment, Leaf, NetworkConfig, SeqTypes, }; +use super::impls::NodeState; + #[async_trait] pub trait StateCatchup: Send + Sync + std::fmt::Debug { /// Try to fetch the given account state, failing without retrying if unable. diff --git a/types/src/v0/v0_1/chain_config.rs b/types/src/v0/v0_1/chain_config.rs index 69cd82800b..1ad7b68bd3 100644 --- a/types/src/v0/v0_1/chain_config.rs +++ b/types/src/v0/v0_1/chain_config.rs @@ -97,3 +97,15 @@ impl From for ResolvableChainConfig { } } } + +impl Default for ChainConfig { + fn default() -> Self { + Self { + chain_id: U256::from(35353).into(), // arbitrarily chosen chain ID + max_block_size: 10240.into(), + base_fee: 0.into(), + fee_contract: None, + fee_recipient: Default::default(), + } + } +} diff --git a/types/src/v0/v0_1/instance_state.rs b/types/src/v0/v0_1/instance_state.rs index 82f75ba4a7..7ab1d1d608 100644 --- a/types/src/v0/v0_1/instance_state.rs +++ b/types/src/v0/v0_1/instance_state.rs @@ -1,14 +1,7 @@ -use std::collections::BTreeMap; - -use std::sync::Arc; - use serde::{Deserialize, Serialize}; use std::fmt::Debug; -use crate::{v0::traits::StateCatchup, ChainConfig, GenesisHeader, L1BlockInfo, ValidatedState}; -use vbs::version::Version; - -use super::l1::L1Client; +use crate::{v0::traits::StateCatchup, v0_3::ChainConfig, GenesisHeader, L1BlockInfo}; /// Represents the specific type of upgrade. #[derive(Clone, Debug, Deserialize, Serialize)] @@ -43,34 +36,3 @@ pub struct Upgrade { #[serde(flatten)] pub upgrade_type: UpgradeType, } - -/// Represents the immutable state of a node. -/// -/// For mutable state, use `ValidatedState`. -#[derive(Debug, Clone)] -pub struct NodeState { - pub node_id: u64, - pub chain_config: ChainConfig, - pub l1_client: L1Client, - pub peers: Arc, - pub genesis_header: GenesisHeader, - pub genesis_state: ValidatedState, - pub l1_genesis: Option, - - /// Map containing all planned and executed upgrades. - /// - /// Currently, only one upgrade can be executed at a time. - /// For multiple upgrades, the node needs to be restarted after each upgrade. - /// - /// This field serves as a record for planned and past upgrades, - /// listed in the genesis TOML file. It will be very useful if multiple upgrades - /// are supported in the future. - pub upgrades: BTreeMap, - /// Current version of the sequencer. - /// - /// This version is checked to determine if an upgrade is planned, - /// and which version variant for versioned types - /// to use in functions such as genesis. - /// (example: genesis returns V2 Header if version is 0.2) - pub current_version: Version, -} diff --git a/types/src/v0/v0_1/state.rs b/types/src/v0/v0_1/state.rs index 9e2df8089c..3a2ba8ad0a 100644 --- a/types/src/v0/v0_1/state.rs +++ b/types/src/v0/v0_1/state.rs @@ -1,13 +1,12 @@ -use crate::ResolvableChainConfig; - use super::{FeeAccount, FeeAmount}; - +use core::fmt::Debug; use jf_merkle_tree::{ prelude::{LightWeightSHA3MerkleTree, Sha3Digest, Sha3Node}, universal_merkle_tree::UniversalMerkleTree, MerkleTreeScheme, }; use serde::{Deserialize, Serialize}; +use std::collections::HashSet; // The block merkle tree accumulates header commitments. However, since the underlying // representation of the commitment type remains the same even while the header itself changes, @@ -18,22 +17,9 @@ pub type BlockMerkleCommitment = ::Commitme pub type FeeMerkleTree = UniversalMerkleTree; pub type FeeMerkleCommitment = ::Commitment; -use core::fmt::Debug; - -use std::collections::HashSet; - pub const BLOCK_MERKLE_TREE_HEIGHT: usize = 32; pub const FEE_MERKLE_TREE_HEIGHT: usize = 20; -#[derive(Hash, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] -pub struct ValidatedState { - /// Frontier of Block Merkle Tree - pub block_merkle_tree: BlockMerkleTree, - /// Fee Merkle Tree - pub fee_merkle_tree: FeeMerkleTree, - pub chain_config: ResolvableChainConfig, -} - #[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq, Eq)] pub struct Delta { pub fees_delta: HashSet, diff --git a/types/src/v0/v0_2/mod.rs b/types/src/v0/v0_2/mod.rs index 9e745f21ff..55e0e76e12 100644 --- a/types/src/v0/v0_2/mod.rs +++ b/types/src/v0/v0_2/mod.rs @@ -5,13 +5,12 @@ pub use super::v0_1::{ AccountQueryData, BlockMerkleCommitment, BlockMerkleTree, BlockSize, BuilderSignature, ChainConfig, ChainId, Delta, FeeAccount, FeeAccountProof, FeeAmount, FeeInfo, FeeMerkleCommitment, FeeMerkleProof, FeeMerkleTree, Header, Index, Iter, L1BlockInfo, L1Client, - L1Snapshot, NamespaceId, NodeState, NsIndex, NsIter, NsPayload, NsPayloadBuilder, - NsPayloadByteLen, NsPayloadOwned, NsPayloadRange, NsProof, NsTable, NsTableBuilder, - NsTableValidationError, NumNss, NumTxs, NumTxsRange, NumTxsUnchecked, Payload, PayloadByteLen, - ResolvableChainConfig, Transaction, TxIndex, TxIter, TxPayload, TxPayloadRange, TxProof, - TxTableEntries, TxTableEntriesRange, Upgrade, UpgradeType, ValidatedState, - BLOCK_MERKLE_TREE_HEIGHT, FEE_MERKLE_TREE_HEIGHT, NS_ID_BYTE_LEN, NS_OFFSET_BYTE_LEN, - NUM_NSS_BYTE_LEN, NUM_TXS_BYTE_LEN, TX_OFFSET_BYTE_LEN, + L1Snapshot, NamespaceId, NsIndex, NsIter, NsPayload, NsPayloadBuilder, NsPayloadByteLen, + NsPayloadOwned, NsPayloadRange, NsProof, NsTable, NsTableBuilder, NsTableValidationError, + NumNss, NumTxs, NumTxsRange, NumTxsUnchecked, Payload, PayloadByteLen, ResolvableChainConfig, + Transaction, TxIndex, TxIter, TxPayload, TxPayloadRange, TxProof, TxTableEntries, + TxTableEntriesRange, Upgrade, UpgradeType, BLOCK_MERKLE_TREE_HEIGHT, FEE_MERKLE_TREE_HEIGHT, + NS_ID_BYTE_LEN, NS_OFFSET_BYTE_LEN, NUM_NSS_BYTE_LEN, NUM_TXS_BYTE_LEN, TX_OFFSET_BYTE_LEN, }; pub const VERSION: Version = Version { major: 0, minor: 2 }; diff --git a/types/src/v0/v0_3/chain_config.rs b/types/src/v0/v0_3/chain_config.rs index 18ac1bf989..7da37ce26d 100644 --- a/types/src/v0/v0_3/chain_config.rs +++ b/types/src/v0/v0_3/chain_config.rs @@ -1,6 +1,8 @@ +use std::str::FromStr; + use crate::{v0_1, BlockSize, ChainId, FeeAccount, FeeAmount}; use committable::{Commitment, Committable}; -use ethers::types::Address; +use ethers::types::{Address, U256}; use itertools::Either; use serde::{Deserialize, Serialize}; @@ -31,7 +33,7 @@ pub struct ChainConfig { pub fee_recipient: FeeAccount, /// Account that receives sequencing bids. - pub bid_recipient: FeeAccount, + pub bid_recipient: Option, } #[derive(Clone, Debug, Copy, PartialEq, Deserialize, Serialize, Eq, Hash)] @@ -91,15 +93,41 @@ impl From for ResolvableChainConfig { } } -impl From for v0_1::ResolvableChainConfig { +impl From<&v0_1::ResolvableChainConfig> for ResolvableChainConfig { fn from( - ResolvableChainConfig { chain_config }: ResolvableChainConfig, - ) -> v0_1::ResolvableChainConfig { + &v0_1::ResolvableChainConfig { chain_config }: &v0_1::ResolvableChainConfig, + ) -> ResolvableChainConfig { match chain_config { - Either::Left(chain_config) => v0_1::ResolvableChainConfig { - chain_config: Either::Left(v0_1::ChainConfig::from(chain_config)), + Either::Left(chain_config) => ResolvableChainConfig { + chain_config: Either::Left(ChainConfig::from(chain_config)), + }, + // TODO * review how `None` is handled in (de)serialization + // * is there a better way to pack an old commitment in a new one? + Either::Right(c) => ResolvableChainConfig { + chain_config: Either::Right(Commitment::from_str(&c.to_string()).unwrap()), }, - Either::Right(_) => unimplemented!(), + } + } +} + +impl From for ChainConfig { + fn from(chain_config: v0_1::ChainConfig) -> ChainConfig { + let v0_1::ChainConfig { + chain_id, + max_block_size, + base_fee, + fee_contract, + fee_recipient, + .. + } = chain_config; + + ChainConfig { + chain_id, + max_block_size, + base_fee, + fee_contract, + fee_recipient, + bid_recipient: None, } } } @@ -124,3 +152,16 @@ impl From for v0_1::ChainConfig { } } } + +impl Default for ChainConfig { + fn default() -> Self { + Self { + chain_id: U256::from(35353).into(), // arbitrarily chosen chain ID + max_block_size: 10240.into(), + base_fee: 0.into(), + fee_contract: None, + fee_recipient: Default::default(), + bid_recipient: Default::default(), + } + } +} diff --git a/types/src/v0/v0_3/mod.rs b/types/src/v0/v0_3/mod.rs index 685f6513e2..0d9548597b 100644 --- a/types/src/v0/v0_3/mod.rs +++ b/types/src/v0/v0_3/mod.rs @@ -4,13 +4,13 @@ use vbs::version::Version; pub use super::v0_1::{ AccountQueryData, BlockMerkleCommitment, BlockMerkleTree, BlockSize, BuilderSignature, ChainId, Delta, FeeAccount, FeeAccountProof, FeeAmount, FeeInfo, FeeMerkleCommitment, FeeMerkleProof, - FeeMerkleTree, Index, Iter, L1BlockInfo, L1Client, L1Snapshot, NamespaceId, NodeState, NsIndex, - NsIter, NsPayload, NsPayloadBuilder, NsPayloadByteLen, NsPayloadOwned, NsPayloadRange, NsProof, + FeeMerkleTree, Index, Iter, L1BlockInfo, L1Client, L1Snapshot, NamespaceId, NsIndex, NsIter, + NsPayload, NsPayloadBuilder, NsPayloadByteLen, NsPayloadOwned, NsPayloadRange, NsProof, NsTable, NsTableBuilder, NsTableValidationError, NumNss, NumTxs, NumTxsRange, NumTxsUnchecked, Payload, PayloadByteLen, Transaction, TxIndex, TxIter, TxPayload, TxPayloadRange, TxProof, - TxTableEntries, TxTableEntriesRange, Upgrade, UpgradeType, ValidatedState, - BLOCK_MERKLE_TREE_HEIGHT, FEE_MERKLE_TREE_HEIGHT, NS_ID_BYTE_LEN, NS_OFFSET_BYTE_LEN, - NUM_NSS_BYTE_LEN, NUM_TXS_BYTE_LEN, TX_OFFSET_BYTE_LEN, + TxTableEntries, TxTableEntriesRange, Upgrade, UpgradeType, BLOCK_MERKLE_TREE_HEIGHT, + FEE_MERKLE_TREE_HEIGHT, NS_ID_BYTE_LEN, NS_OFFSET_BYTE_LEN, NUM_NSS_BYTE_LEN, NUM_TXS_BYTE_LEN, + TX_OFFSET_BYTE_LEN, }; pub const VERSION: Version = Version { major: 0, minor: 3 };