Skip to content

Commit 18cb5ee

Browse files
raymondkfcheunggithub-actions[bot]bkontur
authored
Align Types between Bulletin and SDK (#10578)
The PR aligns types between Bulletin and SDK. Addresses paritytech/polkadot-bulletin-chain#86 Relates to * paritytech/polkadot-bulletin-chain#128 * paritytech/polkadot-bulletin-chain#134 * #10582 --------- Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Branislav Kontur <[email protected]>
1 parent acd0306 commit 18cb5ee

File tree

2 files changed

+61
-14
lines changed

2 files changed

+61
-14
lines changed

prdoc/pr_10578.prdoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
title: Align Types between Bulletin and SDK
2+
doc:
3+
- audience: Runtime Dev
4+
description: The PR aligns types between Bulletin and SDK.
5+
crates:
6+
- name: pallet-transaction-storage
7+
bump: minor

substrate/frame/transaction-storage/src/lib.rs

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@ extern crate alloc;
3232

3333
use alloc::vec::Vec;
3434
use codec::{Decode, Encode, MaxEncodedLen};
35-
use core::result;
35+
use core::{fmt::Debug, result};
3636
use frame_support::{
3737
dispatch::GetDispatchInfo,
38+
pallet_prelude::InvalidTransaction,
3839
traits::{
39-
fungible::{hold::Balanced, Inspect, Mutate, MutateHold},
40-
tokens::fungible::Credit,
40+
fungible::{hold::Balanced, Credit, Inspect, Mutate, MutateHold},
4141
OnUnbalanced,
4242
},
4343
};
44+
use frame_system::pallet_prelude::BlockNumberFor;
4445
use sp_runtime::traits::{BlakeTwo256, Dispatchable, Hash, One, Saturating, Zero};
4546
use sp_transaction_storage_proof::{
4647
encode_index, num_chunks, random_chunk, ChunkIndex, InherentError, TransactionStorageProof,
@@ -56,25 +57,59 @@ pub type CreditOf<T> = Credit<<T as frame_system::Config>::AccountId, <T as Conf
5657
pub use pallet::*;
5758
pub use weights::WeightInfo;
5859

60+
// TODO: https://github.com/paritytech/polkadot-sdk/issues/10591 - Clarify purpose of allocator limits and decide whether to remove or use these constants.
5961
/// Maximum bytes that can be stored in one transaction.
6062
// Setting higher limit also requires raising the allocator limit.
6163
pub const DEFAULT_MAX_TRANSACTION_SIZE: u32 = 8 * 1024 * 1024;
6264
pub const DEFAULT_MAX_BLOCK_TRANSACTIONS: u32 = 512;
6365

66+
/// Encountered an impossible situation, implies a bug.
67+
pub const IMPOSSIBLE: InvalidTransaction = InvalidTransaction::Custom(0);
68+
/// Data size is not in the allowed range.
69+
pub const BAD_DATA_SIZE: InvalidTransaction = InvalidTransaction::Custom(1);
70+
/// Renewed extrinsic not found.
71+
pub const RENEWED_NOT_FOUND: InvalidTransaction = InvalidTransaction::Custom(2);
72+
/// Authorization was not found.
73+
pub const AUTHORIZATION_NOT_FOUND: InvalidTransaction = InvalidTransaction::Custom(3);
74+
/// Authorization has not expired.
75+
pub const AUTHORIZATION_NOT_EXPIRED: InvalidTransaction = InvalidTransaction::Custom(4);
76+
77+
/// Number of transactions and bytes covered by an authorization.
78+
#[derive(PartialEq, Eq, Debug, Encode, Decode, scale_info::TypeInfo, MaxEncodedLen)]
79+
pub struct AuthorizationExtent {
80+
/// Number of transactions.
81+
pub transactions: u32,
82+
/// Number of bytes.
83+
pub bytes: u64,
84+
}
85+
6486
/// Hash of a stored blob of data.
6587
type ContentHash = [u8; 32];
6688

89+
/// The scope of an authorization.
90+
#[derive(Encode, Decode, scale_info::TypeInfo, MaxEncodedLen)]
91+
enum AuthorizationScope<AccountId> {
92+
/// Authorization for the given account to store arbitrary data.
93+
Account(AccountId),
94+
/// Authorization for anyone to store data with a specific hash.
95+
Preimage(ContentHash),
96+
}
97+
98+
type AuthorizationScopeFor<T> = AuthorizationScope<<T as frame_system::Config>::AccountId>;
99+
100+
/// An authorization to store data.
101+
#[derive(Encode, Decode, scale_info::TypeInfo, MaxEncodedLen)]
102+
struct Authorization<BlockNumber> {
103+
/// Extent of the authorization (number of transactions/bytes).
104+
extent: AuthorizationExtent,
105+
/// The block at which this authorization expires.
106+
expiration: BlockNumber,
107+
}
108+
109+
type AuthorizationFor<T> = Authorization<BlockNumberFor<T>>;
110+
67111
/// State data for a stored transaction.
68-
#[derive(
69-
Encode,
70-
Decode,
71-
Clone,
72-
sp_runtime::RuntimeDebug,
73-
PartialEq,
74-
Eq,
75-
scale_info::TypeInfo,
76-
MaxEncodedLen,
77-
)]
112+
#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, scale_info::TypeInfo, MaxEncodedLen)]
78113
pub struct TransactionInfo {
79114
/// Chunk trie root.
80115
chunk_root: <BlakeTwo256 as Hash>::Output,
@@ -86,7 +121,7 @@ pub struct TransactionInfo {
86121
/// is used to find transaction info by block chunk index using binary search.
87122
///
88123
/// Cumulative value of all previous transactions in the block; the last transaction holds the
89-
/// total chunks value.
124+
/// total chunks.
90125
block_chunks: ChunkIndex,
91126
}
92127

@@ -372,6 +407,11 @@ pub mod pallet {
372407
ExpiredPreimageAuthorizationRemoved { content_hash: ContentHash },
373408
}
374409

410+
/// Authorizations, keyed by scope.
411+
#[pallet::storage]
412+
pub(super) type Authorizations<T: Config> =
413+
StorageMap<_, Blake2_128Concat, AuthorizationScopeFor<T>, AuthorizationFor<T>, OptionQuery>;
414+
375415
/// Collection of transaction metadata by block number.
376416
#[pallet::storage]
377417
pub type Transactions<T: Config> = StorageMap<

0 commit comments

Comments
 (0)