Skip to content

Commit

Permalink
Fee Upgrade (#1530)
Browse files Browse the repository at this point in the history
This PR 
- adds a resolvable chain config to ValidatedState which is updated on
every state update.
- catchup  to fetch updated chain config from the peers
- adds upgrade (array of tables) to genesis toml file
- tests for chain config catchup and upgrade.
  • Loading branch information
jbearer authored Jun 17, 2024
2 parents 1951d7a + 57e9cfb commit eec70e4
Show file tree
Hide file tree
Showing 37 changed files with 1,673 additions and 489 deletions.
719 changes: 460 additions & 259 deletions Cargo.lock

Large diffs are not rendered by default.

25 changes: 13 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,29 @@ dotenvy = "0.15"
ethers = { version = "2.0", features = ["solc"] }
futures = "0.3"

hotshot = { git = "https://github.com/EspressoSystems/hotshot", tag = "rc-0.5.57" }
hotshot = { git = "https://github.com/EspressoSystems/hotshot", tag = "rc-0.5.58" }
# Hotshot imports
hotshot-builder-api = { git = "https://github.com/EspressoSystems/HotShot.git", tag = "rc-0.5.57" }
hotshot-builder-core = { git = "https://github.com/EspressoSystems/hotshot-builder-core", tag = "0.1.27" }
hotshot-events-service = { git = "https://github.com/EspressoSystems/hotshot-events-service.git", tag = "0.1.27" }
hotshot-orchestrator = { git = "https://github.com/EspressoSystems/hotshot", tag = "rc-0.5.57" }
hotshot-query-service = { git = "https://github.com/EspressoSystems/hotshot-query-service", tag = "0.1.39" }
hotshot-stake-table = { git = "https://github.com/EspressoSystems/hotshot", tag = "rc-0.5.57" }
hotshot-builder-api = { git = "https://github.com/EspressoSystems/HotShot.git", tag = "rc-0.5.58" }
hotshot-builder-core = { git = "https://github.com/EspressoSystems/hotshot-builder-core", tag = "rc-0.1.28" }
hotshot-events-service = { git = "https://github.com/EspressoSystems/hotshot-events-service.git", tag = "rc-0.1.28" }
hotshot-orchestrator = { git = "https://github.com/EspressoSystems/hotshot", tag = "rc-0.5.58" }
hotshot-query-service = { git = "https://github.com/EspressoSystems/hotshot-query-service", tag = "rc-0.1.40" }
hotshot-stake-table = { git = "https://github.com/EspressoSystems/hotshot", tag = "rc-0.5.58" }
hotshot-state-prover = { version = "0.1.0", path = "hotshot-state-prover" }
hotshot-task = { git = "https://github.com/EspressoSystems/hotshot", tag = "rc-0.5.57" }
hotshot-testing = { git = "https://github.com/EspressoSystems/hotshot", tag = "rc-0.5.57" }
hotshot-types = { git = "https://github.com/EspressoSystems/hotshot", tag = "rc-0.5.57" }
hotshot-task = { git = "https://github.com/EspressoSystems/hotshot", tag = "rc-0.5.58" }
hotshot-testing = { git = "https://github.com/EspressoSystems/hotshot", tag = "rc-0.5.58" }
hotshot-types = { git = "https://github.com/EspressoSystems/hotshot", tag = "rc-0.5.58" }
hotshot-contract-adapter = { version = "0.1.0", path = "contracts/rust/adapter" }

# Push CDN imports
cdn-broker = { git = "https://github.com/EspressoSystems/Push-CDN", features = [
"runtime-async-std",
"global-permits",
], tag = "0.3.6", package = "cdn-broker" }
], tag = "0.3.12", package = "cdn-broker" }
cdn-marshal = { git = "https://github.com/EspressoSystems/Push-CDN", features = [
"runtime-async-std",
"global-permits",
], tag = "0.3.6", package = "cdn-marshal" }
], tag = "0.3.12", package = "cdn-marshal" }

