Skip to content

Commit e7eccd3

Browse files
committed
fix conflict
2 parents e8cdefe + 6bd03ae commit e7eccd3

33 files changed

+1354
-721
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/transaction-priority.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
## Transaction Priority
2+
3+
### Overview
4+
In Subtensor, transaction priority is determined by custom transaction extensions, which alter or override the default Substrate SDK behavior. Extensions affecting transaction priority are:
5+
6+
- **`ChargeTransactionPaymentWrapper`** (wraps `ChargeTransactionPayment`)
7+
- **`DrandPriority`**
8+
9+
Substrate SDK combines priorities from all transaction extensions using addition.
10+
11+
---
12+
13+
### 1. `ChargeTransactionPaymentWrapper`
14+
In the Substrate SDK, `ChargeTransactionPayment` normally calculates transaction priority based on:
15+
- **Tip** — an extra fee paid by the sender.
16+
- **Weight** — computational complexity of the transaction.
17+
- **Dispatch class** — category of the transaction (`Normal`, `Operational`, `Mandatory`).
18+
19+
However, in Subtensor, `ChargeTransactionPaymentWrapper` **overrides** this logic.
20+
It replaces the dynamic calculation with a **flat priority scale** based only on the dispatch class.
21+
22+
#### Current priority values:
23+
| Dispatch Class | Priority Value | Notes |
24+
|---------------------|-------------------|--------------------------------------------------------------|
25+
| `Normal` | `1` | Standard transactions |
26+
| `Mandatory` | `1` | Rarely used, same as `Normal` |
27+
| `Operational` | `10_000_000_000` | Reserved for critical system extrinsics (e.g.: `sudo` calls) |
28+
29+
30+
---
31+
32+
### 2. `DrandPriority`
33+
34+
Special pallet_drand priority: 10_000 for `write_pulse` extrinsic.
35+
36+
---

node/src/benchmarking.rs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
use crate::client::FullClient;
66

77
use node_subtensor_runtime as runtime;
8-
use node_subtensor_runtime::check_nonce;
98
use node_subtensor_runtime::pallet_subtensor;
9+
use node_subtensor_runtime::{check_nonce, transaction_payment_wrapper};
1010
use runtime::{BalancesCall, SystemCall};
1111
use sc_cli::Result;
1212
use sc_client_api::BlockBackend;
@@ -123,21 +123,27 @@ pub fn create_benchmark_extrinsic(
123123
.checked_next_power_of_two()
124124
.map(|c| c / 2)
125125
.unwrap_or(2) as u64;
126-
let extra: runtime::TransactionExtensions = (
127-
frame_system::CheckNonZeroSender::<runtime::Runtime>::new(),
128-
frame_system::CheckSpecVersion::<runtime::Runtime>::new(),
129-
frame_system::CheckTxVersion::<runtime::Runtime>::new(),
130-
frame_system::CheckGenesis::<runtime::Runtime>::new(),
131-
frame_system::CheckEra::<runtime::Runtime>::from(sp_runtime::generic::Era::mortal(
132-
period,
133-
best_block.saturated_into(),
134-
)),
135-
check_nonce::CheckNonce::<runtime::Runtime>::from(nonce),
136-
frame_system::CheckWeight::<runtime::Runtime>::new(),
137-
pallet_transaction_payment::ChargeTransactionPayment::<runtime::Runtime>::from(0),
138-
pallet_subtensor::SubtensorTransactionExtension::<runtime::Runtime>::new(),
139-
frame_metadata_hash_extension::CheckMetadataHash::<runtime::Runtime>::new(true),
140-
);
126+
let extra: runtime::TransactionExtensions =
127+
(
128+
frame_system::CheckNonZeroSender::<runtime::Runtime>::new(),
129+
frame_system::CheckSpecVersion::<runtime::Runtime>::new(),
130+
frame_system::CheckTxVersion::<runtime::Runtime>::new(),
131+
frame_system::CheckGenesis::<runtime::Runtime>::new(),
132+
frame_system::CheckEra::<runtime::Runtime>::from(sp_runtime::generic::Era::mortal(
133+
period,
134+
best_block.saturated_into(),
135+
)),
136+
check_nonce::CheckNonce::<runtime::Runtime>::from(nonce),
137+
frame_system::CheckWeight::<runtime::Runtime>::new(),
138+
transaction_payment_wrapper::ChargeTransactionPaymentWrapper::new(
139+
pallet_transaction_payment::ChargeTransactionPayment::<runtime::Runtime>::from(0),
140+
),
141+
pallet_subtensor::transaction_extension::SubtensorTransactionExtension::<
142+
runtime::Runtime,
143+
>::new(),
144+
pallet_drand::drand_priority::DrandPriority::<runtime::Runtime>::new(),
145+
frame_metadata_hash_extension::CheckMetadataHash::<runtime::Runtime>::new(true),
146+
);
141147

142148
let raw_payload = runtime::SignedPayload::from_raw(
143149
call.clone(),
@@ -152,6 +158,7 @@ pub fn create_benchmark_extrinsic(
152158
(),
153159
(),
154160
(),
161+
(),
155162
None,
156163
),
157164
);

pallets/admin-utils/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,21 @@ pub mod pallet {
16671667
pallet_subtensor::Pallet::<T>::set_commit_reveal_weights_version(version);
16681668
Ok(())
16691669
}
1670+
1671+
/// Sets the number of immune owner neurons
1672+
#[pallet::call_index(72)]
1673+
#[pallet::weight(Weight::from_parts(15_000_000, 0)
1674+
.saturating_add(<T as frame_system::Config>::DbWeight::get().reads(1_u64))
1675+
.saturating_add(<T as frame_system::Config>::DbWeight::get().writes(1_u64)))]
1676+
pub fn sudo_set_owner_immune_neuron_limit(
1677+
origin: OriginFor<T>,
1678+
netuid: NetUid,
1679+
immune_neurons: u16,
1680+
) -> DispatchResult {
1681+
pallet_subtensor::Pallet::<T>::ensure_subnet_owner_or_root(origin, netuid)?;
1682+
pallet_subtensor::Pallet::<T>::set_owner_immune_neuron_limit(netuid, immune_neurons)?;
1683+
Ok(())
1684+
}
16701685
}
16711686
}
16721687

