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

Finishing "Additional priority boost for relayers that have explicitly registered at lane" #2605

Open
wants to merge 66 commits into
base: bridges-v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
663c4c3
per-lane priority boost: prototype
svyatonik Oct 2, 2023
cb2e045
compute_per_lane_priority_boost to discuss new approach
svyatonik Oct 2, 2023
d310fe0
clippy
svyatonik Oct 2, 2023
57cd105
change approach a bit
svyatonik Oct 4, 2023
c1f9d8a
continue
svyatonik Oct 4, 2023
ebd6c61
continue
svyatonik Oct 6, 2023
facf6a5
flush
svyatonik Oct 6, 2023
e208524
continue prototyping
svyatonik Oct 6, 2023
73ea54e
Merge branch 'per-lane-priority-boost-for-discussing' into lane-prior…
svyatonik Oct 6, 2023
16aba6c
lanes now affect valid_till
svyatonik Oct 6, 2023
f473051
fmt
svyatonik Oct 6, 2023
ec87fbb
flush
svyatonik Oct 6, 2023
da47b6b
removed couple of obsolete TODOs
svyatonik Oct 6, 2023
6d52f11
added lost TODO
svyatonik Oct 6, 2023
2a0bae9
relayers are readded to the next set only if they are delivering at l…
svyatonik Oct 9, 2023
104754a
use expected reward from LaneRelayersSet to compute relayer reward
svyatonik Oct 9, 2023
034b38f
added comment to wrong code
svyatonik Oct 9, 2023
5df0872
reward is now a part of unrewarded relayers vector
svyatonik Oct 9, 2023
1a3efe7
remove unneeded constratind
svyatonik Oct 10, 2023
9c134da
set RewardAtSource to be u64
svyatonik Oct 10, 2023
5a86ed4
removed fixed TODO
svyatonik Oct 10, 2023
9b174cd
fmt
svyatonik Oct 10, 2023
579b90b
MaxRewardPerMessage + fixed TODO
svyatonik Oct 10, 2023
60b55af
fixed couple of TODOs + added comments + added new TODO
svyatonik Oct 10, 2023
72d5bbe
more TODO fixes
svyatonik Oct 10, 2023
e225164
fixed another TODO
svyatonik Oct 10, 2023
081523c
make next relayers set larger than the actual set
svyatonik Oct 11, 2023
e0e16cd
fmt
svyatonik Oct 11, 2023
926644d
Merge branch 'master' into lane-priority-prototype
svyatonik Oct 11, 2023
730e368
fix compilation
svyatonik Oct 11, 2023
f926504
added TODO
svyatonik Oct 12, 2023
043908f
tests + more TODOs
svyatonik Oct 12, 2023
2c425de
more tests
svyatonik Oct 12, 2023
2c3fed8
more tests
svyatonik Oct 12, 2023
4ad58da
tests for deregister_at_lane
svyatonik Oct 12, 2023
27e2669
tests for advance_lane_epoch
svyatonik Oct 12, 2023
1f04623
separate calls to manage relayers stake
svyatonik Oct 13, 2023
0638bcc
split active and next relayer sets
svyatonik Oct 13, 2023
38fac9f
Merge branch 'master' into lane-priority-prototype
svyatonik Oct 17, 2023
ce46ebc
removed TODO + added comment
svyatonik Oct 17, 2023
187fc19
intreoduce ActiveLaneRelayersSet and NextLaneRelayersSet
svyatonik Oct 17, 2023
392f93a
more tests
svyatonik Oct 17, 2023
b48a218
fix runtimes
svyatonik Oct 17, 2023
9f4e5cc
CI
svyatonik Oct 17, 2023
6957d6d
CI 2
svyatonik Oct 17, 2023
21f8caa
CI 3
svyatonik Oct 17, 2023
6ef384e
Merge branch 'next-and-active-lane-relayers' into lane-priority-proto…
svyatonik Oct 17, 2023
7e94f24
successful advance_lane_epoch is free for submitter
svyatonik Oct 17, 2023
03bc705
small optimization
svyatonik Oct 17, 2023
772837f
remove lane registrations when slashing relayer
svyatonik Oct 17, 2023
78a56ed
remove obsolete TODO and dev comment
svyatonik Oct 17, 2023
1f70ac7
added benchmarks for increase_stake, decrease_stake and register_at_lane
svyatonik Oct 17, 2023
94018e2
deregister_at_lane benchmark
svyatonik Oct 18, 2023
48504d9
advance_lane_epoch benchmark
svyatonik Oct 18, 2023
e235574
fixed slash_and_deregister benchmark
svyatonik Oct 18, 2023
3218672
added small comment regarding MaxLanesPerRelayer
svyatonik Oct 18, 2023
00dc6b8
removed already fixed TODO
svyatonik Oct 18, 2023
0d6d8a8
relayer_reward_per_message is now Option<RelayerRewardAtSource>
svyatonik Oct 18, 2023
113251e
properly implement relayer_reward_per_message in DeliveryConfirmation…
svyatonik Oct 18, 2023
325a99a
clippy
svyatonik Oct 18, 2023
17b678b
spelling
svyatonik Oct 18, 2023
bd000e2
fmt
svyatonik Oct 18, 2023
b5146bb
fixed benchmarks compilation
svyatonik Oct 18, 2023
cc98138
Merge branch 'master' into lane-priority-prototype
svyatonik Oct 30, 2023
c6b4f45
fix benchmarks
svyatonik Oct 30, 2023
0d761ed
Merge branch 'master' into lane-priority-prototype
svyatonik Feb 5, 2024
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
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.

