Skip to content

devnet deploy 4/1/2025 #1492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 63 commits into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
12e4f10
Add move_stake and transfer_stake to staking precompile v2
gztensor Mar 20, 2025
606df3d
init solution
open-junius Mar 25, 2025
b53b749
commit Cargo.lock
open-junius Mar 25, 2025
67d0567
more code
open-junius Mar 25, 2025
e88256a
compile ok
open-junius Mar 26, 2025
ccceb75
Merge branch 'devnet-ready' into selective-metagraph
open-junius Mar 26, 2025
b3cb0f9
add test case
open-junius Mar 26, 2025
a90ae12
fix clippy
open-junius Mar 26, 2025
62f8189
update version
open-junius Mar 26, 2025
41d3bf9
just store decrypted bytes
JohnReedV Mar 27, 2025
6bcbafc
fix test compile errors
JohnReedV Mar 27, 2025
67c0044
rm deprecated test
JohnReedV Mar 27, 2025
af12395
keep all revealed instead of replacing
JohnReedV Mar 27, 2025
ad0ae60
commit Cargo.lock
open-junius Mar 28, 2025
c38dde8
cargo fix
open-junius Mar 28, 2025
c8539f1
update version
open-junius Mar 28, 2025
7b542e2
Merge branch 'devnet-ready' into stake_on_subnet_precompile
open-junius Mar 28, 2025
7f22435
remove unused func
open-junius Mar 28, 2025
0824f1d
update solidity
open-junius Mar 28, 2025
6ee0b21
bump runtime version
open-junius Mar 28, 2025
c513a4e
add new evm test case
open-junius Mar 28, 2025
f5ddec8
add test file
open-junius Mar 28, 2025
aa2f376
fmt
JohnReedV Mar 28, 2025
05a31c9
add test timelocked_index_complex_scenario_works
JohnReedV Mar 28, 2025
4b7ef1d
add migration for new storage
JohnReedV Mar 28, 2025
bdda4d9
clippy
JohnReedV Mar 28, 2025
f636217
Merge branch 'devnet-ready' into improve-tlocked-commitments
JohnReedV Mar 28, 2025
5ce4d8b
Merge branch 'devnet-ready' into improve-tlocked-commitments
JohnReedV Mar 28, 2025
acbbe52
bump spec
JohnReedV Mar 28, 2025
0c2cd89
don't save bad commitments
JohnReedV Mar 28, 2025
b987c05
add test reveal_timelocked_bad_timelocks_are_removed
JohnReedV Mar 28, 2025
0481bb9
only keep the 10 most recent revealed commitments
JohnReedV Mar 28, 2025
59dfa9b
add tests for revealed limit
JohnReedV Mar 28, 2025
23a0a96
fix test
JohnReedV Mar 28, 2025
8cc4049
fmt
JohnReedV Mar 28, 2025
da30941
clippy
JohnReedV Mar 28, 2025
d4f3413
Do not use saturating_sub for signed types
gztensor Mar 29, 2025
a2e61c5
Merge branch 'devnet-ready' into fix/get-rid-of-i96
gztensor Mar 31, 2025
7ec9477
spec version bump
gztensor Mar 31, 2025
8f1de13
Merge pull request #1472 from opentensor/improve-tlocked-commitments
JohnReedV Mar 31, 2025
cec883e
add new events
JohnReedV Mar 31, 2025
d0d01f8
emit new events
JohnReedV Mar 31, 2025
b6b4531
fmt
JohnReedV Mar 31, 2025
654ee8b
Merge pull request #1488 from opentensor/add-missing-commit-reveal-ev…
sam0x17 Mar 31, 2025
6e896f1
Merge pull request #1485 from opentensor/fix/get-rid-of-i96
sam0x17 Mar 31, 2025
f4d1a25
Use last epoch hotkey alpha for fee calculation
gztensor Mar 31, 2025
79213b2
Merge branch 'devnet-ready' into fix/tx-fees-in-tao
gztensor Mar 31, 2025
ee4941d
Merge devnet-ready
gztensor Mar 31, 2025
cfe38a5
More tests for dividend variables
gztensor Apr 1, 2025
3fc43c5
add min commitment size
JohnReedV Apr 1, 2025
f405515
add test
JohnReedV Apr 1, 2025
7540223
clippy
JohnReedV Apr 1, 2025
f429c01
Merge branch 'devnet-ready' into feat/stake-transfer-precompile
gztensor Apr 1, 2025
13a5bc6
fix new errors in old tests
JohnReedV Apr 1, 2025
76b3fd8
magic number => variable
JohnReedV Apr 1, 2025
8d7ec15
Merge pull request #1491 from opentensor/min-commit-space
sam0x17 Apr 1, 2025
2d47812
Add transferToggle precompile call, deprecate setMinBurn and setWeigh…
gztensor Apr 1, 2025
3cfc000
Merge pull request #1489 from opentensor/fix/tx-fees-in-tao
sam0x17 Apr 1, 2025
2d023f7
Merge branch 'devnet-ready' into selective-metagraph
gztensor Apr 1, 2025
cee6335
Merge remote-tracking branch 'origin/devnet-ready' into stake_on_subn…
sam0x17 Apr 1, 2025
f6f547b
Merge pull request #1438 from opentensor/feat/stake-transfer-precompile
sam0x17 Apr 1, 2025
1a371e3
Merge pull request #1480 from opentensor/stake_on_subnet_precompile
sam0x17 Apr 1, 2025
c3d85bd
Merge pull request #1463 from opentensor/selective-metagraph
sam0x17 Apr 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion evm-tests/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const ETH_LOCAL_URL = 'http://localhost:9944'
export const SUB_LOCAL_URL = 'ws://localhost:9944'
export const SS58_PREFIX = 42;
// set the tx timeout as 2 second when eable the fast-blocks feature.
export const TX_TIMEOUT = 2000;
export const TX_TIMEOUT = 3000;

