-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
feat: add custom rpc #48
Conversation
could you ensure the keys show the address they are staked to? I don't see this in the subspace_getKeyInfo example |
subspace_getKeyInfo updated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer using documentation comments when adding descriptions to fields:
struct Foo {
/// This field defines the BLA. Allowed range is [0, 100).
field: usize,
}
Notice the three slashes there.
pallets/subspace/rpc/src/lib.rs
Outdated
let value = api.get_global_info(at).map_err(runtime_error_into_rpc_err); | ||
Ok(value.unwrap()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let value = api.get_global_info(at).map_err(runtime_error_into_rpc_err); | |
Ok(value.unwrap()) | |
api.get_global_info(at).map_err(runtime_error_into_rpc_err) |
pallets/subspace/rpc/src/lib.rs
Outdated
let value = api.get_subnet_info(at, netuid).map_err(runtime_error_into_rpc_err); | ||
Ok(value.unwrap()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let value = api.get_subnet_info(at, netuid).map_err(runtime_error_into_rpc_err); | |
Ok(value.unwrap()) | |
api.get_subnet_info(at, netuid).map_err(runtime_error_into_rpc_err) |
pallets/subspace/rpc/src/lib.rs
Outdated
let value = api.get_key_info(at, key).map_err(runtime_error_into_rpc_err); | ||
Ok(value.unwrap()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let value = api.get_key_info(at, key).map_err(runtime_error_into_rpc_err); | |
Ok(value.unwrap()) | |
api.get_key_info(at, key).map_err(runtime_error_into_rpc_err) |
pallets/subspace/src/subnet.rs
Outdated
pub fn get_subnet_name(netuid: u16) -> Vec<u8> { | ||
Self::subnet_params(netuid).name | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is reaaaaally inefficient. If someone wishes to fetch only the name of a subnet, let them access it directly:
pub fn get_subnet_name(netuid: u16) -> Vec<u8> { | |
Self::subnet_params(netuid).name | |
} | |
pub fn get_subnet_name(netuid: u16) -> Vec<u8> { | |
SubnetNames::<T>::get(netuid) | |
} |
I would be even better if we didn't need this function at all. I'd say we access SubnetNames directly when we need to find a name.
delegation_fee: params.delegation_fee, | ||
controller: params.controller, | ||
} | ||
} | ||
} | ||
|
||
fn get_key_info(key: AccountId) -> KeyInfo { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also really inefficient. You should iterate through StakeTo
with iter_prefix
, to avoid iterating for modules that the key doesn't have connections to.
Currently, every time someone calls this, it will iterate through every subnet and module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even better if you figure out a way to only iterate through subnets the key is present.
fix according to recommendations |
feat(pallets/subspace): add arbitrary uri parameter
feat(pallets/subspace): add arbitrary uri parameter
Add Custom RPC
Returns global
params
andstats
params:
burn_rate
,max_name_length
,max_allowed_subnets
,max_allowed_modules
,max_registrations_per_block
,max_allowed_weights
,max_proposals
,max_burn
,min_burn
,min_stake
,floor_delegation_fee
,min_weight_stake
,target_registrations_per_interval
,target_registrations_interval
,adjustment_alpha
,unit_emission
,tx_rate_limit
,vote_threshold
,vote_mode
stats:
registrations_per_block
,total_subnets
Returns subnet
params
andstats
params:
founder
,founder_share
,immunity_period
,incentive_ratio
,max_allowed_uids
,max_allowed_weights
,min_allowed_weights
,max_stake
,max_weight_age
,min_stake
,name
,tempo
,trust_ratio
,vote_threshold
,vote_mode
stats:
emission
,n_uids
,pending_emission
,total_stake
Returns user key's
balance
,total_stake
and thestake_to
info across all subnets user stakedstake_to:
netuid
,subnet_name
, Vec<module_name
,stake_amount_to_module
>Returns module
uid
,params
andstats
params:
name
,address
,delegation_fee
,controller
stats:
last_update
,registration_block
,stake_from
,emission
,incentive
,dividends
,weights
runtime/src/lib.rs:1027~1157
Test Custom RPC
build subspace
cargo build --release
run dev node
./target/release/node-subspace --dev
test rpc endpoints using curl
expected results
subspace_getGlobalInfo
subspace_getSubnetInfo
subspace_getKeyInfo
subspace_getModuleInfo