Skip to content

Commit 2fdd3fa

Browse files
twoethsnflaig
andauthored
feat: track on chain proposer rewards per block (#8018)
**Motivation** - we already track produced block consensus value in #7921 - this will track on chain data so that we can improve later if needed cc @nflaig --------- Co-authored-by: Tuyen Nguyen <[email protected]> Co-authored-by: Nico Flaig <[email protected]>
1 parent db77aaa commit 2fdd3fa

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

packages/beacon-node/src/chain/archiveStore/historicalState/metrics.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
BeaconStateTransitionMetrics,
33
EpochTransitionStep,
4+
ProposerRewardType,
45
StateCloneSource,
56
StateHashTreeRootSource,
67
} from "@lodestar/state-transition";
@@ -127,6 +128,11 @@ export function createHistoricalStateTransitionMetrics(
127128
name: "lodestar_historical_state_stfn_attestations_per_block_total",
128129
help: "Count of attestations per block",
129130
}),
131+
proposerRewards: metricsRegister.gauge<{type: ProposerRewardType}>({
132+
name: "lodestar_historical_state_stfn_proposer_rewards_total",
133+
help: "Proposer reward by type per block",
134+
labelNames: ["type"],
135+
}),
130136
};
131137
}
132138

packages/state-transition/src/block/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {processOperations} from "./processOperations.js";
1212
import {processRandao} from "./processRandao.js";
1313
import {processSyncAggregate} from "./processSyncCommittee.js";
1414
import {processWithdrawals} from "./processWithdrawals.js";
15-
import {ProcessBlockOpts} from "./types.js";
15+
import {ProcessBlockOpts, ProposerRewardType} from "./types.js";
1616

1717
// Spec tests
1818
export {
@@ -73,4 +73,9 @@ export function processBlock(
7373
throw Error("dataAvailabilityStatus.PreData");
7474
}
7575
}
76+
77+
const rewards = state.proposerRewards;
78+
metrics?.proposerRewards.set({type: ProposerRewardType.attestation}, rewards.attestations);
79+
metrics?.proposerRewards.set({type: ProposerRewardType.syncAggregate}, rewards.syncAggregate);
80+
metrics?.proposerRewards.set({type: ProposerRewardType.slashing}, rewards.slashing);
7681
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
export interface ProcessBlockOpts {
22
verifySignatures?: boolean;
33
}
4+
5+
export enum ProposerRewardType {
6+
attestation = "attestation",
7+
syncAggregate = "sync_aggregate",
8+
slashing = "slashing",
9+
}

packages/state-transition/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,5 @@ export {becomesNewEth1Data} from "./block/processEth1Data.js";
7171
export {getExpectedWithdrawals} from "./block/processWithdrawals.js";
7272

7373
export {getAttestationParticipationStatus, processAttestationsAltair} from "./block/processAttestationsAltair.js";
74+
75+
export {ProposerRewardType} from "./block/types.js";

packages/state-transition/src/metrics.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {MetricsRegister} from "@lodestar/utils";
2+
import {ProposerRewardType} from "./block/types.js";
23
import {EpochTransitionStep} from "./epoch/index.js";
34
import {StateCloneSource, StateHashTreeRootSource} from "./stateTransition.js";
45
import {CachedBeaconStateAllForks} from "./types.js";
@@ -112,6 +113,11 @@ export function getMetrics(register: MetricsRegister) {
112113
name: "lodestar_stfn_attestations_per_block_total",
113114
help: "Total count of attestations per block",
114115
}),
116+
proposerRewards: register.gauge<{type: ProposerRewardType}>({
117+
name: "lodestar_stfn_proposer_rewards_total",
118+
help: "Proposer reward by type per block",
119+
labelNames: ["type"],
120+
}),
115121
};
116122
}
117123

0 commit comments

Comments
 (0)