Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce bridge relayers pallet #1513

Merged
merged 10 commits into from
Jul 20, 2022
Merged

Conversation

svyatonik
Copy link
Contributor

@svyatonik svyatonik commented Jul 18, 2022

closes #1503

There's still a lot of TODOs here. I'm opening it early so that anyone could ask questions and voice their opinions regarding this new pallet.

Quick intro: we have unsolved #1318 (which I'm planning to discuss once we have some kind of Rococo/Wococo bridge hubs). Till last week I was thinking that we shall not work on that completely, but actually there are parts of the code that may be worked on now. So I've branched off #1503 from #1318. I was going to add new call (claim_rewards) and map to the messages pallet (relayer => reward) first. But then I've remembered #2486, which we also shall solve soon or later. Adding #2486 (whatever solution we'll choose) to the existing messages pallet will make it too complex, so imo it makes sense to move all relayer management code (including paying fees and rewards) to the separate pallet, which I'm introducing in this PR.

@svyatonik svyatonik added P-Runtime PR-audit-needed A PR has to be audited before going live. labels Jul 18, 2022
@svyatonik svyatonik marked this pull request as draft July 18, 2022 12:56
@svyatonik svyatonik marked this pull request as ready for review July 20, 2022 09:45
@svyatonik
Copy link
Contributor Author

So after this PR, all we need to do to solve #1318 is (I hope) to properly implement PaymentProcedure

@svyatonik svyatonik merged commit 7101e9f into master Jul 20, 2022
@svyatonik svyatonik deleted the introduce-bridge-relayers-pallet branch July 20, 2022 10:11
Copy link
Collaborator

@serban300 serban300 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good. I just left a couple of nits.

let reward = maybe_reward.take().ok_or(Error::<T>::NoRewardForRelayer)?;
T::PaymentProcedure::pay_reward(&relayer, reward).map_err(|e| {
log::trace!(
target: "runtime::bridge-relayers",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I would define this in a const LOG_TARGET, as for the other modules.

run_test(|| {
RelayerRewards::<TestRuntime>::insert(REGULAR_RELAYER, 100);
assert_ok!(Pallet::<TestRuntime>::claim_rewards(Origin::signed(REGULAR_RELAYER)));
assert_eq!(RelayerRewards::<TestRuntime>::get(REGULAR_RELAYER), None);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also check if the RewardPaid event was emitted correctly ?

RelayerRewards::<T>::mutate(relayer, |old_reward: &mut Option<T::Reward>| {
let new_reward = old_reward.unwrap_or_else(Zero::zero).saturating_add(reward);
log::trace!(
target: "T::bridge-relayers",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this desired ? Or should it be runtime::bridge-relayers ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My fault again

messages_relayers,
received_range,
);
if !relayers_rewards.is_empty() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I wouldn't test this. If relayers_rewards is empty, almost nothing happens.

}

// Update rewards to given relayers, optionally rewarding confirmation relayer.
fn schedule_relayers_rewards<T: Config>(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering if register_relayers_rewards or update_relayers_rewards would be a better name for this method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is up to you :)

// If delivery confirmation is submitted by this relayer, let's add confirmation fee
// from other relayers to this relayer reward.
confirmation_relayer_reward = confirmation_relayer_reward.saturating_add(reward.reward);
continue
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I would move the schedule_relayer_reward::<T>(&relayer, relayer_reward); in the if branch above and avoid doing continue; here. Seems easier to avoid mistakes in the future.

modules/relayers/src/payment_adapter.rs Show resolved Hide resolved
Comment on lines +90 to +91
let mut confirmation_reward = T::Reward::try_from(reward.messages)
.unwrap_or_else(|_| Bounded::max_value())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think we can use T::Reward::saturated_from(reward.messages)

Comment on lines +18 to +19
#frame-system = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
#sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we delete these commented lines ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My fault - sorry :(

Copy link
Contributor Author

@svyatonik svyatonik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review, all your points seems legit to me!

@serban300
Copy link
Collaborator

Thanks for the review, all your points seems legit to me!

Ok, thanks ! I'll implement them in a follow-up PR.

@serban300 serban300 mentioned this pull request Aug 12, 2022
@serban300
Copy link
Collaborator

The comments were addressed in #1547 . Marking this PR as reviewed.

serban300 pushed a commit to serban300/parity-bridges-common that referenced this pull request Mar 27, 2024
* introduce relayers pallet

* add MessageDeliveryAndDispatchPaymentAdapter

* plug in pallet into test runtimes

* tests prototype

* tests for the relayers pallet

* tests for payment adapter

* mint_reward_payment_procedure_actually_mints_tokens

* benchmarks

* remove irrelevant todo

* remove redundant clone
serban300 pushed a commit to serban300/parity-bridges-common that referenced this pull request Apr 8, 2024
* introduce relayers pallet

* add MessageDeliveryAndDispatchPaymentAdapter

* plug in pallet into test runtimes

* tests prototype

* tests for the relayers pallet

* tests for payment adapter

* mint_reward_payment_procedure_actually_mints_tokens

* benchmarks

* remove irrelevant todo

* remove redundant clone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P-Runtime PR-audit-needed A PR has to be audited before going live.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

On-demand relayer rewards payment
2 participants