Skip to content

Commit

Permalink
wip: add fault_root check
Browse files Browse the repository at this point in the history
  • Loading branch information
herr-seppia committed Jul 16, 2024
1 parent 81548c6 commit a5f5c6d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
9 changes: 8 additions & 1 deletion consensus/src/proposal/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,20 @@ impl<D: Database> ProposalHandler<D> {
return Err(ConsensusError::InvalidBlockHash);
}

let tx_hashes: Vec<[u8; 32]> =
let tx_hashes: Vec<_> =
p.candidate.txs().iter().map(|t| t.hash()).collect();
let tx_root = merkle_root(&tx_hashes[..]);
if tx_root != p.candidate.header().txroot {
return Err(ConsensusError::InvalidBlock);
}

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

if expected_generator != p.sign_info.signer.bytes() {
return Err(ConsensusError::NotCommitteeMember);
}
Expand Down
1 change: 0 additions & 1 deletion consensus/src/validation/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ impl<T: Operations + 'static> ValidationStep<T> {
// Call Verify State Transition to make sure transactions set is
// valid

// TODO: Verify Faults
if let Err(err) = executor
.verify_faults(header.height, candidate.faults())
.await
Expand Down
2 changes: 1 addition & 1 deletion node-data/src/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mod transaction;
pub use transaction::{SpentTransaction, Transaction};

mod faults;
pub use faults::{Fault, Slash, SlashType, InvalidFault};
pub use faults::{Fault, InvalidFault, Slash, SlashType};

mod attestation;
pub use attestation::{
Expand Down
7 changes: 3 additions & 4 deletions node/src/chain/acceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use tokio::sync::RwLock;
use tracing::{debug, info, warn};

use super::consensus::Task;
use crate::chain::header_validation::Validator;
use crate::chain::header_validation::{verify_faults, Validator};
use crate::chain::metrics::AverageElapsedTime;
use crate::database::rocksdb::{
MD_AVG_PROPOSAL, MD_AVG_RATIFICATION, MD_AVG_VALIDATION, MD_HASH_KEY,
Expand Down Expand Up @@ -451,12 +451,11 @@ impl<DB: database::DB, VM: vm::VMExecution, N: Network> Acceptor<N, DB, VM> {
// Persist block in consistency with the VM state update
let (label, finalized) = {
let header = blk.header();
verify_faults(self.db.clone, header.height, blk.faults()).await?;

let vm = self.vm.write().await;

let (txs, rolling_result) = self.db.read().await.update(|db| {

// TODO: Verify Faults

let (txs, verification_output) =
vm.accept(blk, Some(&prev_block_voters[..]))?;

Expand Down

0 comments on commit a5f5c6d

Please sign in to comment.