-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[pallet-transaction-storage] Configurable RetentionPeriod #10656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bkontur
wants to merge
21
commits into
master
Choose a base branch
from
bko-tx-pallet-storage-period
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
5db2223
Add `TransactionStorageApi` definition
bkontur 8a53165
Add pub getter `storage_period` to transaction-storage pallet
bkontur 3c1e637
Add TransactionStorageApi to the kithchensink
bkontur 26214fe
Move `DEFAULT_STORAGE_PERIOD`
bkontur e4bb2e5
Call runtime API to get the storage_period for inherent data provider…
bkontur 432f85b
Licence
bkontur 7c5931c
Update from github-actions[bot] running command 'prdoc --audience run…
github-actions[bot] 5dc9364
Update substrate/frame/transaction-storage/src/lib.rs
bkontur 14cf3f1
Update prdoc/pr_10656.prdoc
bkontur 6f32290
Update from github-actions[bot] running command 'fmt'
github-actions[bot] 1806e30
Update prdoc/pr_10656.prdoc
bkontur 27c42ba
Fix indentation in the prdoc
EgorPopelyaev 58113e4
Fix CI?
bkontur 3e2b9ea
Update prdoc/pr_10656.prdoc
bkontur 041d5e3
Merge branch 'master' into bko-tx-pallet-storage-period
bkontur d0e55e8
Removed transaction_storage_runtime_api_call_works
bkontur b725081
Use directly runtime API, no need for "hacky" workaround `client.call…
bkontur 9f77401
Rename `StoragePeriod` to `RetentionPeriod`
bkontur 863492f
Update from github-actions[bot] running command 'fmt'
github-actions[bot] c92a3fd
Update prdoc/pr_10656.prdoc
bkontur 2773a62
Merge branch 'master' into bko-tx-pallet-storage-period
bkontur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| title: '[pallet-transaction-storage] Configurable StoragePeriod' | ||
| doc: | ||
| - audience: | ||
| - Runtime Dev | ||
| - Node Dev | ||
| description: "Relates to: https://github.com/paritytech/polkadot-sdk/pull/10494\n\ | ||
| Relates to: https://github.com/paritytech/polkadot-bulletin-chain/issues/82\n\ | ||
| Relates to: https://github.com/paritytech/polkadot-bulletin-chain/issues/60\n\n\ | ||
| ## Context/Problem\n\nThis PR refactors `pallet-transaction-storage` and `sp-transaction-storage-proof`\ | ||
| \ (the `new_data_provider` inherent provider), both of which rely on a hard-coded\ | ||
| \ `DEFAULT_STORAGE_PERIOD`.\n\nThe `new_data_provider` uses a hard-coded `pub\ | ||
| \ const DEFAULT_STORAGE_PERIOD: u32 = 100800;`, which forces the runtime to use\ | ||
| \ the same value. This value corresponds to 7 days for 6-second blocks. We want\ | ||
| \ to make this constant configurable and driven by the runtime \u2014 exposed\ | ||
| \ via a runtime API. For example, if we switch to 2-second blocks but still want\ | ||
| \ to keep the 7-day period, we won\u2019t need to coordinate and restart the collators\ | ||
| \ with a new hard-coded constant and so on. Basically, we want to have possibility\ | ||
| \ to set this constant with arbitrary value without affecting the collators or\ | ||
| \ anything.\n\n## Solution\n\nThis PR:\n* adds a new argument `storage_period`\ | ||
| \ to the `new_data_provider`\n* introduces the `TransactionStorageApi::storage_period`\ | ||
| \ runtime API, which the runtime can specify arbitrary\n* provides an example\ | ||
| \ of using `new_data_provider`, with the node client calling the runtime API when\ | ||
| \ constructing inherent provider data\n * I didn't want to complicate the node\ | ||
| \ client traits, so `retrieve_storage_period` uses just direct `call_api_at(\"\ | ||
| TransactionStorageApi_storage_period\", at_block)`\n\n## TODO\n- [ ] Is there\ | ||
| \ any alternative to `call_api_at` for how a node\u2019s custom inherent data\ | ||
| \ provider can call a runtime API declared via `decl_runtime_apis`?\n\n## Follow-up\n\ | ||
| \nIt will be used for Bulletin setup here: https://github.com/paritytech/polkadot-sdk/pull/10494" | ||
bkontur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| crates: | ||
| - name: sp-transaction-storage-proof | ||
| bump: patch | ||
| - name: pallet-transaction-storage | ||
| bump: patch | ||
bkontur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // This file is part of Substrate. | ||
|
|
||
| // Copyright (C) Parity Technologies (UK) Ltd. | ||
| // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 | ||
|
|
||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
|
|
||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
|
|
||
| // You should have received a copy of the GNU General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| #![cfg(unix)] | ||
| use codec::Decode; | ||
| use polkadot_sdk::sp_runtime::traits::NumberFor; | ||
| use std::time::Duration; | ||
| use substrate_cli_test_utils as common; | ||
| use substrate_rpc_client::{ws_client, StateApi}; | ||
|
|
||
| #[tokio::test] | ||
| async fn transaction_storage_runtime_api_call_works() { | ||
| common::run_with_timeout(Duration::from_secs(60 * 10), async move { | ||
| // Run the node. | ||
| let mut node = common::KillChildOnDrop(common::start_node()); | ||
| let stderr = node.stderr.take().unwrap(); | ||
| let ws_url = common::extract_info_from_output(stderr).0.ws_url; | ||
| common::wait_n_finalized_blocks(1, &ws_url).await; | ||
| let block_hash = common::block_hash(1, &ws_url).await.unwrap(); | ||
| node.assert_still_running(); | ||
|
|
||
| // Call the runtime API. | ||
| let rpc = ws_client(ws_url).await.unwrap(); | ||
| let result = rpc | ||
| .call( | ||
| String::from("TransactionStorageApi_storage_period"), | ||
| vec![].into(), | ||
| Some(block_hash), | ||
| ) | ||
| .await | ||
| .unwrap(); | ||
|
|
||
| // Decode and assert the received value. | ||
| let storage_period: NumberFor<kitchensink_runtime::Block> = | ||
| Decode::decode(&mut &result.0[..]).unwrap(); | ||
| assert_eq!(storage_period, 100800); | ||
|
|
||
| node.stop(); | ||
| }) | ||
| .await; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
substrate/primitives/transaction-storage-proof/src/runtime_api.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| // 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 storage period in blocks. | ||
| fn storage_period() -> NumberFor<Block>; | ||
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "std")] | ||
| pub mod client { | ||
| use codec::Decode; | ||
| use sp_api::{ApiError, CallApiAt, CallApiAtParams}; | ||
| use sp_core::traits::CallContext; | ||
| use sp_runtime::traits::Block as BlockT; | ||
| use sp_runtime::traits::NumberFor; | ||
|
|
||
| /// An expected state call key. | ||
| pub const TRANSACTION_STORAGE_API_STORAGE_PERIOD: &'static str = | ||
| "TransactionStorageApi_storage_period"; | ||
|
|
||
| /// Fetches the storage period value for a specific block from the runtime API. | ||
| /// | ||
| /// This function interacts with the `TRANSACTION_STORAGE_API_STORAGE_PERIOD` API | ||
| /// provided by the runtime. | ||
| /// | ||
| /// # Arguments | ||
| /// - `client`: A reference to an object implementing the `CallApiAt` trait, | ||
| /// used to interact with the runtime API. | ||
| /// - `at_block`: The hash of the specific block for which the storage period is queried. | ||
| pub fn retrieve_storage_period<B, C>( | ||
| client: &C, | ||
| at_block: B::Hash, | ||
| ) -> Result<NumberFor<B>, ApiError> | ||
| where | ||
| B: BlockT, | ||
| C: CallApiAt<B>, | ||
| { | ||
| // Call the expected runtime API. | ||
| let result = client.call_api_at(CallApiAtParams { | ||
| at: at_block, | ||
| function: TRANSACTION_STORAGE_API_STORAGE_PERIOD, | ||
| arguments: vec![], | ||
| overlayed_changes: &Default::default(), | ||
| call_context: CallContext::Onchain, | ||
| recorder: &None, | ||
| extensions: &Default::default(), | ||
| })?; | ||
|
|
||
| // Decode to `NumberFor<B>`. | ||
| Decode::decode(&mut &result[..]).map_err(|e| ApiError::FailedToDecodeReturnValue { | ||
| function: TRANSACTION_STORAGE_API_STORAGE_PERIOD, | ||
| error: e, | ||
| raw: result, | ||
| }) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.