mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 09:21:05 +00:00
Ensure that the origin is signed for submit_parachain_heads and submit_finality_proof calls (#2239)
* ensure that the origin is signed for submit_parachain_heads and submit_finality_proof calls * clippy * clippy
This commit is contained in:
committed by
Bastian Köcher
parent
cc1966ff43
commit
504c6bd622
@@ -176,11 +176,12 @@ pub mod pallet {
|
|||||||
justification.votes_ancestries.len().saturated_into(),
|
justification.votes_ancestries.len().saturated_into(),
|
||||||
))]
|
))]
|
||||||
pub fn submit_finality_proof(
|
pub fn submit_finality_proof(
|
||||||
_origin: OriginFor<T>,
|
origin: OriginFor<T>,
|
||||||
finality_target: Box<BridgedHeader<T, I>>,
|
finality_target: Box<BridgedHeader<T, I>>,
|
||||||
justification: GrandpaJustification<BridgedHeader<T, I>>,
|
justification: GrandpaJustification<BridgedHeader<T, I>>,
|
||||||
) -> DispatchResultWithPostInfo {
|
) -> DispatchResultWithPostInfo {
|
||||||
Self::ensure_not_halted().map_err(Error::<T, I>::BridgeModule)?;
|
Self::ensure_not_halted().map_err(Error::<T, I>::BridgeModule)?;
|
||||||
|
ensure_signed(origin)?;
|
||||||
|
|
||||||
let (hash, number) = (finality_target.hash(), *finality_target.number());
|
let (hash, number) = (finality_target.hash(), *finality_target.number());
|
||||||
log::trace!(
|
log::trace!(
|
||||||
@@ -1414,4 +1415,23 @@ mod tests {
|
|||||||
fn maybe_headers_to_keep_returns_correct_value() {
|
fn maybe_headers_to_keep_returns_correct_value() {
|
||||||
assert_eq!(MaybeHeadersToKeep::<TestRuntime, ()>::get(), Some(mock::HeadersToKeep::get()));
|
assert_eq!(MaybeHeadersToKeep::<TestRuntime, ()>::get(), Some(mock::HeadersToKeep::get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn submit_finality_proof_requires_signed_origin() {
|
||||||
|
run_test(|| {
|
||||||
|
initialize_substrate_bridge();
|
||||||
|
|
||||||
|
let header = test_header(1);
|
||||||
|
let justification = make_default_justification(&header);
|
||||||
|
|
||||||
|
assert_noop!(
|
||||||
|
Pallet::<TestRuntime>::submit_finality_proof(
|
||||||
|
RuntimeOrigin::root(),
|
||||||
|
Box::new(header),
|
||||||
|
justification,
|
||||||
|
),
|
||||||
|
DispatchError::BadOrigin,
|
||||||
|
);
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -307,12 +307,13 @@ pub mod pallet {
|
|||||||
parachains.len() as _,
|
parachains.len() as _,
|
||||||
))]
|
))]
|
||||||
pub fn submit_parachain_heads(
|
pub fn submit_parachain_heads(
|
||||||
_origin: OriginFor<T>,
|
origin: OriginFor<T>,
|
||||||
at_relay_block: (RelayBlockNumber, RelayBlockHash),
|
at_relay_block: (RelayBlockNumber, RelayBlockHash),
|
||||||
parachains: Vec<(ParaId, ParaHash)>,
|
parachains: Vec<(ParaId, ParaHash)>,
|
||||||
parachain_heads_proof: ParaHeadsProof,
|
parachain_heads_proof: ParaHeadsProof,
|
||||||
) -> DispatchResultWithPostInfo {
|
) -> DispatchResultWithPostInfo {
|
||||||
Self::ensure_not_halted().map_err(Error::<T, I>::BridgeModule)?;
|
Self::ensure_not_halted().map_err(Error::<T, I>::BridgeModule)?;
|
||||||
|
ensure_signed(origin)?;
|
||||||
|
|
||||||
// we'll need relay chain header to verify that parachains heads are always increasing.
|
// we'll need relay chain header to verify that parachains heads are always increasing.
|
||||||
let (relay_block_number, relay_block_hash) = at_relay_block;
|
let (relay_block_number, relay_block_hash) = at_relay_block;
|
||||||
@@ -417,7 +418,7 @@ pub mod pallet {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// we're refunding weight if update has not happened and if pruning has not happened
|
// we're refunding weight if update has not happened and if pruning has not happened
|
||||||
let is_update_happened = matches!(update_result, Ok(_));
|
let is_update_happened = update_result.is_ok();
|
||||||
if !is_update_happened {
|
if !is_update_happened {
|
||||||
actual_weight = actual_weight.saturating_sub(
|
actual_weight = actual_weight.saturating_sub(
|
||||||
WeightInfoOf::<T, I>::parachain_head_storage_write_weight(
|
WeightInfoOf::<T, I>::parachain_head_storage_write_weight(
|
||||||
@@ -1579,4 +1580,25 @@ pub(crate) mod tests {
|
|||||||
Some(mock::TOTAL_PARACHAINS * mock::HeadsToKeep::get()),
|
Some(mock::TOTAL_PARACHAINS * mock::HeadsToKeep::get()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn submit_finality_proof_requires_signed_origin() {
|
||||||
|
run_test(|| {
|
||||||
|
let (state_root, proof, parachains) =
|
||||||
|
prepare_parachain_heads_proof::<RegularParachainHeader>(vec![(1, head_data(1, 0))]);
|
||||||
|
|
||||||
|
initialize(state_root);
|
||||||
|
|
||||||
|
// `submit_parachain_heads()` should fail when the pallet is halted.
|
||||||
|
assert_noop!(
|
||||||
|
Pallet::<TestRuntime>::submit_parachain_heads(
|
||||||
|
RuntimeOrigin::root(),
|
||||||
|
(0, test_relay_header(0, state_root).hash()),
|
||||||
|
parachains,
|
||||||
|
proof,
|
||||||
|
),
|
||||||
|
DispatchError::BadOrigin
|
||||||
|
);
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user