Skip to content

Commit 2fb3a04

Browse files
committed
fix(validations): solve synchronization and bootstrapping issues
fix #2428
1 parent f946d8f commit 2fb3a04

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

data_structures/src/chain/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,10 @@ pub enum Hash {
11141114

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

validations/src/validations.rs

+12-16
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,14 @@ use witnet_config::defaults::{
1111
PSEUDO_CONSENSUS_CONSTANTS_WIP0022_REWARD_COLLATERAL_RATIO,
1212
PSEUDO_CONSENSUS_CONSTANTS_WIP0027_COLLATERAL_AGE,
1313
};
14-
use witnet_crypto::{
15-
hash::{calculate_sha256, Sha256},
16-
merkle::{merkle_tree_root as crypto_merkle_tree_root, ProgressiveMerkleTree},
17-
signature::{verify, PublicKey, Signature},
18-
};
14+
use witnet_crypto::{hash::{calculate_sha256, Sha256}, hash, merkle::{merkle_tree_root as crypto_merkle_tree_root, ProgressiveMerkleTree}, signature::{PublicKey, Signature, verify}};
1915
use witnet_data_structures::{
2016
chain::{
21-
tapi::ActiveWips, Block, BlockMerkleRoots, CheckpointBeacon, CheckpointVRF,
22-
ConsensusConstants, DataRequestOutput, DataRequestStage, DataRequestState, Epoch,
23-
EpochConstants, Hash, Hashable, Input, KeyedSignature, OutputPointer, PublicKeyHash,
24-
RADRequest, RADTally, RADType, Reputation, ReputationEngine, SignaturesToVerify,
25-
StakeOutput, ValueTransferOutput,
17+
Block, BlockMerkleRoots, CheckpointBeacon, CheckpointVRF, ConsensusConstants,
18+
DataRequestOutput, DataRequestStage, DataRequestState, Epoch, EpochConstants,
19+
Hash, Hashable, Input, KeyedSignature, OutputPointer, PublicKeyHash, RADRequest,
20+
RADTally, RADType, Reputation, ReputationEngine, SignaturesToVerify, StakeOutput,
21+
tapi::ActiveWips, ValueTransferOutput,
2622
},
2723
data_request::{
2824
calculate_reward_collateral_ratio, calculate_tally_change, calculate_witness_reward,
@@ -50,7 +46,7 @@ use witnet_rad::{
5046
error::RadError,
5147
operators::RadonOpCodes,
5248
script::{create_radon_script_from_filters_and_reducer, unpack_radon_script},
53-
types::{serial_iter_decode, RadonTypes},
49+
types::{RadonTypes, serial_iter_decode},
5450
};
5551

5652
// TODO: move to a configuration
@@ -1986,10 +1982,10 @@ pub fn validate_block_transactions(
19861982
// }
19871983
}
19881984

1989-
(Hash::from(st_mt.root()), Hash::from(ut_mt.root()))
1985+
(st_mt.root(), ut_mt.root())
19901986
} else {
19911987
// Nullify stake and unstake merkle roots for the legacy protocol version
1992-
Default::default()
1988+
(hash::EMPTY_SHA256, hash::EMPTY_SHA256)
19931989
};
19941990

19951991
// Validate Merkle Root
@@ -2000,12 +1996,12 @@ pub fn validate_block_transactions(
20001996
commit_hash_merkle_root: Hash::from(co_hash_merkle_root),
20011997
reveal_hash_merkle_root: Hash::from(re_hash_merkle_root),
20021998
tally_hash_merkle_root: Hash::from(ta_hash_merkle_root),
2003-
stake_hash_merkle_root: st_root,
2004-
unstake_hash_merkle_root: ut_root,
1999+
stake_hash_merkle_root: Hash::from(st_root),
2000+
unstake_hash_merkle_root: Hash::from(ut_root),
20052001
};
20062002

20072003
if merkle_roots != block.block_header.merkle_roots {
2008-
println!(
2004+
log::debug!(
20092005
"{:?} vs {:?}",
20102006
merkle_roots, block.block_header.merkle_roots
20112007
);

0 commit comments

Comments
 (0)