Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 25 additions & 1 deletion pallets/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand All @@ -40,6 +43,27 @@ pub struct NoCurrency<AccountId, HoldReason = ()>(
core::marker::PhantomData<(AccountId, HoldReason)>,
);

impl<AccountId, HoldReason> Balanced<AccountId> for NoCurrency<AccountId, HoldReason>
where
HoldReason: Encode + Decode + TypeInfo + 'static,
{
type OnDropDebt = ();
type OnDropCredit = ();
}

impl<AccountId, HoldReason> BalancedHold<AccountId> for NoCurrency<AccountId, HoldReason> where
HoldReason: Encode + Decode + TypeInfo + 'static
{
}

impl<AccountId, HoldReason, Balance> DoneSlash<HoldReason, AccountId, Balance>
for NoCurrency<AccountId, HoldReason>
where
Balance: Sized,
HoldReason: Encode + Decode + TypeInfo + 'static,
{
}

impl<AccountId, HoldReason: Encode + Decode + TypeInfo + 'static> Inspect<AccountId>
for NoCurrency<AccountId, HoldReason>
{
Expand Down
3 changes: 3 additions & 0 deletions pallets/transaction-storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
36 changes: 35 additions & 1 deletion pallets/transaction-storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> =
<<T as Config>::Currency as Inspect<<T as frame_system::Config>::AccountId>>::Balance;
pub type CreditOf<T> = Credit<<T as frame_system::Config>::AccountId, <T as Config>::Currency>;

// Re-export pallet items so that they can be accessed from the crate namespace.
pub use pallet::*;
pub use weights::WeightInfo;
Expand Down Expand Up @@ -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<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// A dispatchable call.
type RuntimeCall: Parameter
+ Dispatchable<RuntimeOrigin = Self::RuntimeOrigin>
+ GetDispatchInfo
+ From<frame_system::Call<Self>>;
/// The fungible type for this pallet.
type Currency: Mutate<Self::AccountId>
+ MutateHold<Self::AccountId, Reason = Self::RuntimeHoldReason>
+ Balanced<Self::AccountId>;
/// The overarching runtime hold reason.
type RuntimeHoldReason: From<HoldReason>;
/// Handler for the unbalanced decrease when fees are burned.
type FeeDestination: OnUnbalanced<CreditOf<Self>>;
/// 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<u32>;
/// Maximum data set in a single transaction in bytes.
Expand Down Expand Up @@ -605,6 +631,14 @@ pub mod pallet {
OptionQuery,
>;

#[pallet::storage]
/// Storage fee per byte.
pub type ByteFee<T: Config> = StorageValue<_, BalanceOf<T>>;

#[pallet::storage]
/// Storage fee per transaction.
pub type EntryFee<T: Config> = StorageValue<_, BalanceOf<T>>;

// Intermediates
#[pallet::storage]
pub(super) type BlockTransactions<T: Config> =
Expand Down
5 changes: 5 additions & 0 deletions pallets/transaction-storage/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Test>;
Expand Down Expand Up @@ -52,6 +53,10 @@ parameter_types! {

impl pallet_transaction_storage::Config for Test {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type Currency = NoCurrency<Self::AccountId, RuntimeHoldReason>;
type RuntimeHoldReason = RuntimeHoldReason;
type FeeDestination = ();
type WeightInfo = ();
type MaxBlockTransactions = ConstU32<{ DEFAULT_MAX_BLOCK_TRANSACTIONS }>;
type MaxTransactionSize = ConstU32<{ DEFAULT_MAX_TRANSACTION_SIZE }>;
Expand Down
2 changes: 1 addition & 1 deletion pallets/transaction-storage/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
5 changes: 5 additions & 0 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Self::AccountId, RuntimeHoldReason>;
type RuntimeHoldReason = RuntimeHoldReason;
type FeeDestination = ();
type WeightInfo = pallet_transaction_storage::weights::SubstrateWeight<Runtime>;
type MaxBlockTransactions = ConstU32<512>;
type MaxTransactionSize = ConstU32<{ 8 * 1024 * 1024 }>;
Expand Down
5 changes: 5 additions & 0 deletions runtimes/bulletin-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self::AccountId, RuntimeHoldReason>;
type RuntimeHoldReason = RuntimeHoldReason;
type FeeDestination = ();
type WeightInfo = weights::pallet_transaction_storage::WeightInfo<Runtime>;
type MaxBlockTransactions = ConstU32<512>;
/// Max transaction size per block needs to be aligned with [`BlockLength`].
Expand Down Expand Up @@ -840,6 +844,7 @@ mod benches {

#[cfg(feature = "runtime-benchmarks")]
use benches::*;
use pallets_common::NoCurrency;

impl_runtime_apis! {
impl sp_api::Core<Block> for Runtime {
Expand Down
4 changes: 4 additions & 0 deletions runtimes/bulletin-westend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
7 changes: 6 additions & 1 deletion runtimes/bulletin-westend/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<Self::AccountId, RuntimeHoldReason>;
type RuntimeHoldReason = RuntimeHoldReason;
type FeeDestination = ();
type WeightInfo = crate::weights::pallet_transaction_storage::WeightInfo<Runtime>;
type MaxBlockTransactions = crate::ConstU32<512>;
/// Max transaction size per block needs to be aligned with `BlockLength`.
Expand Down