Skip to content

Commit

Permalink
index payloads by view
Browse files Browse the repository at this point in the history
  • Loading branch information
bfish713 committed Jan 23, 2024
1 parent 04a6137 commit 30376d0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
7 changes: 3 additions & 4 deletions crates/hotshot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use hotshot_task::{
use hotshot_task_impls::{events::HotShotEvent, network::NetworkTaskKind};

use hotshot_types::{
consensus::{Consensus, ConsensusMetricsValue, PayloadStore, View, ViewInner, ViewQueue},
consensus::{Consensus, ConsensusMetricsValue, View, ViewInner, ViewQueue},
data::Leaf,
error::StorageSnafu,
event::EventType,
Expand Down Expand Up @@ -217,9 +217,8 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>> SystemContext<TYPES, I> {
);

let mut saved_leaves = HashMap::new();
let mut saved_payloads = PayloadStore::default();
let mut saved_payloads = BTreeMap::new();
saved_leaves.insert(anchored_leaf.commit(), anchored_leaf.clone());
let payload_commitment = anchored_leaf.get_payload_commitment();
if let Some(payload) = anchored_leaf.get_block_payload() {
let encoded_txns = match payload.encode() {
// TODO (Keyao) [VALIDATED_STATE] - Avoid collect/copy on the encoded transaction bytes.
Expand All @@ -229,7 +228,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>> SystemContext<TYPES, I> {
return Err(HotShotError::BlockError { source: e });
}
};
saved_payloads.insert(payload_commitment, encoded_txns);
saved_payloads.insert(anchored_leaf.get_view_number(), encoded_txns);
}

let start_view = anchored_leaf.get_view_number();
Expand Down
2 changes: 1 addition & 1 deletion crates/task-impls/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, A: ConsensusApi<TYPES, I> +
// If the block payload is available for this leaf, include it in
// the leaf chain that we send to the client.
if let Some(encoded_txns) =
consensus.saved_payloads.get(leaf.get_payload_commitment())
consensus.saved_payloads.get(&leaf.get_view_number())
{
let payload = BlockPayload::from_bytes(
encoded_txns.clone().into_iter(),
Expand Down
2 changes: 1 addition & 1 deletion crates/task-impls/src/da.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, A: ConsensusApi<TYPES, I> +
// Record the payload we have promised to make available.
consensus
.saved_payloads
.insert(payload_commitment, proposal.data.encoded_transactions);
.insert(view, proposal.data.encoded_transactions);
}
HotShotEvent::DAVoteRecv(ref vote) => {
debug!("DA vote recv, Main Task {:?}", vote.get_view_number());
Expand Down
13 changes: 3 additions & 10 deletions crates/types/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub struct Consensus<TYPES: NodeType> {
///
/// Contains the block payload commitment and encoded transactions for every leaf in
/// `saved_leaves` if that payload is available.
pub saved_payloads: PayloadStore,
pub saved_payloads: BTreeMap<TYPES::Time, Vec<u8>>,

/// The `locked_qc` view number
pub locked_view: TYPES::Time,
Expand Down Expand Up @@ -316,21 +316,14 @@ impl<TYPES: NodeType> Consensus<TYPES> {
// perform gc
self.saved_da_certs
.retain(|view_number, _| *view_number >= old_anchor_view);
self.state_map
.range(old_anchor_view..new_anchor_view)
.filter_map(|(_view_number, view)| view.get_payload_commitment())
.for_each(|payload_commitment| {
self.saved_payloads.remove(payload_commitment);
});
self.state_map
.range(old_anchor_view..new_anchor_view)
.filter_map(|(_view_number, view)| view.get_leaf_commitment())
.for_each(|leaf| {
if let Some(removed) = self.saved_leaves.remove(&leaf) {
self.saved_payloads.remove(removed.get_payload_commitment());
}
self.saved_leaves.remove(&leaf);
});
self.state_map = self.state_map.split_off(&new_anchor_view);
self.saved_payloads = self.saved_payloads.split_off(&new_anchor_view);
}

/// Gets the last decided state
Expand Down

0 comments on commit 30376d0

Please sign in to comment.