From 2f47b5b9c640e3e31f87244831b94c7f9a1b441d Mon Sep 17 00:00:00 2001 From: jacek-casper <145967538+jacek-casper@users.noreply.github.com> Date: Tue, 7 May 2024 10:25:41 +0100 Subject: [PATCH] Update casper node dependencies (#297) * Upgrade casper node dependencies * Rename for consistency * Update references to request name --- Cargo.lock | 4 +- resources/test/rpc_schema.json | 56 ++++++++++++++++++++++ resources/test/speculative_rpc_schema.json | 56 ++++++++++++++++++++++ rpc_sidecar/src/node_client.rs | 4 +- rpc_sidecar/src/rpcs/state.rs | 16 +++---- 5 files changed, 122 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 212c3658..b2ccd6f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -467,7 +467,7 @@ dependencies = [ [[package]] name = "casper-binary-port" version = "1.0.0" -source = "git+https://github.com/casper-network/casper-node?branch=feat-2.0#897332af35f0fcfa78489c23df56f8402e1bb745" +source = "git+https://github.com/casper-network/casper-node?branch=feat-2.0#73178683865ec0353a9bbae50b1ef1e81bf07f1f" dependencies = [ "bincode", "bytes", @@ -666,7 +666,7 @@ dependencies = [ [[package]] name = "casper-types" version = "5.0.0" -source = "git+https://github.com/casper-network/casper-node?branch=feat-2.0#897332af35f0fcfa78489c23df56f8402e1bb745" +source = "git+https://github.com/casper-network/casper-node?branch=feat-2.0#73178683865ec0353a9bbae50b1ef1e81bf07f1f" dependencies = [ "base16", "base64 0.13.1", diff --git a/resources/test/rpc_schema.json b/resources/test/rpc_schema.json index 476806af..29602bf4 100644 --- a/resources/test/rpc_schema.json +++ b/resources/test/rpc_schema.json @@ -3554,6 +3554,13 @@ "enum": [ "ActivateBid" ] + }, + { + "description": "The `change_bid_public_key` native entry point, used to change a bid's public key.", + "type": "string", + "enum": [ + "ChangeBidPublicKey" + ] } ] }, @@ -4794,6 +4801,19 @@ } }, "additionalProperties": false + }, + { + "description": "A bridge record pointing to a new `ValidatorBid` after the public key was changed.", + "type": "object", + "required": [ + "Bridge" + ], + "properties": { + "Bridge": { + "$ref": "#/components/schemas/Bridge" + } + }, + "additionalProperties": false } ] }, @@ -4856,6 +4876,42 @@ }, "additionalProperties": false }, + "Bridge": { + "description": "A bridge record pointing to a new `ValidatorBid` after the public key was changed.", + "type": "object", + "required": [ + "era_id", + "new_validator_public_key", + "old_validator_public_key" + ], + "properties": { + "old_validator_public_key": { + "description": "Previous validator public key associated with the bid.", + "allOf": [ + { + "$ref": "#/components/schemas/PublicKey" + } + ] + }, + "new_validator_public_key": { + "description": "New validator public key associated with the bid.", + "allOf": [ + { + "$ref": "#/components/schemas/PublicKey" + } + ] + }, + "era_id": { + "description": "Era when bridge record was created.", + "allOf": [ + { + "$ref": "#/components/schemas/EraId" + } + ] + } + }, + "additionalProperties": false + }, "ExecutionResultV2": { "description": "The result of executing a single transaction.", "type": "object", diff --git a/resources/test/speculative_rpc_schema.json b/resources/test/speculative_rpc_schema.json index 522beeb6..c164e5e3 100644 --- a/resources/test/speculative_rpc_schema.json +++ b/resources/test/speculative_rpc_schema.json @@ -2876,6 +2876,19 @@ } }, "additionalProperties": false + }, + { + "description": "A bridge record pointing to a new `ValidatorBid` after the public key was changed.", + "type": "object", + "required": [ + "Bridge" + ], + "properties": { + "Bridge": { + "$ref": "#/components/schemas/Bridge" + } + }, + "additionalProperties": false } ] }, @@ -2938,6 +2951,42 @@ }, "additionalProperties": false }, + "Bridge": { + "description": "A bridge record pointing to a new `ValidatorBid` after the public key was changed.", + "type": "object", + "required": [ + "era_id", + "new_validator_public_key", + "old_validator_public_key" + ], + "properties": { + "old_validator_public_key": { + "description": "Previous validator public key associated with the bid.", + "allOf": [ + { + "$ref": "#/components/schemas/PublicKey" + } + ] + }, + "new_validator_public_key": { + "description": "New validator public key associated with the bid.", + "allOf": [ + { + "$ref": "#/components/schemas/PublicKey" + } + ] + }, + "era_id": { + "description": "Era when bridge record was created.", + "allOf": [ + { + "$ref": "#/components/schemas/EraId" + } + ] + } + }, + "additionalProperties": false + }, "Package": { "description": "Entity definition, metadata, and security container.", "type": "object", @@ -3891,6 +3940,13 @@ "enum": [ "ActivateBid" ] + }, + { + "description": "The `change_bid_public_key` native entry point, used to change a bid's public key.", + "type": "string", + "enum": [ + "ChangeBidPublicKey" + ] } ] }, diff --git a/rpc_sidecar/src/node_client.rs b/rpc_sidecar/src/node_client.rs index b4c0b5fd..e2ee8e52 100644 --- a/rpc_sidecar/src/node_client.rs +++ b/rpc_sidecar/src/node_client.rs @@ -87,12 +87,12 @@ pub trait NodeClient: Send + Sync { parse_response::>(&resp.into())?.ok_or(Error::EmptyEnvelope) } - async fn get_balance_by_state_root( + async fn read_balance( &self, state_identifier: Option, purse_identifier: PurseIdentifier, ) -> Result { - let get = GlobalStateRequest::BalanceByStateRoot { + let get = GlobalStateRequest::Balance { state_identifier, purse_identifier, }; diff --git a/rpc_sidecar/src/rpcs/state.rs b/rpc_sidecar/src/rpcs/state.rs index ffdabc4f..f4bf1bf3 100644 --- a/rpc_sidecar/src/rpcs/state.rs +++ b/rpc_sidecar/src/rpcs/state.rs @@ -277,7 +277,7 @@ impl RpcWithParams for GetBalance { let state_id = GlobalStateIdentifier::StateRootHash(params.state_root_hash); let purse_id = PortPurseIdentifier::Purse(purse_uref); let balance = node_client - .get_balance_by_state_root(Some(state_id), purse_id) + .read_balance(Some(state_id), purse_id) .await .map_err(|err| Error::NodeRequest("balance", err))?; @@ -934,9 +934,9 @@ impl RpcWithParams for QueryBalance { ) -> Result { let purse_id = params.purse_identifier.into_port_purse_identifier(); let balance = node_client - .get_balance_by_state_root(params.state_identifier, purse_id) + .read_balance(params.state_identifier, purse_id) .await - .map_err(|err| Error::NodeRequest("balance by state root", err))?; + .map_err(|err| Error::NodeRequest("balance", err))?; Ok(Self::ResponseResult { api_version: CURRENT_API_VERSION, balance: balance.available_balance, @@ -1007,9 +1007,9 @@ impl RpcWithParams for QueryBalanceDetails { ) -> Result { let purse_id = params.purse_identifier.into_port_purse_identifier(); let balance = node_client - .get_balance_by_state_root(params.state_identifier, purse_id) + .read_balance(params.state_identifier, purse_id) .await - .map_err(|err| Error::NodeRequest("balance by state root", err))?; + .map_err(|err| Error::NodeRequest("balance", err))?; let holds = balance .balance_holds @@ -2040,11 +2040,7 @@ mod tests { ) -> Result { match req { BinaryRequest::Get(GetRequest::State(req)) - if matches!( - &*req, - GlobalStateRequest::BalanceByBlock { .. } - | GlobalStateRequest::BalanceByStateRoot { .. } - ) => + if matches!(&*req, GlobalStateRequest::Balance { .. }) => { Ok(BinaryResponseAndRequest::new( BinaryResponse::from_value(self.0.clone(), SUPPORTED_PROTOCOL_VERSION),