diff --git a/packages/beacon-node/src/chain/blocks/importBlock.ts b/packages/beacon-node/src/chain/blocks/importBlock.ts index c6902f080db..b8ad62ef761 100644 --- a/packages/beacon-node/src/chain/blocks/importBlock.ts +++ b/packages/beacon-node/src/chain/blocks/importBlock.ts @@ -309,6 +309,8 @@ export async function importBlock(chain: ImportBlockModules, fullyVerifiedBlock: // Register stat metrics about the block after importing it chain.metrics?.parentBlockDistance.observe(block.message.slot - parentBlock.slot); + chain.metrics?.proposerBalanceDiffAny.observe(fullyVerifiedBlock.proposerBalanceDiff); + chain.metrics?.registerImportedBlock(block.message, fullyVerifiedBlock); // Note: in-lined from previous handler of ChainEvent.block const blockRoot = toHexString(chain.config.getForkTypes(block.message.slot).BeaconBlock.hashTreeRoot(block.message)); diff --git a/packages/beacon-node/src/chain/blocks/types.ts b/packages/beacon-node/src/chain/blocks/types.ts index a9f1299c4f1..afcaa830a3e 100644 --- a/packages/beacon-node/src/chain/blocks/types.ts +++ b/packages/beacon-node/src/chain/blocks/types.ts @@ -51,6 +51,7 @@ export type FullyVerifiedBlock = FullyVerifiedBlockFlags & { block: allForks.SignedBeaconBlock; postState: CachedBeaconStateAllForks; parentBlock: ProtoBlock; + proposerBalanceDiff: number; }; /** diff --git a/packages/beacon-node/src/chain/blocks/verifyBlock.ts b/packages/beacon-node/src/chain/blocks/verifyBlock.ts index 21f1ff34751..a5a9653e8a9 100644 --- a/packages/beacon-node/src/chain/blocks/verifyBlock.ts +++ b/packages/beacon-node/src/chain/blocks/verifyBlock.ts @@ -50,7 +50,11 @@ export async function verifyBlock( ): Promise { const parentBlock = verifyBlockSanityChecks(chain, partiallyVerifiedBlock); - const {postState, executionStatus} = await verifyBlockStateTransition(chain, partiallyVerifiedBlock, opts); + const {postState, executionStatus, proposerBalanceDiff} = await verifyBlockStateTransition( + chain, + partiallyVerifiedBlock, + opts + ); return { block: partiallyVerifiedBlock.block, @@ -58,6 +62,7 @@ export async function verifyBlock( parentBlock, skipImportingAttestations: partiallyVerifiedBlock.skipImportingAttestations, executionStatus, + proposerBalanceDiff, }; } @@ -128,7 +133,7 @@ export async function verifyBlockStateTransition( chain: VerifyBlockModules, partiallyVerifiedBlock: PartiallyVerifiedBlock, opts: BlockProcessOpts -): Promise<{postState: CachedBeaconStateAllForks; executionStatus: ExecutionStatus}> { +): Promise<{postState: CachedBeaconStateAllForks; executionStatus: ExecutionStatus; proposerBalanceDiff: number}> { const {block, validProposerSignature, validSignatures} = partiallyVerifiedBlock; // TODO: Skip in process chain segment @@ -350,7 +355,11 @@ export async function verifyBlockStateTransition( logOnPowBlock(chain, block as bellatrix.SignedBeaconBlock); } - return {postState, executionStatus}; + // For metric block profitability + const proposerIndex = block.message.proposerIndex; + const proposerBalanceDiff = postState.balances.get(proposerIndex) - preState.balances.get(proposerIndex); + + return {postState, executionStatus, proposerBalanceDiff}; } function logOnPowBlock(chain: VerifyBlockModules, block: bellatrix.SignedBeaconBlock): void { diff --git a/packages/beacon-node/src/metrics/metrics/lodestar.ts b/packages/beacon-node/src/metrics/metrics/lodestar.ts index 3210b18a47a..29d2866781e 100644 --- a/packages/beacon-node/src/metrics/metrics/lodestar.ts +++ b/packages/beacon-node/src/metrics/metrics/lodestar.ts @@ -792,8 +792,22 @@ export function createLodestarMetrics( labelNames: ["index", "src"], buckets: [0.1, 1], }), + + // Only for known + proposerBalanceDiffKnown: register.histogram({ + name: "validator_monitor_proposer_balance_diff_known_gwei", + help: "Balance diff of known block proposer after importing a valid block", + // Jul22 mainnet block reward is consistently between 29,000,000-28,000,000 GWei + buckets: [10_000, 100_000, 1e6, 10e6, 20e6, 50e6, 100e6, 1000e6], + }), }, + proposerBalanceDiffAny: register.histogram({ + name: "lodestar_proposer_balance_diff_any_gwei", + help: "Balance diff of every block proposer after importing a valid block", + buckets: [10_000, 100_000, 1e6, 10e6, 20e6, 50e6, 100e6, 1000e6], + }), + // regen metrics stateCache: { diff --git a/packages/beacon-node/src/metrics/validatorMonitor.ts b/packages/beacon-node/src/metrics/validatorMonitor.ts index 79668cfc220..447d94a13db 100644 --- a/packages/beacon-node/src/metrics/validatorMonitor.ts +++ b/packages/beacon-node/src/metrics/validatorMonitor.ts @@ -22,6 +22,7 @@ export interface IValidatorMonitor { registerLocalValidator(index: number): void; registerValidatorStatuses(currentEpoch: Epoch, statuses: IAttesterStatus[], balances?: number[]): void; registerBeaconBlock(src: OpSource, seenTimestampSec: Seconds, block: allForks.BeaconBlock): void; + registerImportedBlock(block: allForks.BeaconBlock, data: {proposerBalanceDiff: number}): void; submitUnaggregatedAttestation( seenTimestampSec: number, indexedAttestation: IndexedAttestation, @@ -275,6 +276,12 @@ export function createValidatorMonitor( } }, + registerImportedBlock(block, {proposerBalanceDiff}) { + if (validators.has(block.proposerIndex)) { + metrics.validatorMonitor.proposerBalanceDiffKnown.observe(proposerBalanceDiff); + } + }, + submitUnaggregatedAttestation(seenTimestampSec, indexedAttestation, subnet, sentPeers) { const data = indexedAttestation.data; // Returns the duration between when the attestation `data` could be produced (1/3rd through the slot) and `seenTimestamp`.