Skip to content

Commit

Permalink
fix(validations): solve synchronization and bootstrapping issues
Browse files Browse the repository at this point in the history
fix #2428
  • Loading branch information
aesedepece committed Oct 31, 2024
1 parent 0dc4e8a commit 72ebd43
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
5 changes: 4 additions & 1 deletion data_structures/src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,10 @@ pub enum Hash {

impl Default for Hash {
fn default() -> Hash {
Hash::SHA256([0; 32])
Hash::SHA256([
227, 176, 196, 66, 152, 252, 28, 20, 154, 251, 244, 200, 153, 111, 185, 36, 39, 174, 65, 228,
100, 155, 147, 76, 164, 149, 153, 27, 120, 82, 184, 85,
])
}
}

Expand Down
28 changes: 12 additions & 16 deletions validations/src/validations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,14 @@ use witnet_config::defaults::{
PSEUDO_CONSENSUS_CONSTANTS_WIP0022_REWARD_COLLATERAL_RATIO,
PSEUDO_CONSENSUS_CONSTANTS_WIP0027_COLLATERAL_AGE,
};
use witnet_crypto::{
hash::{calculate_sha256, Sha256},
merkle::{merkle_tree_root as crypto_merkle_tree_root, ProgressiveMerkleTree},
signature::{verify, PublicKey, Signature},
};
use witnet_crypto::{hash::{calculate_sha256, Sha256}, hash, merkle::{merkle_tree_root as crypto_merkle_tree_root, ProgressiveMerkleTree}, signature::{PublicKey, Signature, verify}};
use witnet_data_structures::{
chain::{
tapi::ActiveWips, Block, BlockMerkleRoots, CheckpointBeacon, CheckpointVRF,
ConsensusConstants, DataRequestOutput, DataRequestStage, DataRequestState, Epoch,
EpochConstants, Hash, Hashable, Input, KeyedSignature, OutputPointer, PublicKeyHash,
RADRequest, RADTally, RADType, Reputation, ReputationEngine, SignaturesToVerify,
StakeOutput, ValueTransferOutput,
Block, BlockMerkleRoots, CheckpointBeacon, CheckpointVRF, ConsensusConstants,
DataRequestOutput, DataRequestStage, DataRequestState, Epoch, EpochConstants,
Hash, Hashable, Input, KeyedSignature, OutputPointer, PublicKeyHash, RADRequest,
RADTally, RADType, Reputation, ReputationEngine, SignaturesToVerify, StakeOutput,
tapi::ActiveWips, ValueTransferOutput,
},
data_request::{
calculate_reward_collateral_ratio, calculate_tally_change, calculate_witness_reward,
Expand Down Expand Up @@ -50,7 +46,7 @@ use witnet_rad::{
error::RadError,
operators::RadonOpCodes,
script::{create_radon_script_from_filters_and_reducer, unpack_radon_script},
types::{serial_iter_decode, RadonTypes},
types::{RadonTypes, serial_iter_decode},
};

// TODO: move to a configuration
Expand Down Expand Up @@ -1988,10 +1984,10 @@ pub fn validate_block_transactions(
// }
}

(Hash::from(st_mt.root()), Hash::from(ut_mt.root()))
(st_mt.root(), ut_mt.root())
} else {
// Nullify stake and unstake merkle roots for the legacy protocol version
Default::default()
(hash::EMPTY_SHA256, hash::EMPTY_SHA256)
};

// Validate Merkle Root
Expand All @@ -2002,12 +1998,12 @@ pub fn validate_block_transactions(
commit_hash_merkle_root: Hash::from(co_hash_merkle_root),
reveal_hash_merkle_root: Hash::from(re_hash_merkle_root),
tally_hash_merkle_root: Hash::from(ta_hash_merkle_root),
stake_hash_merkle_root: st_root,
unstake_hash_merkle_root: ut_root,
stake_hash_merkle_root: Hash::from(st_root),
unstake_hash_merkle_root: Hash::from(ut_root),
};

if merkle_roots != block.block_header.merkle_roots {
println!(
log::debug!(
"{:?} vs {:?}",
merkle_roots, block.block_header.merkle_roots
);
Expand Down

0 comments on commit 72ebd43

Please sign in to comment.