From af8ae29249f7fa9c5ec9d1850b499a35e5b4a642 Mon Sep 17 00:00:00 2001 From: Jacek Malec <145967538+jacek-casper@users.noreply.github.com> Date: Thu, 25 Jul 2024 15:31:06 +0100 Subject: [PATCH 1/2] Return the switch block hash with rewards response Signed-off-by: Jacek Malec <145967538+jacek-casper@users.noreply.github.com> --- Cargo.lock | 4 ++-- Cargo.toml | 4 ++-- resources/test/rpc_schema.json | 10 ++++++++-- rpc_sidecar/src/rpcs/info.rs | 18 +++++++++++++++--- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4f007ce4..12fcc447 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -468,7 +468,7 @@ dependencies = [ [[package]] name = "casper-binary-port" version = "1.0.0" -source = "git+https://github.com/casper-network/casper-node.git?branch=feat-2.0#baccf60f2cd4ba4a5a0e71d1f9e7bf3ec78c477d" +source = "git+https://github.com/jacek-casper/casper-node.git?branch=switch-block-hash-in-reward-resp#17fa48c07c46906875b5dfb4dc87dd401c4451a6" dependencies = [ "bincode", "bytes", @@ -670,7 +670,7 @@ dependencies = [ [[package]] name = "casper-types" version = "5.0.0" -source = "git+https://github.com/casper-network/casper-node.git?branch=feat-2.0#baccf60f2cd4ba4a5a0e71d1f9e7bf3ec78c477d" +source = "git+https://github.com/jacek-casper/casper-node.git?branch=switch-block-hash-in-reward-resp#17fa48c07c46906875b5dfb4dc87dd401c4451a6" dependencies = [ "base16", "base64 0.13.1", diff --git a/Cargo.toml b/Cargo.toml index 0c64330a..4d82421e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,8 +14,8 @@ members = [ anyhow = "1" async-stream = "0.3.4" async-trait = "0.1.77" -casper-types = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0" } -casper-binary-port = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0" } +casper-types = { git = "https://github.com/jacek-casper/casper-node.git", branch = "switch-block-hash-in-reward-resp" } +casper-binary-port = { git = "https://github.com/jacek-casper/casper-node.git", branch = "switch-block-hash-in-reward-resp" } casper-event-sidecar = { path = "./event_sidecar", version = "1.0.0" } casper-event-types = { path = "./types", version = "1.0.0" } casper-rpc-sidecar = { path = "./rpc_sidecar", version = "1.0.0" } diff --git a/resources/test/rpc_schema.json b/resources/test/rpc_schema.json index 44648560..fa4702fb 100644 --- a/resources/test/rpc_schema.json +++ b/resources/test/rpc_schema.json @@ -1571,7 +1571,8 @@ "api_version", "delegation_rate", "era_id", - "reward_amount" + "reward_amount", + "switch_block_hash" ], "properties": { "api_version": { @@ -1591,6 +1592,10 @@ "type": "integer", "format": "uint8", "minimum": 0.0 + }, + "switch_block_hash": { + "description": "The switch block hash at which the reward was distributed.", + "$ref": "#/components/schemas/BlockHash" } }, "additionalProperties": false @@ -1621,7 +1626,8 @@ "api_version": "2.0.0", "reward_amount": "42", "era_id": 1, - "delegation_rate": 20 + "delegation_rate": 20, + "switch_block_hash": "0000000000000000000000000000000000000000000000000000000000000000" } } } diff --git a/rpc_sidecar/src/rpcs/info.rs b/rpc_sidecar/src/rpcs/info.rs index 08b74970..632e2d68 100644 --- a/rpc_sidecar/src/rpcs/info.rs +++ b/rpc_sidecar/src/rpcs/info.rs @@ -104,6 +104,7 @@ static GET_REWARD_RESULT: Lazy = Lazy::new(|| GetRewardResult { reward_amount: U512::from(42), era_id: EraId::new(1), delegation_rate: 20, + switch_block_hash: BlockHash::default(), }); /// Params for "info_get_deploy" RPC request. @@ -550,6 +551,8 @@ pub struct GetRewardResult { pub era_id: EraId, /// The delegation rate of the validator. pub delegation_rate: u8, + /// The switch block hash at which the reward was distributed. + pub switch_block_hash: BlockHash, } impl DocExample for GetRewardResult { @@ -588,6 +591,7 @@ impl RpcWithParams for GetReward { reward_amount: result.amount(), era_id: result.era_id(), delegation_rate: result.delegation_rate(), + switch_block_hash: result.switch_block_hash(), }) } } @@ -820,12 +824,14 @@ mod tests { let validator = PublicKey::random(rng); let delegator = rng.gen::().then(|| PublicKey::random(rng)); let delegation_rate = rng.gen_range(0..100); + let switch_block_hash = BlockHash::random(rng); let resp = GetReward::do_handle_request( Arc::new(RewardMock { reward_amount, era_id, delegation_rate, + switch_block_hash, }), GetRewardParams { era_identifier: Some(EraIdentifier::Era(era_id)), @@ -842,7 +848,8 @@ mod tests { api_version: CURRENT_API_VERSION, reward_amount, era_id, - delegation_rate + delegation_rate, + switch_block_hash } ); } @@ -901,6 +908,7 @@ mod tests { reward_amount: U512, era_id: EraId, delegation_rate: u8, + switch_block_hash: BlockHash, } #[async_trait] @@ -914,8 +922,12 @@ mod tests { if InformationRequestTag::try_from(info_type_tag) == Ok(InformationRequestTag::Reward) => { - let resp = - RewardResponse::new(self.reward_amount, self.era_id, self.delegation_rate); + let resp = RewardResponse::new( + self.reward_amount, + self.era_id, + self.delegation_rate, + self.switch_block_hash, + ); Ok(BinaryResponseAndRequest::new( BinaryResponse::from_value(resp, SUPPORTED_PROTOCOL_VERSION), &[], From e2a459c5db4d1ec1e3822af317dee04906164d7e Mon Sep 17 00:00:00 2001 From: Jacek Malec <145967538+jacek-casper@users.noreply.github.com> Date: Fri, 26 Jul 2024 15:57:53 +0100 Subject: [PATCH 2/2] Point back at casper-node feat-2 --- Cargo.lock | 4 ++-- Cargo.toml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e8f8092a..164e3e06 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -471,7 +471,7 @@ dependencies = [ [[package]] name = "casper-binary-port" version = "1.0.0" -source = "git+https://github.com/jacek-casper/casper-node.git?branch=switch-block-hash-in-reward-resp#17fa48c07c46906875b5dfb4dc87dd401c4451a6" +source = "git+https://github.com/casper-network/casper-node.git?branch=feat-2.0#488a5f96534b26580cfee18c96fd7af1cf57af33" dependencies = [ "bincode", "bytes", @@ -673,7 +673,7 @@ dependencies = [ [[package]] name = "casper-types" version = "5.0.0" -source = "git+https://github.com/jacek-casper/casper-node.git?branch=switch-block-hash-in-reward-resp#17fa48c07c46906875b5dfb4dc87dd401c4451a6" +source = "git+https://github.com/casper-network/casper-node.git?branch=feat-2.0#488a5f96534b26580cfee18c96fd7af1cf57af33" dependencies = [ "base16", "base64 0.13.1", diff --git a/Cargo.toml b/Cargo.toml index 4d82421e..0c64330a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,8 +14,8 @@ members = [ anyhow = "1" async-stream = "0.3.4" async-trait = "0.1.77" -casper-types = { git = "https://github.com/jacek-casper/casper-node.git", branch = "switch-block-hash-in-reward-resp" } -casper-binary-port = { git = "https://github.com/jacek-casper/casper-node.git", branch = "switch-block-hash-in-reward-resp" } +casper-types = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0" } +casper-binary-port = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0" } casper-event-sidecar = { path = "./event_sidecar", version = "1.0.0" } casper-event-types = { path = "./types", version = "1.0.0" } casper-rpc-sidecar = { path = "./rpc_sidecar", version = "1.0.0" }