Skip to content
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

[rpc] Get protocol config endpoint #11510

Merged
merged 8 commits into from
May 5, 2023
Merged

Conversation

oxade
Copy link
Contributor

@oxade oxade commented Apr 29, 2023

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

@vercel
Copy link

vercel bot commented Apr 29, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

4 Ignored Deployments
Name Status Preview Comments Updated (UTC)
explorer ⬜️ Ignored (Inspect) May 5, 2023 6:06pm
explorer-storybook ⬜️ Ignored (Inspect) May 5, 2023 6:06pm
sui-wallet-kit ⬜️ Ignored (Inspect) May 5, 2023 6:06pm
wallet-adapter ⬜️ Ignored (Inspect) May 5, 2023 6:06pm

@oxade oxade requested a review from Jordan-Mysten April 30, 2023 01:36
@oxade oxade changed the title Lookup prot cfg by string [rpc] Get protocol config May 5, 2023
@oxade oxade requested review from patrickkuo, 666lcz, healthydeve, wlmyng and gegaowp and removed request for tnowacki, tzakian, aschran and mystenmark May 5, 2023 03:38
@@ -52,12 +75,33 @@ pub fn getters_macro(input: TokenStream) -> TokenStream {
} else {
panic!("Expected angle bracketed arguments.");
};
Some(quote! {

let getter =quote! {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit spacing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in this PR #11767

@oxade oxade enabled auto-merge (squash) May 5, 2023 18:06
@oxade oxade changed the title [rpc] Get protocol config [rpc] Get protocol config endpoint May 5, 2023
Copy link
Contributor

@wlmyng wlmyng left a comment

Choose a reason for hiding this comment

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

🆒 i feel like half of this battle was wrangling with types and getters lol

/// /// Returns the value of the field if exists at the given version, otherise None
/// pub fn lookup_attr(&self, value: String) -> Option<ProtocolConfigValue>;
///
/// /// Returns a map of all confgis to values
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: configs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in this PR #11767

@oxade oxade merged commit 8f5fcfa into main May 5, 2023
@oxade oxade deleted the protocol_config_lookup_by_string branch May 5, 2023 18:46
@oxade
Copy link
Contributor Author

oxade commented May 5, 2023

🆒 i feel like half of this battle was wrangling with types and getters lol

Indeed, thats the fun part

oxade added a commit that referenced this pull request May 5, 2023
## Description 

Formatting nits from #11510
## Test Plan 

N/A
---
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants