Skip to content

Commit

Permalink
[fix] hyperledger-iroha#2506: Fix the block validation
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Pesterev <pesterev@pm.me>
  • Loading branch information
pesterev authored and appetrosyan committed Dec 20, 2022
1 parent efeae05 commit 4b32e1d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
7 changes: 6 additions & 1 deletion core/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,12 @@ impl ChainedBlock {
) -> ValidBlock {
let mut txs = Vec::new();
let mut rejected = Vec::new();

let wsv_clone = WorldStateView::clone(wsv);
let wsv = if self.header.is_genesis() {
wsv
} else {
&wsv_clone
};
for tx in self.transactions {
match transaction_validator.validate(tx.into_v1(), self.header.is_genesis(), wsv) {
Ok(tx) => txs.push(tx),
Expand Down
24 changes: 12 additions & 12 deletions core/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,19 @@ impl TransactionValidator {
}));
}

// TODO: combine the two. Elide the clone.

// WSV is cloned here so that instructions don't get applied to the blockchain
// Therefore, this instruction execution validates before actually executing
let wsv = wsv.clone();

self.validate_with_builtin_validators(&tx, &wsv, is_genesis)?;

// WSV is cloned here so that instructions don't get applied to the blockchain
// Therefore, this instruction execution validates before actually executing
let wsv = WorldStateView::clone(&wsv);
if is_genesis {
let wsv_cloned = WorldStateView::clone(&wsv);
self.validate_with_builtin_validators(&tx, &wsv_cloned, is_genesis)?;
} else {
self.validate_with_builtin_validators(&tx, &wsv, is_genesis)?;
}

Self::validate_with_runtime_validators(tx, &wsv)
if is_genesis {
let wsv_cloned = WorldStateView::clone(&wsv);
Self::validate_with_runtime_validators(tx, &wsv_cloned)
} else {
Self::validate_with_runtime_validators(tx, &wsv)
}
}

/// Validate signatures for the given transaction
Expand Down

0 comments on commit 4b32e1d

Please sign in to comment.