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 1 commit
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
103 changes: 65 additions & 38 deletions crates/sp-domains-fraud-proof/src/fraud_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,45 +556,72 @@ impl<Number, Hash, DomainHeader: HeaderT> fmt::Display for FraudProof<Number, Ha
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")
}
match self {
Self::InvalidStateTransition(_) => {
write!(
f,
"InvalidStateTransition({domain_id:?}#{bad_receipt_hash:?}) fraud proof"
)
}
.as_str(),
)
Self::InvalidTransaction(_) => {
write!(
f,
"InvalidTransaction({domain_id:?}#{bad_receipt_hash:?}) fraud proof"
)
}
Self::ImproperTransactionSortition(_) => {
write!(
f,
"ImproperTransactionSortition({domain_id:?}#{bad_receipt_hash:?}) fraud proof"
)
}
Self::BundleEquivocation(_) => {
write!(
f,
"BundleEquivocation({domain_id:?}#{bad_operator:?}) fraud proof"
)
}
Self::InvalidExtrinsicsRoot(_) => {
write!(
f,
"InvalidExtrinsicsRoot({domain_id:?}#{bad_receipt_hash:?}) fraud proof"
)
}
Self::InvalidBlockFees(_) => {
write!(
f,
"InvalidBlockFees({domain_id:?}#{bad_receipt_hash:?}) fraud proof"
)
}
Self::ValidBundle(_) => {
write!(
f,
"ValidBundle({domain_id:?}#{bad_receipt_hash:?}) fraud proof"
)
}
Self::InvalidBundles(_) => {
write!(
f,
"InvalidBundles({domain_id:?}#{bad_receipt_hash:?}) fraud proof"
)
}
Self::InvalidDomainBlockHash(_) => {
write!(
f,
"InvalidDomainBlockHash({domain_id:?}#{bad_receipt_hash:?}) fraud proof"
)
}
Self::InvalidTransfers(_) => {
write!(
f,
"InvalidTransfers({domain_id:?}#{bad_receipt_hash:?}) fraud proof"
)
}
#[cfg(any(feature = "std", feature = "runtime-benchmarks"))]
Self::Dummy { .. } => {
write!(f, "Dummy({domain_id:?}#{bad_receipt_hash:?}) fraud proof")
}
}
}
}

Expand Down
13 changes: 8 additions & 5 deletions domains/client/block-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ where
backend: &'a B,
mut extrinsics: VecDeque<Block::Extrinsic>,
maybe_inherent_data: Option<sp_inherents::InherentData>,
is_gemini_3h: bool,
) -> Result<Self, Error> {
let header = <<Block as BlockT>::Header as HeaderT>::new(
parent_number + One::one(),
Expand All @@ -182,11 +183,13 @@ where

// 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();
// HACK: ideally, any network should maintain the inherent extrinsic order to keep consistency
// with the order in the fraud proof verifiaction side, but 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 =
!is_gemini_3h || parent_number >= 168430u32.into();

if maintain_runtime_inherent_extrinsic_order {
// reverse and push the inherents so that order is maintained
Expand Down
11 changes: 11 additions & 0 deletions domains/client/domain-operator/src/domain_block_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use sp_runtime::traits::{Block as BlockT, Header as HeaderT, NumberFor, One, Zer
use sp_runtime::{Digest, Saturating};
use std::cmp::Ordering;
use std::collections::VecDeque;
use std::str::FromStr;
use std::sync::Arc;

struct DomainBlockBuildResult<Block>
Expand Down Expand Up @@ -419,6 +420,15 @@ where
inherent_digests: Digest,
inherent_data: sp_inherents::InherentData,
) -> Result<DomainBlockBuildResult<Block>, sp_blockchain::Error> {
// TODO: This is used to keep compatible with gemini-3h, remove before next network
let is_gemini_3h = self.consensus_client.info().genesis_hash
== FromStr::from_str(
// The genesis hash of gemini-3h
"0c121c75f4ef450f40619e1fca9d1e8e7fbabc42c895bc4790801e85d5a91c34",
)
.map_err(|_| ())
.expect("parsing consensus block hash should success");
Comment on lines +424 to +430
Copy link
Member

Choose a reason for hiding this comment

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

Assuming parsing works, this should do the job, but even better way would be to define genesis has as [u8; 32] constant and store boolean result as a property of the data structure to not query info all the time since genesis hash never changes.


let block_builder = BlockBuilder::new(
&*self.client,
parent_hash,
Expand All @@ -428,6 +438,7 @@ where
&*self.backend,
extrinsics,
Some(inherent_data),
is_gemini_3h,
)?;

let BuiltBlock {
Expand Down
1 change: 1 addition & 0 deletions domains/client/domain-operator/src/fraud_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ where
&*self.backend,
extrinsics.into(),
None,
false,
)?;

let (storage_changes, call_data) = match &execution_phase {
Expand Down
Loading