Skip to content

Commit 182a11b

Browse files
authored
Merge pull request #4 from yrong/ron/improve-comments
Improve comments
2 parents 9648ae1 + 8741f06 commit 182a11b

File tree

9 files changed

+50
-48
lines changed

9 files changed

+50
-48
lines changed

Diff for: bridges/snowbridge/pallets/outbound-queue-v2/README.md

-3
This file was deleted.

Diff for: bridges/snowbridge/pallets/outbound-queue-v2/runtime-api/README.md

-6
This file was deleted.

Diff for: bridges/snowbridge/pallets/outbound-queue-v2/runtime-api/src/lib.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]>
3-
#![cfg_attr(not(feature = "std"), no_std)]
43

4+
//! Ethereum Outbound Queue V2 Runtime API
5+
//!
6+
//! * `prove_message`: Generate a merkle proof for a committed message
7+
//! * `dry_run`: dry run the xcm to get a message structure to execute on Ethereum
8+
9+
#![cfg_attr(not(feature = "std"), no_std)]
510
use frame_support::traits::tokens::Balance as BalanceT;
611
use snowbridge_merkle_tree::MerkleProof;
7-
use snowbridge_outbound_queue_primitives::v2::{OutboundMessage, DryRunError};
12+
use snowbridge_outbound_queue_primitives::v2::{DryRunError, OutboundMessage};
813
use xcm::prelude::Xcm;
914

1015
sp_api::decl_runtime_apis! {
@@ -15,6 +20,8 @@ sp_api::decl_runtime_apis! {
1520
/// `sp_runtime::generic::DigestItem::Other`
1621
fn prove_message(leaf_index: u64) -> Option<MerkleProof>;
1722

23+
/// Dry run the xcm to get the OutboundMessage
24+
/// which can be used to estimate the execution cost on Ethereum
1825
fn dry_run(xcm: Xcm<()>) -> Result<(OutboundMessage,Balance),DryRunError>;
1926
}
2027
}

Diff for: bridges/snowbridge/pallets/outbound-queue-v2/src/lib.rs

