Skip to content

Commit 79010a3

Browse files
authored
Merge pull request #2095 from opentensor/testnet
mainnet deploy 9/30/2025
2 parents 835a2c9 + 5ad0e70 commit 79010a3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+9870
-4801
lines changed

Cargo.lock

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

Cargo.toml

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

evm-tests/test/evm-uid.precompile.lookup.test.ts

Lines changed: 60 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -14,77 +14,76 @@ import { keccak256 } from 'ethers';
1414
import { addNewSubnetwork, forceSetBalanceToSs58Address, startCall } from "../src/subtensor";
1515

1616
describe("Test the UID Lookup precompile", () => {
17-
const hotkey = getRandomSubstrateKeypair();
18-
const coldkey = getRandomSubstrateKeypair();
19-
const evmWallet = generateRandomEthersWallet();
20-
let publicClient: PublicClient;
17+
const hotkey = getRandomSubstrateKeypair();
18+
const coldkey = getRandomSubstrateKeypair();
19+
const evmWallet = generateRandomEthersWallet();
20+
let publicClient: PublicClient;
2121

22-
let api: TypedApi<typeof devnet>
22+
let api: TypedApi<typeof devnet>
2323

24-
let alice: PolkadotSigner;
24+
let alice: PolkadotSigner;
2525

26-
let uid: number;
27-
let blockNumber: number;
28-
let netuid: number;
29-
let blockNumberAssociated: bigint;
26+
let uid: number;
27+
let blockNumber: number;
28+
let netuid: number;
29+
let blockNumberAssociated: bigint;
3030

31-
before(async () => {
32-
publicClient = await getPublicClient(ETH_LOCAL_URL)
33-
api = await getDevnetApi()
34-
alice = await getAliceSigner();
31+
before(async () => {
32+
publicClient = await getPublicClient(ETH_LOCAL_URL)
33+
api = await getDevnetApi()
34+
alice = await getAliceSigner();
3535

36-
await forceSetBalanceToSs58Address(api, convertPublicKeyToSs58(alice.publicKey))
37-
await forceSetBalanceToSs58Address(api, convertPublicKeyToSs58(hotkey.publicKey))
38-
await forceSetBalanceToSs58Address(api, convertPublicKeyToSs58(coldkey.publicKey))
36+
await forceSetBalanceToSs58Address(api, convertPublicKeyToSs58(alice.publicKey))
37+
await forceSetBalanceToSs58Address(api, convertPublicKeyToSs58(hotkey.publicKey))
38+
await forceSetBalanceToSs58Address(api, convertPublicKeyToSs58(coldkey.publicKey))
3939

40-
netuid = await addNewSubnetwork(api, hotkey, coldkey)
41-
await startCall(api, netuid, coldkey)
40+
netuid = await addNewSubnetwork(api, hotkey, coldkey)
41+
await startCall(api, netuid, coldkey)
4242

43-
const maybeUid = await api.query.SubtensorModule.Uids.getValue(netuid, convertPublicKeyToSs58(hotkey.publicKey))
43+
const maybeUid = await api.query.SubtensorModule.Uids.getValue(netuid, convertPublicKeyToSs58(hotkey.publicKey))
4444

45-
if (maybeUid === undefined) {
46-
throw new Error("UID should be defined")
47-
}
48-
uid = maybeUid
45+
if (maybeUid === undefined) {
46+
throw new Error("UID should be defined")
47+
}
48+
uid = maybeUid
4949

50-
// Associate EVM key
51-
blockNumber = await api.query.System.Number.getValue();
52-
const blockNumberBytes = u64.enc(BigInt(blockNumber));
53-
const blockNumberHash = hexToU8a(keccak256(blockNumberBytes));
54-
const concatenatedArray = new Uint8Array([...hotkey.publicKey, ...blockNumberHash]);
55-
const signature = await evmWallet.signMessage(concatenatedArray);
56-
const associateEvmKeyTx = api.tx.SubtensorModule.associate_evm_key({
57-
netuid: netuid,
58-
hotkey: convertPublicKeyToSs58(hotkey.publicKey),
59-
evm_key: convertToFixedSizeBinary(evmWallet.address, 20),
60-
block_number: BigInt(blockNumber),
61-
signature: convertToFixedSizeBinary(signature, 65)
62-
});
63-
const signer = getSignerFromKeypair(coldkey);
64-
await waitForTransactionCompletion(api, associateEvmKeyTx, signer)
65-
.then(() => { })
66-
.catch((error) => { console.log(`transaction error ${error}`) });
50+
// Associate EVM key
51+
blockNumber = await api.query.System.Number.getValue();
52+
const blockNumberBytes = u64.enc(BigInt(blockNumber));
53+
const blockNumberHash = hexToU8a(keccak256(blockNumberBytes));
54+
const concatenatedArray = new Uint8Array([...hotkey.publicKey, ...blockNumberHash]);
55+
const signature = await evmWallet.signMessage(concatenatedArray);
56+
const associateEvmKeyTx = api.tx.SubtensorModule.associate_evm_key({
57+
netuid: netuid,
58+
evm_key: convertToFixedSizeBinary(evmWallet.address, 20),
59+
block_number: BigInt(blockNumber),
60+
signature: convertToFixedSizeBinary(signature, 65)
61+
});
62+
const signer = getSignerFromKeypair(hotkey);
63+
await waitForTransactionCompletion(api, associateEvmKeyTx, signer)
64+
.then(() => { })
65+
.catch((error) => { console.log(`transaction error ${error}`) });
6766

68-
const storedEvmKey = await api.query.SubtensorModule.AssociatedEvmAddress.getValue(netuid, uid)
69-
assert.notEqual(storedEvmKey, undefined, "storedEvmKey should be defined")
70-
if (storedEvmKey !== undefined) {
71-
assert.equal(storedEvmKey[0].asHex(), convertToFixedSizeBinary(evmWallet.address, 20).asHex())
72-
blockNumberAssociated = storedEvmKey[1]
73-
}
74-
})
75-
76-
it("UID lookup via precompile contract works correctly", async () => {
77-
// Get UID for the EVM address
78-
const uidArray = await publicClient.readContract({
79-
abi: IUIDLookupABI,
80-
address: toViemAddress(IUID_LOOKUP_ADDRESS),
81-
functionName: "uidLookup",
82-
args: [netuid, evmWallet.address, 1024]
83-
})
67+
const storedEvmKey = await api.query.SubtensorModule.AssociatedEvmAddress.getValue(netuid, uid)
68+
assert.notEqual(storedEvmKey, undefined, "storedEvmKey should be defined")
69+
if (storedEvmKey !== undefined) {
70+
assert.equal(storedEvmKey[0].asHex(), convertToFixedSizeBinary(evmWallet.address, 20).asHex())
71+
blockNumberAssociated = storedEvmKey[1]
72+
}
73+
})
8474

85-
assert.notEqual(uidArray, undefined, "UID should be defined")
86-
assert.ok(Array.isArray(uidArray), `UID should be an array, got ${typeof uidArray}`)
87-
assert.ok(uidArray.length > 0, "UID array should not be empty")
88-
assert.deepStrictEqual(uidArray[0], { uid: uid, block_associated: blockNumberAssociated })
75+
it("UID lookup via precompile contract works correctly", async () => {
76+
// Get UID for the EVM address
77+
const uidArray = await publicClient.readContract({
78+
abi: IUIDLookupABI,
79+
address: toViemAddress(IUID_LOOKUP_ADDRESS),
80+
functionName: "uidLookup",
81+
args: [netuid, evmWallet.address, 1024]
8982
})
83+
84+
assert.notEqual(uidArray, undefined, "UID should be defined")
85+
assert.ok(Array.isArray(uidArray), `UID should be an array, got ${typeof uidArray}`)
86+
assert.ok(uidArray.length > 0, "UID array should not be empty")
87+
assert.deepStrictEqual(uidArray[0], { uid: uid, block_associated: blockNumberAssociated })
88+
})
9089
});

node/Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ serde_json.workspace = true
3434
sc-chain-spec-derive.workspace = true
3535
sc-cli.workspace = true
3636
sc-consensus-babe.workspace = true
37+
sc-consensus-epochs.workspace = true
3738
sp-consensus.workspace = true
3839
sp-consensus-slots.workspace = true
3940
sp-core.workspace = true
@@ -73,8 +74,9 @@ sp-crypto-ec-utils = { workspace = true, default-features = true, features = [
7374
"bls12-381",
7475
] }
7576
sp-keystore.workspace = true
76-
cumulus-primitives-proof-size-hostfunction.workspace = true
77-
77+
polkadot-sdk = { workspace = true, features = [
78+
"cumulus-primitives-proof-size-hostfunction",
79+
] }
7880

7981
# These dependencies are used for the subtensor's RPCs
8082
jsonrpsee = { workspace = true, features = ["server"] }
@@ -151,6 +153,7 @@ runtime-benchmarks = [
151153
"pallet-commitments/runtime-benchmarks",
152154
"pallet-drand/runtime-benchmarks",
153155
"pallet-transaction-payment/runtime-benchmarks",
156+
"polkadot-sdk/runtime-benchmarks",
154157
]
155158
pow-faucet = []
156159

@@ -163,6 +166,7 @@ try-runtime = [
163166
"sp-runtime/try-runtime",
164167
"pallet-commitments/try-runtime",
165168
"pallet-drand/try-runtime",
169+
"polkadot-sdk/try-runtime",
166170
]
167171

168172
metadata-hash = ["node-subtensor-runtime/metadata-hash"]

node/src/chain_spec/localnet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn localnet_config(single_authority: bool) -> Result<ChainSpec, String> {
2828
.with_name("Bittensor")
2929
.with_protocol_id("bittensor")
3030
.with_id("bittensor")
31-
.with_chain_type(ChainType::Development)
31+
.with_chain_type(ChainType::Local)
3232
.with_genesis_config_patch(localnet_genesis(
3333
// Initial PoA authorities (Validators)
3434
// aura | grandpa

node/src/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use cumulus_primitives_proof_size_hostfunction::storage_proof_size::HostFunctions as ProofSize;
21
use node_subtensor_runtime::{RuntimeApi, opaque::Block};
2+
use polkadot_sdk::cumulus_primitives_proof_size_hostfunction::storage_proof_size::HostFunctions as ProofSize;
33
use sc_executor::WasmExecutor;
44

55
/// Full backend.

node/src/command.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ fn start_babe_service(arg_matches: &ArgMatches) -> Result<(), sc_cli::Error> {
273273
return start_babe_service(arg_matches);
274274
// Unknown error, return it.
275275
} else {
276+
log::error!("Failed to start Babe service: {e:?}");
276277
Err(e.into())
277278
}
278279
}
@@ -288,16 +289,21 @@ fn start_aura_service(arg_matches: &ArgMatches) -> Result<(), sc_cli::Error> {
288289
//
289290
// Passing this atomic bool is a hacky solution, allowing the node to set it to true to indicate
290291
// a Babe service should be spawned on exit instead of a regular shutdown.
291-
let babe_switch = Arc::new(AtomicBool::new(false));
292-
let babe_switch_clone = babe_switch.clone();
292+
let custom_service_signal = Arc::new(AtomicBool::new(false));
293+
let custom_service_signal_clone = custom_service_signal.clone();
293294
match runner.run_node_until_exit(|config| async move {
294295
let config = customise_config(arg_matches, config);
295-
service::build_full::<AuraConsensus>(config, cli.eth, cli.sealing, Some(babe_switch_clone))
296-
.await
296+
service::build_full::<AuraConsensus>(
297+
config,
298+
cli.eth,
299+
cli.sealing,
300+
Some(custom_service_signal_clone),
301+
)
302+
.await
297303
}) {
298304
Ok(()) => Ok(()),
299305
Err(e) => {
300-
if babe_switch.load(std::sync::atomic::Ordering::Relaxed) {
306+
if custom_service_signal.load(std::sync::atomic::Ordering::Relaxed) {
301307
start_babe_service(arg_matches)
302308
} else {
303309
Err(e.into())

0 commit comments

Comments
 (0)