Skip to content

Commit

Permalink
save last state height
Browse files Browse the repository at this point in the history
  • Loading branch information
imabdulbasit committed Apr 10, 2024
1 parent 188cd79 commit 71d680e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
7 changes: 6 additions & 1 deletion builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ pub mod testing {
traits::{block_contents::BlockHeader, metrics::NoMetrics},
ExecutionType, HotShotConfig, PeerConfig, ValidatorConfig,
};
use portpicker::pick_unused_port;
//use sequencer::persistence::NoStorage;
use async_broadcast::{
broadcast, Receiver as BroadcastReceiver, RecvError, Sender as BroadcastSender,
Expand Down Expand Up @@ -223,7 +224,11 @@ pub mod testing {
view_sync_timeout: Duration::from_secs(5),
fixed_leader_for_gpuvid: 0,
// ???
builder_url: Url::parse("http://127.0.0.1").unwrap(),
builder_url: Url::parse(&format!(
"http://127.0.0.1:{}",
pick_unused_port().unwrap()
))
.unwrap(),
};

Self {
Expand Down
2 changes: 1 addition & 1 deletion sequencer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ testing = ["hotshot-testing"]
[dev-dependencies]
espresso-macros = { git = "https://github.com/EspressoSystems/espresso-macros.git", tag = "0.1.0" }
hotshot-query-service = { workspace = true, features = ["testing"] }
portpicker = "0.1.1"
rand = "0.8.5"
tempfile = "3.9.0"

Expand Down Expand Up @@ -87,6 +86,7 @@ typenum = { version = "1.15.0", default-features = false, features = [
] }
url = { workspace = true }
vbs = { workspace = true }
portpicker = "0.1.1"

[package.metadata.cargo-udeps.ignore]
normal = ["hotshot-testing"]
19 changes: 16 additions & 3 deletions sequencer/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use hotshot::{
use hotshot_orchestrator::client::OrchestratorClient;
// Should move `STAKE_TABLE_CAPACITY` in the sequencer repo when we have variate stake table support
use hotshot_stake_table::config::STAKE_TABLE_CAPACITY;
use hotshot_testing::block_builder::{SimpleBuilderImplementation, TestBuilderImplementation};
use hotshot_types::{
consensus::ConsensusMetricsValue,
traits::{election::Membership, metrics::Metrics},
Expand Down Expand Up @@ -71,7 +72,7 @@ impl<N: network::Type, P: SequencerPersistence, Ver: StaticVersionType + 'static
{
#[allow(clippy::too_many_arguments)]
pub async fn init(
config: HotShotConfig<PubKey, ElectionConfig>,
mut config: HotShotConfig<PubKey, ElectionConfig>,
instance_state: NodeState,
persistence: P,
networks: Networks<SeqTypes, Node<N, P>>,
Expand All @@ -91,14 +92,14 @@ impl<N: network::Type, P: SequencerPersistence, Ver: StaticVersionType + 'static
);
let membership = GeneralStaticCommittee::create_election(
config.known_nodes_with_stake.clone(),
election_config,
election_config.clone(),
0,
);
let memberships = Memberships {
quorum_membership: membership.clone(),
da_membership: membership.clone(),
vid_membership: membership.clone(),
view_sync_membership: membership,
view_sync_membership: membership.clone(),
};

let stake_table_commit =
Expand All @@ -112,6 +113,13 @@ impl<N: network::Type, P: SequencerPersistence, Ver: StaticVersionType + 'static

let persistence = Arc::new(RwLock::new(persistence));

let (builder_task, builder_url) =
<SimpleBuilderImplementation as TestBuilderImplementation<SeqTypes>>::start(Arc::new(
membership,
))
.await;

config.builder_url = builder_url;
let handle = SystemContext::init(
config.my_own_validator_config.public_key,
config.my_own_validator_config.private_key.clone(),
Expand All @@ -131,6 +139,11 @@ impl<N: network::Type, P: SequencerPersistence, Ver: StaticVersionType + 'static
state_signer = state_signer.with_relay_server(url);
}

// Hook the builder up to the event stream from the first node
if let Some(builder_task) = builder_task {
builder_task.start(Box::new(handle.get_event_stream()));
}

Ok(Self::new(
handle,
persistence,
Expand Down
8 changes: 7 additions & 1 deletion sequencer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ pub mod testing {
traits::{block_contents::BlockHeader, metrics::NoMetrics},
ExecutionType, HotShotConfig, PeerConfig, ValidatorConfig,
};
use portpicker::pick_unused_port;

use std::time::Duration;

#[derive(Clone)]
Expand Down Expand Up @@ -478,7 +480,11 @@ pub mod testing {
view_sync_timeout: Duration::from_secs(1),
data_request_delay: Duration::from_secs(1),
//??
builder_url: Url::parse("http://127.0.0.1").unwrap(),
builder_url: Url::parse(&format!(
"http://127.0.0.1:{}",
pick_unused_port().unwrap()
))
.unwrap(),
};

Self {
Expand Down
6 changes: 6 additions & 0 deletions sequencer/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,12 @@ pub async fn update_state_storage(
.store_state::<BlockMerkleTree, 3>(proof.proof, path, block_number)
.await
.context("failed to insert merkle nodes for block merkle tree")?;

storage
.write()
.await
.set_last_state_height(block_number as usize)
.await?;
}

Ok(())
Expand Down

0 comments on commit 71d680e

Please sign in to comment.