5 changes: 4 additions & 1 deletion bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,10 @@ impl pallet_bridge_relayers::Config for Runtime {
ConstU64<1_000>,
ConstU64<8>,
>;
type MaxRelayersPerLane = ConstU32<16>;
type SlotLength = ConstU64<16>;
type PriorityBoostPerMessage = PriorityBoostPerMessage;
type PriorityBoostForLaneRelayer = ConstU64<0>;
type WeightInfo = ();
}

Expand Down Expand Up @@ -660,7 +664,6 @@ pub type BridgeRefundRialtoParachainMessages =
bp_relayers::RuntimeWithUtilityPallet<Runtime>,
WithRialtoParachainsInstance,
WithRialtoParachainMessagesInstance,
PriorityBoostPerMessage,
>,
>;

Expand Down
8 changes: 7 additions & 1 deletion bin/rialto-parachain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ use sp_api::impl_runtime_apis;
use sp_core::{crypto::KeyTypeId, ConstBool, OpaqueMetadata};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{AccountIdLookup, Block as BlockT, ConstU128, DispatchInfoOf, SignedExtension},
traits::{
AccountIdLookup, Block as BlockT, ConstU128, ConstU64, DispatchInfoOf, SignedExtension,
},
transaction_validity::{TransactionSource, TransactionValidity, TransactionValidityError},
ApplyExtrinsicResult,
};
Expand Down Expand Up @@ -539,6 +541,10 @@ impl pallet_bridge_relayers::Config for Runtime {
type PaymentProcedure =
bp_relayers::PayRewardFromAccount<pallet_balances::Pallet<Runtime>, AccountId>;
type StakeAndSlash = ();
type MaxRelayersPerLane = ConstU32<16>;
type SlotLength = ConstU32<16>;
type PriorityBoostPerMessage = ConstU64<0>;
type PriorityBoostForLaneRelayer = ConstU64<0>;
type WeightInfo = ();
}

Expand Down
4 changes: 4 additions & 0 deletions bin/rialto/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,10 @@ impl pallet_bridge_relayers::Config for Runtime {
type PaymentProcedure =
bp_relayers::PayRewardFromAccount<pallet_balances::Pallet<Runtime>, AccountId>;
type StakeAndSlash = ();
type MaxRelayersPerLane = ConstU32<16>;
type SlotLength = ConstU32<16>;
type PriorityBoostPerMessage = ConstU64<0>;
type PriorityBoostForLaneRelayer = ConstU64<0>;
type WeightInfo = ();
}

