Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
5 changes: 5 additions & 0 deletions contract-tests/src/contracts/precompileWrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ interface ISubnet {
string memory additional
) external payable;
function getServingRateLimit(uint16 netuid) external view returns (uint64);
function getNetworkRegistrationBlock(uint16 netuid) external view returns (uint64);
}

interface INeuron {
Expand Down Expand Up @@ -223,6 +224,10 @@ contract PrecompileWrapper {
return subnet.getServingRateLimit(netuid);
}

function getNetworkRegistrationBlock(uint16 netuid) external view returns (uint64) {
return subnet.getNetworkRegistrationBlock(netuid);
}

// ============ Neuron Functions ============

function burnedRegister(uint16 netuid, bytes32 hotkey) external payable {
Expand Down
21 changes: 20 additions & 1 deletion contract-tests/src/contracts/precompileWrapper.ts

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions contract-tests/src/contracts/subnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,25 @@ export const ISubnetABI = [
stateMutability: "view",
type: "function",
},
{
inputs: [
{
internalType: "uint16",
name: "netuid",
type: "uint16",
},
],
name: "getNetworkRegistrationBlock",
outputs: [
{
internalType: "uint64",
name: "",
type: "uint64",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [
{
Expand Down
9 changes: 9 additions & 0 deletions contract-tests/test/precompileWrapper.direct-call.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ describe("PrecompileWrapper - Direct Call Tests", () => {
assert.ok(rateLimitViaWrapper !== undefined, "Rate limit should be not undefined");
});

it("Should get network registered block via wrapper", async () => {
const onchainValue = await api.query.SubtensorModule.NetworkRegisteredAt.getValue(netuid);

const valueViaWrapper = Number(await wrapperContract.getNetworkRegistrationBlock(netuid));

assert.ok(valueViaWrapper > 0, "Network registered block should be greater than 0");
assert.equal(valueViaWrapper, onchainValue, "Network registered block should match on-chain value");
});

it("Should register network with details via wrapper", async () => {
const newHotkey = getRandomSubstrateKeypair();
await forceSetBalanceToSs58Address(api, convertPublicKeyToSs58(newHotkey.publicKey));
Expand Down
41 changes: 40 additions & 1 deletion precompiles/src/subnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use frame_support::traits::ConstU32;
use frame_support::traits::IsSubType;
use frame_system::RawOrigin;
use pallet_evm::{AddressMapping, PrecompileHandle};
use precompile_utils::{EvmResult, prelude::BoundedString};
use precompile_utils::{
EvmResult,
prelude::{BoundedString, RuntimeHelper},
};
use sp_core::H256;
use sp_runtime::traits::{AsSystemOriginSigner, Dispatchable};
use sp_std::vec;
Expand Down Expand Up @@ -161,6 +164,18 @@ where
)
}

#[precompile::public("getNetworkRegistrationBlock(uint16)")]
#[precompile::view]
fn get_network_registration_block(
handle: &mut impl PrecompileHandle,
netuid: u16,
) -> EvmResult<u64> {
handle.record_cost(RuntimeHelper::<R>::db_read_gas_cost())?;
Ok(pallet_subtensor::NetworkRegisteredAt::<R>::get(
NetUid::from(netuid),
))
}

#[precompile::public("getServingRateLimit(uint16)")]
#[precompile::view]
fn get_serving_rate_limit(_: &mut impl PrecompileHandle, netuid: u16) -> EvmResult<u64> {
Expand Down Expand Up @@ -1225,4 +1240,28 @@ mod tests {
);
});
}

#[test]
fn subnet_precompile_gets_network_registered_block() {
new_test_ext().execute_with(|| {
let caller = addr_from_index(0x5003);
let netuid = setup_owner_subnet(caller);
let precompiles = precompiles::<SubnetPrecompile<Runtime>>();
let precompile_addr = addr_from_index(SubnetPrecompile::<Runtime>::INDEX);

let registration_block: u64 = 42;
pallet_subtensor::NetworkRegisteredAt::<Runtime>::insert(netuid, registration_block);

assert_static_call(
&precompiles,
caller,
precompile_addr,
encode_with_selector(
selector_u32("getNetworkRegistrationBlock(uint16)"),
(TEST_NETUID_U16,),
),
U256::from(registration_block),
);
});
}
}
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// `spec_version`, and `authoring_version` are the same between Wasm and native.
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
// the compatible custom types.
spec_version: 413,
spec_version: 414,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down
Loading