Skip to content

Commit

Permalink
consensus: adjust hash to digest terminology
Browse files Browse the repository at this point in the history
  • Loading branch information
Neotamandua committed Dec 5, 2024
1 parent 220488c commit 1348139
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions consensus/src/proposal/block_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ impl<T: Operations> Generator<T> {

// We always write the faults len in a u32
let mut faults_size = u32::SIZE;
let faults_hashes: Vec<_> = faults
let fault_digests: Vec<_> = faults
.iter()
.map(|f| {
faults_size += f.size();
f.hash()
f.digest()
})
.collect();

blk_header.faultroot = merkle_root(&faults_hashes);
blk_header.faultroot = merkle_root(&fault_digests);

// We know for sure that this operation cannot underflow
let max_txs_bytes = MAX_BLOCK_SIZE - header_size - faults_size;
Expand All @@ -140,10 +140,10 @@ impl<T: Operations> Generator<T> {
blk_header.state_hash = result.verification_output.state_root;
blk_header.event_bloom = result.verification_output.event_bloom;

let tx_hashes: Vec<_> =
result.txs.iter().map(|t| t.inner.hash()).collect();
let tx_digests: Vec<_> =
result.txs.iter().map(|t| t.inner.digest()).collect();
let txs: Vec<_> = result.txs.into_iter().map(|t| t.inner).collect();
blk_header.txroot = merkle_root(&tx_hashes[..]);
blk_header.txroot = merkle_root(&tx_digests[..]);

blk_header.timestamp = max(
ru.timestamp() + *MINIMUM_BLOCK_TIME,
Expand Down
12 changes: 6 additions & 6 deletions consensus/src/proposal/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ fn verify_candidate_msg(
}

// Verify tx_root
let tx_hashes: Vec<_> =
p.candidate.txs().iter().map(|t| t.hash()).collect();
let tx_root = merkle_root(&tx_hashes[..]);
let tx_digests: Vec<_> =
p.candidate.txs().iter().map(|t| t.digest()).collect();
let tx_root = merkle_root(&tx_digests[..]);
if tx_root != p.candidate.header().txroot {
return Err(ConsensusError::InvalidBlock);
}
Expand All @@ -186,9 +186,9 @@ fn verify_candidate_msg(
}

// Verify fault_root
let fault_hashes: Vec<_> =
p.candidate.faults().iter().map(|t| t.hash()).collect();
let fault_root = merkle_root(&fault_hashes[..]);
let fault_digests: Vec<_> =
p.candidate.faults().iter().map(|t| t.digest()).collect();
let fault_root = merkle_root(&fault_digests[..]);
if fault_root != p.candidate.header().faultroot {
return Err(ConsensusError::InvalidBlock);
}
Expand Down

0 comments on commit 1348139

Please sign in to comment.