Skip to content
This repository has been archived by the owner on Dec 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #140 from EspressoSystems/bf/update-hs
Browse files Browse the repository at this point in the history
Update Hotshot to 0.5.55
  • Loading branch information
bfish713 authored May 17, 2024
2 parents ebbf1c8 + f75309a commit 96f0a14
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 64 deletions.
19 changes: 10 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ clap = { version = "4.4", features = ["derive", "env"] }
committable = "0.2"
derivative = "2.2"
futures = "0.3"
hotshot = { git = "https://github.com/EspressoSystems/HotShot.git", tag = "0.5.54" }
hotshot-builder-api = { git = "https://github.com/EspressoSystems/HotShot.git", tag = "0.5.54" }
hotshot-events-service = { git = "https://github.com/EspressoSystems/hotshot-events-service.git", tag = "0.1.22" }
hotshot-types = { git = "https://github.com/EspressoSystems/HotShot.git", tag = "0.5.54" }
hotshot = { git = "https://github.com/EspressoSystems/HotShot.git", tag = "0.5.55" }
hotshot-builder-api = { git = "https://github.com/EspressoSystems/HotShot.git", tag = "0.5.55" }
hotshot-events-service = { git = "https://github.com/EspressoSystems/hotshot-events-service.git", tag = "0.1.23" }
hotshot-types = { git = "https://github.com/EspressoSystems/HotShot.git", tag = "0.5.55" }
serde = { version = "1.0", features = ["derive"] }
sha2 = "0.10"
snafu = "0.8"
Expand All @@ -31,4 +31,4 @@ tracing = "0.1"
vbs = "0.1"

[dev-dependencies]
hotshot-example-types = { git = "https://github.com/EspressoSystems/HotShot.git", tag = "0.5.54" }
hotshot-example-types = { git = "https://github.com/EspressoSystems/HotShot.git", tag = "0.5.55" }
50 changes: 18 additions & 32 deletions src/builder_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use hotshot_types::{
traits::{
block_contents::precompute_vid_commitment,
node_implementation::{ConsensusTime, NodeType},
EncodeBytes,
},
utils::BuilderCommitment,
vid::{VidCommitment, VidPrecomputeData},
vote::Certificate,
};

