Skip to content

Commit

Permalink
Introduced "state_get_auction_info_v2" json rpc method. (#392)
Browse files Browse the repository at this point in the history
* Introduced "state_get_auction_info_v2" json rpc method.

---------

Co-authored-by: Jakub Zajkowski <[email protected]>
  • Loading branch information
zajko and Jakub Zajkowski authored Jan 16, 2025
1 parent cbce3a8 commit b28ca20
Show file tree
Hide file tree
Showing 11 changed files with 1,103 additions and 162 deletions.
227 changes: 116 additions & 111 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion event_sidecar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pin-project = "1.1.5"
rand = "0.8.3"
regex = "1.6.0"
reqwest = "0.12.5"
schemars = "0.8.16"
schemars = "0.8.21"
sea-query = "0.30"
serde = { workspace = true, default-features = true, features = ["derive", "rc"] }
serde_json = "1.0"
Expand Down
165 changes: 162 additions & 3 deletions resources/test/rpc_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2359,7 +2359,7 @@
},
{
"name": "state_get_auction_info",
"summary": "returns the bids and validators as of either a specific block (by height or hash), or the most recently added block",
"summary": "returns the bids and validators as of either a specific block (by height or hash), or the most recently added block. This is a casper 1.x retro-compatibility endpoint. For blocks created in 1.x protocol it will work exactly the same as it used to. \n For 2.x blocks it will try to retrofit the changed data structure into previous schema - but it is a lossy process. Use `state_get_auction_info_v2` endpoint to get data in new format. *IMPORTANT* This method is deprecated, has been added only for compatibility with retired nodes json-rpc API and will be removed in a future release of sidecar.",
"params": [
{
"name": "block_identifier",
Expand Down Expand Up @@ -2452,6 +2452,108 @@
}
]
},
{
"name": "state_get_auction_info_v2",
"summary": "returns the bids and validators as of either a specific block (by height or hash), or the most recently added block. It works for blocks created in 1.x and 2.x",
"params": [
{
"name": "block_identifier",
"schema": {
"description": "The block identifier.",
"$ref": "#/components/schemas/BlockIdentifier"
},
"required": false
}
],
"result": {
"name": "state_get_auction_info_v2_result",
"schema": {
"description": "Result for \"state_get_auction_info\" RPC response.",
"type": "object",
"required": [
"api_version",
"auction_state"
],
"properties": {
"api_version": {
"description": "The RPC API version.",
"type": "string"
},
"auction_state": {
"description": "The auction state.",
"$ref": "#/components/schemas/AuctionStateV2"
}
},
"additionalProperties": false
}
},
"examples": [
{
"name": "state_get_auction_info_v2_example",
"params": [
{
"name": "block_identifier",
"value": {
"Hash": "0707070707070707070707070707070707070707070707070707070707070707"
}
}
],
"result": {
"name": "state_get_auction_info_v2_example_result",
"value": {
"api_version": "2.0.0",
"auction_state": {
"state_root_hash": "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b",
"block_height": 10,
"era_validators": [
{
"era_id": 10,
"validator_weights": [
{
"public_key": "01197f6b23e16c8532c6abc838facd5ea789be0c76b2920334039bfa8b3d368d61",
"weight": "10"
}
]
}
],
"bids": [
{
"public_key": "01197f6b23e16c8532c6abc838facd5ea789be0c76b2920334039bfa8b3d368d61",
"bid": {
"Validator": {
"validator_public_key": "01197f6b23e16c8532c6abc838facd5ea789be0c76b2920334039bfa8b3d368d61",
"bonding_purse": "uref-fafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafa-007",
"staked_amount": "20",
"delegation_rate": 0,
"vesting_schedule": null,
"inactive": false,
"minimum_delegation_amount": 0,
"maximum_delegation_amount": 18446744073709551615,
"reserved_slots": 0
}
}
},
{
"public_key": "01197f6b23e16c8532c6abc838facd5ea789be0c76b2920334039bfa8b3d368d61",
"bid": {
"Delegator": {
"delegator_kind": {
"PublicKey": "014508a07aa941707f3eb2db94c8897a80b2c1197476b6de213ac273df7d86c4ff"
},
"staked_amount": "10",
"bonding_purse": "uref-fbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbfb-007",
"validator_public_key": "01197f6b23e16c8532c6abc838facd5ea789be0c76b2920334039bfa8b3d368d61",
"vesting_schedule": null
}
}
}
]
}
}
}
}
]
},
{
"name": "chain_get_era_summary",
"summary": "returns the era summary at either a specific block (by height or hash), or the most recently added block",
Expand Down Expand Up @@ -8472,13 +8574,13 @@
"validator_weights": {
"type": "array",
"items": {
"$ref": "#/components/schemas/JsonValidatorWeights"
"$ref": "#/components/schemas/JsonValidatorWeight"
}
}
},
"additionalProperties": false
},
"JsonValidatorWeights": {
"JsonValidatorWeight": {
"description": "A validator's weight.",
"type": "object",
"required": [
Expand Down Expand Up @@ -8526,6 +8628,63 @@
]
}
}
},
"AuctionStateV2": {
"description": "Data structure summarizing auction contract data.",
"type": "object",
"required": [
"bids",
"block_height",
"era_validators",
"state_root_hash"
],
"properties": {
"state_root_hash": {
"description": "Global state hash.",
"allOf": [
{
"$ref": "#/components/schemas/Digest"
}
]
},
"block_height": {
"description": "Block height.",
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"era_validators": {
"description": "Era validators.",
"type": "array",
"items": {
"$ref": "#/components/schemas/JsonEraValidators"
}
},
"bids": {
"description": "All bids.",
"type": "array",
"items": {
"$ref": "#/components/schemas/BidKindWrapper"
}
}
},
"additionalProperties": false
},
"BidKindWrapper": {
"type": "object",
"required": [
"bid",
"public_key"
],
"properties": {
"public_key": {
"$ref": "#/components/schemas/PublicKey"
},
"bid": {
"$ref": "#/components/schemas/BidKind"
}
},
"additionalProperties": false
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion rpc_sidecar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ num-traits = { version = "0.2.10", default-features = false }
once_cell.workspace = true
portpicker = "0.1.1"
rand = "0.8.3"
schemars = { version = "0.8.16", features = ["preserve_order", "impl_json_schema"] }
schemars = { version = "0.8.21", features = ["preserve_order", "impl_json_schema"] }
serde = { workspace = true, default-features = true, features = ["derive"] }
serde_json = { version = "1", features = ["preserve_order"] }
serde-map-to-array = "1.1.0"
Expand Down
2 changes: 2 additions & 0 deletions rpc_sidecar/src/http_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use super::rpcs::{
GetAccountInfo, GetAuctionInfo, GetBalance, GetDictionaryItem, GetItem, GetTrie,
QueryBalance, QueryGlobalState,
},
state_get_auction_info_v2::GetAuctionInfo as GetAuctionInfoV2,
RpcWithOptionalParams, RpcWithParams, RpcWithoutParams,
};

Expand Down Expand Up @@ -59,6 +60,7 @@ pub async fn run(
GetEraInfoBySwitchBlock::register_as_handler(node.clone(), &mut handlers);
GetEraSummary::register_as_handler(node.clone(), &mut handlers);
GetAuctionInfo::register_as_handler(node.clone(), &mut handlers);
GetAuctionInfoV2::register_as_handler(node.clone(), &mut handlers);
GetTrie::register_as_handler(node.clone(), &mut handlers);
GetValidatorChanges::register_as_handler(node.clone(), &mut handlers);
RpcDiscover::register_as_handler(node.clone(), &mut handlers);
Expand Down
3 changes: 3 additions & 0 deletions rpc_sidecar/src/rpcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ pub mod info;
pub mod speculative_exec;
pub mod speculative_open_rpc_schema;
pub mod state;
pub(crate) mod state_get_auction_info_v2;
#[cfg(test)]
pub(crate) mod test_utils;
mod types;

use std::{fmt, str, sync::Arc, time::Duration};
Expand Down
14 changes: 13 additions & 1 deletion rpc_sidecar/src/rpcs/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use super::{
GetAccountInfo, GetAddressableEntity, GetAuctionInfo, GetBalance, GetDictionaryItem,
GetItem, GetPackage, QueryBalance, QueryBalanceDetails, QueryGlobalState,
},
state_get_auction_info_v2::GetAuctionInfo as GetAuctionInfoV2,
ApiVersion, NodeClient, RpcError, RpcWithOptionalParams, RpcWithParams, RpcWithoutParams,
CURRENT_API_VERSION,
};
Expand Down Expand Up @@ -116,7 +117,12 @@ pub(crate) static OPEN_RPC_SCHEMA: Lazy<OpenRpcSchema> = Lazy::new(|| {
);
schema.push_with_optional_params::<GetAuctionInfo>(
"returns the bids and validators as of either a specific block (by height or hash), or \
the most recently added block",
the most recently added block. This is a casper 1.x retro-compatibility endpoint. For blocks created in 1.x protocol it will work exactly the same as it used to.
For 2.x blocks it will try to retrofit the changed data structure into previous schema - but it is a lossy process. Use `state_get_auction_info_v2` endpoint to get data in new format. *IMPORTANT* This method is deprecated, has been added only for compatibility with retired nodes json-rpc API and will be removed in a future release of sidecar.",
);
schema.push_with_optional_params::<GetAuctionInfoV2>(
"returns the bids and validators as of either a specific block (by height or hash), or \
the most recently added block. It works for blocks created in 1.x and 2.x",
);
schema.push_with_optional_params::<GetEraSummary>(
"returns the era summary at either a specific block (by height or hash), or the most \
Expand Down Expand Up @@ -602,4 +608,10 @@ mod tests {
let incorrect_optional_params = check_optional_params_fields::<GetAuctionInfo>();
assert!(incorrect_optional_params.is_empty())
}

#[test]
fn check_state_get_auction_info_v2_required_fields() {
let incorrect_optional_params = check_optional_params_fields::<GetAuctionInfoV2>();
assert!(incorrect_optional_params.is_empty())
}
}
Loading

0 comments on commit b28ca20

Please sign in to comment.