+25-15
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,38 @@
55
//! # Overview
66
//!
77
//! Messages come either from sibling parachains via XCM, or BridgeHub itself
8-
//! via the `snowbridge-pallet-system`:
8+
//! via the `snowbridge-pallet-system-v2`:
99
//!
1010
//! 1. `snowbridge_outbound_queue_primitives::v2::EthereumBlobExporter::deliver`
11-
//! 2. `snowbridge_pallet_system::Pallet::send_v2`
11+
//! 2. `snowbridge_pallet_system_v2::Pallet::send`
1212
//!
1313
//! The message submission pipeline works like this:
1414
//! 1. The message is first validated via the implementation for
1515
//! [`snowbridge_outbound_queue_primitives::v2::SendMessage::validate`]
1616
//! 2. The message is then enqueued for later processing via the implementation for
1717
//! [`snowbridge_outbound_queue_primitives::v2::SendMessage::deliver`]
1818
//! 3. The underlying message queue is implemented by [`Config::MessageQueue`]
19-
//! 4. The message queue delivers messages back to this pallet via the implementation for
19+
//! 4. The message queue delivers messages to this pallet via the implementation for
2020
//! [`frame_support::traits::ProcessMessage::process_message`]
21-
//! 5. The message is processed in `Pallet::do_process_message`: a. Assigned a nonce b. ABI-encoded,
22-
//! hashed, and stored in the `MessageLeaves` vector
23-
//! 6. At the end of the block, a merkle root is constructed from all the leaves in `MessageLeaves`.
21+
//! 5. The message is processed in `Pallet::do_process_message`:
22+
//! a. Convert to `OutboundMessage`, and stored into the `Messages` vector storage
23+
//! b. ABI-encoded the OutboundMessage, with commited hash stored into the `MessageLeaves` storage
24+
//! c. Generate `PendingOrder` with assigned nonce and fee attach, stored into the `PendingOrders`
25+
//! map storage, with nonce as the key
26+
//! d. Increment nonce and update the `Nonce` storage
27+
//! 6. At the end of the block, a merkle root is constructed from all the leaves in `MessageLeaves`,
28+
//! then `MessageLeaves` is dropped so that it is never committed to storage or included in PoV.
2429
//! 7. This merkle root is inserted into the parachain header as a digest item
25-
//! 8. Offchain relayers are able to relay the message to Ethereum after: a. Generating a merkle
26-
//! proof for the committed message using the `prove_message` runtime API b. Reading the actual
27-
//! message content from the `Messages` vector in storage
28-
//!
29-
//! On the Ethereum side, the message root is ultimately the thing being
30-
//! verified by the Polkadot light client.
30+
//! 8. Offchain relayers are able to relay the message to Ethereum after:
31+
//! a. Generating a merkle proof for the committed message using the `prove_message` runtime API
32+
//! b. Reading the actual message content from the `Messages` vector in storage
33+
//! 9. On the Ethereum side, the message root is ultimately the thing being verified by the Beefy
34+
//! light client. When the message has been verified and executed, the relayer will call the
35+
//! extrinsic `submit_delivery_proof` work the way as follows:
36+
//! a. Verify the message with proof for a transaction receipt containing the event log,
37+
//! same as the inbound queue verification flow
38+
//! b. Fetch the pending order by nonce of the message, pay reward with fee attached in the order
39+
//! c. Remove the order from `PendingOrders` map storage by nonce
3140
//!
3241
//! # Message Priorities
3342
//!
@@ -38,6 +47,7 @@
3847
//! # Extrinsics
3948
//!
4049
//! * [`Call::set_operating_mode`]: Set the operating mode
50+
//! * [`Call::submit_delivery_proof`]: Submit delivery proof
4151
//!
4252
//! # Runtime API
4353
//!
@@ -334,7 +344,7 @@ pub mod pallet {
334344
let nonce = Nonce::<T>::get();
335345

336346
// Decode bytes into Message and
337-
// a. Convert to InboundMessage and save into Messages
347+
// a. Convert to OutboundMessage and save into Messages
338348
// b. Convert to committed hash and save into MessageLeaves
339349
// c. Save nonce&fee into PendingOrders
340350
let message: Message = Message::decode(&mut message).map_err(|_| Corrupt)?;
@@ -367,12 +377,12 @@ pub mod pallet {
367377
<T as Config>::Hashing::hash(&committed_message.abi_encode());
368378
MessageLeaves::<T>::append(message_abi_encoded_hash);
369379

370-
let inbound_message = OutboundMessage {
380+
let outbound_message = OutboundMessage {
371381
origin: message.origin,
372382
nonce,
373383
commands: commands.try_into().map_err(|_| Corrupt)?,
374384
};
375-
Messages::<T>::append(Box::new(inbound_message));
385+
Messages::<T>::append(Box::new(outbound_message));
376386

377387
let order = PendingOrder {
378388
nonce,

Diff for: bridges/snowbridge/pallets/system-frontend/README.md

-3
This file was deleted.

Diff for: bridges/snowbridge/pallets/system-frontend/src/lib.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]>
3-
//! Frontend for calling Snowbridge System Pallet on BridgeHub
3+
//! Frontend which will be deployed on AssetHub for calling the V2 system pallet
4+
//! on BridgeHub.
45
//!
56
//! # Extrinsics
67
//!
7-
//! * [`Call::create_agent`]: Create agent for any sovereign location from non-system parachain
8-
//! * [`Call::register_token`]: Register a foreign token location from non-system parachain
8+
//! * [`Call::create_agent`]: Create agent for any kind of sovereign location on Polkadot network.
9+
//! * [`Call::register_token`]: Register Polkadot native asset as a wrapped ERC20 token on Ethereum.
910
#![cfg_attr(not(feature = "std"), no_std)]
1011
#[cfg(test)]
1112
mod mock;
@@ -113,10 +114,9 @@ pub mod pallet {
113114

114115
#[pallet::call]
115116
impl<T: Config> Pallet<T> {
116-
/// Call `create_agent` on Bridge Hub to instantiate a new agent contract representing
117-
/// `origin`.
118-
/// - `origin`: Must be `Location` from a sibling parachain
119-
/// - `fee`: Fee in Ether
117+
/// Call `create_agent` to instantiate a new agent contract representing `origin`.
118+
/// - `origin`: Can be any sovereign `Location`
119+
/// - `fee`: Fee in Ether paying for the execution cost on Ethreum
120120
#[pallet::call_index(1)]
121121
#[pallet::weight(T::WeightInfo::create_agent())]
122122
pub fn create_agent(origin: OriginFor<T>, fee: u128) -> DispatchResult {
@@ -150,6 +150,7 @@ pub mod pallet {
150150
/// - `origin`: Must be `Location` from a sibling parachain
151151
/// - `asset_id`: Location of the asset (should starts from the dispatch origin)
152152
/// - `metadata`: Metadata to include in the instantiated ERC20 contract on Ethereum
153+
/// - `fee`: Fee in Ether paying for the execution cost on Ethreum
153154
#[pallet::call_index(2)]
154155
#[pallet::weight(T::WeightInfo::register_token())]
155156
pub fn register_token(

Diff for: bridges/snowbridge/pallets/system-v2/README.md

-4
This file was deleted.

Diff for: bridges/snowbridge/pallets/system-v2/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
//! Agents are smart contracts on Ethereum that act as proxies for consensus systems on Polkadot
1010
//! networks.
1111
//!
12-
//! * [`Call::create_agent`]: Create agent for a sibling parachain
12+
//! * [`Call::create_agent`]: Create agent for any kind of sovereign location on Polkadot network,
13+
//! can be a sibling parachain, pallet or smart contract or signed account in that parachain, etc
14+
1315
//! ## Polkadot-native tokens on Ethereum
1416
//!
1517
//! Tokens deposited on AssetHub pallet can be bridged to Ethereum as wrapped ERC20 tokens. As a

Diff for: bridges/snowbridge/primitives/outbound-queue/src/v2/message_receipt.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]>
33
use crate::Log;
4-
5-
use sp_core::{RuntimeDebug, H160};
6-
use sp_std::prelude::*;
7-
84
use alloy_core::{primitives::B256, sol, sol_types::SolEvent};
95
use codec::Decode;
106
use frame_support::pallet_prelude::{Encode, TypeInfo};
7+
use sp_core::{RuntimeDebug, H160};
8+
use sp_std::prelude::*;
119

1210
sol! {
1311
event InboundMessageDispatched(uint64 indexed nonce, bool success, bytes32 reward_address);
1412
}
1513

16-
/// An inbound message that has had its outer envelope decoded.
14+
/// Envelope of the delivery proof
1715
#[derive(Clone, RuntimeDebug)]
1816
pub struct MessageReceipt<AccountId>
1917
where
20-
AccountId: From<[u8; 32]> + Clone
18+
AccountId: From<[u8; 32]> + Clone,
2119
{
2220
/// The address of the outbound queue on Ethereum that emitted this message as an event log
2321
pub gateway: H160,
@@ -37,7 +35,7 @@ pub enum MessageReceiptDecodeError {
3735

3836
impl<AccountId> TryFrom<&Log> for MessageReceipt<AccountId>
3937
where
40-
AccountId: From<[u8; 32]> + Clone
38+
AccountId: From<[u8; 32]> + Clone,
4139
{
4240
type Error = MessageReceiptDecodeError;
4341

0 commit comments

Comments
 (0)