mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 09:21:04 +00:00
BridgeHubRococo/Wococo nits + updated subtree (#2572)
* Nits (merge before separatelly) * Small cosmetics for Rococo/Wococo bridge local run * Squashed 'bridges/' changes from 04b3dda6aa..5fc377ab34 5fc377ab34 Support for kusama-polkadot relaying (#2128) 01f4b7f1ba Fix clippy warnings (#2127) 696ff1c368 BHK/P alignments (#2115) 2a66aa3248 Small fixes (#2126) 7810f1a988 Cosmetics (#2124) daf250f69c Remove some `expect()` statements (#2123) 1c5fba8274 temporarily remove balance guard (#2121) 3d0e547361 Propagate message receival confirmation errors (#2116) 1c33143f07 Propagate message verification errors (#2114) b075b00910 Bump time from 0.3.20 to 0.3.21 51a3a51618 Bump serde from 1.0.160 to 1.0.162 da88d044a6 Bump clap from 4.2.5 to 4.2.7 cdca322cd6 Bump sysinfo from 0.28.4 to 0.29.0 git-subtree-dir: bridges git-subtree-split: 5fc377ab34f7dfd3293099c5feec49255e827812 * Fix * Allow to change storage constants (DeliveryReward, RequiredStakeForStakeAndSlash) + tests * Clippy * New SA for RO/WO * Squashed 'bridges/' changes from 5fc377ab34..0f6091d481 0f6091d481 Bump polkadot/substrate (#2134) 9233f0a337 Bump tokio from 1.28.0 to 1.28.1 a29c1caa93 Bump serde from 1.0.162 to 1.0.163 git-subtree-dir: bridges git-subtree-split: 0f6091d48184ebb4f75cb3089befa6b92cf37335
This commit is contained in:
@@ -91,6 +91,8 @@ pub mod pallet {
|
||||
BoundedStorageValue<<T as Config<I>>::MaxParaHeadDataSize, ParaStoredHeaderData>;
|
||||
/// Weight info of the given parachains pallet.
|
||||
pub type WeightInfoOf<T, I> = <T as Config<I>>::WeightInfo;
|
||||
type GrandpaPalletOf<T, I> =
|
||||
pallet_bridge_grandpa::Pallet<T, <T as Config<I>>::BridgesGrandpaPalletInstance>;
|
||||
|
||||
#[pallet::event]
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
@@ -125,14 +127,8 @@ pub mod pallet {
|
||||
UnknownRelayChainBlock,
|
||||
/// The number of stored relay block is different from what the relayer has provided.
|
||||
InvalidRelayChainBlockNumber,
|
||||
/// Error generated by a method defined in `bp-header-chain`.
|
||||
HeaderChain(HeaderChainError),
|
||||
/// Given parachain head is unknown.
|
||||
UnknownParaHead,
|
||||
/// The storage proof doesn't contains storage root. So it is invalid for given header.
|
||||
StorageRootMismatch,
|
||||
/// Failed to extract state root from given parachain head.
|
||||
FailedToExtractStateRoot,
|
||||
/// Parachain heads storage proof is invalid.
|
||||
HeaderChainStorageProof(HeaderChainError),
|
||||
/// Error generated by the `OwnedBridgeModule` trait.
|
||||
BridgeModule(bp_runtime::OwnedBridgeModuleError),
|
||||
}
|
||||
@@ -337,112 +333,113 @@ pub mod pallet {
|
||||
parachains.len() as _,
|
||||
);
|
||||
|
||||
pallet_bridge_grandpa::Pallet::<T, T::BridgesGrandpaPalletInstance>::parse_finalized_storage_proof(
|
||||
let mut storage = GrandpaPalletOf::<T, I>::storage_proof_checker(
|
||||
relay_block_hash,
|
||||
parachain_heads_proof.0,
|
||||
move |mut storage| {
|
||||
for (parachain, parachain_head_hash) in parachains {
|
||||
let parachain_head = match Pallet::<T, I>::read_parachain_head(&mut storage, parachain) {
|
||||
Ok(Some(parachain_head)) => parachain_head,
|
||||
Ok(None) => {
|
||||
log::trace!(
|
||||
target: LOG_TARGET,
|
||||
"The head of parachain {:?} is None. {}",
|
||||
parachain,
|
||||
if ParasInfo::<T, I>::contains_key(parachain) {
|
||||
"Looks like it is not yet registered at the source relay chain"
|
||||
} else {
|
||||
"Looks like it has been deregistered from the source relay chain"
|
||||
},
|
||||
);
|
||||
Self::deposit_event(Event::MissingParachainHead { parachain });
|
||||
continue;
|
||||
},
|
||||
Err(e) => {
|
||||
log::trace!(
|
||||
target: LOG_TARGET,
|
||||
"The read of head of parachain {:?} has failed: {:?}",
|
||||
parachain,
|
||||
e,
|
||||
);
|
||||
Self::deposit_event(Event::MissingParachainHead { parachain });
|
||||
continue;
|
||||
},
|
||||
};
|
||||
)
|
||||
.map_err(Error::<T, I>::HeaderChainStorageProof)?;
|
||||
|
||||
// if relayer has specified invalid parachain head hash, ignore the head
|
||||
// (this isn't strictly necessary, but better safe than sorry)
|
||||
let actual_parachain_head_hash = parachain_head.hash();
|
||||
if parachain_head_hash != actual_parachain_head_hash {
|
||||
for (parachain, parachain_head_hash) in parachains {
|
||||
let parachain_head = match Self::read_parachain_head(&mut storage, parachain) {
|
||||
Ok(Some(parachain_head)) => parachain_head,
|
||||
Ok(None) => {
|
||||
log::trace!(
|
||||
target: LOG_TARGET,
|
||||
"The head of parachain {:?} is None. {}",
|
||||
parachain,
|
||||
if ParasInfo::<T, I>::contains_key(parachain) {
|
||||
"Looks like it is not yet registered at the source relay chain"
|
||||
} else {
|
||||
"Looks like it has been deregistered from the source relay chain"
|
||||
},
|
||||
);
|
||||
Self::deposit_event(Event::MissingParachainHead { parachain });
|
||||
continue
|
||||
},
|
||||
Err(e) => {
|
||||
log::trace!(
|
||||
target: LOG_TARGET,
|
||||
"The read of head of parachain {:?} has failed: {:?}",
|
||||
parachain,
|
||||
e,
|
||||
);
|
||||
Self::deposit_event(Event::MissingParachainHead { parachain });
|
||||
continue
|
||||
},
|
||||
};
|
||||
|
||||
// if relayer has specified invalid parachain head hash, ignore the head
|
||||
// (this isn't strictly necessary, but better safe than sorry)
|
||||
let actual_parachain_head_hash = parachain_head.hash();
|
||||
if parachain_head_hash != actual_parachain_head_hash {
|
||||
log::trace!(
|
||||
target: LOG_TARGET,
|
||||
"The submitter has specified invalid parachain {:?} head hash: \
|
||||
{:?} vs {:?}",
|
||||
parachain,
|
||||
parachain_head_hash,
|
||||
actual_parachain_head_hash,
|
||||
);
|
||||
Self::deposit_event(Event::IncorrectParachainHeadHash {
|
||||
parachain,
|
||||
parachain_head_hash,
|
||||
actual_parachain_head_hash,
|
||||
});
|
||||
continue
|
||||
}
|
||||
|
||||
// convert from parachain head into stored parachain head data
|
||||
let parachain_head_data =
|
||||
match T::ParaStoredHeaderDataBuilder::try_build(parachain, ¶chain_head) {
|
||||
Some(parachain_head_data) => parachain_head_data,
|
||||
None => {
|
||||
log::trace!(
|
||||
target: LOG_TARGET,
|
||||
"The submitter has specified invalid parachain {:?} head hash: {:?} vs {:?}",
|
||||
"The head of parachain {:?} has been provided, but it is not tracked by the pallet",
|
||||
parachain,
|
||||
parachain_head_hash,
|
||||
actual_parachain_head_hash,
|
||||
);
|
||||
Self::deposit_event(Event::IncorrectParachainHeadHash {
|
||||
parachain,
|
||||
parachain_head_hash,
|
||||
actual_parachain_head_hash,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
Self::deposit_event(Event::UntrackedParachainRejected { parachain });
|
||||
continue
|
||||
},
|
||||
};
|
||||
|
||||
// convert from parachain head into stored parachain head data
|
||||
let parachain_head_data = match T::ParaStoredHeaderDataBuilder::try_build(
|
||||
let update_result: Result<_, ()> =
|
||||
ParasInfo::<T, I>::try_mutate(parachain, |stored_best_head| {
|
||||
let artifacts = Pallet::<T, I>::update_parachain_head(
|
||||
parachain,
|
||||
¶chain_head,
|
||||
) {
|
||||
Some(parachain_head_data) => parachain_head_data,
|
||||
None => {
|
||||
log::trace!(
|
||||
target: LOG_TARGET,
|
||||
"The head of parachain {:?} has been provided, but it is not tracked by the pallet",
|
||||
parachain,
|
||||
);
|
||||
Self::deposit_event(Event::UntrackedParachainRejected { parachain });
|
||||
continue;
|
||||
},
|
||||
};
|
||||
stored_best_head.take(),
|
||||
relay_block_number,
|
||||
parachain_head_data,
|
||||
parachain_head_hash,
|
||||
)?;
|
||||
*stored_best_head = Some(artifacts.best_head);
|
||||
Ok(artifacts.prune_happened)
|
||||
});
|
||||
|
||||
let update_result: Result<_, ()> = ParasInfo::<T, I>::try_mutate(parachain, |stored_best_head| {
|
||||
let artifacts = Pallet::<T, I>::update_parachain_head(
|
||||
parachain,
|
||||
stored_best_head.take(),
|
||||
relay_block_number,
|
||||
parachain_head_data,
|
||||
parachain_head_hash,
|
||||
)?;
|
||||
*stored_best_head = Some(artifacts.best_head);
|
||||
Ok(artifacts.prune_happened)
|
||||
});
|
||||
// we're refunding weight if update has not happened and if pruning has not happened
|
||||
let is_update_happened = matches!(update_result, Ok(_));
|
||||
if !is_update_happened {
|
||||
actual_weight = actual_weight.saturating_sub(
|
||||
WeightInfoOf::<T, I>::parachain_head_storage_write_weight(
|
||||
T::DbWeight::get(),
|
||||
),
|
||||
);
|
||||
}
|
||||
let is_prune_happened = matches!(update_result, Ok(true));
|
||||
if !is_prune_happened {
|
||||
actual_weight = actual_weight.saturating_sub(
|
||||
WeightInfoOf::<T, I>::parachain_head_pruning_weight(T::DbWeight::get()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// we're refunding weight if update has not happened and if pruning has not happened
|
||||
let is_update_happened = matches!(update_result, Ok(_));
|
||||
if !is_update_happened {
|
||||
actual_weight = actual_weight
|
||||
.saturating_sub(WeightInfoOf::<T, I>::parachain_head_storage_write_weight(T::DbWeight::get()));
|
||||
}
|
||||
let is_prune_happened = matches!(update_result, Ok(true));
|
||||
if !is_prune_happened {
|
||||
actual_weight = actual_weight
|
||||
.saturating_sub(WeightInfoOf::<T, I>::parachain_head_pruning_weight(T::DbWeight::get()));
|
||||
}
|
||||
}
|
||||
|
||||
// even though we may have accepted some parachain heads, we can't allow relayers to submit
|
||||
// proof with unused trie nodes
|
||||
// => treat this as an error
|
||||
//
|
||||
// (we can throw error here, because now all our calls are transactional)
|
||||
storage.ensure_no_unused_nodes()
|
||||
},
|
||||
)
|
||||
.and_then(|r| r.map_err(HeaderChainError::StorageProof))
|
||||
.map_err(|e| {
|
||||
log::trace!(target: LOG_TARGET, "Parachain heads storage proof is invalid: {:?}", e);
|
||||
Error::<T, I>::HeaderChain(e)
|
||||
// even though we may have accepted some parachain heads, we can't allow relayers to
|
||||
// submit proof with unused trie nodes
|
||||
// => treat this as an error
|
||||
//
|
||||
// (we can throw error here, because now all our calls are transactional)
|
||||
storage.ensure_no_unused_nodes().map_err(|e| {
|
||||
Error::<T, I>::HeaderChainStorageProof(HeaderChainError::StorageProof(e))
|
||||
})?;
|
||||
|
||||
Ok(PostDispatchInfo { actual_weight: Some(actual_weight), pays_fee: Pays::Yes })
|
||||
@@ -1438,7 +1435,7 @@ pub(crate) mod tests {
|
||||
// try to import head#5 of parachain#1 at relay chain block #0
|
||||
assert_noop!(
|
||||
import_parachain_1_head(0, Default::default(), parachains, proof),
|
||||
Error::<TestRuntime>::HeaderChain(HeaderChainError::StorageProof(
|
||||
Error::<TestRuntime>::HeaderChainStorageProof(HeaderChainError::StorageProof(
|
||||
StorageProofError::StorageRootMismatch
|
||||
))
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user