mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 16:51:02 +00:00
Select header that will be fully refunded in on-demand batch finality relay (#2729)
* select header that will be fully refunded for submission in on-demand **batch** finality relay * added the only possible test * spelling * nl * updated comment
This commit is contained in:
committed by
Bastian Köcher
parent
6d35de23be
commit
6c31cdbe19
@@ -15,7 +15,10 @@
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{weights::WeightInfo, BridgedBlockNumber, BridgedHeader, Config, Error, Pallet};
|
||||
use bp_header_chain::{justification::GrandpaJustification, ChainWithGrandpa};
|
||||
use bp_header_chain::{
|
||||
justification::GrandpaJustification, max_expected_submit_finality_proof_arguments_size,
|
||||
ChainWithGrandpa, GrandpaConsensusLogReader,
|
||||
};
|
||||
use bp_runtime::{BlockNumberOf, OwnedBridgeModule};
|
||||
use codec::Encode;
|
||||
use frame_support::{dispatch::CallableCallFor, traits::IsSubType, weights::Weight};
|
||||
@@ -169,28 +172,28 @@ pub(crate) fn submit_finality_proof_info_from_args<T: Config<I>, I: 'static>(
|
||||
Weight::zero()
|
||||
};
|
||||
|
||||
// check if the `finality_target` is a mandatory header. If so, we are ready to refund larger
|
||||
// size
|
||||
let is_mandatory_finality_target =
|
||||
GrandpaConsensusLogReader::<BridgedBlockNumber<T, I>>::find_scheduled_change(
|
||||
finality_target.digest(),
|
||||
)
|
||||
.is_some();
|
||||
|
||||
// we can estimate extra call size easily, without any additional significant overhead
|
||||
let actual_call_size: u32 = finality_target
|
||||
.encoded_size()
|
||||
.saturating_add(justification.encoded_size())
|
||||
.saturated_into();
|
||||
let max_expected_call_size = max_expected_call_size::<T, I>(required_precommits);
|
||||
let max_expected_call_size = max_expected_submit_finality_proof_arguments_size::<T::BridgedChain>(
|
||||
is_mandatory_finality_target,
|
||||
required_precommits,
|
||||
);
|
||||
let extra_size = actual_call_size.saturating_sub(max_expected_call_size);
|
||||
|
||||
SubmitFinalityProofInfo { block_number, extra_weight, extra_size }
|
||||
}
|
||||
|
||||
/// Returns maximal expected size of `submit_finality_proof` call arguments.
|
||||
fn max_expected_call_size<T: Config<I>, I: 'static>(required_precommits: u32) -> u32 {
|
||||
let max_expected_justification_size =
|
||||
GrandpaJustification::<BridgedHeader<T, I>>::max_reasonable_size::<T::BridgedChain>(
|
||||
required_precommits,
|
||||
);
|
||||
|
||||
// call arguments are header and justification
|
||||
T::BridgedChain::MAX_HEADER_SIZE.saturating_add(max_expected_justification_size)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{
|
||||
|
||||
@@ -86,9 +86,8 @@ impl ChainWithGrandpa for TestBridgedChain {
|
||||
const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = "";
|
||||
const MAX_AUTHORITIES_COUNT: u32 = MAX_BRIDGED_AUTHORITIES;
|
||||
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 8;
|
||||
const MAX_HEADER_SIZE: u32 = 256;
|
||||
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
|
||||
const WORST_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
|
||||
const MAX_MANDATORY_HEADER_SIZE: u32 = 256;
|
||||
const AVERAGE_HEADER_SIZE: u32 = 64;
|
||||
}
|
||||
|
||||
/// Return test externalities to use in tests.
|
||||
|
||||
Reference in New Issue
Block a user