Skip to content

Commit

Permalink
revert dont reward relayer
Browse files Browse the repository at this point in the history
  • Loading branch information
claravanstaden committed Jun 19, 2024
1 parent 50de744 commit 60774cd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 70 deletions.
17 changes: 4 additions & 13 deletions bridges/snowbridge/parachain/pallets/inbound-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,14 @@ use envelope::Envelope;
use frame_support::{
traits::{
fungible::{Inspect, Mutate},
tokens::{Fortitude, Preservation},
tokens::Preservation,
},
weights::WeightToFee,
PalletError,
};
use frame_system::ensure_signed;
use scale_info::TypeInfo;
use sp_core::{H160, H256};
use sp_runtime::traits::Zero;
use sp_std::{convert::TryFrom, vec};
use xcm::prelude::{
send_xcm, Instruction::SetTopic, Junction::*, Location, SendError as XcmpSendError, SendXcm,
Expand Down Expand Up @@ -262,19 +261,11 @@ pub mod pallet {
}
})?;

// Reward relayer from the sovereign account of the destination parachain, only if funds
// are available
// Reward relayer from the sovereign account of the destination parachain
// Expected to fail if sovereign account has no funds
let sovereign_account = sibling_sovereign_account::<T>(channel.para_id);
let delivery_cost = Self::calculate_delivery_cost(message.encode().len() as u32);
let amount = T::Token::reducible_balance(
&sovereign_account,
Preservation::Preserve,
Fortitude::Polite,
)
.min(delivery_cost);
if !amount.is_zero() {
T::Token::transfer(&sovereign_account, &who, amount, Preservation::Preserve)?;
}
T::Token::transfer(&sovereign_account, &who, delivery_cost, Preservation::Preserve)?;

// Decode message into XCM
let (xcm, fee) =
Expand Down
10 changes: 3 additions & 7 deletions bridges/snowbridge/parachain/pallets/inbound-queue/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use super::*;

use frame_support::{
derive_impl, parameter_types,
traits::{ConstU32, Everything},
parameter_types,
traits::{ConstU128, ConstU32, Everything},
weights::IdentityFee,
};
use hex_literal::hex;
Expand Down Expand Up @@ -76,18 +76,14 @@ impl frame_system::Config for Test {
type Block = Block;
}

parameter_types! {
pub const ExistentialDeposit: u128 = 1;
}

impl pallet_balances::Config for Test {
type MaxLocks = ();
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
type Balance = Balance;
type RuntimeEvent = RuntimeEvent;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type ExistentialDeposit = ConstU128<1>;
type AccountStore = System;
type WeightInfo = ();
type FreezeIdentifier = ();
Expand Down
58 changes: 10 additions & 48 deletions bridges/snowbridge/parachain/pallets/inbound-queue/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use frame_support::{assert_noop, assert_ok};
use hex_literal::hex;
use snowbridge_core::{inbound::Proof, ChannelId};
use sp_keyring::AccountKeyring as Keyring;
use sp_runtime::DispatchError;
use sp_runtime::{DispatchError, TokenError};
use sp_std::convert::From;

use crate::{Error, Event as InboundQueueEvent};
Expand Down Expand Up @@ -146,25 +146,28 @@ fn test_submit_with_invalid_nonce() {
}

#[test]
fn test_submit_no_funds_to_reward_relayers_just_ignore() {
fn test_submit_no_funds_to_reward_relayers() {
new_tester().execute_with(|| {
let relayer: AccountId = Keyring::Bob.into();
let origin = RuntimeOrigin::signed(relayer);

// Reset balance of sovereign_account to zero first
// Reset balance of sovereign_account to zero so to trigger the FundsUnavailable error
let sovereign_account = sibling_sovereign_account::<Test>(ASSET_HUB_PARAID.into());
Balances::set_balance(&sovereign_account, 0);

// Submit message
let message = Message {
event_log: mock_event_log(),
proof: Proof {
receipt_proof: Default::default(),
execution_proof: mock_execution_proof(),
block_hash: Default::default(),
tx_index: Default::default(),
data: Default::default(),
},
};
// Check submit successfully in case no funds available
assert_ok!(InboundQueue::submit(origin.clone(), message.clone()));
assert_noop!(
InboundQueue::submit(origin.clone(), message.clone()),
TokenError::FundsUnavailable
);
});
}

Expand Down Expand Up @@ -202,44 +205,3 @@ fn test_set_operating_mode_root_only() {
);
});
}

#[test]
fn test_submit_no_funds_to_reward_relayers_and_ed_preserved() {
new_tester().execute_with(|| {
let relayer: AccountId = Keyring::Bob.into();
let origin = RuntimeOrigin::signed(relayer);

// Reset balance of sovereign account to (ED+1) first
let sovereign_account = sibling_sovereign_account::<Test>(ASSET_HUB_PARAID.into());
Balances::set_balance(&sovereign_account, ExistentialDeposit::get() + 1);

// Submit message successfully
let message = Message {
event_log: mock_event_log(),
proof: Proof {
receipt_proof: Default::default(),
execution_proof: mock_execution_proof(),
},
};
assert_ok!(InboundQueue::submit(origin.clone(), message.clone()));

// Check balance of sovereign account to ED
let amount = Balances::balance(&sovereign_account);
assert_eq!(amount, ExistentialDeposit::get());

// Submit another message with nonce set as 2
let mut event_log = mock_event_log();
event_log.data[31] = 2;
let message = Message {
event_log,
proof: Proof {
receipt_proof: Default::default(),
execution_proof: mock_execution_proof(),
},
};
assert_ok!(InboundQueue::submit(origin.clone(), message.clone()));
// Check balance of sovereign account as ED does not change
let amount = Balances::balance(&sovereign_account);
assert_eq!(amount, ExistentialDeposit::get());
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use snowbridge_router_primitives::inbound::{
Command, GlobalConsensusEthereumConvertsFor, MessageV1, VersionedMessage,
};
use sp_core::H256;
use sp_runtime::{DispatchError::Token, TokenError::FundsUnavailable};
use sp_runtime::{ArithmeticError::Underflow, DispatchError::Arithmetic};
use testnet_parachains_constants::rococo::snowbridge::EthereumNetwork;

const INITIAL_FUND: u128 = 5_000_000_000 * ROCOCO_ED;
Expand Down Expand Up @@ -515,7 +515,7 @@ fn send_token_from_ethereum_to_asset_hub_fail_for_insufficient_fund() {
BridgeHubRococo::fund_para_sovereign(AssetHubRococo::para_id().into(), 1_000);

BridgeHubRococo::execute_with(|| {
assert_err!(send_inbound_message(make_register_token_message()), Token(FundsUnavailable));
assert_err!(send_inbound_message(make_register_token_message()), Arithmetic(Underflow));
});
}

Expand Down

0 comments on commit 60774cd

Please sign in to comment.