Skip to content

Commit

Permalink
v2.0: Simplify RPC partitioned_epoch_reward_enabled determination (ba…
Browse files Browse the repository at this point in the history
…ckport of #2802) (#2823)

Simplify RPC partitioned_epoch_reward_enabled determination (#2802)

* Check num_reward_partitions for partitioned_epoch_reward_enabled

* Make expect slightly more correct

* Better variable name

(cherry picked from commit 22b823c)

Co-authored-by: Tyera <[email protected]>
  • Loading branch information
mergify[bot] and CriesofCarrots authored Sep 4, 2024
1 parent 1e9a514 commit f111b36
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,24 +609,6 @@ impl JsonRpcRequestProcessor {
// epoch
let bank = self.get_bank_with_config(context_config)?;

// DO NOT CLEAN UP with feature_set::partitioned_epoch_rewards_superfeature
// This logic needs to be retained indefinitely to support historical
// rewards before and after feature activation.
let partitioned_epoch_reward_enabled_slot = bank
.feature_set
.activated_slot(&feature_set::partitioned_epoch_rewards_superfeature::id())
.or_else(|| {
// The order of these checks should not matter, since we will
// not ever have both features active on a live cluster. This
// check can be removed with
// feature_set::enable_partitioned_epoch_reward
bank.feature_set
.activated_slot(&feature_set::enable_partitioned_epoch_reward::id())
});
let partitioned_epoch_reward_enabled = partitioned_epoch_reward_enabled_slot
.map(|slot| slot <= first_confirmed_block_in_epoch)
.unwrap_or(false);

// Get first block in the epoch
let Ok(Some(epoch_boundary_block)) = self
.get_block(
Expand Down Expand Up @@ -655,6 +637,8 @@ impl JsonRpcRequestProcessor {
.into());
}

let epoch_has_partitioned_rewards = epoch_boundary_block.num_reward_partitions.is_some();

// Collect rewards from first block in the epoch if partitioned epoch
// rewards not enabled, or address is a vote account
let mut reward_map: HashMap<String, (Reward, Slot)> = {
Expand All @@ -666,17 +650,17 @@ impl JsonRpcRequestProcessor {
&addresses,
&|reward_type| -> bool {
reward_type == RewardType::Voting
|| (!partitioned_epoch_reward_enabled && reward_type == RewardType::Staking)
|| (!epoch_has_partitioned_rewards && reward_type == RewardType::Staking)
},
)
};

// Append stake account rewards from partitions if partitions epoch
// rewards is enabled
if partitioned_epoch_reward_enabled {
if epoch_has_partitioned_rewards {
let num_partitions = epoch_boundary_block.num_reward_partitions.expect(
"epoch-boundary block should have num_reward_partitions after partitioned epoch \
rewards enabled",
"epoch-boundary block should have num_reward_partitions for epochs with \
partitioned rewards enabled",
);

let num_partitions = usize::try_from(num_partitions)
Expand Down

0 comments on commit f111b36

Please sign in to comment.