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

XDM: Relayer and Fraud proof updates #2562

Merged
merged 6 commits into from
Mar 5, 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
20 changes: 19 additions & 1 deletion Cargo.lock

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

7 changes: 7 additions & 0 deletions crates/pallet-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1988,6 +1988,13 @@ impl<T: Config> Pallet<T> {
.unwrap_or_default()
}

pub fn latest_confirmed_domain_block(
domain_id: DomainId,
) -> Option<(DomainBlockNumberFor<T>, T::DomainHash)> {
LatestConfirmedDomainBlock::<T>::get(domain_id)
.map(|block| (block.block_number, block.block_hash))
}

/// Returns the domain block limit of the given domain.
pub fn domain_block_limit(domain_id: DomainId) -> Option<DomainBlockLimit> {
DomainRegistry::<T>::get(domain_id).map(|domain_obj| DomainBlockLimit {
Expand Down
5 changes: 4 additions & 1 deletion crates/sp-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1245,9 +1245,12 @@ sp_api::decl_runtime_apis! {
/// Returns the execution receipt hash of the given domain and domain block number
fn receipt_hash(domain_id: DomainId, domain_number: HeaderNumberFor<DomainHeader>) -> Option<HeaderHashFor<DomainHeader>>;

/// Reture the consensus chain byte fee that will used to charge the domain transaction for consensus
/// Return the consensus chain byte fee that will used to charge the domain transaction for consensus
/// chain storage fee
fn consensus_chain_byte_fee() -> Balance;

/// Returns the latest confirmed domain block number and hash
fn latest_confirmed_domain_block(domain_id: DomainId) -> Option<(HeaderNumberFor<DomainHeader>, HeaderHashFor<DomainHeader>)>;
}

pub trait BundleProducerElectionApi<Balance: Encode + Decode> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ fn main() -> Result<(), Error> {
})?
.unwrap_or_default();

let consensus_state_pruning_mode = consensus_chain_config
let consensus_state_pruning = consensus_chain_config
.state_pruning
.clone()
.unwrap_or_default();
Expand Down Expand Up @@ -273,7 +273,7 @@ fn main() -> Result<(), Error> {
let relayer_worker =
domain_client_message_relayer::worker::relay_consensus_chain_messages(
consensus_chain_node.client.clone(),
consensus_state_pruning_mode,
consensus_state_pruning.clone(),
consensus_chain_node.sync_service.clone(),
xdm_gossip_worker_builder.gossip_msg_sink(),
);
Expand Down Expand Up @@ -338,6 +338,7 @@ fn main() -> Result<(), Error> {
consensus_sync_service: consensus_chain_node.sync_service.clone(),
domain_message_receiver,
gossip_message_sink: xdm_gossip_worker_builder.gossip_msg_sink(),
consensus_state_pruning,
};

consensus_chain_node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use sc_consensus_subspace::block_import::BlockImportingNotification;
use sc_consensus_subspace::notification::SubspaceNotificationStream;
use sc_consensus_subspace::slot_worker::NewSlotNotification;
use sc_network::NetworkPeers;
use sc_service::PruningMode;
use sc_transaction_pool_api::OffchainTransactionPoolFactory;
use sc_utils::mpsc::{TracingUnboundedReceiver, TracingUnboundedSender};
use sp_core::traits::SpawnEssentialNamed;
Expand Down Expand Up @@ -40,6 +41,7 @@ pub struct DomainInstanceStarter<CNetwork> {
pub domain_message_receiver: TracingUnboundedReceiver<ChainTxPoolMsg>,
pub gossip_message_sink: TracingUnboundedSender<Message>,
pub consensus_network: Arc<CNetwork>,
pub consensus_state_pruning: PruningMode,
}

impl<CNetwork> DomainInstanceStarter<CNetwork>
Expand Down Expand Up @@ -74,6 +76,7 @@ where
domain_message_receiver,
gossip_message_sink,
consensus_network,
consensus_state_pruning,
} = self;

let domain_id = domain_cli.domain_id.into();
Expand Down Expand Up @@ -150,6 +153,7 @@ where
skip_empty_bundle_production: true,
// Always set it to `None` to not running the normal bundle producer
maybe_operator_id: None,
consensus_state_pruning,
};

let mut domain_node = domain_service::new_full::<
Expand Down
11 changes: 6 additions & 5 deletions crates/subspace-node/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ pub async fn run(run_options: RunOptions) -> Result<(), Error> {
info!("🏷 Node name: {}", subspace_configuration.network.node_name);
info!("💾 Node path: {}", base_path.display());

let consensus_state_pruning = subspace_configuration
.state_pruning
.clone()
.unwrap_or_default();
let mut task_manager = {
let consensus_state_pruning_mode = subspace_configuration
.state_pruning
.clone()
.unwrap_or_default();
let consensus_chain_node = {
let span = info_span!("Consensus");
let _enter = span.enter();
Expand Down Expand Up @@ -178,7 +178,7 @@ pub async fn run(run_options: RunOptions) -> Result<(), Error> {
Box::pin(
domain_client_message_relayer::worker::relay_consensus_chain_messages(
consensus_chain_node.client.clone(),
consensus_state_pruning_mode,
consensus_state_pruning.clone(),
consensus_chain_node.sync_service.clone(),
xdm_gossip_worker_builder.gossip_msg_sink(),
),
Expand Down Expand Up @@ -242,6 +242,7 @@ pub async fn run(run_options: RunOptions) -> Result<(), Error> {
consensus_network_sync_oracle: consensus_chain_node.sync_service,
domain_message_receiver,
gossip_message_sink,
consensus_state_pruning,
};

consensus_chain_node
Expand Down
5 changes: 4 additions & 1 deletion crates/subspace-node/src/commands/run/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use sc_informant::OutputFormat;
use sc_network::config::{MultiaddrWithPeerId, NonReservedPeerMode, SetConfig, TransportConfig};
use sc_network::NetworkPeers;
use sc_service::config::KeystoreConfig;
use sc_service::Configuration;
use sc_service::{Configuration, PruningMode};
use sc_transaction_pool_api::OffchainTransactionPoolFactory;
use sc_utils::mpsc::{TracingUnboundedReceiver, TracingUnboundedSender};
use sp_core::crypto::SecretString;
Expand Down Expand Up @@ -384,6 +384,7 @@ pub(super) struct DomainStartOptions<CNetwork> {
pub(super) domain_message_receiver:
TracingUnboundedReceiver<cross_domain_message_gossip::ChainTxPoolMsg>,
pub(super) gossip_message_sink: TracingUnboundedSender<cross_domain_message_gossip::Message>,
pub(super) consensus_state_pruning: PruningMode,
}

pub(super) async fn run_evm_domain<CNetwork>(
Expand Down Expand Up @@ -426,6 +427,7 @@ where
consensus_network_sync_oracle,
domain_message_receiver,
gossip_message_sink,
consensus_state_pruning,
} = domain_start_options;

let block_importing_notification_stream = block_importing_notification_stream.subscribe().then(
Expand Down Expand Up @@ -484,6 +486,7 @@ where
provider: eth_provider,
skip_empty_bundle_production: true,
maybe_operator_id: operator_id,
consensus_state_pruning,
};

let mut domain_node = domain_service::new_full::<
Expand Down
34 changes: 16 additions & 18 deletions crates/subspace-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ use sp_domains::{
};
use sp_domains_fraud_proof::fraud_proof::FraudProof;
use sp_messenger::endpoint::{Endpoint, EndpointHandler as EndpointHandlerT, EndpointId};
use sp_messenger::messages::{BlockMessagesWithStorageKey, ChainId, CrossDomainMessage, MessageId};
use sp_messenger::messages::{
BlockMessagesWithStorageKey, ChainId, CrossDomainMessage, MessageId, MessageKey,
};
use sp_messenger_host_functions::{get_storage_key, StorageKeyRequest};
use sp_mmr_primitives::{EncodableOpaqueLeaf, Proof};
use sp_runtime::traits::{
Expand Down Expand Up @@ -499,17 +501,17 @@ impl sp_messenger::StorageKeys for StorageKeys {
Some(Domains::confirmed_domain_block_storage_key(domain_id))
}

fn outbox_storage_key(chain_id: ChainId, message_id: MessageId) -> Option<Vec<u8>> {
fn outbox_storage_key(chain_id: ChainId, message_key: MessageKey) -> Option<Vec<u8>> {
get_storage_key(StorageKeyRequest::OutboxStorageKey {
chain_id,
message_id,
message_key,
})
}

fn inbox_responses_storage_key(chain_id: ChainId, message_id: MessageId) -> Option<Vec<u8>> {
fn inbox_responses_storage_key(chain_id: ChainId, message_key: MessageKey) -> Option<Vec<u8>> {
get_storage_key(StorageKeyRequest::InboxResponseStorageKey {
chain_id,
message_id,
message_key,
})
}
}
Expand Down Expand Up @@ -1104,6 +1106,10 @@ impl_runtime_apis! {
fn consensus_chain_byte_fee() -> Balance {
DOMAIN_STORAGE_FEE_MULTIPLIER * TransactionFees::transaction_byte_fee()
}

fn latest_confirmed_domain_block(domain_id: DomainId) -> Option<(DomainNumber, DomainHash)>{
Domains::latest_confirmed_domain_block(domain_id)
}
}

impl sp_domains::BundleProducerElectionApi<Block, Balance> for Runtime {
Expand Down Expand Up @@ -1166,24 +1172,16 @@ impl_runtime_apis! {
Domains::confirmed_domain_block_storage_key(domain_id)
}

fn outbox_storage_key(message_id: MessageId) -> Vec<u8> {
Messenger::outbox_storage_key(message_id)
fn outbox_storage_key(message_key: MessageKey) -> Vec<u8> {
Messenger::outbox_storage_key(message_key)
}

fn inbox_response_storage_key(message_id: MessageId) -> Vec<u8> {
Messenger::inbox_response_storage_key(message_id)
fn inbox_response_storage_key(message_key: MessageKey) -> Vec<u8> {
Messenger::inbox_response_storage_key(message_key)
}
}

impl sp_messenger::RelayerApi<Block, BlockNumber> for Runtime {
fn chain_id() -> ChainId {
SelfChainId::get()
}

fn relay_confirmation_depth() -> BlockNumber {
RelayConfirmationDepth::get()
}

impl sp_messenger::RelayerApi<Block, BlockNumber, <Block as BlockT>::Hash> for Runtime {
fn block_messages() -> BlockMessagesWithStorageKey {
Messenger::get_block_messages()
}
Expand Down
11 changes: 11 additions & 0 deletions crates/subspace-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ use sp_consensus_subspace::digests::extract_pre_digest;
use sp_consensus_subspace::{
FarmerPublicKey, KzgExtension, PosExtension, PotExtension, PotNextSlotInput, SubspaceApi,
};
use sp_core::offchain::storage::OffchainDb;
use sp_core::offchain::OffchainDbExt;
use sp_core::traits::SpawnEssentialNamed;
use sp_core::H256;
use sp_domains::{BundleProducerElectionApi, DomainsApi};
Expand Down Expand Up @@ -227,6 +229,7 @@ pub type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;
struct SubspaceExtensionsFactory<PosTable, Client, DomainBlock> {
kzg: Kzg,
client: Arc<Client>,
backend: Arc<FullBackend>,
pot_verifier: PotVerifier,
executor: Arc<RuntimeExecutor>,
domains_executor: Arc<sc_domains::RuntimeExecutor>,
Expand Down Expand Up @@ -389,6 +392,13 @@ where
),
)));

// if the offchain storage is available, then add offchain extension
// to generate and verify MMR proofs
if let Some(offchain_storage) = self.backend.offchain_storage() {
let offchain_db = OffchainDb::new(offchain_storage);
exts.register(OffchainDbExt::new(offchain_db));
}

exts
}
}
Expand Down Expand Up @@ -485,6 +495,7 @@ where
pot_verifier: pot_verifier.clone(),
executor: executor.clone(),
domains_executor: Arc::new(domains_executor),
backend: backend.clone(),
_pos_table: PhantomData,
});

Expand Down
10 changes: 5 additions & 5 deletions domains/client/block-preprocessor/src/stateless_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use sp_api::{ApiError, Core};
use sp_core::traits::{CallContext, CodeExecutor, FetchRuntimeCode, RuntimeCode};
use sp_core::Hasher;
use sp_domains::core_api::DomainCoreApi;
use sp_messenger::messages::MessageId;
use sp_messenger::messages::MessageKey;
use sp_messenger::MessengerApi;
use sp_runtime::traits::{Block as BlockT, NumberFor};
use sp_runtime::Storage;
Expand Down Expand Up @@ -148,20 +148,20 @@ where
})
}

pub fn outbox_storage_key(&self, message_id: MessageId) -> Result<Vec<u8>, ApiError> {
pub fn outbox_storage_key(&self, message_key: MessageKey) -> Result<Vec<u8>, ApiError> {
let storage_key = <Self as MessengerApi<Block, _>>::outbox_storage_key(
self,
Default::default(),
message_id,
message_key,
)?;
Ok(storage_key)
}

pub fn inbox_response_storage_key(&self, message_id: MessageId) -> Result<Vec<u8>, ApiError> {
pub fn inbox_response_storage_key(&self, message_key: MessageKey) -> Result<Vec<u8>, ApiError> {
let storage_key = <Self as MessengerApi<Block, _>>::inbox_response_storage_key(
self,
Default::default(),
message_id,
message_key,
)?;
Ok(storage_key)
}
Expand Down
3 changes: 3 additions & 0 deletions domains/client/domain-operator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ evm-domain-test-runtime = { version = "0.1.0", path = "../../test/runtime/evm" }
frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" }
pallet-balances = { version = "4.0.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" }
pallet-domains = { version = "0.1.0", path = "../../../crates/pallet-domains" }
pallet-messenger = { version = "0.1.0", path = "../../../domains/pallets/messenger" }
pallet-sudo = { version = "4.0.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" }
pallet-timestamp = { version = "4.0.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" }
pallet-transporter = { version = "0.1.0", path = "../../../domains/pallets/transporter" }
sc-cli = { version = "0.10.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8", default-features = false }
sc-service = { version = "0.10.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8", default-features = false }
sc-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" }
Expand Down
Loading