Skip to content
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

Collect the domain transaction fee and use as the operator reward #1859

Merged
merged 7 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
32 changes: 32 additions & 0 deletions domains/pallets/domain-transaction-fees/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "pallet-domain-transaction-fees"
NingLin-P marked this conversation as resolved.
Show resolved Hide resolved
version = "0.1.0"
authors = ["Subspace Labs <https://subspace.network>"]
edition = "2021"
license = "Apache-2.0"
homepage = "https://subspace.network"
repository = "https://github.com/subspace/subspace"
description = "Subspace node pallet for charging and re-distributing domain transaction fees"
include = [
"/src",
"/Cargo.toml",
]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.6.3", default-features = false, features = ["derive"] }
frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "55c157cff49b638a59d81a9f971f0f9a66829c71" }
frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "55c157cff49b638a59d81a9f971f0f9a66829c71" }
scale-info = { version = "2.7.0", default-features = false, features = ["derive"] }
sp-runtime = { version = "24.0.0", default-features = false, git = "https://github.com/subspace/substrate", rev = "55c157cff49b638a59d81a9f971f0f9a66829c71" }
sp-std = { version = "8.0.0", default-features = false, git = "https://github.com/subspace/substrate", rev = "55c157cff49b638a59d81a9f971f0f9a66829c71" }

[features]
default = ["std"]
std = [
"codec/std",
"frame-support/std",
"frame-system/std",
"scale-info/std",
"sp-runtime/std",
"sp-std/std",
]
72 changes: 72 additions & 0 deletions domains/pallets/domain-transaction-fees/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (C) 2023 Subspace Labs, Inc.
// 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.

//! Pallet Domain Transaction Fees

#![cfg_attr(not(feature = "std"), no_std)]

pub use pallet::*;

#[frame_support::pallet]
mod pallet {
use codec::{Codec, MaxEncodedLen};
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use scale_info::TypeInfo;
use sp_runtime::traits::{AtLeast32BitUnsigned, MaybeSerializeDeserialize, Saturating, Zero};
use sp_runtime::FixedPointOperand;
use sp_std::fmt::Debug;

#[pallet::config]
pub trait Config: frame_system::Config {
/// The balance of an account.
type Balance: Parameter
+ Member
+ AtLeast32BitUnsigned
+ Codec
+ Default
+ Copy
+ MaybeSerializeDeserialize
+ Debug
+ MaxEncodedLen
+ TypeInfo
+ FixedPointOperand;
}

// The accumulated transaction fee of all transactions included in current block
#[pallet::storage]
#[pallet::getter(fn block_transaction_fee)]
pub(super) type BlockTransactionFee<T: Config> = StorageValue<_, T::Balance, ValueQuery>;
NingLin-P marked this conversation as resolved.
Show resolved Hide resolved

/// Pallet domain-transaction-fees to store the domain block transaction fee.
#[pallet::pallet]
#[pallet::without_storage_info]
pub struct Pallet<T>(_);

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(_now: BlockNumberFor<T>) -> Weight {
BlockTransactionFee::<T>::set(Zero::zero());
T::DbWeight::get().writes(1)
}
}

impl<T: Config> Pallet<T> {
pub fn note_transaction_fees(tx_fee: T::Balance) {
let next_tx_fee = BlockTransactionFee::<T>::get().saturating_add(tx_fee);
BlockTransactionFee::<T>::set(next_tx_fee);
}
}
}