export const IED25519VERIFY_ADDRESS = "0x0000000000000000000000000000000000000402";
export const IEd25519VerifyABI = [
Expand Down
48 changes: 48 additions & 0 deletions evm-tests/src/contracts/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,30 @@ export const IStakingV2ABI = [
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "hotkey",
"type": "bytes32"
},
{
"internalType": "uint256",
"name": "netuid",
"type": "uint256"
}
],
"name": "getAlphaStakedValidators",
"outputs": [
{
"internalType": "uint256[]",
"name": "",
"type": "uint256[]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -166,6 +190,30 @@ export const IStakingV2ABI = [
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "hotkey",
"type": "bytes32"
},
{
"internalType": "uint256",
"name": "netuid",
"type": "uint256"
}
],
"name": "getTotalAlphaStaked",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down
57 changes: 57 additions & 0 deletions evm-tests/test/staking.precompile.stake-get.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import * as assert from "assert";
import { getDevnetApi, getRandomSubstrateKeypair } from "../src/substrate"
import { devnet } from "@polkadot-api/descriptors"
import { TypedApi } from "polkadot-api";
import { convertPublicKeyToSs58 } from "../src/address-utils"
import { tao } from "../src/balance-math"
import {
forceSetBalanceToSs58Address, addNewSubnetwork, addStake,
} from "../src/subtensor"
import { ethers } from "ethers";
import { generateRandomEthersWallet } from "../src/utils"
import { ISTAKING_V2_ADDRESS, IStakingV2ABI } from "../src/contracts/staking"
import { log } from "console";

