Signed extension to refund relayer at the target chain (#1657)

* add utlity pallet to the Millau runtime

* RefundRelayerForMessagesDeliveryFromParachain prototype

* done with RefundRelayerForMessagesDeliveryFromParachain::post_dispatch

* parse calls

* check batch for obsolete headers/messages

* fmt

* shorten generic arg names + add parachain id generic arg

* check lane_id

* impl all state read functions

* fix typos from review

* renamed extension + reference issue from TODO

* tests for pre-dispaytch

* renamed extension source file

* tests for post-dispatch

* abstract fee calculation

* clippy

* actually fix clippy

* Update bin/runtime-common/src/refund_relayer_extension.rs

Co-authored-by: Adrian Catangiu <adrian@parity.io>

* Update bin/runtime-common/src/refund_relayer_extension.rs

Co-authored-by: Adrian Catangiu <adrian@parity.io>

* Update bin/runtime-common/src/refund_relayer_extension.rs

Co-authored-by: Adrian Catangiu <adrian@parity.io>

* Update bin/runtime-common/src/refund_relayer_extension.rs

Co-authored-by: Adrian Catangiu <adrian@parity.io>

Co-authored-by: Adrian Catangiu <adrian@parity.io>
This commit is contained in:
Svyatoslav Nikolsky
2022-12-09 12:15:27 +03:00
committed by Bastian Köcher
parent aeeb53343e
commit 161d861d9b
10 changed files with 889 additions and 4 deletions
+7
View File
@@ -540,6 +540,13 @@ pub mod pallet {
}
}
impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// Get the best finalized block number.
pub fn best_finalized_number() -> Option<BridgedBlockNumber<T, I>> {
BestFinalized::<T, I>::get().map(|id| id.number())
}
}
/// Bridge GRANDPA pallet as header chain.
pub type GrandpaChainHeaders<T, I> = Pallet<T, I>;
+7 -2
View File
@@ -168,10 +168,10 @@ pub mod pallet {
}
/// Shortcut to messages proof type for Config.
type MessagesProofOf<T, I> =
pub type MessagesProofOf<T, I> =
<<T as Config<I>>::SourceHeaderChain as SourceHeaderChain>::MessagesProof;
/// Shortcut to messages delivery proof type for Config.
type MessagesDeliveryProofOf<T, I> =
pub type MessagesDeliveryProofOf<T, I> =
<<T as Config<I>>::TargetHeaderChain as TargetHeaderChain<
<T as Config<I>>::OutboundPayload,
<T as frame_system::Config>::AccountId,
@@ -631,6 +631,11 @@ pub mod pallet {
dispatch_weight: T::MessageDispatch::dispatch_weight(&mut dispatch_message),
}
}
/// Return inbound lane data.
pub fn inbound_lane_data(lane: LaneId) -> InboundLaneData<T::InboundRelayer> {
InboundLanes::<T, I>::get(lane).0
}
}
}
+5
View File
@@ -401,6 +401,11 @@ pub mod pallet {
}
impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// Get stored parachain info.
pub fn best_parachain_info(parachain: ParaId) -> Option<ParaInfo> {
ParasInfo::<T, I>::get(parachain)
}
/// Get best finalized header of the given parachain.
pub fn best_parachain_head(parachain: ParaId) -> Option<ParaHead> {
let best_para_head_hash = ParasInfo::<T, I>::get(parachain)?.best_head_hash.head_hash;
+2
View File
@@ -22,6 +22,7 @@ frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch =
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-arithmetic = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
[dev-dependencies]
@@ -42,6 +43,7 @@ std = [
"log/std",
"scale-info/std",
"sp-arithmetic/std",
"sp-runtime/std",
"sp-std/std",
]
runtime-benchmarks = [
+3 -1
View File
@@ -109,8 +109,9 @@ pub mod pallet {
log::trace!(
target: crate::LOG_TARGET,
"Relayer {:?} can now claim reward: {:?}",
"Relayer {:?} can now claim reward for serving lane {:?}: {:?}",
relayer,
lane_id,
new_reward,
);
});
@@ -141,6 +142,7 @@ pub mod pallet {
/// Map of the relayer => accumulated reward.
#[pallet::storage]
#[pallet::getter(fn relayer_reward)]
pub type RelayerRewards<T: Config> = StorageDoubleMap<
_,
Blake2_128Concat,