Every subnet must have a way for subnet nodes to register on-chain using the Hypertensor extrinsic:
Copy pub fn register_subnet_node(
origin: OriginFor<T>,
subnet_id: u32,
peer_id: PeerId,
stake_to_be_added: u128,
a: Option<BoundedVec<u8, DefaultSubnetNodeParamLimit>>,
b: Option<BoundedVec<u8, DefaultSubnetNodeParamLimit>>,
c: Option<BoundedVec<u8, DefaultSubnetNodeParamLimit>>,
)
For example, in the Hypertensor DSN standard, each subnet node must stake on-chain to verify its proof-of-stake before being authenticated to enter the subnet. Once the subnet is registered on-chain, it will then enter using the CLI within the subnet before activating itself on-chain.
After registering, the subnet node has up to the MaxSubnetNodeRegistrationEpochs
to activate.
Copy def register_subnet_node(
substrate: SubstrateInterface,
keypair: Keypair,
subnet_id: int,
peer_id: str,
stake_to_be_added: int,
a: Optional[str] = None,
b: Optional[str] = None,
c: Optional[str] = None,
) -> ExtrinsicReceipt:
call = substrate.compose_call(
call_module='Network',
call_function='register_subnet_node',
call_params={
'subnet_id': subnet_id,
'peer_id': peer_id,
'stake_to_be_added': stake_to_be_added,
'a': a,
'b': b,
'c': c,
}
)
extrinsic = substrate.create_signed_extrinsic(call=call, keypair=keypair)
@retry(wait=wait_exponential(multiplier=1, min=4, max=10), stop=stop_after_attempt(4))
def submit_extrinsic():
try:
receipt = substrate.submit_extrinsic(extrinsic, wait_for_inclusion=True)
return receipt
except SubstrateRequestException as e:
print("Failed to send: {}".format(e))
return submit_extrinsic()