Skip to content

Commit

Permalink
Return the switch block hash with rewards response (#336)
Browse files Browse the repository at this point in the history
* Return the switch block hash with rewards response

Signed-off-by: Jacek Malec <[email protected]>

* Point back at casper-node feat-2

---------

Signed-off-by: Jacek Malec <[email protected]>
  • Loading branch information
jacek-casper authored Jul 26, 2024
1 parent 48fc103 commit 055e6d0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions resources/test/rpc_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,8 @@
"api_version",
"delegation_rate",
"era_id",
"reward_amount"
"reward_amount",
"switch_block_hash"
],
"properties": {
"api_version": {
Expand All @@ -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
Expand Down Expand Up @@ -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"
}
}
}
Expand Down
18 changes: 15 additions & 3 deletions rpc_sidecar/src/rpcs/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ static GET_REWARD_RESULT: Lazy<GetRewardResult> = 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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
})
}
}
Expand Down Expand Up @@ -820,12 +824,14 @@ mod tests {
let validator = PublicKey::random(rng);
let delegator = rng.gen::<bool>().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)),
Expand All @@ -842,7 +848,8 @@ mod tests {
api_version: CURRENT_API_VERSION,
reward_amount,
era_id,
delegation_rate
delegation_rate,
switch_block_hash
}
);
}
Expand Down Expand Up @@ -901,6 +908,7 @@ mod tests {
reward_amount: U512,
era_id: EraId,
delegation_rate: u8,
switch_block_hash: BlockHash,
}

#[async_trait]
Expand All @@ -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),
&[],
Expand Down

0 comments on commit 055e6d0

Please sign in to comment.