Expand Down
1 change: 1 addition & 0 deletions modules/messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ pub mod pallet {

// let's now deal with relayer payments
T::DeliveryPayments::pay_reward(
lane_id,
relayer_id_at_this_chain,
total_messages,
valid_messages,
Expand Down
12 changes: 2 additions & 10 deletions modules/relayers/src/extension/grandpa_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ use pallet_bridge_messages::{
CallSubType as BridgeMessagesCallSubType, Config as BridgeMessagesConfig,
};
use sp_runtime::{
traits::{Dispatchable, Get},
transaction_validity::{TransactionPriority, TransactionValidityError},
Saturating,
traits::Dispatchable, transaction_validity::TransactionValidityError, Saturating,
};
use sp_std::marker::PhantomData;

Expand All @@ -54,21 +52,17 @@ pub struct WithGrandpaChainExtensionConfig<
BridgeGrandpaPalletInstance,
// instance of BridgedChainthe `pallet-bridge-messages`, tracked by this extension
BridgeMessagesPalletInstance,
// message delivery transaction priority boost for every additional message
PriorityBoostPerMessage,
>(
PhantomData<(
IdProvider,
Runtime,
BatchCallUnpacker,
BridgeGrandpaPalletInstance,
BridgeMessagesPalletInstance,
PriorityBoostPerMessage,
)>,
);

impl<ID, R, BCU, GI, MI, P> ExtensionConfig
for WithGrandpaChainExtensionConfig<ID, R, BCU, GI, MI, P>
impl<ID, R, BCU, GI, MI> ExtensionConfig for WithGrandpaChainExtensionConfig<ID, R, BCU, GI, MI>
where
ID: StaticStrProvider,
R: BridgeRelayersConfig
Expand All @@ -77,7 +71,6 @@ where
BCU: BatchCallUnpacker<R>,
GI: 'static,
MI: 'static,
P: Get<TransactionPriority>,
R::RuntimeCall: Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>
+ BridgeGrandpaCallSubtype<R, GI>
+ BridgeMessagesCallSubType<R, MI>,
Expand All @@ -86,7 +79,6 @@ where
type Runtime = R;
type BatchCallUnpacker = BCU;
type BridgeMessagesPalletInstance = MI;
type PriorityBoostPerMessage = P;
type Reward = R::Reward;
type RemoteGrandpaChainBlockNumber = pallet_bridge_grandpa::BridgedBlockNumber<R, GI>;

Expand Down
40 changes: 22 additions & 18 deletions modules/relayers/src/extension/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use frame_support::{
dispatch::{DispatchInfo, PostDispatchInfo},
CloneNoBound, DefaultNoBound, EqNoBound, PartialEqNoBound, RuntimeDebugNoBound,
};
use frame_system::Config as SystemConfig;
use frame_system::{pallet_prelude::BlockNumberFor, Config as SystemConfig};
use pallet_bridge_messages::{CallHelper as MessagesCallHelper, Config as BridgeMessagesConfig};
use pallet_transaction_payment::{
Config as TransactionPaymentConfig, OnChargeTransaction, Pallet as TransactionPaymentPallet,
Expand Down Expand Up @@ -106,6 +106,7 @@ where
R::RuntimeCall: Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>,
<R as TransactionPaymentConfig>::OnChargeTransaction:
OnChargeTransaction<R, Balance = R::Reward>,
usize: TryFrom<BlockNumberFor<R>>,
{
/// Returns number of bundled messages `Some(_)`, if the given call info is a:
///
Expand All @@ -117,16 +118,15 @@ where
/// virtually boosted. The relayer registration (we only boost priority for registered
/// relayer transactions) must be checked outside.
fn bundled_messages_for_priority_boost(
call_info: Option<&ExtensionCallInfo<C::RemoteGrandpaChainBlockNumber>>,
call_info: &ExtensionCallInfo<C::RemoteGrandpaChainBlockNumber>,
) -> Option<MessageNonce> {
// we only boost priority of message delivery transactions
let parsed_call = match call_info {
Some(parsed_call) if parsed_call.is_receive_messages_proof_call() => parsed_call,
_ => return None,
};
if !call_info.is_receive_messages_proof_call() {
return None
}

// compute total number of messages in transaction
let bundled_messages = parsed_call.messages_call_info().bundled_messages().saturating_len();
let bundled_messages = call_info.messages_call_info().bundled_messages().saturating_len();

// a quick check to avoid invalid high-priority transactions
let max_unconfirmed_messages_in_confirmation_tx = <R as BridgeMessagesConfig<C::BridgeMessagesPalletInstance>>::BridgedChain
Expand Down Expand Up @@ -178,8 +178,7 @@ where
//
// - when relayer is registered after `validate` is called and priority is not boosted:
// relayer should be ready for slashing after registration.
let may_slash_relayer =
Self::bundled_messages_for_priority_boost(Some(&call_info)).is_some();
let may_slash_relayer = Self::bundled_messages_for_priority_boost(&call_info).is_some();
let slash_relayer_if_delivery_result = may_slash_relayer
.then(|| RelayerAccountAction::Slash(relayer.clone(), reward_account_params))
.unwrap_or(RelayerAccountAction::None);
Expand Down Expand Up @@ -254,6 +253,8 @@ where
R::RuntimeCall: Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>,
<R as TransactionPaymentConfig>::OnChargeTransaction:
OnChargeTransaction<R, Balance = R::Reward>,
usize: TryFrom<BlockNumberFor<R>>,
usize: TryFrom<BlockNumberFor<R>>,
{
const IDENTIFIER: &'static str = C::IdProvider::STR;
type AccountId = R::AccountId;
Expand All @@ -277,13 +278,15 @@ where
// we're not calling `validate` from `pre_dispatch` directly because of performance
// reasons, so if you're adding some code that may fail here, please check if it needs
// to be added to the `pre_dispatch` as well
let parsed_call = C::parse_and_check_for_obsolete_call(call)?;
let parsed_call = match C::parse_and_check_for_obsolete_call(call)? {
Some(parsed_call) => parsed_call,
None => return Ok(Default::default()),
};

// the following code just plays with transaction priority and never returns an error

// we only boost priority of presumably correct message delivery transactions
let bundled_messages = match Self::bundled_messages_for_priority_boost(parsed_call.as_ref())
{
let bundled_messages = match Self::bundled_messages_for_priority_boost(&parsed_call) {
Some(bundled_messages) => bundled_messages,
None => return Ok(Default::default()),
};
Expand All @@ -294,16 +297,19 @@ where
}

// compute priority boost
let priority_boost =
priority::compute_priority_boost::<C::PriorityBoostPerMessage>(bundled_messages);
let priority_boost = priority::compute_priority_boost::<R>(
parsed_call.messages_call_info().lane_id(),
bundled_messages,
who,
);
let valid_transaction = ValidTransactionBuilder::default().priority(priority_boost);

log::trace!(
target: LOG_TARGET,
"{}.{:?}: has boosted priority of message delivery transaction \
of relayer {:?}: {} messages -> {} priority",
Self::IDENTIFIER,
parsed_call.as_ref().map(|p| p.messages_call_info().lane_id()),
parsed_call.messages_call_info().lane_id(),
who,
bundled_messages,
priority_boost,
Expand Down Expand Up @@ -424,7 +430,7 @@ mod tests {
use pallet_bridge_parachains::Call as ParachainsCall;
use pallet_utility::Call as UtilityCall;
use sp_runtime::{
traits::{ConstU64, Header as HeaderT},
traits::Header as HeaderT,
transaction_validity::{InvalidTransaction, ValidTransaction},
DispatchError,
};
Expand Down Expand Up @@ -452,7 +458,6 @@ mod tests {
RuntimeWithUtilityPallet<TestRuntime>,
(),
(),
ConstU64<1>,
>;
type TestGrandpaExtension =
BridgeRelayersSignedExtension<TestRuntime, TestGrandpaExtensionConfig>;
Expand All @@ -462,7 +467,6 @@ mod tests {
RuntimeWithUtilityPallet<TestRuntime>,
(),
(),
ConstU64<1>,
>;
type TestExtension = BridgeRelayersSignedExtension<TestRuntime, TestExtensionConfig>;

Expand Down
12 changes: 2 additions & 10 deletions modules/relayers/src/extension/parachain_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ use pallet_bridge_parachains::{
CallSubType as BridgeParachainsCallSubtype, Config as BridgeParachainsConfig,
SubmitParachainHeadsHelper,
};
use sp_runtime::{
traits::{Dispatchable, Get},
transaction_validity::{TransactionPriority, TransactionValidityError},
};
use sp_runtime::{traits::Dispatchable, transaction_validity::TransactionValidityError};
use sp_std::marker::PhantomData;

/// Adapter to be used in signed extension configuration, when bridging with remote parachains.
Expand All @@ -58,20 +55,17 @@ pub struct WithParachainExtensionConfig<
BridgeParachainsPalletInstance,
// instance of BridgedChainthe `pallet-bridge-messages`, tracked by this extension
BridgeMessagesPalletInstance,
// message delivery transaction priority boost for every additional message
PriorityBoostPerMessage,
>(
PhantomData<(
IdProvider,
Runtime,
BatchCallUnpacker,
BridgeParachainsPalletInstance,
BridgeMessagesPalletInstance,
PriorityBoostPerMessage,
)>,
);

impl<ID, R, BCU, PI, MI, P> ExtensionConfig for WithParachainExtensionConfig<ID, R, BCU, PI, MI, P>
impl<ID, R, BCU, PI, MI> ExtensionConfig for WithParachainExtensionConfig<ID, R, BCU, PI, MI>
where
ID: StaticStrProvider,
R: BridgeRelayersConfig
Expand All @@ -81,7 +75,6 @@ where
BCU: BatchCallUnpacker<R>,
PI: 'static,
MI: 'static,
P: Get<TransactionPriority>,
R::RuntimeCall: Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>
+ BridgeGrandpaCallSubtype<R, R::BridgesGrandpaPalletInstance>
+ BridgeParachainsCallSubtype<R, PI>
Expand All @@ -92,7 +85,6 @@ where
type Runtime = R;
type BatchCallUnpacker = BCU;
type BridgeMessagesPalletInstance = MI;
type PriorityBoostPerMessage = P;
type Reward = R::Reward;
type RemoteGrandpaChainBlockNumber =
pallet_bridge_grandpa::BridgedBlockNumber<R, R::BridgesGrandpaPalletInstance>;
Expand Down
Loading