Skip to content

Add getNetworkRegisteredBlock view to SubnetPrecompile#2674

Open
fine135 wants to merge 1 commit into
opentensor:devnet-readyfrom
bittensor-church:feat/subnet-precompile-network-registered-block
Open

Add getNetworkRegisteredBlock view to SubnetPrecompile#2674
fine135 wants to merge 1 commit into
opentensor:devnet-readyfrom
bittensor-church:feat/subnet-precompile-network-registered-block

Conversation

@fine135
Copy link
Copy Markdown

@fine135 fine135 commented May 19, 2026

Description

Adds getNetworkRegisteredBlock(uint16) as a view function to SubnetPrecompile, allowing smart contracts to query the block number at which a given subnet was registered. The function reads directly from NetworkRegisteredAt storage and explicitly records db_read_gas_cost so callers are correctly charged when invoked from within a contract.

Also adds the corresponding ABI entry to contract-tests/src/contracts/subnet.ts and an e2e test in contract-tests/test/precompileWrapper.direct-call.test.ts.

Related Issue(s)

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Other (please describe):

Breaking Change

N/A

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have run ./scripts/fix_rust.sh to ensure my code is formatted and linted correctly
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Screenshots (if applicable)

N/A

Additional Notes

The function follows the same pattern as other view functions in SubnetPrecompile (e.g. getServingRateLimit), with the addition of explicit gas metering via handle.record_cost(RuntimeHelper::<R>::db_read_gas_cost()) - unlike the existing view functions which omit this.

@open-junius open-junius added the skip-cargo-audit This PR fails cargo audit but needs to be merged anyway label May 20, 2026
@open-junius
Copy link
Copy Markdown
Contributor

Thanks for the contribution. I will scan all view functions defined in precompiles, record the cost of reading data from storage.

string memory additional
) external payable;
function getServingRateLimit(uint16 netuid) external view returns (uint64);
function getNetworkRegisteredBlock(uint16 netuid) external view returns (uint64);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have the name getNetworkRegisteredAt to map the actual storage name? Or eventually getNetworkRegistrationBlock if we want to decouple it from storage name? It reads better imo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-cargo-audit This PR fails cargo audit but needs to be merged anyway

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants