Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep domain compatible with gemini-3h #2638

Merged
merged 4 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/pallet-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,7 @@ mod pallet {
if let Err(e) = Self::validate_fraud_proof(fraud_proof) {
log::warn!(
target: "runtime::domains",
"Bad fraud proof {:?}, error: {e:?}", fraud_proof.domain_id(),
"Bad fraud proof {fraud_proof}, error: {e:?}",
);
return InvalidTransactionCode::FraudProof.into();
}
Expand Down
48 changes: 48 additions & 0 deletions crates/sp-domains-fraud-proof/src/fraud_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::verification::InvalidBundleEquivocationError;
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use codec::{Decode, Encode};
use core::fmt;
use scale_info::TypeInfo;
use sp_consensus_slots::Slot;
use sp_core::H256;
Expand Down Expand Up @@ -550,6 +551,53 @@ where
}
}

impl<Number, Hash, DomainHeader: HeaderT> fmt::Display for FraudProof<Number, Hash, DomainHeader> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let domain_id = self.domain_id();
let bad_receipt_hash = self.targeted_bad_receipt_hash();
let bad_operator = self.targeted_bad_operator_and_slot_for_bundle_equivocation();
f.write_str(
match self {
Self::InvalidStateTransition(_) => {
format!("InvalidStateTransition({domain_id:?}#{bad_receipt_hash:?}) fraud proof")
}
Self::InvalidTransaction(_) => {
format!("InvalidTransaction({domain_id:?}#{bad_receipt_hash:?}) fraud proof")
}
Self::ImproperTransactionSortition(_) => {
format!("ImproperTransactionSortition({domain_id:?}#{bad_receipt_hash:?}) fraud proof")
}
Self::BundleEquivocation(_) => {
format!("BundleEquivocation({domain_id:?}#{bad_operator:?}) fraud proof")
}
Self::InvalidExtrinsicsRoot(_) => {
format!("InvalidExtrinsicsRoot({domain_id:?}#{bad_receipt_hash:?}) fraud proof")
}
Self::InvalidBlockFees(_) => {
format!("InvalidBlockFees({domain_id:?}#{bad_receipt_hash:?}) fraud proof")
}
Self::ValidBundle(_) => {
format!("ValidBundle({domain_id:?}#{bad_receipt_hash:?}) fraud proof")
}
Self::InvalidBundles(_) => {
format!("InvalidBundles({domain_id:?}#{bad_receipt_hash:?}) fraud proof")
}
Self::InvalidDomainBlockHash(_) => {
format!("InvalidDomainBlockHash({domain_id:?}#{bad_receipt_hash:?}) fraud proof")
}
Self::InvalidTransfers(_) => {
format!("InvalidTransfers({domain_id:?}#{bad_receipt_hash:?}) fraud proof")
}
#[cfg(any(feature = "std", feature = "runtime-benchmarks"))]
Self::Dummy { .. } => {
format!("Dummy({domain_id:?}#{bad_receipt_hash:?}) fraud proof")
}
}
.as_str(),
)
}
}

/// Proves an invalid state transition by challenging the trace at specific index in a bad receipt.
#[derive(Debug, Decode, Encode, TypeInfo, PartialEq, Eq, Clone)]
pub struct InvalidStateTransitionProof<ReceiptHash> {
Expand Down
21 changes: 18 additions & 3 deletions domains/client/block-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,24 @@ where

if let Some(inherent_data) = maybe_inherent_data {
let inherent_extrinsics = Self::create_inherents(parent_hash, &api, inherent_data)?;
// reverse and push the inherents so that order is maintained
for inherent_extrinsic in inherent_extrinsics.into_iter().rev() {
extrinsics.push_front(inherent_extrinsic)

// TODO: This is used to keep compatible with gemini-3h, remove before next network
//
// HACK: in gemini-3h, the domain inherent extrinsic order is changed in the ER that derived
// from the consensus block #168431, we have to follow this change in the client side to ensure
// every domain node that sync from genesis will produce the same ER and hence can successfully
// submit ER to exend the previous ER.
let maintain_runtime_inherent_extrinsic_order = parent_number >= 168430u32.into();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also check that the chain is in fact Gemini 3h using genesis hash or something equivalent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added code to determine if the node is running in gemini-3h by checking the genesis hash, and tested in gemini-3h.


if maintain_runtime_inherent_extrinsic_order {
// reverse and push the inherents so that order is maintained
for inherent_extrinsic in inherent_extrinsics.into_iter().rev() {
extrinsics.push_front(inherent_extrinsic)
}
} else {
for inherent_extrinsic in inherent_extrinsics {
extrinsics.push_front(inherent_extrinsic)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,7 @@ where
if let Some(mismatched_receipts) = self.find_mismatch_receipt(consensus_block_hash)? {
let fraud_proof = self.generate_fraud_proof(mismatched_receipts)?;

tracing::info!("Submit fraud proof: {fraud_proof}");
let consensus_best_hash = self.consensus_client.info().best_hash;
let mut runtime_api = self.consensus_client.runtime_api();
runtime_api.register_extension(
Expand Down
Loading