Skip to content

Commit c06a4e9

Browse files
committed
Refactor subnet precompile
1 parent 2cfdb41 commit c06a4e9

File tree

8 files changed

+583
-1471
lines changed

8 files changed

+583
-1471
lines changed

runtime/src/precompiles/balance_transfer.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ use crate::Runtime;
1717

1818
pub struct BalanceTransferPrecompile;
1919

20+
impl PrecompileExt for BalanceTransferPrecompile {
21+
const INDEX: u64 = 2048;
22+
const ADDRESS_SS58: [u8; 32] = [
23+
0x07, 0xec, 0x71, 0x2a, 0x5d, 0x38, 0x43, 0x4d, 0xdd, 0x03, 0x3f, 0x8f, 0x02, 0x4e, 0xcd,
24+
0xfc, 0x4b, 0xb5, 0x95, 0x1c, 0x13, 0xc3, 0x08, 0x5c, 0x39, 0x9c, 0x8a, 0x5f, 0x62, 0x93,
25+
0x70, 0x5d,
26+
];
27+
}
28+
2029
#[precompile_utils::precompile]
2130
impl BalanceTransferPrecompile {
2231
#[precompile::public("transfer(bytes32)")]
@@ -38,12 +47,3 @@ impl BalanceTransferPrecompile {
3847
handle.try_dispatch_runtime_call(call, contract_to_origin(&Self::ADDRESS_SS58)?)
3948
}
4049
}
41-
42-
impl PrecompileExt for BalanceTransferPrecompile {
43-
const INDEX: u64 = 2048;
44-
const ADDRESS_SS58: [u8; 32] = [
45-
0x07, 0xec, 0x71, 0x2a, 0x5d, 0x38, 0x43, 0x4d, 0xdd, 0x03, 0x3f, 0x8f, 0x02, 0x4e, 0xcd,
46-
0xfc, 0x4b, 0xb5, 0x95, 0x1c, 0x13, 0xc3, 0x08, 0x5c, 0x39, 0x9c, 0x8a, 0x5f, 0x62, 0x93,
47-
0x70, 0x5d,
48-
];
49-
}

runtime/src/precompiles/ed25519.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ use crate::precompiles::{parse_slice, PrecompileExt};
99

1010
pub struct Ed25519Verify;
1111

12+
impl PrecompileExt for Ed25519Verify {
13+
const INDEX: u64 = 1026;
14+
const ADDRESS_SS58: [u8; 32] = [0; 32];
15+
}
16+
1217
impl LinearCostPrecompile for Ed25519Verify {
1318
const BASE: u64 = 15;
1419
const WORD: u64 = 3;
@@ -41,8 +46,3 @@ impl LinearCostPrecompile for Ed25519Verify {
4146
Ok((ExitSucceed::Returned, buf.to_vec()))
4247
}
4348
}
44-
45-
impl PrecompileExt for Ed25519Verify {
46-
const INDEX: u64 = 1026;
47-
const ADDRESS_SS58: [u8; 32] = [0; 32];
48-
}

runtime/src/precompiles/metagraph.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ use crate::Runtime;
1414

1515
pub struct MetagraphPrecompile;
1616

17+
impl PrecompileExt for MetagraphPrecompile {
18+
const INDEX: u64 = 2050;
19+
const ADDRESS_SS58: [u8; 32] = [0; 32];
20+
}
21+
1722
#[precompile_utils::precompile]
1823
impl MetagraphPrecompile {
1924
#[precompile::public("getUidCount(uint16)")]
@@ -149,11 +154,6 @@ impl MetagraphPrecompile {
149154
}
150155
}
151156

