Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proposerBalanceDiff metric #4124

Merged
merged 2 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/beacon-node/src/chain/blocks/importBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions packages/beacon-node/src/chain/blocks/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export type FullyVerifiedBlock = FullyVerifiedBlockFlags & {
block: allForks.SignedBeaconBlock;
postState: CachedBeaconStateAllForks;
parentBlock: ProtoBlock;
proposerBalanceDiff: number;
};

/**
Expand Down
15 changes: 12 additions & 3 deletions packages/beacon-node/src/chain/blocks/verifyBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,19 @@ export async function verifyBlock(
): Promise<FullyVerifiedBlock> {
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,
postState,
parentBlock,
skipImportingAttestations: partiallyVerifiedBlock.skipImportingAttestations,
executionStatus,
proposerBalanceDiff,
};
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 14 additions & 0 deletions packages/beacon-node/src/metrics/metrics/lodestar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
7 changes: 7 additions & 0 deletions packages/beacon-node/src/metrics/validatorMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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`.
Expand Down