Skip to content

Commit

Permalink
chore: Add missing code coverage in EndOfStakingPeriodUpdater (#13158)
Browse files Browse the repository at this point in the history
Signed-off-by: Neeharika-Sompalli <neeharika.sompalli@swirldslabs.com>
  • Loading branch information
Neeharika-Sompalli committed May 10, 2024
1 parent 636f929 commit 0d82f26
Show file tree
Hide file tree
Showing 2 changed files with 228 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static com.hedera.node.app.service.token.impl.handlers.staking.EndOfStakingPeriodUtils.computeNextStake;
import static com.hedera.node.app.service.token.impl.handlers.staking.EndOfStakingPeriodUtils.readableNonZeroHistory;
import static com.hedera.node.app.spi.workflows.record.SingleTransactionRecordBuilder.transactionWith;
import static java.util.Objects.requireNonNull;

import com.google.common.annotations.VisibleForTesting;
import com.hedera.hapi.node.base.Fraction;
Expand Down Expand Up @@ -127,7 +128,7 @@ public void updateNodes(@NonNull final TokenContext context) {
final Map<Long, StakingNodeInfo> updatedNodeInfos = new HashMap<>();
final Map<Long, Long> newPendingRewardRates = new HashMap<>();
for (final var nodeNum : nodeIds.stream().sorted().toList()) {
var currStakingInfo = stakingInfoStore.getForModify(nodeNum);
var currStakingInfo = requireNonNull(stakingInfoStore.getForModify(nodeNum));

// The return value here includes both the new reward sum history, and the reward rate
// (tinybars-per-hbar-staked-to-reward) that will be paid to all accounts who had staked-to-reward for this
Expand All @@ -144,7 +145,8 @@ public void updateNodes(@NonNull final TokenContext context) {
.rewardSumHistory(newRewardSumHistory.rewardSumHistory())
.build();
log.info(
" > Non-zero reward sum history is now {}",
"Non-zero reward sum history for node number {} is now {}",
() -> nodeNum,
() -> readableNonZeroHistory(newRewardSumHistory.rewardSumHistory()));

final var oldStakeRewardStart = currStakingInfo.stakeRewardStart();
Expand Down Expand Up @@ -350,8 +352,7 @@ public static int calculateWeightFromStake(
* @return the timestamp that is just before midnight of the day of the given consensus time
*/
@VisibleForTesting
public static com.hedera.hapi.node.base.Timestamp lastInstantOfPreviousPeriodFor(
@NonNull final Instant consensusTime) {
public static Timestamp lastInstantOfPreviousPeriodFor(@NonNull final Instant consensusTime) {
final var justBeforeMidNightTime = LocalDate.ofInstant(consensusTime, ZoneId.of("UTC"))
.atStartOfDay()
.minusNanos(1); // give out the timestamp that is just before midnight
Expand Down Expand Up @@ -430,8 +431,7 @@ long rescaledPerHbarRewardRate(
}

private long getRewardsBalance(@NonNull final ReadableAccountStore accountStore) {
return accountStore
.getAccountById(asAccount(accountNumbers.stakingRewardAccount()))
return requireNonNull(accountStore.getAccountById(asAccount(accountNumbers.stakingRewardAccount())))
.tinybarBalance();
}

Expand Down Expand Up @@ -471,9 +471,9 @@ private static NodeStake fromStakingInfo(final long rewardRate, StakingNodeInfo
* @return the transaction builder with the {@code NodeStakeUpdateTransactionBody} set
*/
private static TransactionBody.Builder newNodeStakeUpdateBuilder(
final com.hedera.hapi.node.base.Timestamp stakingPeriodEnd,
final List<NodeStake> nodeStakes,
final StakingConfig stakingConfig,
final Timestamp stakingPeriodEnd,
@NonNull final List<NodeStake> nodeStakes,
@NonNull final StakingConfig stakingConfig,
final long totalStakedRewardStart,
final long maxPerHbarRewardRate,
final long reservedStakingRewards,
Expand All @@ -484,7 +484,7 @@ private static TransactionBody.Builder newNodeStakeUpdateBuilder(
final var stakingPeriod = stakingConfig.periodMins();
final var stakingPeriodsStored = stakingConfig.rewardHistoryNumStoredPeriods();

final var nodeRewardFeeFraction = com.hedera.hapi.node.base.Fraction.newBuilder()
final var nodeRewardFeeFraction = Fraction.newBuilder()
.numerator(stakingConfig.feesNodeRewardPercentage())
.denominator(100L)
.build();
Expand Down

0 comments on commit 0d82f26

Please sign in to comment.