mirror of
https://github.com/ChainSafe/lodestar.git
synced 2026-01-08 23:28:10 -05:00
chore: simplify computeBlockRewards()
This commit is contained in:
@@ -1298,9 +1298,9 @@ export class BeaconChain implements IBeaconChain {
|
||||
|
||||
preState = processSlots(preState, block.slot); // Dial preState's slot to block.slot
|
||||
|
||||
const postState = this.regen.getStateSync(toRootHex(block.stateRoot)) ?? undefined;
|
||||
const proposerRewards = this.regen.getStateSync(toRootHex(block.stateRoot))?.proposerRewards ?? undefined;
|
||||
|
||||
return computeBlockRewards(this.config, block, preState, postState);
|
||||
return computeBlockRewards(this.config, block, preState, proposerRewards);
|
||||
}
|
||||
|
||||
async getAttestationsRewards(
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
} from "@lodestar/params";
|
||||
import {BeaconBlock, altair, phase0, rewards} from "@lodestar/types";
|
||||
import {processAttestationsAltair} from "../block/processAttestationsAltair.js";
|
||||
import {RewardCache} from "../cache/rewardCache.js";
|
||||
import {CachedBeaconStateAllForks, CachedBeaconStateAltair, CachedBeaconStatePhase0} from "../cache/stateCache.js";
|
||||
import {getAttesterSlashableIndices} from "../util/attestation.js";
|
||||
|
||||
@@ -24,14 +25,13 @@ export async function computeBlockRewards(
|
||||
config: BeaconConfig,
|
||||
block: BeaconBlock,
|
||||
preStateIn: CachedBeaconStateAllForks,
|
||||
postStateIn?: CachedBeaconStateAllForks
|
||||
proposerRewards?: RewardCache
|
||||
): Promise<rewards.BlockRewards> {
|
||||
const preState = preStateIn.clone();
|
||||
const postState = postStateIn?.clone();
|
||||
|
||||
const fork = config.getForkName(block.slot);
|
||||
const {attestations: cachedAttestationsReward = 0, syncAggregate: cachedSyncAggregateReward = 0} =
|
||||
postState?.proposerRewards ?? {};
|
||||
proposerRewards ?? {};
|
||||
let blockAttestationReward = cachedAttestationsReward;
|
||||
let syncAggregateReward = cachedSyncAggregateReward;
|
||||
|
||||
|
||||
@@ -151,13 +151,13 @@ describe("chain / rewards / blockRewards", () => {
|
||||
|
||||
// Set postState's reward cache
|
||||
const rewardCache = postState.proposerRewards; // Grab original reward cache before overwritten
|
||||
postState.proposerRewards = {attestations: 1000, syncAggregate: 1001, slashing: 1002};
|
||||
const proposerRewards = {attestations: 1000, syncAggregate: 1001, slashing: 1002};
|
||||
|
||||
const calculatedBlockReward = await computeBlockRewards(
|
||||
config,
|
||||
block.message,
|
||||
preState as CachedBeaconStateAllForks,
|
||||
postState
|
||||
proposerRewards
|
||||
);
|
||||
const {proposerIndex, total, attestations, syncAggregate, proposerSlashings, attesterSlashings} =
|
||||
calculatedBlockReward;
|
||||
|
||||
Reference in New Issue
Block a user