152-
impl PrecompileExt for MetagraphPrecompile {
153-
const INDEX: u64 = 2050;
154-
const ADDRESS_SS58: [u8; 32] = [0; 32];
155-
}
156-
157157
#[derive(Codec)]
158158
struct AxonInfo {
159159
block: u64,

runtime/src/precompiles/neuron.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,17 @@ use crate::precompiles::{
1515
};
1616
use crate::{Runtime, RuntimeCall};
1717

18-
// max paramter lenght 4K
19-
pub const MAX_PARAMETER_SIZE: usize = 4 * 1024;
20-
2118
pub struct NeuronPrecompile;
2219

20+
impl PrecompileExt for NeuronPrecompile {
21+
const INDEX: u64 = 2052;
22+
const ADDRESS_SS58: [u8; 32] = [
23+
0xbc, 0x46, 0x35, 0x79, 0xbc, 0x99, 0xf9, 0xee, 0x7c, 0x59, 0xed, 0xee, 0x20, 0x61, 0xa3,
24+
0x09, 0xd2, 0x1e, 0x68, 0xd5, 0x39, 0xb6, 0x40, 0xec, 0x66, 0x46, 0x90, 0x30, 0xab, 0x74,
25+
0xc1, 0xdb,
26+
];
27+
}
28+
2329
#[precompile_utils::precompile]
2430
impl NeuronPrecompile {
2531
#[precompile::public("setWeights(uint16,uint16[],uint16[],uint64)")]
@@ -91,12 +97,3 @@ impl NeuronPrecompile {
9197
handle.try_dispatch_runtime_call(call, RawOrigin::Signed(coldkey))
9298
}
9399
}
94-
95-
impl PrecompileExt for NeuronPrecompile {
96-
const INDEX: u64 = 2052;
97-
const ADDRESS_SS58: [u8; 32] = [
98-
0xbc, 0x46, 0x35, 0x79, 0xbc, 0x99, 0xf9, 0xee, 0x7c, 0x59, 0xed, 0xee, 0x20, 0x61, 0xa3,
99-
0x09, 0xd2, 0x1e, 0x68, 0xd5, 0x39, 0xb6, 0x40, 0xec, 0x66, 0x46, 0x90, 0x30, 0xab, 0x74,
100-
0xc1, 0xdb,
101-
];
102-
}

runtime/src/precompiles/solidity/subnet.abi

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@
148148
"name": "getImmunityPeriod",
149149
"outputs": [
150150
{
151-
"internalType": "uint64",
151+
"internalType": "uint16",
152152
"name": "",
153-
"type": "uint64"
153+
"type": "uint16"
154154
}
155155
],
156156
"stateMutability": "view",
@@ -243,9 +243,9 @@
243243
"name": "getMaxWeightLimit",
244244
"outputs": [
245245
{
246-
"internalType": "uint64",
246+
"internalType": "uint16",
247247
"name": "",
248-
"type": "uint64"
248+
"type": "uint16"
249249
}
250250
],
251251
"stateMutability": "view",
@@ -443,39 +443,39 @@
443443
"type": "bytes32"
444444
},
445445
{
446-
"internalType": "bytes",
446+
"internalType": "string",
447447
"name": "subnetName",
448-
"type": "bytes"
448+
"type": "string"
449449
},
450450
{
451-
"internalType": "bytes",
451+
"internalType": "string",
452452
"name": "githubRepo",
453-
"type": "bytes"
453+
"type": "string"
454454
},
455455
{
456-
"internalType": "bytes",
456+
"internalType": "string",
457457
"name": "subnetContact",
458-
"type": "bytes"
458+
"type": "string"
459459
},
460460
{
461-
"internalType": "bytes",
461+
"internalType": "string",
462462
"name": "subnetUrl",
463-
"type": "bytes"
463+
"type": "string"
464464
},
465465
{
466-
"internalType": "bytes",
466+
"internalType": "string",
467467
"name": "discord",
468-
"type": "bytes"
468+
"type": "string"
469469
},
470470
{
471-
"internalType": "bytes",
471+
"internalType": "string",
472472
"name": "description",
473-
"type": "bytes"
473+
"type": "string"
474474
},
475475
{
476-
"internalType": "bytes",
476+
"internalType": "string",
477477
"name": "additional",
478-
"type": "bytes"
478+
"type": "string"
479479
}
480480
],
481481
"name": "registerNetwork",
@@ -622,9 +622,9 @@
622622
"type": "uint16"
623623
},
624624
{
625-
"internalType": "uint64",
625+
"internalType": "uint16",
626626
"name": "immunityPeriod",
627-
"type": "uint64"
627+
"type": "uint16"
628628
}
629629
],
630630
"name": "setImmunityPeriod",
@@ -712,9 +712,9 @@
712712
"type": "uint16"
713713
},
714714
{
715-
"internalType": "uint64",
715+
"internalType": "uint16",
716716
"name": "maxWeightLimit",
717-
"type": "uint64"
717+
"type": "uint16"
718718
}
719719
],
720720
"name": "setMaxWeightLimit",
@@ -884,4 +884,4 @@
884884
"stateMutability": "payable",
885885
"type": "function"
886886
}
887-
]
887+
]

