Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions prdoc/pr_10593.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
title: Align Storages between Bulletin and SDK
doc:
- audience: Runtime Dev
description: The PR aligns Storages between Bulletin and SDK.
crates:
- name: pallet-transaction-storage
bump: major
32 changes: 26 additions & 6 deletions substrate/frame/transaction-storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub type CreditOf<T> = Credit<<T as frame_system::Config>::AccountId, <T as Conf
pub use pallet::*;
pub use weights::WeightInfo;

// TODO: https://github.com/paritytech/polkadot-sdk/issues/10591 - Clarify purpose of allocator limits and decide whether to remove or use these constants.
// TODO: https://github.com/paritytech/polkadot-bulletin-chain/issues/139 - Clarify purpose of allocator limits and decide whether to remove or use these constants.
/// Maximum bytes that can be stored in one transaction.
// Setting higher limit also requires raising the allocator limit.
pub const DEFAULT_MAX_TRANSACTION_SIZE: u32 = 8 * 1024 * 1024;
Expand Down Expand Up @@ -168,8 +168,10 @@ pub mod pallet {
/// Weight information for extrinsics in this pallet.
type WeightInfo: WeightInfo;
/// Maximum number of indexed transactions in the block.
#[pallet::constant]
type MaxBlockTransactions: Get<u32>;
/// Maximum data set in a single transaction in bytes.
#[pallet::constant]
type MaxTransactionSize: Get<u32>;
}

Expand Down Expand Up @@ -248,19 +250,37 @@ pub mod pallet {
},
"Storage proof must be checked once in the block"
);

// Insert new transactions, iff they have chunks.
let transactions = BlockTransactions::<T>::take();
let total_chunks = TransactionInfo::total_chunks(&transactions);
if total_chunks != 0 {
Transactions::<T>::insert(n, transactions);
}
}

fn integrity_test() {
assert!(
!T::MaxBlockTransactions::get().is_zero(),
"MaxTransactionSize must be greater than zero"
);
assert!(
!T::MaxTransactionSize::get().is_zero(),
"MaxTransactionSize must be greater than zero"
);
let default_period = sp_transaction_storage_proof::DEFAULT_STORAGE_PERIOD.into();
let storage_period = GenesisConfig::<T>::default().storage_period;
assert_eq!(
storage_period, default_period,
"GenesisConfig.storage_period must match DEFAULT_STORAGE_PERIOD"
);
}
}

#[pallet::call]
impl<T: Config> Pallet<T> {
/// Index and store data off chain. Minimum data size is 1 bytes, maximum is
/// `MaxTransactionSize`. Data will be removed after `STORAGE_PERIOD` blocks, unless `renew`
/// Index and store data off chain. Minimum data size is 1 byte, maximum is
/// `MaxTransactionSize`. Data will be removed after `StoragePeriod` blocks, unless `renew`
/// is called.
/// ## Complexity
/// - O(n*log(n)) of data size, as all data is pushed to an in-memory trie.
Expand Down Expand Up @@ -464,9 +484,9 @@ pub mod pallet {
#[pallet::genesis_build]
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
fn build(&self) {
ByteFee::<T>::put(&self.byte_fee);
EntryFee::<T>::put(&self.entry_fee);
StoragePeriod::<T>::put(&self.storage_period);
ByteFee::<T>::put(self.byte_fee);
EntryFee::<T>::put(self.entry_fee);
StoragePeriod::<T>::put(self.storage_period);
}
}

Expand Down
Loading