mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 06:21:02 +00:00
Fix delivery transaction estimation used by rational relayer (#1109)
* fix delivery transaction estimation in greedy relayer * fixed typo * improve logging * improve logging * fmt * fix compilation * fmt * Update relays/lib-substrate-relay/src/messages_target.rs Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * review Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
This commit is contained in:
committed by
Bastian Köcher
parent
2101ed9cc5
commit
03a54df398
@@ -24,7 +24,6 @@ use crate::on_demand_headers::OnDemandHeadersRelay;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use bp_messages::{LaneId, MessageNonce, UnrewardedRelayersState};
|
||||
use bp_runtime::messages::DispatchFeePayment;
|
||||
use bridge_runtime_common::messages::{
|
||||
source::FromBridgedChainMessagesDeliveryProof, target::FromBridgedChainMessagesProof,
|
||||
};
|
||||
@@ -43,7 +42,10 @@ use relay_substrate_client::{
|
||||
};
|
||||
use relay_utils::{relay_loop::Client as RelayClient, BlockNumberBase, HeaderId};
|
||||
use sp_core::Bytes;
|
||||
use sp_runtime::{traits::Header as HeaderT, DeserializeOwned};
|
||||
use sp_runtime::{
|
||||
traits::{AtLeast32BitUnsigned, Header as HeaderT},
|
||||
DeserializeOwned,
|
||||
};
|
||||
use std::ops::RangeInclusive;
|
||||
|
||||
/// Intermediate message proof returned by the source Substrate node. Includes everything
|
||||
@@ -121,6 +123,7 @@ where
|
||||
>,
|
||||
<P::MessageLane as MessageLane>::TargetHeaderNumber: Decode,
|
||||
<P::MessageLane as MessageLane>::TargetHeaderHash: Decode,
|
||||
<P::MessageLane as MessageLane>::SourceChainBalance: AtLeast32BitUnsigned,
|
||||
{
|
||||
async fn state(&self) -> Result<SourceClientState<P::MessageLane>, SubstrateError> {
|
||||
// we can't continue to deliver confirmations if source node is out of sync, because
|
||||
@@ -264,6 +267,7 @@ where
|
||||
prepare_dummy_messages_delivery_proof::<P::SourceChain, P::TargetChain>(),
|
||||
))
|
||||
.await
|
||||
.map(|fee| fee.inclusion_fee())
|
||||
.unwrap_or_else(|_| BalanceOf::<P::SourceChain>::max_value())
|
||||
}
|
||||
}
|
||||
@@ -397,7 +401,7 @@ fn make_message_details_map<C: Chain>(
|
||||
dispatch_weight: details.dispatch_weight,
|
||||
size: details.size as _,
|
||||
reward: details.delivery_and_dispatch_fee,
|
||||
dispatch_fee_payment: DispatchFeePayment::AtSourceChain,
|
||||
dispatch_fee_payment: details.dispatch_fee_payment,
|
||||
},
|
||||
);
|
||||
expected_nonce = details.nonce + 1;
|
||||
@@ -411,12 +415,12 @@ fn make_message_details_map<C: Chain>(
|
||||
mod tests {
|
||||
use super::*;
|
||||
use bp_runtime::messages::DispatchFeePayment;
|
||||
use relay_millau_client::Millau;
|
||||
use relay_rialto_client::Rialto;
|
||||
use relay_rococo_client::Rococo;
|
||||
use relay_wococo_client::Wococo;
|
||||
|
||||
fn message_details_from_rpc(
|
||||
nonces: RangeInclusive<MessageNonce>,
|
||||
) -> Vec<bp_messages::MessageDetails<bp_rialto::Balance>> {
|
||||
) -> Vec<bp_messages::MessageDetails<bp_wococo::Balance>> {
|
||||
nonces
|
||||
.into_iter()
|
||||
.map(|nonce| bp_messages::MessageDetails {
|
||||
@@ -432,7 +436,7 @@ mod tests {
|
||||
#[test]
|
||||
fn make_message_details_map_succeeds_if_no_messages_are_missing() {
|
||||
assert_eq!(
|
||||
make_message_details_map::<relay_rialto_client::Rialto>(message_details_from_rpc(1..=3), 1..=3,).unwrap(),
|
||||
make_message_details_map::<Wococo>(message_details_from_rpc(1..=3), 1..=3,).unwrap(),
|
||||
vec![
|
||||
(
|
||||
1,
|
||||
@@ -470,7 +474,7 @@ mod tests {
|
||||
#[test]
|
||||
fn make_message_details_map_succeeds_if_head_messages_are_missing() {
|
||||
assert_eq!(
|
||||
make_message_details_map::<relay_rialto_client::Rialto>(message_details_from_rpc(2..=3), 1..=3,).unwrap(),
|
||||
make_message_details_map::<Wococo>(message_details_from_rpc(2..=3), 1..=3,).unwrap(),
|
||||
vec![
|
||||
(
|
||||
2,
|
||||
@@ -501,7 +505,7 @@ mod tests {
|
||||
let mut message_details_from_rpc = message_details_from_rpc(1..=3);
|
||||
message_details_from_rpc.remove(1);
|
||||
assert!(matches!(
|
||||
make_message_details_map::<relay_rialto_client::Rialto>(message_details_from_rpc, 1..=3,),
|
||||
make_message_details_map::<Wococo>(message_details_from_rpc, 1..=3,),
|
||||
Err(SubstrateError::Custom(_))
|
||||
));
|
||||
}
|
||||
@@ -509,7 +513,7 @@ mod tests {
|
||||
#[test]
|
||||
fn make_message_details_map_fails_if_tail_messages_are_missing() {
|
||||
assert!(matches!(
|
||||
make_message_details_map::<relay_rialto_client::Rialto>(message_details_from_rpc(1..=2), 1..=3,),
|
||||
make_message_details_map::<Wococo>(message_details_from_rpc(1..=2), 1..=3,),
|
||||
Err(SubstrateError::Custom(_))
|
||||
));
|
||||
}
|
||||
@@ -517,15 +521,15 @@ mod tests {
|
||||
#[test]
|
||||
fn make_message_details_map_fails_if_all_messages_are_missing() {
|
||||
assert!(matches!(
|
||||
make_message_details_map::<relay_rialto_client::Rialto>(vec![], 1..=3),
|
||||
make_message_details_map::<Wococo>(vec![], 1..=3),
|
||||
Err(SubstrateError::Custom(_))
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn prepare_dummy_messages_delivery_proof_works() {
|
||||
let expected_minimal_size = Rialto::MAXIMAL_ENCODED_ACCOUNT_ID_SIZE + Millau::STORAGE_PROOF_OVERHEAD;
|
||||
let dummy_proof = prepare_dummy_messages_delivery_proof::<Rialto, Millau>();
|
||||
let expected_minimal_size = Wococo::MAXIMAL_ENCODED_ACCOUNT_ID_SIZE + Rococo::STORAGE_PROOF_OVERHEAD;
|
||||
let dummy_proof = prepare_dummy_messages_delivery_proof::<Wococo, Rococo>();
|
||||
assert!(
|
||||
dummy_proof.1.encode().len() as u32 > expected_minimal_size,
|
||||
"Expected proof size at least {}. Got: {}",
|
||||
|
||||
Reference in New Issue
Block a user