Skip to content

Commit b8d6f86

Browse files
authored
Merge pull request #190 from subspace/transaction-fees
Split fees into storage/compute/tip, add storage fee escrow
2 parents 11620f9 + f8ce741 commit b8d6f86

File tree

14 files changed

+579
-64
lines changed

14 files changed

+579
-64
lines changed

Cargo.lock

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/pallet-rewards/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition = "2021"
66
license = "Apache-2.0"
77
homepage = "https://subspace.network"
88
repository = "https://github.com/subspace/subspace"
9-
description = "Subspace pallet for issuing rewards to block producers"
9+
description = "Pallet for issuing rewards to block producers"
1010
readme = "README.md"
1111
include = [
1212
"/src",
@@ -22,7 +22,6 @@ codec = { package = "parity-scale-codec", version = "2.3.0", default-features =
2222
frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate", rev = "b6c1c1bcfa5d831bfd1f278064d7af757f9b38f5" }
2323
frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate", rev = "b6c1c1bcfa5d831bfd1f278064d7af757f9b38f5" }
2424
scale-info = { version = "1.0", default-features = false, features = ["derive"] }
25-
sp-consensus-subspace = { version = "0.1.0", default-features = false, path = "../sp-consensus-subspace" }
2625

2726
[features]
2827
default = ["std"]
@@ -31,6 +30,5 @@ std = [
3130
"frame-support/std",
3231
"frame-system/std",
3332
"scale-info/std",
34-
"sp-consensus-subspace/std",
3533
]
3634
try-runtime = ["frame-support/try-runtime"]

crates/pallet-rewards/src/lib.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,17 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
//! Subspace pallet for issuing rewards to block producers.
16+
//! Pallet for issuing rewards to block producers.
1717
1818
#![cfg_attr(not(feature = "std"), no_std)]
1919
#![forbid(unsafe_code)]
2020
#![warn(rust_2018_idioms, missing_debug_implementations)]
2121

2222
mod default_weights;
2323

24-
use frame_support::traits::{Currency, Get};
24+
use frame_support::traits::{Currency, FindAuthor, Get};
2525
use frame_support::weights::Weight;
2626
pub use pallet::*;
27-
use sp_consensus_subspace::digests::CompatibleDigestItem;
2827

2928
pub trait WeightInfo {
3029
fn on_initialize() -> Weight;
@@ -34,7 +33,7 @@ pub trait WeightInfo {
3433
mod pallet {
3534
use super::WeightInfo;
3635
use frame_support::pallet_prelude::*;
37-
use frame_support::traits::Currency;
36+
use frame_support::traits::{Currency, FindAuthor};
3837
use frame_system::pallet_prelude::*;
3938

4039
type BalanceOf<T> =
@@ -51,6 +50,8 @@ mod pallet {
5150
#[pallet::constant]
5251
type BlockReward: Get<BalanceOf<Self>>;
5352

53+
type FindAuthor: FindAuthor<Self::AccountId>;
54+
5455
type WeightInfo: WeightInfo;
5556
}
5657

@@ -81,19 +82,20 @@ mod pallet {
8182

8283
impl<T: Config> Pallet<T> {
8384
fn do_initialize(_n: T::BlockNumber) {
84-
if let Some(block_author) = frame_system::Pallet::<T>::digest()
85-
.logs
86-
.iter()
87-
.find_map(|s| s.as_subspace_pre_digest())
88-
.map(|pre_digest| pre_digest.solution.public_key)
89-
{
90-
let reward = T::BlockReward::get();
91-
T::Currency::deposit_creating(&block_author, reward);
92-
93-
Self::deposit_event(Event::BlockReward {
94-
block_author,
95-
reward,
96-
});
97-
}
85+
let block_author = T::FindAuthor::find_author(
86+
frame_system::Pallet::<T>::digest()
87+
.logs
88+
.iter()
89+
.filter_map(|d| d.as_pre_runtime()),
90+
)
91+
.expect("Block author must always be present; qed");
92+
93+
let reward = T::BlockReward::get();
94+
T::Currency::deposit_creating(&block_author, reward);
95+
96+
Self::deposit_event(Event::BlockReward {
97+
block_author,
98+
reward,
99+
});
98100
}
99101
}

crates/pallet-subspace/src/lib.rs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ use sp_runtime::transaction_validity::{
5757
use sp_runtime::{
5858
generic::DigestItem,
5959
traits::{One, SaturatedConversion, Saturating, Zero},
60+
ConsensusEngineId,
6061
};
6162
use sp_std::prelude::*;
6263
use subspace_core_primitives::{crypto, RootBlock, PIECE_SIZE, RANDOMNESS_LENGTH, SALT_SIZE};
@@ -200,11 +201,6 @@ mod pallet {
200201
#[pallet::constant]
201202
type RecordedHistorySegmentSize: Get<u32>;
202203

203-
/// Replication factor, defines minimum desired number of replicas of the blockchain to be
204-
/// stored by the network.
205-
#[pallet::constant]
206-
type ReplicationFactor: Get<u16>;
207-
208204
/// Subspace requires some logic to be triggered on every block to query for whether an epoch
209205
/// has ended and to perform the transition to the next epoch.
210206
///
@@ -698,14 +694,15 @@ impl<T: Config> Pallet<T> {
698694

699695
// TODO: Temporary testnet hack, we don't update solution range for the first 15_000 blocks
700696
// in order to seed the blockchain with data quickly
701-
#[cfg(all(feature = "no-early-solution-range-updates", not(test)))]
702-
let solution_range = if block_number < 15_000_u32.into() {
703-
previous_solution_range
697+
let solution_range = if cfg!(all(feature = "no-early-solution-range-updates", not(test))) {
698+
if block_number < 15_000_u32.into() {
699+
previous_solution_range
700+
} else {
701+
(previous_solution_range as f64 * adjustment_factor).round() as u64
702+
}
704703
} else {
705704
(previous_solution_range as f64 * adjustment_factor).round() as u64
706705
};
707-
#[cfg(not(all(feature = "no-early-solution-range-updates", not(test))))]
708-
let solution_range = (previous_solution_range as f64 * adjustment_factor).round() as u64;
709706

710707
SolutionRange::<T>::put(solution_range);
711708
EraStartSlot::<T>::put(current_slot);
@@ -1110,6 +1107,23 @@ impl<T: Config> OnTimestampSet<T::Moment> for Pallet<T> {
11101107
}
11111108
}
11121109

1110+
impl<T: Config> frame_support::traits::FindAuthor<T::AccountId> for Pallet<T> {
1111+
fn find_author<'a, I>(digests: I) -> Option<T::AccountId>
1112+
where
1113+
I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,
1114+
{
1115+
digests.into_iter().find_map(|(id, mut data)| {
1116+
if id == SUBSPACE_ENGINE_ID {
1117+
PreDigest::decode(&mut data)
1118+
.map(|pre_digest| pre_digest.solution.public_key)
1119+
.ok()
1120+
} else {
1121+
None
1122+
}
1123+
})
1124+
}
1125+
}
1126+
11131127
impl<T: Config> frame_support::traits::Lateness<T::BlockNumber> for Pallet<T> {
11141128
fn lateness(&self) -> T::BlockNumber {
11151129
Self::lateness()

crates/pallet-subspace/src/mock.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ impl Config for Test {
165165
type ConfirmationDepthK = ConfirmationDepthK;
166166
type RecordSize = RecordSize;
167167
type RecordedHistorySegmentSize = RecordedHistorySegmentSize;
168-
type ReplicationFactor = ReplicationFactor;
169168
type EpochChangeTrigger = NormalEpochChange;
170169
type EraChangeTrigger = NormalEraChange;
171170
type EonChangeTrigger = NormalEonChange;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[package]
2+
name = "pallet-transaction-fees"
3+
version = "0.1.0"
4+
authors = ["Nazar Mokrynskyi <[email protected]>"]
5+
edition = "2021"
6+
license = "Apache-2.0"
7+
homepage = "https://subspace.network"
8+
repository = "https://github.com/subspace/subspace"
9+
description = "Pallet for charging and re-distributing transaction fees"
10+
readme = "README.md"
11+
include = [
12+
"/src",
13+
"/Cargo.toml",
14+
"/README.md",
15+
]
16+
17+
[package.metadata.docs.rs]
18+
targets = ["x86_64-unknown-linux-gnu"]
19+
20+
[dependencies]
21+
codec = { package = "parity-scale-codec", version = "2.3.0", default-features = false, features = ["derive"] }
22+
frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate", rev = "b6c1c1bcfa5d831bfd1f278064d7af757f9b38f5" }
23+
frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate", rev = "b6c1c1bcfa5d831bfd1f278064d7af757f9b38f5" }
24+
scale-info = { version = "1.0", default-features = false, features = ["derive"] }
25+
26+
[features]
27+
default = ["std"]
28+
std = [
29+
"codec/std",
30+
"frame-support/std",
31+
"frame-system/std",
32+
"scale-info/std",
33+
]
34+
try-runtime = ["frame-support/try-runtime"]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Pallet Transaction Fees
2+
3+
Pallet for charging and re-distributing transaction fees.
4+
5+
License: Apache-2.0
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (C) 2021 Subspace Labs, Inc.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
//! Default weights for the Rewards Pallet
17+
//! This file was not auto-generated.
18+
19+
use frame_support::weights::Weight;
20+
21+
impl crate::WeightInfo for () {
22+
fn on_initialize() -> Weight {
23+
// TODO: Correct value
24+
1
25+
}
26+
}

0 commit comments

Comments
 (0)