diff --git a/Cargo.lock b/Cargo.lock index 17ad4d464..e9efba87d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1460,6 +1460,7 @@ dependencies = [ "pallet-transaction-storage", "pallet-xcm", "pallet-xcm-benchmarks", + "pallets-common", "parachains-common", "parachains-runtimes-test-utils", "parity-scale-codec", @@ -7209,6 +7210,7 @@ name = "pallet-transaction-storage" version = "4.0.0-dev" dependencies = [ "array-bytes 6.2.3", + "pallets-common", "parity-scale-codec", "polkadot-sdk-frame", "scale-info", diff --git a/pallets/common/src/lib.rs b/pallets/common/src/lib.rs index 1c02dcac0..d8579044a 100644 --- a/pallets/common/src/lib.rs +++ b/pallets/common/src/lib.rs @@ -19,7 +19,10 @@ use codec::{Decode, Encode}; use polkadot_sdk_frame::{ deps::frame_support, prelude::{ - fungible::{Dust, Inspect, InspectHold, Mutate, MutateHold, Unbalanced, UnbalancedHold}, + fungible::{ + hold::DoneSlash, Balanced, BalancedHold, Dust, Inspect, InspectHold, Mutate, + MutateHold, Unbalanced, UnbalancedHold, + }, DepositConsequence, DispatchError, DispatchResult, Fortitude, Preservation, Provenance, WithdrawConsequence, Zero, }, @@ -40,6 +43,27 @@ pub struct NoCurrency( core::marker::PhantomData<(AccountId, HoldReason)>, ); +impl Balanced for NoCurrency +where + HoldReason: Encode + Decode + TypeInfo + 'static, +{ + type OnDropDebt = (); + type OnDropCredit = (); +} + +impl BalancedHold for NoCurrency where + HoldReason: Encode + Decode + TypeInfo + 'static +{ +} + +impl DoneSlash + for NoCurrency +where + Balance: Sized, + HoldReason: Encode + Decode + TypeInfo + 'static, +{ +} + impl Inspect for NoCurrency { diff --git a/pallets/transaction-storage/Cargo.toml b/pallets/transaction-storage/Cargo.toml index d1e37a32a..f966b288f 100644 --- a/pallets/transaction-storage/Cargo.toml +++ b/pallets/transaction-storage/Cargo.toml @@ -23,6 +23,9 @@ polkadot-sdk-frame = { workspace = true, default-features = false, features = [ ] } sp-transaction-storage-proof = { workspace = true, default-features = false } +[dev-dependencies] +pallets-common = { workspace = true } + [features] default = ["std"] runtime-benchmarks = [ diff --git a/pallets/transaction-storage/src/lib.rs b/pallets/transaction-storage/src/lib.rs index b6d5bab3d..420828c0b 100644 --- a/pallets/transaction-storage/src/lib.rs +++ b/pallets/transaction-storage/src/lib.rs @@ -36,12 +36,18 @@ use codec::{Decode, Encode, MaxEncodedLen}; use polkadot_sdk_frame::{ deps::{sp_core::sp_std::prelude::*, *}, prelude::*, + traits::fungible::{Balanced, Credit, Inspect, Mutate, MutateHold}, }; use sp_transaction_storage_proof::{ encode_index, num_chunks, random_chunk, ChunkIndex, InherentError, TransactionStorageProof, CHUNK_SIZE, INHERENT_IDENTIFIER, }; +/// A type alias for the balance type from this pallet's point of view. +type BalanceOf = + <::Currency as Inspect<::AccountId>>::Balance; +pub type CreditOf = Credit<::AccountId, ::Currency>; + // Re-export pallet items so that they can be accessed from the crate namespace. pub use pallet::*; pub use weights::WeightInfo; @@ -155,14 +161,34 @@ impl CheckContext { pub mod pallet { use super::*; + /// A reason for this pallet placing a hold on funds. + #[pallet::composite_enum] + pub enum HoldReason { + /// The funds are held as deposit for the used storage. + StorageFeeHold, + } + #[pallet::config] pub trait Config: frame_system::Config { /// The overarching event type. #[allow(deprecated)] type RuntimeEvent: From> + IsType<::RuntimeEvent>; + /// A dispatchable call. + type RuntimeCall: Parameter + + Dispatchable + + GetDispatchInfo + + From>; + /// The fungible type for this pallet. + type Currency: Mutate + + MutateHold + + Balanced; + /// The overarching runtime hold reason. + type RuntimeHoldReason: From; + /// Handler for the unbalanced decrease when fees are burned. + type FeeDestination: OnUnbalanced>; /// Weight information for extrinsics in this pallet. type WeightInfo: WeightInfo; - /// Maximum number of indexed transactions in a block. + /// Maximum number of indexed transactions in the block. #[pallet::constant] type MaxBlockTransactions: Get; /// Maximum data set in a single transaction in bytes. @@ -605,6 +631,14 @@ pub mod pallet { OptionQuery, >; + #[pallet::storage] + /// Storage fee per byte. + pub type ByteFee = StorageValue<_, BalanceOf>; + + #[pallet::storage] + /// Storage fee per transaction. + pub type EntryFee = StorageValue<_, BalanceOf>; + // Intermediates #[pallet::storage] pub(super) type BlockTransactions = diff --git a/pallets/transaction-storage/src/mock.rs b/pallets/transaction-storage/src/mock.rs index 523d10c25..2d673e801 100644 --- a/pallets/transaction-storage/src/mock.rs +++ b/pallets/transaction-storage/src/mock.rs @@ -21,6 +21,7 @@ use crate::{ self as pallet_transaction_storage, TransactionStorageProof, DEFAULT_MAX_BLOCK_TRANSACTIONS, DEFAULT_MAX_TRANSACTION_SIZE, }; +use pallets_common::NoCurrency; use polkadot_sdk_frame::{prelude::*, runtime::prelude::*, testing_prelude::*}; type Block = MockBlock; @@ -52,6 +53,10 @@ parameter_types! { impl pallet_transaction_storage::Config for Test { type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type Currency = NoCurrency; + type RuntimeHoldReason = RuntimeHoldReason; + type FeeDestination = (); type WeightInfo = (); type MaxBlockTransactions = ConstU32<{ DEFAULT_MAX_BLOCK_TRANSACTIONS }>; type MaxTransactionSize = ConstU32<{ DEFAULT_MAX_TRANSACTION_SIZE }>; diff --git a/pallets/transaction-storage/src/tests.rs b/pallets/transaction-storage/src/tests.rs index 35cea7f63..624599b0a 100644 --- a/pallets/transaction-storage/src/tests.rs +++ b/pallets/transaction-storage/src/tests.rs @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Tests for transction-storage pallet. +//! Tests for transaction-storage pallet. use super::{ mock::{ diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 9409ff31a..9bd1ff274 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -57,6 +57,7 @@ use frame_support::{ pub use frame_system::Call as SystemCall; pub use pallet_timestamp::Call as TimestampCall; use pallet_transaction_payment::RuntimeDispatchInfo; +use pallets_common::NoCurrency; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; @@ -344,6 +345,10 @@ impl pallet_sudo::Config for Runtime { impl pallet_transaction_storage::Config for Runtime { type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type Currency = NoCurrency; + type RuntimeHoldReason = RuntimeHoldReason; + type FeeDestination = (); type WeightInfo = pallet_transaction_storage::weights::SubstrateWeight; type MaxBlockTransactions = ConstU32<512>; type MaxTransactionSize = ConstU32<{ 8 * 1024 * 1024 }>; diff --git a/runtimes/bulletin-polkadot/src/lib.rs b/runtimes/bulletin-polkadot/src/lib.rs index 7ff01606d..8b0aa1abc 100644 --- a/runtimes/bulletin-polkadot/src/lib.rs +++ b/runtimes/bulletin-polkadot/src/lib.rs @@ -343,6 +343,10 @@ impl pallet_timestamp::Config for Runtime { impl pallet_transaction_storage::Config for Runtime { type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type Currency = NoCurrency; + type RuntimeHoldReason = RuntimeHoldReason; + type FeeDestination = (); type WeightInfo = weights::pallet_transaction_storage::WeightInfo; type MaxBlockTransactions = ConstU32<512>; /// Max transaction size per block needs to be aligned with [`BlockLength`]. @@ -840,6 +844,7 @@ mod benches { #[cfg(feature = "runtime-benchmarks")] use benches::*; +use pallets_common::NoCurrency; impl_runtime_apis! { impl sp_api::Core for Runtime { diff --git a/runtimes/bulletin-westend/Cargo.toml b/runtimes/bulletin-westend/Cargo.toml index b112356cd..c6ff56d19 100644 --- a/runtimes/bulletin-westend/Cargo.toml +++ b/runtimes/bulletin-westend/Cargo.toml @@ -37,6 +37,7 @@ pallet-timestamp = { workspace = true } pallet-transaction-payment = { workspace = true } pallet-transaction-payment-rpc-runtime-api = { workspace = true } pallet-transaction-storage = { workspace = true } +pallets-common = { workspace = true } sp-api = { workspace = true } sp-block-builder = { workspace = true } sp-consensus-aura = { workspace = true } @@ -120,6 +121,7 @@ std = [ "pallet-transaction-storage/std", "pallet-xcm-benchmarks?/std", "pallet-xcm/std", + "pallets-common/std", "parachain-info/std", "parachains-common/std", "polkadot-parachain-primitives/std", @@ -170,6 +172,7 @@ runtime-benchmarks = [ "pallet-transaction-storage/runtime-benchmarks", "pallet-xcm-benchmarks/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", + "pallets-common/runtime-benchmarks", "parachains-common/runtime-benchmarks", "polkadot-parachain-primitives/runtime-benchmarks", "polkadot-runtime-common/runtime-benchmarks", @@ -201,6 +204,7 @@ try-runtime = [ "pallet-transaction-payment/try-runtime", "pallet-transaction-storage/try-runtime", "pallet-xcm/try-runtime", + "pallets-common/try-runtime", "parachain-info/try-runtime", "parachains-common/try-runtime", "polkadot-runtime-common/try-runtime", diff --git a/runtimes/bulletin-westend/src/storage.rs b/runtimes/bulletin-westend/src/storage.rs index 306f68d40..648c0f193 100644 --- a/runtimes/bulletin-westend/src/storage.rs +++ b/runtimes/bulletin-westend/src/storage.rs @@ -16,12 +16,13 @@ //! Storage-specific configurations. -use super::{Runtime, RuntimeEvent}; +use super::{Runtime, RuntimeCall, RuntimeEvent, RuntimeHoldReason}; use frame_support::{ parameter_types, traits::{EitherOfDiverse, Equals}, }; use pallet_xcm::EnsureXcm; +use pallets_common::NoCurrency; use sp_runtime::transaction_validity::{TransactionLongevity, TransactionPriority}; use testnet_parachains_constants::westend::locations::PeopleLocation; @@ -42,6 +43,10 @@ parameter_types! { /// The main business of the Bulletin chain. impl pallet_transaction_storage::Config for Runtime { type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type Currency = NoCurrency; + type RuntimeHoldReason = RuntimeHoldReason; + type FeeDestination = (); type WeightInfo = crate::weights::pallet_transaction_storage::WeightInfo; type MaxBlockTransactions = crate::ConstU32<512>; /// Max transaction size per block needs to be aligned with `BlockLength`.