diff --git a/packages/beacon-node/src/chain/chain.ts b/packages/beacon-node/src/chain/chain.ts index 01c14ce3b5..a42a4e21db 100644 --- a/packages/beacon-node/src/chain/chain.ts +++ b/packages/beacon-node/src/chain/chain.ts @@ -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( diff --git a/packages/state-transition/src/rewards/blockRewards.ts b/packages/state-transition/src/rewards/blockRewards.ts index 591b8b0855..d455595aae 100644 --- a/packages/state-transition/src/rewards/blockRewards.ts +++ b/packages/state-transition/src/rewards/blockRewards.ts @@ -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 { 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; diff --git a/packages/state-transition/test/unit/rewards/blockRewards.test.ts b/packages/state-transition/test/unit/rewards/blockRewards.test.ts index 522e494c51..dfdf8a4ee5 100644 --- a/packages/state-transition/test/unit/rewards/blockRewards.test.ts +++ b/packages/state-transition/test/unit/rewards/blockRewards.test.ts @@ -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;