Skip to content
This repository was archived by the owner on Aug 15, 2025. It is now read-only.
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
Next Next commit
Ignore rewarding when funds unavailable
  • Loading branch information
yrong committed Feb 27, 2024
commit 77b8304a7ef17098c44120b14debf2c07d2b4be3
13 changes: 13 additions & 0 deletions bridges/snowbridge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,16 @@ derivable_impls = { level = "allow", priority = 2 } # false pos
stable_sort_primitive = { level = "allow", priority = 2 } # prefer stable sort
extra-unused-type-parameters = { level = "allow", priority = 2 } # stylistic
default_constructed_unit_structs = { level = "allow", priority = 2 } # stylistic

[workspace.dependencies]
polkavm-linker = "0.8.2"
polkavm-derive = "0.8.0"
log = { version = "0.4.20", default-features = false }
quote = { version = "1.0.33" }
serde = { version = "1.0.197", default-features = false }
serde-big-array = { version = "0.3.2" }
serde_derive = { version = "1.0.117" }
serde_json = { version = "1.0.114", default-features = false }
serde_yaml = { version = "0.9" }
syn = { version = "2.0.50" }
thiserror = { version = "1.0.48" }
17 changes: 13 additions & 4 deletions bridges/snowbridge/pallets/inbound-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ use envelope::Envelope;
use frame_support::{
traits::{
fungible::{Inspect, Mutate},
tokens::Preservation,
tokens::{Fortitude, 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 @@ -261,11 +262,19 @@ pub mod pallet {
}
})?;

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

// Decode message into XCM
let (xcm, fee) =
Expand Down
9 changes: 3 additions & 6 deletions bridges/snowbridge/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, TokenError};
use sp_runtime::DispatchError;
use sp_std::convert::From;

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

#[test]
fn test_submit_no_funds_to_reward_relayers() {
fn test_submit_no_funds_to_reward_relayers_just_ignore() {
new_tester().execute_with(|| {
let relayer: AccountId = Keyring::Bob.into();
let origin = RuntimeOrigin::signed(relayer);
Expand All @@ -168,10 +168,7 @@ fn test_submit_no_funds_to_reward_relayers() {
data: Default::default(),
},
};
assert_noop!(
InboundQueue::submit(origin.clone(), message.clone()),
TokenError::FundsUnavailable
);
assert_ok!(InboundQueue::submit(origin.clone(), message.clone()));
});
}

Expand Down