Skip to content

Commit 82c776b

Browse files
committed
Merge remote-tracking branch 'origin/devnet-ready' into sam-fix-hotfix-merge-conflict-4-7-2025
2 parents 719a6f5 + 8091fb4 commit 82c776b

Some content is hidden

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

54 files changed

+3690
-530
lines changed

Diff for: .github/workflows/docker.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ jobs:
6666
push: true
6767
platforms: linux/amd64
6868
tags: |
69-
ghcr.io/${{ github.repository }}:${{ env.tag }}
70-
${{ env.latest_tag == 'true' && format('ghcr.io/{0}:latest', github.repository) || '' }}
69+
ghcr.io/${{ github.repository }}:${{ env.tag }}-amd64
70+
${{ env.latest_tag == 'true' && format('ghcr.io/{0}:latest-amd64', github.repository) || '' }}
7171
publish-arm:
7272
runs-on: SubtensorCI
7373

@@ -112,5 +112,5 @@ jobs:
112112
push: true
113113
platforms: linux/arm64
114114
tags: |
115-
ghcr.io/${{ github.repository }}:${{ env.tag }}
116-
${{ env.latest_tag == 'true' && format('ghcr.io/{0}:latest', github.repository) || '' }}
115+
ghcr.io/${{ github.repository }}:${{ env.tag }}-arm64
116+
${{ env.latest_tag == 'true' && format('ghcr.io/{0}:latest-arm64', github.repository) || '' }}

Diff for: Cargo.lock

+5-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ futures = "0.3.30"
6767
hex = { version = "0.4", default-features = false }
6868
hex-literal = "0.4.1"
6969
jsonrpsee = { version = "0.24.4", default-features = false }
70+
libsecp256k1 = { version = "0.7.2", default-features = false }
7071
log = { version = "0.4.21", default-features = false }
7172
memmap2 = "0.9.4"
7273
ndarray = { version = "0.15.6", default-features = false }

Diff for: evm-tests/src/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export const ETH_LOCAL_URL = 'http://localhost:9944'
22
export const SUB_LOCAL_URL = 'ws://localhost:9944'
33
export const SS58_PREFIX = 42;
44
// set the tx timeout as 2 second when eable the fast-blocks feature.
5-
export const TX_TIMEOUT = 2000;
5+
export const TX_TIMEOUT = 3000;
66

