Skip to content

Commit f3c8a44

Browse files
committed
Check pending validation code exists before setting GoAhead`.
1 parent 215bbf1 commit f3c8a44

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

core/src/common/empty_block/inherents/custom_idps/para_parachain.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ pub fn get_last_relay_chain_block_number<B: BlockT>(
5858
})
5959
}
6060

61+
/// Check if `PendingValidationCode` is set in storage.
62+
pub fn has_pending_validation_code<B: BlockT>(ext: &mut TestExternalities<HashingFor<B>>) -> bool {
63+
let pending_validation_code_key = [
64+
twox_128(b"ParachainSystem"),
65+
twox_128(b"PendingValidationCode"),
66+
]
67+
.concat();
68+
69+
ext.execute_with(|| sp_io::storage::exists(&pending_validation_code_key))
70+
}
71+
6172
/// Provides parachain-system pallet inherents.
6273
pub struct InherentDataProvider<B: BlockT> {
6374
pub timestamp: sp_timestamp::Timestamp,
@@ -108,6 +119,16 @@ impl<B: BlockT> sp_inherents::InherentDataProvider for InherentDataProvider<B> {
108119
),
109120
];
110121

122+
// Check if `PendingValidationCode` exists in storage before setting `GoAhead`.
123+
// The parachain-system pallet panics if `GoAhead` is provided without a pending validation code.
124+
// See: https://github.com/paritytech/polkadot-sdk/blob/master/cumulus/pallets/parachain-system/src/lib.rs#L667
125+
let has_pending = has_pending_validation_code::<B>(ext);
126+
let upgrade_go_ahead = if has_pending {
127+
Some(UpgradeGoAhead::GoAhead)
128+
} else {
129+
None
130+
};
131+
111132
cumulus_client_parachain_inherent::MockValidationDataInherentDataProvider {
112133
current_para_block: Default::default(),
113134
current_para_block_head: Default::default(),
@@ -120,7 +141,7 @@ impl<B: BlockT> sp_inherents::InherentDataProvider for InherentDataProvider<B> {
120141
raw_horizontal_messages: Default::default(),
121142
additional_key_values: Some(additional_key_values),
122143
para_id: para_id.into(),
123-
upgrade_go_ahead: Some(UpgradeGoAhead::GoAhead),
144+
upgrade_go_ahead,
124145
}
125146
.provide_inherent_data(inherent_data)
126147
.await

0 commit comments

Comments
 (0)