Skip to content

Commit 18b96df

Browse files
authored
dynamic versioning (#1878)
* dynamic versioning * initialize versions from genesis file * add base and upgrade version serialization * fix tests * add slow prefix to test_merklized_state_api * update demo.toml * replace v0.1 w marketplace version for dev-rollup * remove Versions type requirement from node-metrics * rename ver to apiver * remove comment * make panic message clearer * remove upgrade lock from node-metrics test * message compat test for each version * lint * fix test * better aliases
1 parent 232529d commit 18b96df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1774
-638
lines changed

builder/src/bin/permissioned-builder.rs

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,25 @@ use std::{
55
use anyhow::{bail, Context};
66
use builder::permissioned::init_node;
77
use clap::Parser;
8-
use espresso_types::{eth_signature_key::EthKeyPair, parse_duration};
8+
use espresso_types::{
9+
eth_signature_key::EthKeyPair, parse_duration, FeeVersion, MarketplaceVersion,
10+
SequencerVersions, V0_1,
11+
};
912
use ethers::types::Address;
1013
use hotshot_types::{
1114
data::ViewNumber,
1215
light_client::StateSignKey,
1316
signature_key::BLSPrivKey,
14-
traits::{metrics::NoMetrics, node_implementation::ConsensusTime},
17+
traits::{
18+
metrics::NoMetrics,
19+
node_implementation::{ConsensusTime, Versions},
20+
},
1521
};
1622
use libp2p::Multiaddr;
1723
use sequencer::{persistence::no_storage::NoStorage, Genesis, L1Params, NetworkParams};
1824
use sequencer_utils::logging;
1925
use url::Url;
20-
use vbs::version::{StaticVersion, StaticVersionType};
26+
use vbs::version::StaticVersionType;
2127

2228
#[derive(Parser, Clone, Debug)]
2329
pub struct PermissionedBuilderOptions {
@@ -214,11 +220,12 @@ impl PermissionedBuilderOptions {
214220
}
215221
}
216222
}
217-
#[async_std::main]
218-
async fn main() -> anyhow::Result<()> {
219-
let opt = PermissionedBuilderOptions::parse();
220-
opt.logging.init();
221223

224+
async fn run<V: Versions>(
225+
genesis: Genesis,
226+
opt: PermissionedBuilderOptions,
227+
versions: V,
228+
) -> anyhow::Result<()> {
222229
let (private_staking_key, private_state_key) = opt.private_keys()?;
223230

224231
let l1_params = L1Params {
@@ -259,8 +266,6 @@ async fn main() -> anyhow::Result<()> {
259266
catchup_backoff: Default::default(),
260267
};
261268

262-
let sequencer_version = StaticVersion::<0, 1>::instance();
263-
264269
let builder_server_url: Url = format!("http://0.0.0.0:{}", opt.port).parse().unwrap();
265270

266271
let bootstrapped_view = ViewNumber::new(opt.view_number);
@@ -273,7 +278,7 @@ async fn main() -> anyhow::Result<()> {
273278

274279
// it will internally spawn the builder web server
275280
let ctx = init_node(
276-
Genesis::from_file(&opt.genesis_file)?,
281+
genesis,
277282
network_params,
278283
&NoMetrics,
279284
l1_params,
@@ -282,7 +287,7 @@ async fn main() -> anyhow::Result<()> {
282287
bootstrapped_view,
283288
opt.tx_channel_capacity,
284289
opt.event_channel_capacity,
285-
sequencer_version,
290+
versions,
286291
NoStorage,
287292
max_api_response_timeout_duration,
288293
buffer_view_num_count,
@@ -296,3 +301,32 @@ async fn main() -> anyhow::Result<()> {
296301

297302
Ok(())
298303
}
304+
305+
#[async_std::main]
306+
async fn main() -> anyhow::Result<()> {
307+
let opt = PermissionedBuilderOptions::parse();
308+
opt.logging.init();
309+
310+
let genesis = Genesis::from_file(&opt.genesis_file)?;
311+
tracing::info!(?genesis, "genesis");
312+
313+
let base = genesis.base_version;
314+
let upgrade = genesis.upgrade_version;
315+
316+
match (base, upgrade) {
317+
(V0_1::VERSION, FeeVersion::VERSION) => {
318+
run(genesis, opt, SequencerVersions::<V0_1, FeeVersion>::new()).await
319+
}
320+
(FeeVersion::VERSION, MarketplaceVersion::VERSION) => {
321+
run(
322+
genesis,
323+
opt,
324+
SequencerVersions::<FeeVersion, MarketplaceVersion>::new(),
325+
)
326+
.await
327+
}
328+
_ => panic!(
329+
"Invalid base ({base}) and upgrade ({upgrade}) versions specified in the toml file."
330+
),
331+
}
332+
}

builder/src/bin/permissionless-builder.rs

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@ use std::{num::NonZeroUsize, path::PathBuf, time::Duration};
22

33
use builder::non_permissioned::{build_instance_state, BuilderConfig};
44
use clap::Parser;
5-
use espresso_types::{eth_signature_key::EthKeyPair, parse_duration};
5+
use espresso_types::{
6+
eth_signature_key::EthKeyPair, parse_duration, FeeVersion, MarketplaceVersion,
7+
SequencerVersions, V0_1,
8+
};
69
use hotshot::traits::ValidatedState;
7-
use hotshot_types::{data::ViewNumber, traits::node_implementation::ConsensusTime};
10+
use hotshot_types::{
11+
data::ViewNumber,
12+
traits::node_implementation::{ConsensusTime, Versions},
13+
};
814
use sequencer::{Genesis, L1Params};
915
use sequencer_utils::logging;
1016
use url::Url;
11-
use vbs::version::{StaticVersion, StaticVersionType};
17+
use vbs::version::StaticVersionType;
1218

1319
#[derive(Parser, Clone, Debug)]
1420
struct NonPermissionedBuilderOptions {
@@ -92,7 +98,34 @@ async fn main() -> anyhow::Result<()> {
9298
opt.logging.init();
9399

94100
let genesis = Genesis::from_file(&opt.genesis_file)?;
101+
tracing::info!(?genesis, "genesis");
102+
103+
let base = genesis.base_version;
104+
let upgrade = genesis.upgrade_version;
105+
106+
match (base, upgrade) {
107+
(V0_1::VERSION, FeeVersion::VERSION) => {
108+
run(genesis, opt, SequencerVersions::<V0_1, FeeVersion>::new()).await
109+
}
110+
(FeeVersion::VERSION, MarketplaceVersion::VERSION) => {
111+
run(
112+
genesis,
113+
opt,
114+
SequencerVersions::<FeeVersion, MarketplaceVersion>::new(),
115+
)
116+
.await
117+
}
118+
_ => panic!(
119+
"Invalid base ({base}) and upgrade ({upgrade}) versions specified in the toml file."
120+
),
121+
}
122+
}
95123

124+
async fn run<V: Versions>(
125+
genesis: Genesis,
126+
opt: NonPermissionedBuilderOptions,
127+
versions: V,
128+
) -> anyhow::Result<()> {
96129
let l1_params = L1Params {
97130
url: opt.l1_provider_url,
98131
events_max_block_range: 10000,
@@ -103,13 +136,8 @@ async fn main() -> anyhow::Result<()> {
103136

104137
let builder_server_url: Url = format!("http://0.0.0.0:{}", opt.port).parse().unwrap();
105138

106-
let instance_state = build_instance_state(
107-
genesis.chain_config,
108-
l1_params,
109-
opt.state_peers,
110-
StaticVersion::<0, 1>::instance(),
111-
)
112-
.unwrap();
139+
let instance_state =
140+
build_instance_state::<V>(genesis.chain_config, l1_params, opt.state_peers).unwrap();
113141

114142
let base_fee = genesis.max_base_fee();
115143

@@ -136,6 +164,7 @@ async fn main() -> anyhow::Result<()> {
136164
buffer_view_num_count,
137165
txn_timeout_duration,
138166
base_fee,
167+
versions,
139168
)
140169
.await?;
141170

builder/src/lib.rs

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ use sequencer::{
6565
context::{Consensus, SequencerContext},
6666
network,
6767
state_signature::{static_stake_table_commitment, StakeTableCommitmentType, StateSigner},
68-
L1Params, NetworkParams, Node,
68+
L1Params, NetworkParams, Node, SequencerApiVersion,
6969
};
7070
use tide_disco::{app, method::ReadState, App, Url};
7171
use vbs::version::{StaticVersion, StaticVersionType};
@@ -98,7 +98,7 @@ pub fn run_builder_api_service(url: Url, source: ProxyGlobalState<SeqTypes>) {
9898
app.register_module("txn_submit", private_mempool_api)
9999
.expect("Failed to register the private mempool API");
100100

101-
async_spawn(app.serve(url, StaticVersion::<0, 1>::instance()));
101+
async_spawn(app.serve(url, SequencerApiVersion::instance()));
102102
}
103103

104104
#[cfg(test)]
@@ -167,13 +167,13 @@ pub mod testing {
167167
block_contents::{vid_commitment, BlockHeader, GENESIS_VID_NUM_STORAGE_NODES},
168168
metrics::NoMetrics,
169169
network::Topic,
170-
node_implementation::ConsensusTime,
170+
node_implementation::{ConsensusTime, Versions},
171171
signature_key::BuilderSignatureKey as _,
172172
},
173173
ExecutionType, HotShotConfig, PeerConfig, ValidatorConfig,
174174
};
175175
use portpicker::pick_unused_port;
176-
use sequencer::{state_signature::StateSignatureMemStorage, testing::TestConfig};
176+
use sequencer::{state_signature::StateSignatureMemStorage, SequencerApiVersion};
177177
use serde::{Deserialize, Serialize};
178178
use surf_disco::Client;
179179
use vbs::version::StaticVersion;
@@ -345,11 +345,14 @@ pub mod testing {
345345
}
346346
}
347347

348-
pub async fn init_nodes<P: SequencerPersistence, Ver: StaticVersionType + 'static>(
348+
pub async fn init_nodes<P: SequencerPersistence, V: Versions>(
349349
&self,
350-
bind_version: Ver,
350+
bind_version: V,
351351
options: impl PersistenceOptions<Persistence = P>,
352-
) -> Vec<(Arc<Consensus<network::Memory, P>>, Option<StateSigner<Ver>>)> {
352+
) -> Vec<(
353+
Arc<Consensus<network::Memory, P, V>>,
354+
Option<StateSigner<SequencerApiVersion>>,
355+
)> {
353356
let num_staked_nodes = self.num_staked_nodes();
354357
let mut is_staked = false;
355358
let stake_table_commit = static_stake_table_commitment(
@@ -379,15 +382,18 @@ pub mod testing {
379382
.await
380383
}
381384

382-
pub async fn init_node<P: SequencerPersistence, Ver: StaticVersionType + 'static>(
385+
pub async fn init_node<P: SequencerPersistence, V: Versions>(
383386
&self,
384387
i: usize,
385388
is_staked: bool,
386389
stake_table_commit: StakeTableCommitmentType,
387390
metrics: &dyn Metrics,
388-
bind_version: Ver,
391+
bind_version: V,
389392
persistence: P,
390-
) -> (Consensus<network::Memory, P>, StateSigner<Ver>) {
393+
) -> (
394+
Consensus<network::Memory, P, V>,
395+
StateSigner<SequencerApiVersion>,
396+
) {
391397
let mut config = self.config.clone();
392398

393399
let num_staked_nodes = self.num_staked_nodes();
@@ -410,8 +416,8 @@ pub mod testing {
410416
ChainConfig::default(),
411417
L1Client::new(self.anvil.endpoint().parse().unwrap(), 1),
412418
MockStateCatchup::default(),
419+
V::Base::VERSION,
413420
)
414-
.with_current_version(Ver::VERSION)
415421
.with_genesis(ValidatedState::default());
416422

417423
tracing::info!("Before init hotshot");
@@ -463,14 +469,14 @@ pub mod testing {
463469
app.register_module("hotshot-events", hotshot_events_api)
464470
.expect("Failed to register hotshot events API");
465471

466-
async_spawn(app.serve(url, StaticVersion::<0, 1>::instance()));
472+
async_spawn(app.serve(url, SequencerApiVersion::instance()));
467473
}
468474
// enable hotshot event streaming
469-
pub fn enable_hotshot_node_event_streaming<P: SequencerPersistence>(
475+
pub fn enable_hotshot_node_event_streaming<P: SequencerPersistence, V: Versions>(
470476
hotshot_events_api_url: Url,
471477
known_nodes_with_stake: Vec<PeerConfig<VerKey>>,
472478
num_non_staking_nodes: usize,
473-
hotshot_context_handle: Arc<Consensus<network::Memory, P>>,
479+
hotshot_context_handle: Arc<Consensus<network::Memory, P, V>>,
474480
) {
475481
// create a event streamer
476482
let events_streamer = Arc::new(RwLock::new(EventsStreamer::new(
@@ -538,10 +544,11 @@ pub mod testing {
538544
impl NonPermissionedBuilderTestConfig {
539545
pub const SUBSCRIBED_DA_NODE_ID: usize = 5;
540546

541-
pub async fn init_non_permissioned_builder(
547+
pub async fn init_non_permissioned_builder<V: Versions>(
542548
hotshot_events_streaming_api_url: Url,
543549
hotshot_builder_api_url: Url,
544550
num_nodes: usize,
551+
versions: V,
545552
) -> Self {
546553
// generate builder keys
547554
let seed = [201_u8; 32];
@@ -562,14 +569,15 @@ pub mod testing {
562569
tx_channel_capacity,
563570
event_channel_capacity,
564571
node_count,
565-
NodeState::default(),
572+
NodeState::default().with_current_version(V::Base::VERSION),
566573
ValidatedState::default(),
567574
hotshot_events_streaming_api_url,
568575
hotshot_builder_api_url,
569576
Duration::from_millis(2000),
570577
15,
571578
Duration::from_millis(500),
572579
ChainConfig::default().base_fee,
580+
versions,
573581
)
574582
.await
575583
.unwrap();
@@ -581,25 +589,20 @@ pub mod testing {
581589
}
582590
}
583591

584-
pub struct PermissionedBuilderTestConfig<
585-
P: SequencerPersistence,
586-
Ver: StaticVersionType + 'static,
587-
> {
588-
pub builder_context: BuilderContext<network::Memory, P, Ver>,
592+
pub struct PermissionedBuilderTestConfig<P: SequencerPersistence, V: Versions> {
593+
pub builder_context: BuilderContext<network::Memory, P, V>,
589594
pub fee_account: FeeAccount,
590595
}
591596

592-
impl<P: SequencerPersistence, Ver: StaticVersionType + 'static>
593-
PermissionedBuilderTestConfig<P, Ver>
594-
{
597+
impl<P: SequencerPersistence, V: Versions> PermissionedBuilderTestConfig<P, V> {
595598
pub async fn init_permissioned_builder(
596-
hotshot_handle: Arc<Consensus<network::Memory, P>>,
599+
hotshot_handle: Arc<Consensus<network::Memory, P, V>>,
597600
node_id: u64,
598-
state_signer: Arc<StateSigner<Ver>>,
601+
state_signer: Arc<StateSigner<SequencerApiVersion>>,
599602
hotshot_builder_api_url: Url,
600603
) -> Self {
601604
// setup the instance state
602-
let node_state = NodeState::default();
605+
let node_state = NodeState::default().with_current_version(V::Base::VERSION);
603606

604607
// generate builder keys
605608
let seed = [201_u8; 32];
@@ -784,7 +787,7 @@ pub mod testing {
784787
mod test {
785788
use async_std::stream::IntoStream;
786789
use clap::builder;
787-
use espresso_types::{Header, NodeState, Payload, ValidatedState};
790+
use espresso_types::{Header, MockSequencerVersions, NodeState, Payload, ValidatedState};
788791
use ethers::providers::Quorum;
789792
use futures::StreamExt;
790793
use hotshot::types::EventType::Decide;
@@ -811,13 +814,13 @@ mod test {
811814
async fn test_non_voting_hotshot_node() {
812815
setup_test();
813816

814-
let ver = StaticVersion::<0, 1>::instance();
815-
816817
let success_height = 5;
817818
// Assign `config` so it isn't dropped early.
818819
let config = HotShotTestConfig::default();
819820
tracing::debug!("Done with hotshot test config");
820-
let handles = config.init_nodes(ver, no_storage::Options).await;
821+
let handles = config
822+
.init_nodes(MockSequencerVersions::new(), no_storage::Options)
823+
.await;
821824
tracing::debug!("Done with init nodes");
822825
let total_nodes = HotShotTestConfig::total_nodes();
823826

0 commit comments

Comments
 (0)