jf-plonk = { git = "https://github.com/EspressoSystems/jellyfish", tag = "0.4.5", features = [
"test-apis",
Expand Down Expand Up @@ -115,6 +115,7 @@ serde = { version = "1.0.195", features = ["derive"] }
toml = "0.8"
url = "2.3"
vbs = "0.1"
vec1 = "1.12"
vergen = { version = "8.3", features = ["git", "gitcl"] }
zeroize = "1.7"
committable = "0.2"
Expand Down
1 change: 1 addition & 0 deletions builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ tide-disco = { workspace = true }
tracing = { workspace = true }
url = { workspace = true }
vbs = { workspace = true }
vec1 = { workspace = true }

[dev-dependencies]
sequencer = { path = "../sequencer", features = ["testing"] }
5 changes: 3 additions & 2 deletions builder/src/bin/permissionless-builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,26 +122,27 @@ async fn main() -> anyhow::Result<()> {
)
.unwrap();

let validated_state = ValidatedState::genesis(&instance_state).0;

let api_response_timeout_duration = opt.max_api_timeout_duration;

// make the txn timeout as 1/4 of the api_response_timeout_duration
let txn_timeout_duration = api_response_timeout_duration / 4;

let buffer_view_num_count = opt.buffer_view_num_count;
let validated_state = ValidatedState::genesis(&instance_state).0;

let _builder_config = BuilderConfig::init(
builder_key_pair,
bootstrapped_view,
opt.channel_capacity,
opt.node_count,
instance_state,
validated_state,
opt.hotshot_event_streaming_url,
builder_server_url,
api_response_timeout_duration,
buffer_view_num_count,
txn_timeout_duration,
validated_state,
)
.await;

Expand Down
57 changes: 28 additions & 29 deletions builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ use futures::{
stream::{Stream, StreamExt},
};
use hotshot::{
traits::{
election::static_committee::GeneralStaticCommittee, implementations::NetworkingMetricsValue,
},
traits::election::static_committee::GeneralStaticCommittee,
types::{SignatureKey, SystemContextHandle},
HotShotInitializer, Memberships, Networks, SystemContext,
};
Expand All @@ -21,12 +19,11 @@ use hotshot_orchestrator::{
};
use hotshot_types::{
consensus::ConsensusMetricsValue,
constants::{Version01, STATIC_VER_0_1},
constants::Base,
event::Event,
light_client::StateKeyPair,
signature_key::{BLSPrivKey, BLSPubKey},
traits::election::Membership,
traits::metrics::Metrics,
traits::{election::Membership, metrics::Metrics},
HotShotConfig, PeerConfig, ValidatorConfig,
};
use std::fmt::Display;
Expand Down Expand Up @@ -68,20 +65,18 @@ pub mod permissioned;
// It runs the api service for the builder
pub fn run_builder_api_service(url: Url, source: ProxyGlobalState<SeqTypes>) {
// it is to serve hotshot
let builder_api = hotshot_builder_api::builder::define_api::<
ProxyGlobalState<SeqTypes>,
SeqTypes,
Version01,
>(&HotshotBuilderApiOptions::default())
.expect("Failed to construct the builder APIs");
let builder_api =
hotshot_builder_api::builder::define_api::<ProxyGlobalState<SeqTypes>, SeqTypes, Base>(
&HotshotBuilderApiOptions::default(),
)
.expect("Failed to construct the builder APIs");

// it enables external clients to submit txn to the builder's private mempool
let private_mempool_api = hotshot_builder_api::builder::submit_api::<
ProxyGlobalState<SeqTypes>,
SeqTypes,
Version01,
>(&HotshotBuilderApiOptions::default())
.expect("Failed to construct the builder API for private mempool txns");
let private_mempool_api =
hotshot_builder_api::builder::submit_api::<ProxyGlobalState<SeqTypes>, SeqTypes, Base>(
&HotshotBuilderApiOptions::default(),
)
.expect("Failed to construct the builder API for private mempool txns");

let mut app: App<ProxyGlobalState<SeqTypes>, BuilderApiError> = App::with_state(source);

Expand All @@ -91,7 +86,7 @@ pub fn run_builder_api_service(url: Url, source: ProxyGlobalState<SeqTypes>) {
app.register_module("txn_submit", private_mempool_api)
.expect("Failed to register the private mempool API");

async_spawn(app.serve(url, STATIC_VER_0_1));
async_spawn(app.serve(url, Base::instance()));
}

#[cfg(test)]
Expand Down Expand Up @@ -121,6 +116,7 @@ pub mod testing {
ExecutionType, HotShotConfig, PeerConfig, ValidatorConfig,
};
use portpicker::pick_unused_port;
use vbs::version::StaticVersion;
//use sequencer::persistence::NoStorage;
use async_broadcast::{
broadcast, Receiver as BroadcastReceiver, RecvError, Sender as BroadcastSender,
Expand Down Expand Up @@ -160,7 +156,6 @@ pub mod testing {
events::{Error as EventStreamApiError, Options as EventStreamingApiOptions},
events_source::{EventConsumer, EventsStreamer},
};
use hotshot_types::constants::{Version01, STATIC_VER_0_1};
use serde::{Deserialize, Serialize};
use snafu::{guide::feature_flags, *};

Expand All @@ -172,7 +167,7 @@ pub mod testing {
staking_nodes_state_key_pairs: Vec<StateKeyPair>,
non_staking_nodes_state_key_pairs: Vec<StateKeyPair>,
non_staking_nodes_stake_entries: Vec<PeerConfig<hotshot_state_prover::QCVerKey>>,
master_map: Arc<MasterMap<Message<SeqTypes>, PubKey>>,
master_map: Arc<MasterMap<PubKey>>,
anvil: Arc<AnvilInstance>,
}

Expand Down Expand Up @@ -220,12 +215,16 @@ pub mod testing {
data_request_delay: Duration::from_millis(200),
view_sync_timeout: Duration::from_secs(5),
fixed_leader_for_gpuvid: 0,
builder_url,
builder_urls: vec1::vec1![builder_url],
builder_timeout: Duration::from_secs(1),
start_threshold: (
known_nodes_with_stake.clone().len() as u64,
known_nodes_with_stake.clone().len() as u64,
),
start_proposing_view: 0,
stop_proposing_view: 0,
start_voting_view: 0,
stop_voting_view: 0,
};

Self {
Expand Down Expand Up @@ -378,8 +377,7 @@ pub mod testing {

let network = Arc::new(MemoryNetwork::new(
config.my_own_validator_config.public_key,
NetworkingMetricsValue::new(metrics),
self.master_map.clone(),
&self.master_map,
None,
));
let networks = Networks {
Expand Down Expand Up @@ -436,7 +434,7 @@ pub mod testing {
let hotshot_events_api = hotshot_events_service::events::define_api::<
Arc<RwLock<EventsStreamer<SeqTypes>>>,
SeqTypes,
Version01,
Base,
>(&EventStreamingApiOptions::default())
.expect("Failed to define hotshot eventsAPI");

Expand All @@ -445,7 +443,7 @@ pub mod testing {
app.register_module("hotshot-events", hotshot_events_api)
.expect("Failed to register hotshot events API");

async_spawn(app.serve(url, STATIC_VER_0_1));
async_spawn(app.serve(url, Base::instance()));
}
// enable hotshot event streaming
pub fn enable_hotshot_node_event_streaming<P: SequencerPersistence>(
Expand Down Expand Up @@ -555,12 +553,12 @@ pub mod testing {
channel_capacity,
node_count,
node_state,
ValidatedState::default(),
hotshot_events_streaming_api_url,
hotshot_builder_api_url,
Duration::from_millis(2000),
15,
Duration::from_millis(500),
ValidatedState::default(),
)
.await
.unwrap();
Expand Down Expand Up @@ -620,11 +618,11 @@ pub mod testing {
bootstrapped_view,
channel_capacity,
node_state,
ValidatedState::default(),
hotshot_builder_api_url,
Duration::from_millis(2000),
15,
Duration::from_millis(500),
ValidatedState::default(),
)
.await
.unwrap();
Expand Down Expand Up @@ -703,10 +701,11 @@ mod test {
}

let genesis_state = NodeState::mock();
let validated_state = ValidatedState::default();
let mut parent = {
// TODO refactor repeated code from other tests
let (genesis_payload, genesis_ns_table) =
Payload::from_transactions([], &ValidatedState::default(), &genesis_state)
Payload::from_transactions([], &validated_state, &genesis_state)
.await
.expect("unable to create genesis payload");
let builder_commitment = genesis_payload.builder_commitment(&genesis_ns_table);
Expand Down
20 changes: 8 additions & 12 deletions builder/src/non_permissioned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use hotshot_builder_core::{
};

use hotshot_types::{
constants::{Version01, STATIC_VER_0_1},
data::{fake_commitment, Leaf, ViewNumber},
traits::{
block_contents::{vid_commitment, GENESIS_VID_NUM_STORAGE_NODES},
Expand Down Expand Up @@ -82,12 +81,12 @@ impl BuilderConfig {
channel_capacity: NonZeroUsize,
node_count: NonZeroUsize,
instance_state: NodeState,
validated_state: ValidatedState,
hotshot_events_api_url: Url,
hotshot_builder_apis_url: Url,
max_api_timeout_duration: Duration,
buffered_view_num_count: usize,
maximize_txns_count_timeout_duration: Duration,
validated_state: ValidatedState,
) -> anyhow::Result<Self> {
tracing::info!(
address = %builder_key_pair.fee_account(),
Expand Down Expand Up @@ -161,8 +160,7 @@ impl BuilderConfig {
.base_fee
.as_u64()
.context("the base fee exceeds the maximum amount that a builder can pay (defined by u64::MAX)")?,
Arc::new(instance_state),
Duration::from_secs(60),
Arc::new(instance_state), Duration::from_secs(60),
Arc::new(validated_state),
);

Expand Down Expand Up @@ -232,12 +230,10 @@ mod test {
events::{Error as EventStreamApiError, Options as EventStreamingApiOptions},
events_source::{BuilderEvent, EventConsumer, EventsStreamer},
};
use hotshot_types::{
constants::{Version01, STATIC_VER_0_1},
traits::{
block_contents::{BlockPayload, GENESIS_VID_NUM_STORAGE_NODES},
node_implementation::NodeType,
},
use hotshot_types::constants::Base;
use hotshot_types::traits::{
block_contents::{BlockPayload, GENESIS_VID_NUM_STORAGE_NODES},
node_implementation::NodeType,
};
use hotshot_types::{signature_key::BLSPubKey, traits::signature_key::SignatureKey};
use sequencer::{
Expand Down Expand Up @@ -294,7 +290,7 @@ mod test {
);

// builder api url
let hotshot_builder_api_url = hotshot_config.config.builder_url.clone();
let hotshot_builder_api_url = hotshot_config.config.builder_urls[0].clone();

let builder_config = NonPermissionedBuilderTestConfig::init_non_permissioned_builder(
&hotshot_config,
Expand All @@ -306,7 +302,7 @@ mod test {
let builder_pub_key = builder_config.fee_account;

// Start a builder api client
let builder_client = Client::<hotshot_builder_api::builder::Error, Version01>::new(
let builder_client = Client::<hotshot_builder_api::builder::Error, Base>::new(
hotshot_builder_api_url.clone(),
);
assert!(builder_client.connect(Some(Duration::from_secs(60))).await);
Expand Down
Loading

0 comments on commit eec70e4

Please sign in to comment.