mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 14:31:13 +00:00
Reject transactions if bridge pallets are halted (#2600)
* reject transactions if bridge pallets are halted * fixed CI (#2598)
This commit is contained in:
committed by
Bastian Köcher
parent
2d15d1062f
commit
fe90a2d8ce
@@ -601,7 +601,7 @@ mod tests {
|
||||
.is_some());
|
||||
assert_eq!(
|
||||
ImportedBlockNumbers::<TestRuntime>::get(index),
|
||||
Some(index + 1).map(Into::into)
|
||||
Some(Into::into(index + 1)),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -619,7 +619,7 @@ mod tests {
|
||||
.is_some());
|
||||
assert_eq!(
|
||||
ImportedBlockNumbers::<TestRuntime>::get(0),
|
||||
Some(commitments_to_keep + 1).map(Into::into)
|
||||
Some(Into::into(commitments_to_keep + 1)),
|
||||
);
|
||||
// the side effect of the import is that the commitment#1 is pruned
|
||||
assert!(ImportedCommitments::<TestRuntime>::get(1).is_none());
|
||||
@@ -638,7 +638,7 @@ mod tests {
|
||||
.is_some());
|
||||
assert_eq!(
|
||||
ImportedBlockNumbers::<TestRuntime>::get(1),
|
||||
Some(commitments_to_keep + 2).map(Into::into)
|
||||
Some(Into::into(commitments_to_keep + 2)),
|
||||
);
|
||||
// the side effect of the import is that the commitment#2 is pruned
|
||||
assert!(ImportedCommitments::<TestRuntime>::get(1).is_none());
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
use crate::{weights::WeightInfo, BridgedBlockNumber, BridgedHeader, Config, Error, Pallet};
|
||||
use bp_header_chain::{justification::GrandpaJustification, ChainWithGrandpa};
|
||||
use bp_runtime::BlockNumberOf;
|
||||
use bp_runtime::{BlockNumberOf, OwnedBridgeModule};
|
||||
use codec::Encode;
|
||||
use frame_support::{dispatch::CallableCallFor, traits::IsSubType, weights::Weight};
|
||||
use sp_runtime::{
|
||||
@@ -126,6 +126,10 @@ pub trait CallSubType<T: Config<I, RuntimeCall = Self>, I: 'static>:
|
||||
_ => return Ok(ValidTransaction::default()),
|
||||
};
|
||||
|
||||
if Pallet::<T, I>::ensure_not_halted().is_err() {
|
||||
return InvalidTransaction::Call.into()
|
||||
}
|
||||
|
||||
match SubmitFinalityProofHelper::<T, I>::check_obsolete(finality_target.block_number) {
|
||||
Ok(_) => Ok(ValidTransaction::default()),
|
||||
Err(Error::<T, I>::OldHeader) => InvalidTransaction::Stale.into(),
|
||||
@@ -192,10 +196,10 @@ mod tests {
|
||||
use crate::{
|
||||
call_ext::CallSubType,
|
||||
mock::{run_test, test_header, RuntimeCall, TestBridgedChain, TestNumber, TestRuntime},
|
||||
BestFinalized, Config, WeightInfo,
|
||||
BestFinalized, Config, PalletOperatingMode, WeightInfo,
|
||||
};
|
||||
use bp_header_chain::ChainWithGrandpa;
|
||||
use bp_runtime::HeaderId;
|
||||
use bp_runtime::{BasicOperatingMode, HeaderId};
|
||||
use bp_test_utils::{
|
||||
make_default_justification, make_justification_for_header, JustificationGeneratorParams,
|
||||
};
|
||||
@@ -238,6 +242,17 @@ mod tests {
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extension_rejects_new_header_if_pallet_is_halted() {
|
||||
run_test(|| {
|
||||
// when pallet is halted => tx is rejected
|
||||
sync_to_header_10();
|
||||
PalletOperatingMode::<TestRuntime, ()>::put(BasicOperatingMode::Halted);
|
||||
|
||||
assert!(!validate_block_submit(15));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extension_accepts_new_header() {
|
||||
run_test(|| {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
use crate::{Config, Pallet, RelayBlockNumber};
|
||||
use bp_parachains::BestParaHeadHash;
|
||||
use bp_polkadot_core::parachains::{ParaHash, ParaId};
|
||||
use bp_runtime::OwnedBridgeModule;
|
||||
use frame_support::{dispatch::CallableCallFor, traits::IsSubType};
|
||||
use sp_runtime::{
|
||||
transaction_validity::{InvalidTransaction, TransactionValidity, ValidTransaction},
|
||||
@@ -141,6 +142,10 @@ pub trait CallSubType<T: Config<I, RuntimeCall = Self>, I: 'static>:
|
||||
None => return Ok(ValidTransaction::default()),
|
||||
};
|
||||
|
||||
if Pallet::<T, I>::ensure_not_halted().is_err() {
|
||||
return InvalidTransaction::Call.into()
|
||||
}
|
||||
|
||||
if SubmitParachainHeadsHelper::<T, I>::is_obsolete(&update) {
|
||||
return InvalidTransaction::Stale.into()
|
||||
}
|
||||
@@ -160,10 +165,11 @@ where
|
||||
mod tests {
|
||||
use crate::{
|
||||
mock::{run_test, RuntimeCall, TestRuntime},
|
||||
CallSubType, ParaInfo, ParasInfo, RelayBlockNumber,
|
||||
CallSubType, PalletOperatingMode, ParaInfo, ParasInfo, RelayBlockNumber,
|
||||
};
|
||||
use bp_parachains::BestParaHeadHash;
|
||||
use bp_polkadot_core::parachains::{ParaHash, ParaHeadsProof, ParaId};
|
||||
use bp_runtime::BasicOperatingMode;
|
||||
|
||||
fn validate_submit_parachain_heads(
|
||||
num: RelayBlockNumber,
|
||||
@@ -221,6 +227,17 @@ mod tests {
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extension_rejects_header_if_pallet_is_halted() {
|
||||
run_test(|| {
|
||||
// when pallet is halted => tx is rejected
|
||||
sync_to_relay_header_10();
|
||||
PalletOperatingMode::<TestRuntime, ()>::put(BasicOperatingMode::Halted);
|
||||
|
||||
assert!(!validate_submit_parachain_heads(15, vec![(ParaId(1), [2u8; 32].into())]));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extension_accepts_new_header() {
|
||||
run_test(|| {
|
||||
|
||||
Reference in New Issue
Block a user