diff --git a/Cargo.lock b/Cargo.lock index 35e1fe00fec50..de6b71a7b6638 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23907,6 +23907,7 @@ dependencies = [ "async-trait", "parity-scale-codec", "scale-info", + "sp-api", "sp-core 39.0.0", "sp-inherents", "sp-runtime", diff --git a/cumulus/pallets/parachain-system/Cargo.toml b/cumulus/pallets/parachain-system/Cargo.toml index 00417f5857b93..92331ec562bbd 100644 --- a/cumulus/pallets/parachain-system/Cargo.toml +++ b/cumulus/pallets/parachain-system/Cargo.toml @@ -118,3 +118,13 @@ try-runtime = [ "polkadot-runtime-parachains/try-runtime", "sp-runtime/try-runtime", ] + +# Enables `TransactionIndex` host functions for parachain validation +# without requiring maintenance of a transaction index. +# However, the host environment (polkadot-prepare/execute-worker) still expects these functions to exist, +# so we provide a replacement no-op implementation gated by this feature. +# +# Used by: `validate_block::implementation::validate_block`. +# +# Note: The parachain collator software is expected to use/include `transaction_index::HostFunctions`. +transaction-index = [] diff --git a/cumulus/pallets/parachain-system/src/validate_block/implementation.rs b/cumulus/pallets/parachain-system/src/validate_block/implementation.rs index 29905d921f375..3cde27324e8d4 100644 --- a/cumulus/pallets/parachain-system/src/validate_block/implementation.rs +++ b/cumulus/pallets/parachain-system/src/validate_block/implementation.rs @@ -122,6 +122,10 @@ where sp_io::offchain_index::host_clear.replace_implementation(host_offchain_index_clear), cumulus_primitives_proof_size_hostfunction::storage_proof_size::host_storage_proof_size .replace_implementation(host_storage_proof_size), + #[cfg(feature = "transaction-index")] + sp_io::transaction_index::host_index.replace_implementation(host_transaction_index_index), + #[cfg(feature = "transaction-index")] + sp_io::transaction_index::host_renew.replace_implementation(host_transaction_index_renew), ); let block_data = codec::decode_from_bytes::>(block_data) @@ -221,7 +225,6 @@ where if overlay.storage(well_known_keys::CODE).is_some() && num_blocks > 1 { panic!("When applying a runtime upgrade, only one block per PoV is allowed. Received {num_blocks}.") } - run_with_externalities_and_recorder::( &backend, &mut Default::default(), @@ -539,3 +542,21 @@ fn host_default_child_storage_next_key(storage_key: &[u8], key: &[u8]) -> Option fn host_offchain_index_set(_key: &[u8], _value: &[u8]) {} fn host_offchain_index_clear(_key: &[u8]) {} + +/// Parachain validation does not require maintaining a transaction index, +/// and indexing transactions does **not** contribute to the parachain state. +/// However, the host environment still expects this function to exist, +/// so we provide a no-op implementation. +#[cfg(feature = "transaction-index")] +fn host_transaction_index_index(_extrinsic: u32, _size: u32, _context_hash: [u8; 32]) { + // No-op host function used during parachain validation. +} + +/// Parachain validation does not require maintaining a transaction index, +/// and indexing transactions does **not** contribute to the parachain state. +/// However, the host environment still expects this function to exist, +/// so we provide a no-op implementation. +#[cfg(feature = "transaction-index")] +fn host_transaction_index_renew(_extrinsic: u32, _context_hash: [u8; 32]) { + // No-op host function used during parachain validation. +} diff --git a/prdoc/pr_11467.prdoc b/prdoc/pr_11467.prdoc new file mode 100644 index 0000000000000..bd6c7b01fdb9d --- /dev/null +++ b/prdoc/pr_11467.prdoc @@ -0,0 +1,14 @@ +title: "[stable2512] Backport #10662 - Bulletin as parachain missing features (partial)" +doc: +- audience: Runtime Dev + description: |- + Partial backport of #10662 to stable2512. This PR includes: + 1. Add `transaction_index::HostFunctions` with NO-OP impl to the cumulus `ParachainSystem` `validate_block` for polkadot-prepare/execute-worker, gated behind the `transaction-index` feature. + 2. Introduce the `TransactionStorageApi::retention_period` runtime API in `sp-transaction-storage-proof`. +crates: +- name: cumulus-pallet-parachain-system + bump: patch +- name: pallet-transaction-storage + bump: patch +- name: sp-transaction-storage-proof + bump: minor diff --git a/substrate/frame/transaction-storage/Cargo.toml b/substrate/frame/transaction-storage/Cargo.toml index 76a3de85ca9d0..baa0fec60a2f8 100644 --- a/substrate/frame/transaction-storage/Cargo.toml +++ b/substrate/frame/transaction-storage/Cargo.toml @@ -46,6 +46,7 @@ std = [ "sp-inherents/std", "sp-io/std", "sp-runtime/std", + "sp-transaction-storage-proof/std", "tracing/std", ] runtime-benchmarks = [ diff --git a/substrate/primitives/transaction-storage-proof/Cargo.toml b/substrate/primitives/transaction-storage-proof/Cargo.toml index 3e683ff7eeb7a..81e4188e1a7d9 100644 --- a/substrate/primitives/transaction-storage-proof/Cargo.toml +++ b/substrate/primitives/transaction-storage-proof/Cargo.toml @@ -19,6 +19,7 @@ targets = ["x86_64-unknown-linux-gnu"] async-trait = { optional = true, workspace = true } codec = { features = ["derive"], workspace = true } scale-info = { features = ["derive"], workspace = true } +sp-api = { workspace = true } sp-core = { optional = true, workspace = true } sp-inherents.workspace = true sp-runtime.workspace = true @@ -30,6 +31,7 @@ std = [ "async-trait", "codec/std", "scale-info/std", + "sp-api/std", "sp-core/std", "sp-inherents/std", "sp-runtime/std", diff --git a/substrate/primitives/transaction-storage-proof/src/lib.rs b/substrate/primitives/transaction-storage-proof/src/lib.rs index 0dad6a748b385..db2bc9823f0f0 100644 --- a/substrate/primitives/transaction-storage-proof/src/lib.rs +++ b/substrate/primitives/transaction-storage-proof/src/lib.rs @@ -20,6 +20,8 @@ #![cfg_attr(not(feature = "std"), no_std)] +pub mod runtime_api; + extern crate alloc; use core::result::Result; diff --git a/substrate/primitives/transaction-storage-proof/src/runtime_api.rs b/substrate/primitives/transaction-storage-proof/src/runtime_api.rs new file mode 100644 index 0000000000000..b7d920a8a8f61 --- /dev/null +++ b/substrate/primitives/transaction-storage-proof/src/runtime_api.rs @@ -0,0 +1,28 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Runtime API definition for the transaction storage proof processing. + +use sp_runtime::traits::NumberFor; + +sp_api::decl_runtime_apis! { + /// Runtime API trait for transaction storage support. + pub trait TransactionStorageApi { + /// Get the actual value of a retention period in blocks. + fn retention_period() -> NumberFor; + } +}