Skip to content

Commit

Permalink
Merge pull request #2046 from subspace/fraud_proof/host_function
Browse files Browse the repository at this point in the history
Fraud proof: Add Host function and update timestamp extrinsic derivation
  • Loading branch information
vedhavyas authored Oct 10, 2023
2 parents e7ed38e + 8a20edc commit f567ca7
Show file tree
Hide file tree
Showing 33 changed files with 659 additions and 567 deletions.
33 changes: 29 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/pallet-domains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ log = { version = "0.4.20", default-features = false }
scale-info = { version = "2.7.0", default-features = false, features = ["derive"] }
sp-core = { version = "21.0.0", default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "c90d6edfd8c63168eff0dce6f2ace4d66dd139f7" }
sp-domains = { version = "0.1.0", default-features = false, path = "../sp-domains" }
sp-domains-fraud-proof = { version = "0.1.0", default-features = false, path = "../sp-domains-fraud-proof" }
sp-io = { version = "23.0.0", default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "c90d6edfd8c63168eff0dce6f2ace4d66dd139f7" }
sp-runtime = { version = "24.0.0", default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "c90d6edfd8c63168eff0dce6f2ace4d66dd139f7" }
sp-std = { version = "8.0.0", default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "c90d6edfd8c63168eff0dce6f2ace4d66dd139f7" }
Expand All @@ -45,6 +46,7 @@ std = [
"scale-info/std",
"sp-core/std",
"sp-domains/std",
"sp-domains-fraud-proof/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
Expand Down
21 changes: 9 additions & 12 deletions crates/pallet-domains/src/block_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::pallet::StateRoots;
use crate::{
BalanceOf, BlockTree, Config, ConsensusBlockInfo, DomainBlockDescendants, DomainBlocks,
BalanceOf, BlockTree, Config, ConsensusBlockHash, DomainBlockDescendants, DomainBlocks,
ExecutionInbox, ExecutionReceiptOf, HeadReceiptNumber, InboxedBundleAuthor,
};
use codec::{Decode, Encode};
Expand Down Expand Up @@ -169,8 +169,8 @@ pub(crate) fn verify_execution_receipt<T: Config>(
);

let excepted_consensus_block_hash =
match ConsensusBlockInfo::<T>::get(domain_id, consensus_block_number) {
Some((hash, _)) => hash,
match ConsensusBlockHash::<T>::get(domain_id, consensus_block_number) {
Some(hash) => hash,
// The `initialize_block` of non-system pallets is skipped in the `validate_transaction`,
// thus the hash of best block, which is recorded in the this pallet's `on_initialize` hook,
// is unavailable at this point.
Expand Down Expand Up @@ -310,7 +310,7 @@ pub(crate) fn process_execution_receipt<T: Config>(
// its receipt's `extrinsics_root` anymore.
let _ = ExecutionInbox::<T>::clear_prefix((domain_id, to_prune), u32::MAX, None);

ConsensusBlockInfo::<T>::remove(
ConsensusBlockHash::<T>::remove(
domain_id,
execution_receipt.consensus_block_number,
);
Expand Down Expand Up @@ -469,11 +469,8 @@ mod tests {
if block_number != 1 {
// `ConsensusBlockHash` should be set to `Some` since last consensus block contains bundle
assert_eq!(
ConsensusBlockInfo::<Test>::get(domain_id, block_number - 1),
Some((
frame_system::Pallet::<Test>::block_hash(block_number - 1),
H256::default()
))
ConsensusBlockHash::<Test>::get(domain_id, block_number - 1),
Some(frame_system::Pallet::<Test>::block_hash(block_number - 1))
);
// ER point to last consensus block should have `NewHead` type
assert_eq!(
Expand Down Expand Up @@ -554,7 +551,7 @@ mod tests {
verify_execution_receipt::<Test>(domain_id, &pruned_receipt),
Error::InvalidExtrinsicsRoots
);
assert!(ConsensusBlockInfo::<Test>::get(
assert!(ConsensusBlockHash::<Test>::get(
domain_id,
pruned_receipt.consensus_block_number,
)
Expand Down Expand Up @@ -760,10 +757,10 @@ mod tests {
verify_execution_receipt::<Test>(domain_id, &future_receipt),
Error::UnavailableConsensusBlockHash
);
ConsensusBlockInfo::<Test>::insert(
ConsensusBlockHash::<Test>::insert(
domain_id,
future_receipt.consensus_block_number,
(future_receipt.consensus_block_hash, H256::default()),
future_receipt.consensus_block_hash,
);

// Return `UnknownParentBlockReceipt` error as its parent receipt is missing from the block tree
Expand Down
Loading

0 comments on commit f567ca7

Please sign in to comment.