Skip to content

Commit ef5f1a7

Browse files
committed
merge target
2 parents 506092d + ffa23bc commit ef5f1a7

File tree

13 files changed

+225
-113
lines changed

13 files changed

+225
-113
lines changed

.github/workflows/run-benchmarks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ concurrency:
1616

1717
jobs:
1818
validate-benchmarks:
19-
runs-on: [self-hosted, type-ccx33]
19+
runs-on: Benchmarking
2020

2121
env:
2222
SKIP_BENCHMARKS: "0"

Cargo.lock

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

pallets/admin-utils/src/lib.rs

Lines changed: 29 additions & 29 deletions
Large diffs are not rendered by default.

pallets/commitments/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ pub mod pallet {
205205
/// Set the commitment for a given netuid
206206
#[pallet::call_index(0)]
207207
#[pallet::weight((
208-
Weight::from_parts(25_070_000, 0)
208+
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)),
211211
DispatchClass::Operational,
@@ -343,7 +343,7 @@ pub mod pallet {
343343
/// Sudo-set MaxSpace
344344
#[pallet::call_index(2)]
345345
#[pallet::weight((
346-
Weight::from_parts(1_660_000, 0)
346+
Weight::from_parts(2_856_000, 0)
347347
.saturating_add(T::DbWeight::get().reads(0_u64))
348348
.saturating_add(T::DbWeight::get().writes(1_u64)),
349349
DispatchClass::Operational,

pallets/drand/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ pub mod pallet {
404404
/// * `origin`: the root user
405405
/// * `config`: the beacon configuration
406406
#[pallet::call_index(1)]
407-
#[pallet::weight(Weight::from_parts(5_450_000, 0)
407+
#[pallet::weight(Weight::from_parts(8_766_000, 0)
408408
.saturating_add(T::DbWeight::get().reads(0_u64))
409409
.saturating_add(T::DbWeight::get().writes(2_u64)))]
410410
pub fn set_beacon_config(
@@ -425,7 +425,7 @@ pub mod pallet {
425425

426426
/// allows the root user to set the oldest stored round
427427
#[pallet::call_index(2)]
428-
#[pallet::weight(Weight::from_parts(3_350_000, 0)
428+
#[pallet::weight(Weight::from_parts(5_370_000, 0)
429429
.saturating_add(T::DbWeight::get().reads(0_u64))
430430
.saturating_add(T::DbWeight::get().writes(1_u64)))]
431431
pub fn set_oldest_stored_round(origin: OriginFor<T>, oldest_round: u64) -> DispatchResult {

pallets/subtensor/src/macros/dispatches.rs

Lines changed: 36 additions & 36 deletions
Large diffs are not rendered by default.

pallets/subtensor/src/tests/registration.rs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(clippy::unwrap_used)]
22