pallets/commitments/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ pub mod pallet {
208208
Weight::from_parts(33_480_000, 0)
209209
.saturating_add(T::DbWeight::get().reads(5_u64))
210210
.saturating_add(T::DbWeight::get().writes(4_u64)),
211-
DispatchClass::Operational,
211+
DispatchClass::Normal,
212212
Pays::No
213213
))]
214214
pub fn set_commitment(

pallets/drand/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ frame-system.workspace = true
2727
sp-core.workspace = true
2828
sp-io.workspace = true
2929
sp-runtime.workspace = true
30+
sp-std.workspace = true
3031
# arkworks dependencies
3132
sp-ark-bls12-381.workspace = true
3233
ark-bls12-381 = { workspace = true, features = ["curve"] }
@@ -55,6 +56,7 @@ std = [
5556
"frame-system/std",
5657
"scale-info/std",
5758
"sp-core/std",
59+
"sp-std/std",
5860
"sp-io/std",
5961
"sp-keystore/std",
6062
"sp-keyring/std",
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
use crate::{Call, Config};
2+
use codec::{Decode, DecodeWithMemTracking, Encode};
3+
use frame_support::dispatch::{DispatchInfo, PostDispatchInfo};
4+
use frame_support::pallet_prelude::Weight;
5+
use frame_support::traits::IsSubType;
6+
use scale_info::TypeInfo;
7+
use sp_runtime::traits::{
8+
DispatchInfoOf, DispatchOriginOf, Dispatchable, Implication, TransactionExtension,
9+
ValidateResult,
10+
};
11+
use sp_runtime::transaction_validity::{
12+
TransactionPriority, TransactionSource, TransactionValidityError, ValidTransaction,
13+
};
14+
use sp_std::marker::PhantomData;
15+
use subtensor_macros::freeze_struct;
16+
17+
pub type RuntimeCallFor<T> = <T as frame_system::Config>::RuntimeCall;
18+
19+
#[freeze_struct("d0d094192bd6390e")]
20+
#[derive(Default, Encode, Decode, DecodeWithMemTracking, Clone, Eq, PartialEq, TypeInfo)]
21+
pub struct DrandPriority<T: Config + Send + Sync + TypeInfo>(pub PhantomData<T>);
22+
23+
impl<T: Config + Send + Sync + TypeInfo> sp_std::fmt::Debug for DrandPriority<T> {
24+
fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
25+
write!(f, "DrandPriority")
26+
}
27+
}
28+
29+
impl<T: Config + Send + Sync + TypeInfo> DrandPriority<T> {
30+
pub fn new() -> Self {
31+
Self(PhantomData)
32+
}
33+
34+
fn get_drand_priority() -> TransactionPriority {
35+
10_000u64
36+
}
37+
}
38+
39+
impl<T: Config + Send + Sync + TypeInfo> TransactionExtension<RuntimeCallFor<T>>
40+
for DrandPriority<T>
41+
where
42+
<T as frame_system::Config>::RuntimeCall:
43+
Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>,
44+
<T as frame_system::Config>::RuntimeCall: IsSubType<Call<T>>,
45+
{
46+
const IDENTIFIER: &'static str = "DrandPriority";
47+
type Implicit = ();
48+
type Val = ();
49+
type Pre = ();
50+
51+
fn weight(&self, _call: &RuntimeCallFor<T>) -> Weight {
52+
// TODO: benchmark transaction extension
53+
Weight::zero()
54+
}
55+
56+
fn validate(
57+
&self,
58+
origin: DispatchOriginOf<RuntimeCallFor<T>>,
59+
call: &RuntimeCallFor<T>,
60+
_info: &DispatchInfoOf<RuntimeCallFor<T>>,
61+
_len: usize,
62+
_self_implicit: Self::Implicit,
63+
_inherited_implication: &impl Implication,
64+
_source: TransactionSource,
65+
) -> ValidateResult<Self::Val, RuntimeCallFor<T>> {
66+
match call.is_sub_type() {
67+
Some(Call::write_pulse { .. }) => {
68+
let validity = ValidTransaction {
69+
priority: Self::get_drand_priority(),
70+
..Default::default()
71+
};
72+
73+
Ok((validity, (), origin))
74+
}
75+
_ => Ok((Default::default(), (), origin)),
76+
}
77+
}
78+
79+
fn prepare(
80+
self,
81+
_val: Self::Val,
82+
_origin: &DispatchOriginOf<RuntimeCallFor<T>>,
83+
_call: &RuntimeCallFor<T>,
84+
_info: &DispatchInfoOf<RuntimeCallFor<T>>,
85+
_len: usize,
86+
) -> Result<Self::Pre, TransactionValidityError> {
87+
Ok(())
88+
}
89+
}

pallets/drand/src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ use sp_runtime::{
5858
};
5959

6060
pub mod bls12_381;
61+
pub mod drand_priority;
6162
pub mod migrations;
6263
pub mod types;
6364
pub mod utils;
@@ -404,9 +405,9 @@ pub mod pallet {
404405
/// * `origin`: the root user
405406
/// * `config`: the beacon configuration
406407
#[pallet::call_index(1)]
407-
#[pallet::weight(Weight::from_parts(8_766_000, 0)
408+
#[pallet::weight((Weight::from_parts(8_766_000, 0)
408409
.saturating_add(T::DbWeight::get().reads(0_u64))
409-
.saturating_add(T::DbWeight::get().writes(2_u64)))]
410+
.saturating_add(T::DbWeight::get().writes(2_u64)), DispatchClass::Operational))]
410411
pub fn set_beacon_config(
411412
origin: OriginFor<T>,
412413
config_payload: BeaconConfigurationPayload<T::Public, BlockNumberFor<T>>,
@@ -425,9 +426,9 @@ pub mod pallet {
425426

426427
/// allows the root user to set the oldest stored round
427428
#[pallet::call_index(2)]
428-
#[pallet::weight(Weight::from_parts(5_370_000, 0)
429+
#[pallet::weight((Weight::from_parts(5_370_000, 0)
429430
.saturating_add(T::DbWeight::get().reads(0_u64))
430-
.saturating_add(T::DbWeight::get().writes(1_u64)))]
431+
.saturating_add(T::DbWeight::get().writes(1_u64)), DispatchClass::Operational))]
431432
pub fn set_oldest_stored_round(origin: OriginFor<T>, oldest_round: u64) -> DispatchResult {
432433
ensure_root(origin)?;
433434
OldestStoredRound::<T>::put(oldest_round);

pallets/registry/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub mod pallet {
113113
#[pallet::call_index(0)]
114114
#[pallet::weight((
115115
T::WeightInfo::set_identity(),
116-
DispatchClass::Operational
116+
DispatchClass::Normal
117117
))]
118118
pub fn set_identity(
119119
origin: OriginFor<T>,

pallets/subtensor/src/coinbase/reveal_commits.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ impl<T: Config> Pallet<T> {
4545
let reveal_epoch = cur_epoch.saturating_sub(reveal_period);
4646

4747
// Clean expired commits
48-
for (epoch, _) in CRV3WeightCommitsV2::<T>::iter_prefix(netuid) {
48+
for (epoch, _) in TimelockedWeightCommits::<T>::iter_prefix(netuid) {
4949
if epoch < reveal_epoch {
50-
CRV3WeightCommitsV2::<T>::remove(netuid, epoch);
50+
TimelockedWeightCommits::<T>::remove(netuid, epoch);
5151
}
5252
}
5353

@@ -57,7 +57,7 @@ impl<T: Config> Pallet<T> {
5757
return Ok(());
5858
}
5959

60-
let mut entries = CRV3WeightCommitsV2::<T>::take(netuid, reveal_epoch);
60+
let mut entries = TimelockedWeightCommits::<T>::take(netuid, reveal_epoch);
6161
let mut unrevealed = VecDeque::new();
6262

6363
// Keep popping items off the front of the queue until we successfully reveal a commit.
@@ -185,11 +185,11 @@ impl<T: Config> Pallet<T> {
185185
continue;
186186
}
187187

188-
Self::deposit_event(Event::CRV3WeightsRevealed(netuid, who));
188+
Self::deposit_event(Event::TimelockedWeightsRevealed(netuid, who));
189189
}
190190

191191
if !unrevealed.is_empty() {
192-
CRV3WeightCommitsV2::<T>::insert(netuid, reveal_epoch, unrevealed);
192+
TimelockedWeightCommits::<T>::insert(netuid, reveal_epoch, unrevealed);
193193
}
194194

195195
Ok(())

0 commit comments

Comments
 (0)