77
export const IED25519VERIFY_ADDRESS = "0x0000000000000000000000000000000000000402";
88
export const IEd25519VerifyABI = [

Diff for: evm-tests/src/contracts/staking.ts

+48
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,30 @@ export const IStakingV2ABI = [
137137
"stateMutability": "payable",
138138
"type": "function"
139139
},
140+
{
141+
"inputs": [
142+
{
143+
"internalType": "bytes32",
144+
"name": "hotkey",
145+
"type": "bytes32"
146+
},
147+
{
148+
"internalType": "uint256",
149+
"name": "netuid",
150+
"type": "uint256"
151+
}
152+
],
153+
"name": "getAlphaStakedValidators",
154+
"outputs": [
155+
{
156+
"internalType": "uint256[]",
157+
"name": "",
158+
"type": "uint256[]"
159+
}
160+
],
161+
"stateMutability": "view",
162+
"type": "function"
163+
},
140164
{
141165
"inputs": [
142166
{
@@ -166,6 +190,30 @@ export const IStakingV2ABI = [
166190
"stateMutability": "view",
167191
"type": "function"
168192
},
193+
{
194+
"inputs": [
195+
{
196+
"internalType": "bytes32",
197+
"name": "hotkey",
198+
"type": "bytes32"
199+
},
200+
{
201+
"internalType": "uint256",
202+
"name": "netuid",
203+
"type": "uint256"
204+
}
205+
],
206+
"name": "getTotalAlphaStaked",
207+
"outputs": [
208+
{
209+
"internalType": "uint256",
210+
"name": "",
211+
"type": "uint256"
212+
}
213+
],
214+
"stateMutability": "view",
215+
"type": "function"
216+
},
169217
{
170218
"inputs": [
171219
{

Diff for: evm-tests/test/staking.precompile.stake-get.test.ts

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import * as assert from "assert";
2+
import { getDevnetApi, getRandomSubstrateKeypair } from "../src/substrate"
3+
import { devnet } from "@polkadot-api/descriptors"
4+
import { TypedApi } from "polkadot-api";
5+
import { convertPublicKeyToSs58 } from "../src/address-utils"
6+
import { tao } from "../src/balance-math"
7+
import {
8+
forceSetBalanceToSs58Address, addNewSubnetwork, addStake,
9+
} from "../src/subtensor"
10+
import { ethers } from "ethers";
11+
import { generateRandomEthersWallet } from "../src/utils"
12+
import { ISTAKING_V2_ADDRESS, IStakingV2ABI } from "../src/contracts/staking"
13+
import { log } from "console";
14+
15+
describe("Test staking precompile get methods", () => {
16+
const hotkey = getRandomSubstrateKeypair();
17+
const coldkey = getRandomSubstrateKeypair();
18+
const wallet1 = generateRandomEthersWallet();
19+
20+
let api: TypedApi<typeof devnet>
21+
22+
before(async () => {
23+
api = await getDevnetApi()
24+
await forceSetBalanceToSs58Address(api, convertPublicKeyToSs58(hotkey.publicKey))
25+
await forceSetBalanceToSs58Address(api, convertPublicKeyToSs58(coldkey.publicKey))
26+
let netuid = await addNewSubnetwork(api, hotkey, coldkey)
27+
console.log("will test in subnet: ", netuid)
28+
})
29+
30+
it("Staker receives rewards", async () => {
31+
let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1
32+
33+
await addStake(api, netuid, convertPublicKeyToSs58(hotkey.publicKey), tao(1), coldkey)
34+
35+
const contract = new ethers.Contract(
36+
ISTAKING_V2_ADDRESS,
37+
IStakingV2ABI,
38+
wallet1
39+
);
40+
41+
const stake = BigInt(
42+
await contract.getStake(hotkey.publicKey, coldkey.publicKey, netuid)
43+
);
44+
45+
// validator returned as bigint now.
46+
const validators =
47+
await contract.getAlphaStakedValidators(hotkey.publicKey, netuid)
48+
49+
const alpha = BigInt(
50+
await contract.getTotalAlphaStaked(hotkey.publicKey, netuid)
51+
);
52+
assert.ok(stake > 0)
53+
assert.equal(validators.length, 1)
54+
assert.ok(alpha > 0)
55+
56+
})
57+
})

Diff for: pallets/commitments/src/lib.rs

+28-53
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ pub mod pallet {
172172
u16,
173173
Twox64Concat,
174174
T::AccountId,
175-
RevealedData<BalanceOf<T>, T::MaxFields, BlockNumberFor<T>>,
175+
Vec<(Vec<u8>, u64)>, // Reveals<(Data, RevealBlock)>
176176
OptionQuery,
177177
>;
178178

@@ -221,11 +221,13 @@ pub mod pallet {
221221

222222
let cur_block = <frame_system::Pallet<T>>::block_number();
223223

224+
let min_used_space: u64 = 100;
224225
let required_space: u64 = info
225226
.fields
226227
.iter()
227228
.map(|field| field.len_for_rate_limit())
228-
.sum();
229+
.sum::<u64>()
230+
.max(min_used_space);
229231

230232
let mut usage = UsedSpaceOf::<T>::get(netuid, &who).unwrap_or_default();
231233
let cur_block_u64 = cur_block.saturated_into::<u64>();
@@ -478,7 +480,6 @@ where
478480

479481
impl<T: Config> Pallet<T> {
480482
pub fn reveal_timelocked_commitments() -> DispatchResult {
481-
let current_block = <frame_system::Pallet<T>>::block_number();
482483
let index = TimelockedIndex::<T>::get();
483484
for (netuid, who) in index.clone() {
484485
let Some(mut registration) = <CommitmentOf<T>>::get(netuid, &who) else {
@@ -528,10 +529,7 @@ impl<T: Config> Pallet<T> {
528529
.ok();
529530

530531
let Some(sig) = sig else {
531-
remain_fields.push(Data::TimelockEncrypted {
532-
encrypted,
533-
reveal_round,
534-
});
532+
log::warn!("No sig after deserialization");
535533
continue;
536534
};
537535

@@ -547,10 +545,7 @@ impl<T: Config> Pallet<T> {
547545
.ok();
548546

549547
let Some(commit) = commit else {
550-
remain_fields.push(Data::TimelockEncrypted {
551-
encrypted,
552-
reveal_round,
553-
});
548+
log::warn!("No commit after deserialization");
554549
continue;
555550
};
556551

@@ -563,61 +558,41 @@ impl<T: Config> Pallet<T> {
563558
.unwrap_or_default();
564559

565560
if decrypted_bytes.is_empty() {
566-
remain_fields.push(Data::TimelockEncrypted {
567-
encrypted,
568-
reveal_round,
569-
});
561+
log::warn!("Bytes were decrypted for {:?} but they are empty", who);
570562
continue;
571563
}
572564

573-
let mut reader = &decrypted_bytes[..];
574-
let revealed_info: CommitmentInfo<T::MaxFields> =
575-
match Decode::decode(&mut reader) {
576-
Ok(info) => info,
577-
Err(e) => {
578-
log::warn!(
579-
"Failed to decode decrypted data for {:?}: {:?}",
580-
who,
581-
e
582-
);
583-
remain_fields.push(Data::TimelockEncrypted {
584-
encrypted,
585-
reveal_round,
586-
});
587-
continue;
588-
}
589-
};
590-
591-
revealed_fields.push(revealed_info);
565+
revealed_fields.push(decrypted_bytes);
592566
}
593567

594568
other => remain_fields.push(other),
595569
}
596570
}
597571

598572
if !revealed_fields.is_empty() {
599-
let mut all_revealed_data = Vec::new();
600-
for info in revealed_fields {
601-
all_revealed_data.extend(info.fields.into_inner());
602-
}
573+
let mut existing_reveals =
574+
RevealedCommitments::<T>::get(netuid, &who).unwrap_or_default();
603575

604-
let bounded_revealed = BoundedVec::try_from(all_revealed_data)
605-
.map_err(|_| "Could not build BoundedVec for revealed fields")?;
576+
let current_block = <frame_system::Pallet<T>>::block_number();
577+
let block_u64 = current_block.saturated_into::<u64>();
606578

607-
let combined_revealed_info = CommitmentInfo {
608-
fields: bounded_revealed,
609-
};
579+
// Push newly revealed items onto the tail of existing_reveals and emit the event
580+
for revealed_bytes in revealed_fields {
581+
existing_reveals.push((revealed_bytes, block_u64));
610582

611-
let revealed_data = RevealedData {
612-
info: combined_revealed_info,
613-
revealed_block: current_block,
614-
deposit: registration.deposit,
615-
};
616-
<RevealedCommitments<T>>::insert(netuid, &who, revealed_data);
617-
Self::deposit_event(Event::CommitmentRevealed {
618-
netuid,
619-
who: who.clone(),
620-
});
583+
Self::deposit_event(Event::CommitmentRevealed {
584+
netuid,
585+
who: who.clone(),
586+
});
587+
}
588+
589+
const MAX_REVEALS: usize = 10;
590+
if existing_reveals.len() > MAX_REVEALS {
591+
let remove_count = existing_reveals.len().saturating_sub(MAX_REVEALS);
592+
existing_reveals.drain(0..remove_count);
593+
}
594+
595+
RevealedCommitments::<T>::insert(netuid, &who, existing_reveals);
621596
}
622597

623598
registration.info.fields = BoundedVec::try_from(remain_fields)

Diff for: pallets/commitments/src/mock.rs

+1
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ use tle::{ibe::fullident::Identity, stream_ciphers::AESGCMStreamCipherProvider,
207207
pub const DRAND_QUICKNET_PUBKEY_HEX: &str = "83cf0f2896adee7eb8b5f01fcad3912212c437e0073e911fb90022d3e760183c8c4b450b6\
208208
a0a6c3ac6a5776a2d1064510d1fec758c921cc22b0e17e63aaf4bcb5ed66304de9cf809b\
209209
d274ca73bab4af5a6e9c76a4bc09e76eae8991ef5ece45a";
210+
pub const DRAND_QUICKNET_SIG_2000_HEX: &str = "b6cb8f482a0b15d45936a4c4ea08e98a087e71787caee3f4d07a8a9843b1bc5423c6b3c22f446488b3137eaca799c77e"; // round 20000
210211
pub const DRAND_QUICKNET_SIG_HEX: &str = "b44679b9a59af2ec876b1a6b1ad52ea9b1615fc3982b19576350f93447cb1125e342b73a8dd2bacbe47e4b6b63ed5e39";
211212

212213
/// Inserts a Drand pulse for `round` with the given `signature_bytes`.

0 commit comments

Comments
 (0)