describe("Test staking precompile get methods", () => {
const hotkey = getRandomSubstrateKeypair();
const coldkey = getRandomSubstrateKeypair();
const wallet1 = generateRandomEthersWallet();

let api: TypedApi<typeof devnet>

before(async () => {
api = await getDevnetApi()
await forceSetBalanceToSs58Address(api, convertPublicKeyToSs58(hotkey.publicKey))
await forceSetBalanceToSs58Address(api, convertPublicKeyToSs58(coldkey.publicKey))
let netuid = await addNewSubnetwork(api, hotkey, coldkey)
console.log("will test in subnet: ", netuid)
})

it("Staker receives rewards", async () => {
let netuid = (await api.query.SubtensorModule.TotalNetworks.getValue()) - 1

await addStake(api, netuid, convertPublicKeyToSs58(hotkey.publicKey), tao(1), coldkey)

const contract = new ethers.Contract(
ISTAKING_V2_ADDRESS,
IStakingV2ABI,
wallet1
);

const stake = BigInt(
await contract.getStake(hotkey.publicKey, coldkey.publicKey, netuid)
);

// validator returned as bigint now.
const validators =
await contract.getAlphaStakedValidators(hotkey.publicKey, netuid)

const alpha = BigInt(
await contract.getTotalAlphaStaked(hotkey.publicKey, netuid)
);
assert.ok(stake > 0)
assert.equal(validators.length, 1)
assert.ok(alpha > 0)

})
})
81 changes: 28 additions & 53 deletions pallets/commitments/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ pub mod pallet {
u16,
Twox64Concat,
T::AccountId,
RevealedData<BalanceOf<T>, T::MaxFields, BlockNumberFor<T>>,
Vec<(Vec<u8>, u64)>, // Reveals<(Data, RevealBlock)>
OptionQuery,
>;

Expand Down Expand Up @@ -221,11 +221,13 @@ pub mod pallet {

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

let min_used_space: u64 = 100;
let required_space: u64 = info
.fields
.iter()
.map(|field| field.len_for_rate_limit())
.sum();
.sum::<u64>()
.max(min_used_space);

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

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

let Some(sig) = sig else {
remain_fields.push(Data::TimelockEncrypted {
encrypted,
reveal_round,
});
log::warn!("No sig after deserialization");
continue;
};

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

let Some(commit) = commit else {
remain_fields.push(Data::TimelockEncrypted {
encrypted,
reveal_round,
});
log::warn!("No commit after deserialization");
continue;
};

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

if decrypted_bytes.is_empty() {
remain_fields.push(Data::TimelockEncrypted {
encrypted,
reveal_round,
});
log::warn!("Bytes were decrypted for {:?} but they are empty", who);
continue;
}

let mut reader = &decrypted_bytes[..];
let revealed_info: CommitmentInfo<T::MaxFields> =
match Decode::decode(&mut reader) {
Ok(info) => info,
Err(e) => {
log::warn!(
"Failed to decode decrypted data for {:?}: {:?}",
who,
e
);
remain_fields.push(Data::TimelockEncrypted {
encrypted,
reveal_round,
});
continue;
}
};

revealed_fields.push(revealed_info);
revealed_fields.push(decrypted_bytes);
}

other => remain_fields.push(other),
}
}

if !revealed_fields.is_empty() {
let mut all_revealed_data = Vec::new();
for info in revealed_fields {
all_revealed_data.extend(info.fields.into_inner());
}
let mut existing_reveals =
RevealedCommitments::<T>::get(netuid, &who).unwrap_or_default();

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

let combined_revealed_info = CommitmentInfo {
fields: bounded_revealed,
};
// Push newly revealed items onto the tail of existing_reveals and emit the event
for revealed_bytes in revealed_fields {
existing_reveals.push((revealed_bytes, block_u64));

let revealed_data = RevealedData {
info: combined_revealed_info,
revealed_block: current_block,
deposit: registration.deposit,
};
<RevealedCommitments<T>>::insert(netuid, &who, revealed_data);
Self::deposit_event(Event::CommitmentRevealed {
netuid,
who: who.clone(),
});
Self::deposit_event(Event::CommitmentRevealed {
netuid,
who: who.clone(),
});
}

const MAX_REVEALS: usize = 10;
if existing_reveals.len() > MAX_REVEALS {
let remove_count = existing_reveals.len().saturating_sub(MAX_REVEALS);
existing_reveals.drain(0..remove_count);
}

RevealedCommitments::<T>::insert(netuid, &who, existing_reveals);
}

registration.info.fields = BoundedVec::try_from(remain_fields)
Expand Down
1 change: 1 addition & 0 deletions pallets/commitments/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ use tle::{ibe::fullident::Identity, stream_ciphers::AESGCMStreamCipherProvider,
pub const DRAND_QUICKNET_PUBKEY_HEX: &str = "83cf0f2896adee7eb8b5f01fcad3912212c437e0073e911fb90022d3e760183c8c4b450b6\
a0a6c3ac6a5776a2d1064510d1fec758c921cc22b0e17e63aaf4bcb5ed66304de9cf809b\
d274ca73bab4af5a6e9c76a4bc09e76eae8991ef5ece45a";
pub const DRAND_QUICKNET_SIG_2000_HEX: &str = "b6cb8f482a0b15d45936a4c4ea08e98a087e71787caee3f4d07a8a9843b1bc5423c6b3c22f446488b3137eaca799c77e"; // round 20000
pub const DRAND_QUICKNET_SIG_HEX: &str = "b44679b9a59af2ec876b1a6b1ad52ea9b1615fc3982b19576350f93447cb1125e342b73a8dd2bacbe47e4b6b63ed5e39";

/// Inserts a Drand pulse for `round` with the given `signature_bytes`.
Expand Down
Loading
Loading