Skip to content

Commit

Permalink
use sparse bitmap
Browse files Browse the repository at this point in the history
  • Loading branch information
claravanstaden committed Nov 21, 2024
1 parent 6f238eb commit b0115cd
Show file tree
Hide file tree
Showing 8 changed files with 452 additions and 441 deletions.
8 changes: 4 additions & 4 deletions bridges/snowbridge/pallets/inbound-queue-v2/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use snowbridge_router_primitives::inbound::v2::{ConvertMessage, Message};
use xcm::latest::Xcm;

pub fn dry_run<T>(message: Message, _proof: Proof) -> Result<Xcm<()>, Error<T>>
where
T: Config,
where
T: Config,
{
let xcm = T::MessageConverter::convert(message).map_err(|e| Error::<T>::ConvertMessage(e))?;
Ok(xcm)
let xcm = T::MessageConverter::convert(message).map_err(|e| Error::<T>::ConvertMessage(e))?;
Ok(xcm)
}
32 changes: 16 additions & 16 deletions bridges/snowbridge/pallets/inbound-queue-v2/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ use snowbridge_pallet_inbound_queue_fixtures_v2::register_token::make_register_t

#[benchmarks]
mod benchmarks {
use super::*;
use super::*;

#[benchmark]
fn submit() -> Result<(), BenchmarkError> {
let caller: T::AccountId = whitelisted_caller();
#[benchmark]
fn submit() -> Result<(), BenchmarkError> {
let caller: T::AccountId = whitelisted_caller();

let create_message = make_register_token_message();
let create_message = make_register_token_message();

T::Helper::initialize_storage(
create_message.finalized_header,
create_message.block_roots_root,
);
T::Helper::initialize_storage(
create_message.finalized_header,
create_message.block_roots_root,
);

#[block]
{
assert_ok!(InboundQueue::<T>::submit(
#[block]
{
assert_ok!(InboundQueue::<T>::submit(
RawOrigin::Signed(caller.clone()).into(),
create_message.message,
));
}
}

Ok(())
}
Ok(())
}

impl_benchmark_test_suite!(InboundQueue, crate::mock::new_tester(), crate::mock::Test);
impl_benchmark_test_suite!(InboundQueue, crate::mock::new_tester(), crate::mock::Test);
}
40 changes: 20 additions & 20 deletions bridges/snowbridge/pallets/inbound-queue-v2/src/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,33 @@ sol! {
/// An inbound message that has had its outer envelope decoded.
#[derive(Clone, RuntimeDebug)]
pub struct Envelope {
/// The address of the outbound queue on Ethereum that emitted this message as an event log
pub gateway: H160,
/// A nonce for enforcing replay protection and ordering.
pub nonce: u64,
/// Total fee paid in Ether on Ethereum, should cover all the cost
pub fee: u128,
/// The inner payload generated from the source application.
pub payload: Vec<u8>,
/// The address of the outbound queue on Ethereum that emitted this message as an event log
pub gateway: H160,
/// A nonce for enforcing replay protection and ordering.
pub nonce: u64,
/// Total fee paid in Ether on Ethereum, should cover all the cost
pub fee: u128,
/// The inner payload generated from the source application.
pub payload: Vec<u8>,
}

#[derive(Copy, Clone, RuntimeDebug)]
pub struct EnvelopeDecodeError;

impl TryFrom<&Log> for Envelope {
type Error = EnvelopeDecodeError;
type Error = EnvelopeDecodeError;

fn try_from(log: &Log) -> Result<Self, Self::Error> {
let topics: Vec<B256> = log.topics.iter().map(|x| B256::from_slice(x.as_ref())).collect();
fn try_from(log: &Log) -> Result<Self, Self::Error> {
let topics: Vec<B256> = log.topics.iter().map(|x| B256::from_slice(x.as_ref())).collect();

let event = OutboundMessageAccepted::decode_log(topics, &log.data, true)
.map_err(|_| EnvelopeDecodeError)?;
let event = OutboundMessageAccepted::decode_log(topics, &log.data, true)
.map_err(|_| EnvelopeDecodeError)?;

Ok(Self {
gateway: log.address,
nonce: event.nonce,
fee: event.fee,
payload: event.payload,
})
}
Ok(Self {
gateway: log.address,
nonce: event.nonce,
fee: event.fee,
payload: event.payload,
})
}
}
Loading

0 comments on commit b0115cd

Please sign in to comment.