runtime/src/precompiles/solidity/subnet.sol

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ interface ISubnet {
88
/// Registers a new network with specified subnet name, GitHub repository, and contact information.
99
function registerNetwork(
1010
bytes32 hotkey,
11-
bytes memory subnetName,
12-
bytes memory githubRepo,
13-
bytes memory subnetContact,
14-
bytes memory subnetUrl,
15-
bytes memory discord,
16-
bytes memory description,
17-
bytes memory additional
11+
string memory subnetName,
12+
string memory githubRepo,
13+
string memory subnetContact,
14+
string memory subnetUrl,
15+
string memory discord,
16+
string memory description,
17+
string memory additional
1818
) external payable;
1919

2020
function getServingRateLimit(uint16 netuid) external view returns (uint64);
@@ -61,14 +61,14 @@ interface ISubnet {
6161
uint64 adjustmentAlpha
6262
) external payable;
6363

64-
function getMaxWeightLimit(uint16 netuid) external view returns (uint64);
64+
function getMaxWeightLimit(uint16 netuid) external view returns (uint16);
6565

6666
function setMaxWeightLimit(
6767
uint16 netuid,
68-
uint64 maxWeightLimit
68+
uint16 maxWeightLimit
6969
) external payable;
7070

71-
function getImmunityPeriod(uint16) external view returns (uint64);
71+
function getImmunityPeriod(uint16) external view returns (uint16);
7272

7373
function setImmunityPeriod(
7474
uint16 netuid,

runtime/src/precompiles/staking.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ use crate::{ProxyType, Runtime, RuntimeCall};
4444

4545
pub struct StakingPrecompile;
4646

47+
impl PrecompileExt for StakingPrecompile {
48+
const INDEX: u64 = 2049;
49+
const ADDRESS_SS58: [u8; 32] = [
50+
0x26, 0xf4, 0x10, 0x1e, 0x52, 0xb7, 0x57, 0x34, 0x33, 0x24, 0x5b, 0xc3, 0x0a, 0xe1, 0x8b,
51+
0x63, 0x99, 0x53, 0xd8, 0x41, 0x79, 0x33, 0x03, 0x61, 0x4d, 0xfa, 0xcf, 0xf0, 0x37, 0xf7,
52+
0x12, 0x94,
53+
];
54+
}
55+
4756
#[precompile_utils::precompile]
4857
impl StakingPrecompile {
4958
#[precompile::public("addStake(bytes32,uint256)")]
@@ -167,12 +176,3 @@ impl StakingPrecompile {
167176
Ok(())
168177
}
169178
}
170-
171-
impl PrecompileExt for StakingPrecompile {
172-
const INDEX: u64 = 2049;
173-
const ADDRESS_SS58: [u8; 32] = [
174-
0x26, 0xf4, 0x10, 0x1e, 0x52, 0xb7, 0x57, 0x34, 0x33, 0x24, 0x5b, 0xc3, 0x0a, 0xe1, 0x8b,
175-
0x63, 0x99, 0x53, 0xd8, 0x41, 0x79, 0x33, 0x03, 0x61, 0x4d, 0xfa, 0xcf, 0xf0, 0x37, 0xf7,
176-
0x12, 0x94,
177-
];
178-
}

0 commit comments

Comments
 (0)