Skip to content

Commit

Permalink
Add topic id for outbound tracing (paritytech#35)
Browse files Browse the repository at this point in the history
* Add topic id

* Update Cargo.lock

* Update the abi Message

* Update test fixture
  • Loading branch information
yrong authored Mar 7, 2025
1 parent a0b609e commit e2a43b4
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
1 change: 1 addition & 0 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 bridges/snowbridge/pallets/outbound-queue-v2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ pub mod pallet {
let committed_message = OutboundMessageWrapper {
origin: FixedBytes::from(origin.as_fixed_bytes()),
nonce,
topic: FixedBytes::from(id.as_fixed_bytes()),
commands: abi_commands,
};
let message_abi_encoded_hash =
Expand All @@ -344,6 +345,7 @@ pub mod pallet {
let outbound_message = OutboundMessage {
origin,
nonce,
topic: id,
commands: commands.try_into().map_err(|_| Corrupt)?,
};
Messages::<T>::append(outbound_message);
Expand Down
15 changes: 15 additions & 0 deletions bridges/snowbridge/pallets/outbound-queue-v2/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,18 @@ pub fn mock_message(sibling_para_id: u32) -> Message {
.unwrap(),
}
}

pub fn mock_register_token_message(sibling_para_id: u32) -> Message {
Message {
origin: H256::from_low_u64_be(sibling_para_id as u64),
id: H256::from_low_u64_be(1),
fee: 1_000,
commands: BoundedVec::try_from(vec![Command::RegisterForeignToken {
token_id: H256::from_low_u64_be(1),
name: vec![],
symbol: vec![],
decimals: 12,
}])
.unwrap(),
}
}
22 changes: 18 additions & 4 deletions bridges/snowbridge/pallets/outbound-queue-v2/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,7 @@ fn encode_digest_item() {
});
}

#[test]
fn encode_mock_message() {
let message: Message = mock_message(1000);
fn encode_mock_message(message: Message) -> Vec<u8> {
let commands: Vec<CommandWrapper> = message
.commands
.into_iter()
Expand All @@ -247,9 +245,25 @@ fn encode_mock_message() {
let committed_message = OutboundMessageWrapper {
origin: FixedBytes::from(message.origin.as_fixed_bytes()),
nonce: 1,
topic: FixedBytes::from(message.id.as_fixed_bytes()),
commands,
};
let message_abi_encoded = committed_message.abi_encode();
message_abi_encoded
}

#[test]
fn encode_unlock_message() {
let message: Message = mock_message(1000);
let message_abi_encoded = encode_mock_message(message);
println!("{}", HexDisplay::from(&message_abi_encoded));
assert_eq!(hex!("000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000003e800000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000186a000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000060000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000eda338e4dc46038493b885327842fd3e301cab3900000000000000000000000000000000000000000000000000000000000f4240").to_vec(), message_abi_encoded)
}

#[test]
fn encode_register_pna() {
let message: Message = mock_register_token_message(1000);
let message_abi_encoded = encode_mock_message(message);
println!("{}", HexDisplay::from(&message_abi_encoded));
assert_eq!(hex!("000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000003e80000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000186a000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000060000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000eda338e4dc46038493b885327842fd3e301cab3900000000000000000000000000000000000000000000000000000000000f4240").to_vec(), message_abi_encoded)
assert_eq!(hex!("000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000003e80000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000124f80000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").to_vec(), message_abi_encoded)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub mod abi {
bytes32 origin;
// Message nonce
uint64 nonce;
// Topic
bytes32 topic;
// Commands
CommandWrapper[] commands;
}
Expand Down Expand Up @@ -110,6 +112,8 @@ pub struct OutboundMessage {
pub origin: H256,
/// Nonce
pub nonce: u64,
/// Topic
pub topic: H256,
/// Commands
pub commands: BoundedVec<OutboundCommandWrapper, ConstU32<MAX_COMMANDS>>,
}
Expand Down

0 comments on commit e2a43b4

Please sign in to comment.