33
use approx::assert_abs_diff_eq;
4-
use frame_support::dispatch::{DispatchClass, DispatchInfo, GetDispatchInfo, Pays};
4+
use frame_support::dispatch::DispatchInfo;
55
use frame_support::sp_runtime::{DispatchError, transaction_validity::TransactionSource};
66
use frame_support::traits::Currency;
77
use frame_support::{assert_err, assert_noop, assert_ok};
@@ -18,36 +18,6 @@ use crate::{AxonInfoOf, CustomTransactionError, Error, SubtensorTransactionExten
1818
subscribing::subscribe() tests
1919
*********************************************/
2020

21-
// Tests a basic registration dispatch passes.
22-
#[test]
23-
fn test_registration_subscribe_ok_dispatch_info_ok() {
24-
new_test_ext(1).execute_with(|| {
25-
let block_number: u64 = 0;
26-
let nonce: u64 = 0;
27-
let netuid = NetUid::from(1);
28-
let work: Vec<u8> = vec![0; 32];
29-
let hotkey: U256 = U256::from(0);
30-
let coldkey: U256 = U256::from(0);
31-
let call = RuntimeCall::SubtensorModule(SubtensorCall::register {
32-
netuid,
33-
block_number,
34-
nonce,
35-
work,
36-
hotkey,
37-
coldkey,
38-
});
39-
assert_eq!(
40-
call.get_dispatch_info(),
41-
DispatchInfo {
42-
call_weight: frame_support::weights::Weight::from_parts(3_111_800_000, 0),
43-
extension_weight: frame_support::weights::Weight::zero(),
44-
class: DispatchClass::Normal,
45-
pays_fee: Pays::No
46-
}
47-
);
48-
});
49-
}
50-
5121
#[test]
5222
fn test_registration_difficulty() {
5323
new_test_ext(1).execute_with(|| {

pallets/swap/rpc/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ sp-api.workspace = true
1111
sp-blockchain.workspace = true
1212
sp-runtime.workspace = true
1313
pallet-subtensor-swap-runtime-api.workspace = true
14+
subtensor-runtime-common = { workspace = true, default-features = false }
15+
subtensor-swap-interface.workspace = true
1416

1517
[features]
1618
default = ["std"]
@@ -19,4 +21,6 @@ std = [
1921
"pallet-subtensor-swap-runtime-api/std",
2022
"sp-api/std",
2123
"sp-runtime/std",
24+
"subtensor-runtime-common/std",
25+
"subtensor-swap-interface/std",
2226
]

pallets/swap/rpc/src/lib.rs

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! RPC interface for the Swap pallet
22
3+
use codec::Encode;
34
use std::sync::Arc;
45

56
use jsonrpsee::{
@@ -10,13 +11,28 @@ use jsonrpsee::{
1011
use sp_api::ProvideRuntimeApi;
1112
use sp_blockchain::HeaderBackend;
1213
use sp_runtime::traits::Block as BlockT;
14+
use subtensor_runtime_common::{AlphaCurrency, NetUid, TaoCurrency};
1315

1416
pub use pallet_subtensor_swap_runtime_api::SwapRuntimeApi;
1517

1618
#[rpc(client, server)]
1719
pub trait SwapRpcApi<BlockHash> {
1820
#[method(name = "swap_currentAlphaPrice")]
19-
fn current_alpha_price(&self, netuid: u16, at: Option<BlockHash>) -> RpcResult<u64>;
21+
fn current_alpha_price(&self, netuid: NetUid, at: Option<BlockHash>) -> RpcResult<u64>;
22+
#[method(name = "swap_simSwapTaoForAlpha")]
23+
fn sim_swap_tao_for_alpha(
24+
&self,
25+
netuid: NetUid,
26+
tao: TaoCurrency,
27+
at: Option<BlockHash>,
28+
) -> RpcResult<Vec<u8>>;
29+
#[method(name = "swap_simSwapAlphaForTao")]
30+
fn sim_swap_alpha_for_tao(
31+
&self,
32+
netuid: NetUid,
33+
alpha: AlphaCurrency,
34+
at: Option<BlockHash>,
35+
) -> RpcResult<Vec<u8>>;
2036
}
2137

2238
/// Error type of this RPC api.
@@ -65,7 +81,7 @@ where
6581
{
6682
fn current_alpha_price(
6783
&self,
68-
netuid: u16,
84+
netuid: NetUid,
6985
at: Option<<Block as BlockT>::Hash>,
7086
) -> RpcResult<u64> {
7187
let api = self.client.runtime_api();
@@ -75,4 +91,40 @@ where
7591
Error::RuntimeError(format!("Unable to get current alpha price: {e:?}")).into()
7692
})
7793
}
94+
95+
fn sim_swap_tao_for_alpha(
96+
&self,
97+
netuid: NetUid,
98+
tao: TaoCurrency,
99+
at: Option<<Block as BlockT>::Hash>,
100+
) -> RpcResult<Vec<u8>> {
101+
let api = self.client.runtime_api();
102+
let at = at.unwrap_or_else(|| self.client.info().best_hash);
103+
104+
match api.sim_swap_tao_for_alpha(at, netuid, tao) {
105+
Ok(result) => Ok(result.encode()),
106+
Err(e) => Err(Error::RuntimeError(format!(
107+
"Unable to simulate tao -> alpha swap: {e:?}"
108+
))
109+
.into()),
110+
}
111+
}
112+
113+
fn sim_swap_alpha_for_tao(
114+
&self,
115+
netuid: NetUid,
116+
alpha: AlphaCurrency,
117+
at: Option<<Block as BlockT>::Hash>,
118+
) -> RpcResult<Vec<u8>> {
119+
let api = self.client.runtime_api();
120+
let at = at.unwrap_or_else(|| self.client.info().best_hash);
121+
122+
match api.sim_swap_alpha_for_tao(at, netuid, alpha) {
123+
Ok(result) => Ok(result.encode()),
124+
Err(e) => Err(Error::RuntimeError(format!(
125+
"Unable to simulate alpha -> tao swap: {e:?}"
126+
))
127+
.into()),
128+
}
129+
}
78130
}

pallets/swap/runtime-api/Cargo.toml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,22 @@ edition.workspace = true
66

77
[dependencies]
88
codec = { workspace = true, features = ["derive"] }
9+
frame-support.workspace = true
910
scale-info.workspace = true
1011
sp-api.workspace = true
1112
sp-std.workspace = true
13+
subtensor-macros.workspace = true
14+
subtensor-runtime-common = { workspace = true, default-features = false }
15+
subtensor-swap-interface.workspace = true
1216

1317
[features]
1418
default = ["std"]
15-
std = ["codec/std", "scale-info/std", "sp-api/std", "sp-std/std"]
19+
std = [
20+
"codec/std",
21+
"frame-support/std",
22+
"scale-info/std",
23+
"sp-api/std",
24+
"sp-std/std",
25+
"subtensor-runtime-common/std",
26+
"subtensor-swap-interface/std"
27+
]

0 commit comments

Comments
 (0)