Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[rpc] Get protocol config endpoint(#11510)
## Description ### Adds RPC support to get protocol config. If the protocol config is not specified, the node returns the config for the epoch its currently processing. Examples **1. Valid protocol version (9) specified** ``` curl --location --request POST 0.0.0.0:9000 \ --header 'Content-Type: application/json' \ --data-raw '{ "jsonrpc":"2.0", "id":1, "method":"sui_getProtocolConfig", "params":["9"] }'| jq % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 8546 100 8453 100 93 547k 6169 --:--:-- --:--:-- --:--:-- 1043k { "jsonrpc": "2.0", "result": { "minSupportedProtocolVersion": "1", "maxSupportedProtocolVersion": "10", "protocolVersion": "9", "featureFlags": { "advance_epoch_start_time_in_safe_mode": true, "advance_to_highest_supported_protocol_version": true, "ban_entry_init": true, "commit_root_state_digest": false, .............[truncated]................... }, "attributes": { "address_from_bytes_cost_base": { "u64": "52" }, "address_from_u256_cost_base": { "u64": "52" }, "address_to_u256_cost_base": { "u64": "52" }, .............[truncated]................... ``` **2. Invalid protocol version specified** ``` curl --location --request POST 0.0.0.0:9000 \ --header 'Content-Type: application/json' \ --data-raw '{ "jsonrpc":"2.0", "id":1, "method":"sui_getProtocolConfig", "params":["19"] }'| jq % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 230 100 136 100 94 9841 6802 --:--:-- --:--:-- --:--:-- 224k { "jsonrpc": "2.0", "error": { "code": -32000, "message": "Unsupported protocol version requested. Min supported: 1, max supported: 10" }, "id": 1 } ``` **3. No protocol version specified** Although this node supports protocol version 1-10, it is currently syncing TXs at version 1, so it returns 1 as thats the highest it can process currently given its objects state. ``` curl --location --request POST 0.0.0.0:9000 \ --header 'Content-Type: application/json' \ --data-raw '{ "jsonrpc":"2.0", "id":1, "method":"sui_getProtocolConfig" }'| jq % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 8469 100 8396 100 73 1022k 9107 --:--:-- --:--:-- --:--:-- 4135k { "jsonrpc": "2.0", "result": { "minSupportedProtocolVersion": "1", "maxSupportedProtocolVersion": "10", "protocolVersion": "1", "featureFlags": { "advance_epoch_start_time_in_safe_mode": false, "advance_to_highest_supported_protocol_version": false, "ban_entry_init": false, "commit_root_state_digest": false, .............[truncated]................... }, "attributes": { "address_from_bytes_cost_base": { "u64": "52" }, "address_from_u256_cost_base": { "u64": "52" }, "address_to_u256_cost_base": { .............[truncated]................... ``` ### Other utilities Adds some utilities useful for CLI and protocol config attr discovery. Needed to support RPC queries of protocol config info. First a wrapper enum is introduced since config value types are heterogenous. The wrapper will automatically pick up the type for all config attributes and add it to the enum variant ``` pub enum ProtocolConfigValue { u32(u32), u64(u64), .... } ``` **1. Logic to lookup protocol config attributes by string repr** `lookup_attr(&self, attr_as_string) -> Option<ProtocolConfigValue>` ``` let prot: ProtocolConfig = ProtocolConfig::get_for_version(ProtocolVersion::new(9)); // Result should be Some(128) assert!( prot.lookup_attr("max_move_identifier_len".to_string()) == Some(ProtocolConfigValue::u64(prot.max_move_identifier_len())) ); ``` **2. Logic to return a BTreeMap of config attrs to their values** `attr_map(&self) -> BTreeMap<String, Option<ProtocolConfigValue>>` This is equivalent to looping over all entries of `lookup_attr(value)` and putting them in a map ``` // attr_map() returns BTreeMap<String, Option<ProtocolConfigValue>> // where each key is the string repr of the attribute assert!( prot.attr_map().get("max_arguments").unwrap() == &Some(ProtocolConfigValue::u32(prot.max_arguments())) ); ``` ## Test Plan Unit tests --- If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process. ### Type of Change (Check all that apply) - [ ] user-visible impact - [ ] breaking change for a client SDKs - [ ] breaking change for FNs (FN binary must upgrade) - [ ] breaking change for validators or node operators (must upgrade binaries) - [ ] breaking change for on-chain data layout - [ ] necessitate either a data wipe or data migration ### Release notes
- Loading branch information