use committable::{Commitment, Committable};
Expand Down Expand Up @@ -301,9 +301,8 @@ impl<TYPES: NodeType> BuilderProgress<TYPES> for BuilderState<TYPES> {
// To handle both cases, we can have the bootstrap builder running,
// and only doing the insertion if and only if intended builder state for a particulat view is not present
// check the presence of da_msg.proposal.data.view_number-1 in the spawned_builder_states list
if self.built_from_proposed_block.view_number.get_u64()
== self.bootstrap_view_number.get_u64()
&& (da_msg.proposal.data.view_number.get_u64() == 0
if self.built_from_proposed_block.view_number.u64() == self.bootstrap_view_number.u64()
&& (da_msg.proposal.data.view_number.u64() == 0
|| !self
.global_state
.read_arc()
Expand All @@ -319,8 +318,8 @@ impl<TYPES: NodeType> BuilderProgress<TYPES> for BuilderState<TYPES> {
handled_by_bootstrap = true;
}
// Do the validation check
else if da_msg.proposal.data.view_number.get_u64()
!= self.built_from_proposed_block.view_number.get_u64() + 1
else if da_msg.proposal.data.view_number.u64()
!= self.built_from_proposed_block.view_number.u64() + 1
{
tracing::debug!("View number is not equal to built_from_view + 1, so returning");
return;
Expand Down Expand Up @@ -423,9 +422,8 @@ impl<TYPES: NodeType> BuilderProgress<TYPES> for BuilderState<TYPES> {
// To handle both cases, we can have the bootstrap builder running,
// and only doing the insertion if and only if intended builder state for a particulat view is not present
// check the presence of da_msg.proposal.data.view_number-1 in the spawned_builder_states
if self.built_from_proposed_block.view_number.get_u64()
== self.bootstrap_view_number.get_u64()
&& (qc_msg.proposal.data.view_number.get_u64() == 0
if self.built_from_proposed_block.view_number.u64() == self.bootstrap_view_number.u64()
&& (qc_msg.proposal.data.view_number.u64() == 0
|| !self
.global_state
.read_arc()
Expand All @@ -438,11 +436,11 @@ impl<TYPES: NodeType> BuilderProgress<TYPES> for BuilderState<TYPES> {
handled_by_bootstrap = true;
} else if qc_msg.proposal.data.justify_qc.view_number
!= self.built_from_proposed_block.view_number
|| (qc_msg.proposal.data.justify_qc.get_data().leaf_commit
|| (qc_msg.proposal.data.justify_qc.data.leaf_commit
!= self.built_from_proposed_block.leaf_commit)
{
tracing::debug!("Either View number {:?} or leaf commit{:?} from justify qc does not match the built-in info {:?}, so returning",
qc_msg.proposal.data.justify_qc.view_number, qc_msg.proposal.data.justify_qc.get_data().leaf_commit, self.built_from_proposed_block);
qc_msg.proposal.data.justify_qc.view_number, qc_msg.proposal.data.justify_qc.data.leaf_commit, self.built_from_proposed_block);
return;
}

Expand Down Expand Up @@ -515,29 +513,27 @@ impl<TYPES: NodeType> BuilderProgress<TYPES> for BuilderState<TYPES> {
// the special value can be 0 itself, or a view number 0 is also right answer
let _block_size = decide_msg.block_size;
let latest_leaf_view_number = decide_msg.latest_decide_view_number;
let latest_leaf_view_number_as_i64 = latest_leaf_view_number.get_u64() as i64;
let latest_leaf_view_number_as_i64 = latest_leaf_view_number.u64() as i64;

// Garbage collection
// Keep the builder states stay active till their built in view + BUFFER_VIEW_NUM
if self.built_from_proposed_block.view_number.get_u64()
== self.bootstrap_view_number.get_u64()
{
if self.built_from_proposed_block.view_number.u64() == self.bootstrap_view_number.u64() {
// required to convert to prevent underflow on u64's
let last_bootstrap_garbage_collected_as_i64 = self
.last_bootstrap_garbage_collected_decided_seen_view_num
.get_u64() as i64;
.u64() as i64;

if (latest_leaf_view_number_as_i64 - last_bootstrap_garbage_collected_as_i64)
>= 2 * self.buffer_view_num_count as i64
{
tracing::info!(
"Bootstrapped builder state garbage collected for view number {:?}",
latest_leaf_view_number.get_u64()
latest_leaf_view_number.u64()
);

let to_be_garbage_collected_view_num =
<<TYPES as NodeType>::Time as ConsensusTime>::new(
latest_leaf_view_number.get_u64() - self.buffer_view_num_count,
latest_leaf_view_number.u64() - self.buffer_view_num_count,
);

let to_garbage_collect: HashSet<(VidCommitment, BuilderCommitment, TYPES::Time)> =
Expand Down Expand Up @@ -580,7 +576,7 @@ impl<TYPES: NodeType> BuilderProgress<TYPES> for BuilderState<TYPES> {
//return Some(Status::ShouldContinue);
}
} else if self.built_from_proposed_block.view_number < latest_leaf_view_number {
tracing::info!("Task view is less than the currently decided leaf view {:?}; exiting builder state for view {:?}", latest_leaf_view_number.get_u64(), self.built_from_proposed_block.view_number.get_u64());
tracing::info!("Task view is less than the currently decided leaf view {:?}; exiting builder state for view {:?}", latest_leaf_view_number.u64(), self.built_from_proposed_block.view_number.u64());
self.global_state.write_arc().await.remove_handles(
&self.built_from_proposed_block.vid_commitment,
self.builder_commitments.clone(),
Expand Down Expand Up @@ -704,17 +700,7 @@ impl<TYPES: NodeType> BuilderProgress<TYPES> for BuilderState<TYPES> {
requested_view_number,
));

let encoded_txns: Vec<u8> = payload
.encode()
.inspect_err(|e| {
tracing::error!(
"Failed to encode block payload for parent {:?}@{:?}: {e}",
matching_vid,
requested_view_number
)
})
.ok()?
.to_vec();
let encoded_txns: Vec<u8> = payload.encode().to_vec();
let block_size: u64 = encoded_txns.len() as u64;
let offered_fee: u64 = self.base_fee * block_size;

Expand Down Expand Up @@ -760,8 +746,8 @@ impl<TYPES: NodeType> BuilderProgress<TYPES> for BuilderState<TYPES> {
// If a spawned clone is active then it will handle the request, otherwise the bootstrapped builder will handle
if (requested_vid_commitment == self.built_from_proposed_block.vid_commitment
&& requested_view_number == self.built_from_proposed_block.view_number)
|| (self.built_from_proposed_block.view_number.get_u64()
== self.bootstrap_view_number.get_u64())
|| (self.built_from_proposed_block.view_number.u64()
== self.bootstrap_view_number.u64())
{
tracing::info!(
"Request handled by builder with view {:?} for (parent {:?}, view_num: {:?})",
Expand Down
16 changes: 8 additions & 8 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ where
>>::Error: Display,
for<'a> <Types::SignatureKey as TryFrom<&'a TaggedBase64>>::Error: Display,
{
async fn get_available_blocks(
async fn available_blocks(
&self,
for_parent: &VidCommitment,
view_number: u64,
Expand Down Expand Up @@ -617,7 +617,7 @@ where
})
}
}
async fn get_builder_address(
async fn builder_address(
&self,
) -> Result<<Types as NodeType>::BuilderSignatureKey, BuildError> {
Ok(self.builder_keys.0.clone())
Expand Down Expand Up @@ -781,7 +781,7 @@ pub async fn run_non_permissioned_standalone_builder_service<Types: NodeType>(
// DA proposal event
BuilderEventType::HotshotDaProposal { proposal, sender } => {
// get the leader for current view
let leader = membership.get_leader(proposal.data.view_number);
let leader = membership.leader(proposal.data.view_number);
// get the committee mstatked node count
let total_nodes = membership.total_nodes();

Expand All @@ -797,7 +797,7 @@ pub async fn run_non_permissioned_standalone_builder_service<Types: NodeType>(
// QC proposal event
BuilderEventType::HotshotQuorumProposal { proposal, sender } => {
// get the leader for current view
let leader = membership.get_leader(proposal.data.view_number);
let leader = membership.leader(proposal.data.view_number);
handle_qc_event(&qc_sender, proposal, sender, leader).await;
}
_ => {
Expand Down Expand Up @@ -844,7 +844,7 @@ pub async fn run_permissioned_standalone_builder_service<
// hotshot context handle
hotshot_handle: SystemContextHandle<Types, I>,
) {
let mut event_stream = hotshot_handle.get_event_stream();
let mut event_stream = hotshot_handle.event_stream();
loop {
tracing::debug!("Waiting for events from HotShot");
match event_stream.next().await {
Expand All @@ -867,14 +867,14 @@ pub async fn run_permissioned_standalone_builder_service<
block_size,
..
} => {
let latest_decide_view_number = leaf_chain[0].leaf.get_view_number();
let latest_decide_view_number = leaf_chain[0].leaf.view_number();
handle_decide_event(&decide_sender, latest_decide_view_number, block_size)
.await;
}
// DA proposal event
EventType::DaProposal { proposal, sender } => {
// get the leader for current view
let leader = hotshot_handle.get_leader(proposal.data.view_number).await;
let leader = hotshot_handle.leader(proposal.data.view_number).await;
// get the committee staked node count
let total_nodes = hotshot_handle.total_nodes();

Expand All @@ -883,7 +883,7 @@ pub async fn run_permissioned_standalone_builder_service<
// QC proposal event
EventType::QuorumProposal { proposal, sender } => {
// get the leader for current view
let leader = hotshot_handle.get_leader(proposal.data.view_number).await;
let leader = hotshot_handle.leader(proposal.data.view_number).await;
handle_qc_event(&qc_sender, proposal, sender, leader).await;
}
_ => {
Expand Down
17 changes: 7 additions & 10 deletions src/testing/basic_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ mod tests {
// generate num_test messages for each type and send it to the respective channels;
for i in 0..num_test_messages as u32 {
// Prepare the transaction message
let tx = TestTransaction(vec![i as u8]);
let encoded_transactions = TestTransaction::encode(&[tx.clone()]).unwrap();
let tx = TestTransaction::new(vec![i as u8]);
let encoded_transactions = TestTransaction::encode(&[tx.clone()]);

let stx_msg = TransactionMessage::<TestTypes> {
txns: vec![tx.clone()],
Expand Down Expand Up @@ -211,17 +211,14 @@ mod tests {
leaf_commit: leaf.commit(),
};

let previous_qc_view_number = sqc_msgs[(i - 1) as usize]
.proposal
.data
.view_number
.get_u64();
let previous_qc_view_number =
sqc_msgs[(i - 1) as usize].proposal.data.view_number.u64();
let view_number = if previous_qc_view_number == 0
&& previous_justify_qc.view_number.get_u64() == 0
&& previous_justify_qc.view_number.u64() == 0
{
ViewNumber::new(0)
} else {
ViewNumber::new(1 + previous_justify_qc.view_number.get_u64())
ViewNumber::new(1 + previous_justify_qc.view_number.u64())
};
// form a justify qc
SimpleCertificate::<TestTypes, QuorumData<TestTypes>, SuccessThreshold> {
Expand Down Expand Up @@ -286,7 +283,7 @@ mod tests {
};

let sdecide_msg = DecideMessage::<TestTypes> {
latest_decide_view_number: leaf.get_view_number(),
latest_decide_view_number: leaf.view_number(),
block_size: Some(encoded_transactions.len() as u64),
};

Expand Down

0 comments on commit 96f0a14

Please sign in to comment.