Skip to content

Commit

Permalink
Introduced "state_get_auction_info_v2" json rpc method.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Zajkowski authored and zajko committed Jan 16, 2025
1 parent cbce3a8 commit 6bebdda
Show file tree
Hide file tree
Showing 8 changed files with 937 additions and 43 deletions.
120 changes: 119 additions & 1 deletion 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/AuctionState"
}
},
"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 @@ -8526,6 +8628,22 @@
]
}
}
},
"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: 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 6bebdda

Please sign in to comment.