Skip to content

Commit

Permalink
[fix] #2128: Fix MerkleTree construction and iteration (#2318)
Browse files Browse the repository at this point in the history
Signed-off-by: Shunkichi Sato <[email protected]>
  • Loading branch information
s8sato authored Jun 26, 2022
1 parent 6a28d6a commit ab15532
Show file tree
Hide file tree
Showing 6 changed files with 249 additions and 287 deletions.
20 changes: 10 additions & 10 deletions core/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,14 @@ impl ChainedBlock {
.iter()
.map(VersionedValidTransaction::hash)
.collect::<MerkleTree<_>>()
.root_hash();
.hash()
.unwrap_or(Hash::zeroed().typed());
header.rejected_transactions_hash = rejected
.iter()
.map(VersionedRejectedTransaction::hash)
.collect::<MerkleTree<_>>()
.root_hash();
.hash()
.unwrap_or(Hash::zeroed().typed());
let event_recommendations = self.event_recommendations;
// TODO: Validate Event recommendations somehow?
ValidBlock {
Expand Down Expand Up @@ -659,14 +661,12 @@ impl From<&ValidBlock> for Vec<Event> {
)
.into()
}))
.chain(iter::once(
PipelineEvent::new(
PipelineEntityKind::Block,
PipelineStatus::Validating,
block.hash().into(),
)
.into(),
))
.chain([PipelineEvent::new(
PipelineEntityKind::Block,
PipelineStatus::Validating,
block.hash().into(),
)
.into()])
.collect()
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/kura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl<IO: DiskIO> Handler<GetBlockHash> for KuraWithIO<IO> {
return None;
}
// Block height starts with 1
self.merkle_tree.get_leaf(height - 1)
self.merkle_tree.get_leaf_hash(height - 1)
}
}

Expand Down Expand Up @@ -235,7 +235,7 @@ impl<IO: DiskIO> KuraWithIO<IO> {
) -> Result<HashOf<VersionedCommittedBlock>> {
match self.block_store.write(&block).await {
Ok(block_hash) => {
self.merkle_tree = self.merkle_tree.add(block_hash);
self.merkle_tree.add(block_hash);
self.broker.issue_send(ContinueSync).await;
Ok(block_hash)
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/sumeragi/fault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ impl<G: GenesisNetworkTrait, K: KuraTrait, F: FaultInjection> SumeragiWithFault<
network_topology
.validating_peers()
.iter()
.chain(std::iter::once(network_topology.leader()))
.chain([network_topology.leader()])
.chain(network_topology.peers_set_b()),
)
.await;
Expand Down
2 changes: 1 addition & 1 deletion core/src/sumeragi/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ impl BlockSigned {
network_topology
.validating_peers()
.iter()
.chain(std::iter::once(network_topology.leader()))
.chain([network_topology.leader()])
.chain(network_topology.peers_set_b()),
)
.await;
Expand Down
2 changes: 1 addition & 1 deletion core/test_network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ where
let mut configuration = default_configuration.unwrap_or_else(Configuration::test);
configuration.sumeragi.trusted_peers.peers = peers
.values()
.chain(std::iter::once(&genesis))
.chain([&genesis])
.map(|peer| peer.id.clone())
.collect();

Expand Down
Loading

0 comments on commit ab15532

Please sign in to comment.