Skip to content

Commit

Permalink
improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech committed Aug 8, 2023
1 parent b5011cf commit 0940b6f
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions packages/beacon-node/src/chain/produceBlock/produceBlockBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export type BlockAttributes = {
};

export enum BlockType {
Full,
Blinded,
Full = "Full",
Blinded = "Blinded",
}
export type AssembledBodyType<T extends BlockType> = T extends BlockType.Full
? allForks.BeaconBlockBody
Expand Down Expand Up @@ -98,6 +98,14 @@ export async function produceBlockBody<T extends BlockType>(
// TODO: Does not guarantee that preDeneb enum goes with a preDeneb block
let blobsResult: BlobsResult;
let blockValue: Wei;
const fork = currentState.config.getForkName(blockSlot);

const logMeta: Record<string, string | number | bigint> = {
fork,
blockType,
slot: blockSlot,
};
this.logger.verbose("Producing beacon block body", logMeta);

// TODO:
// Iterate through the naive aggregation pool and ensure all the attestations from there
Expand Down Expand Up @@ -127,8 +135,6 @@ export async function produceBlockBody<T extends BlockType>(
voluntaryExits,
};

this.logger.verbose("Produced phase0 beacon block body", {slot: blockSlot, numAttestations: attestations.length});

const blockEpoch = computeEpochAtSlot(blockSlot);

if (blockEpoch >= this.config.ALTAIR_FORK_EPOCH) {
Expand All @@ -139,12 +145,25 @@ export async function produceBlockBody<T extends BlockType>(
(blockBody as altair.BeaconBlockBody).syncAggregate = syncAggregate;
}

const fork = currentState.config.getForkName(blockSlot);
Object.assign(logMeta, {
attestations: attestations.length,
deposits: deposits.length,
voluntaryExits: voluntaryExits.length,
attesterSlashings: attesterSlashings.length,
proposerSlashings: proposerSlashings.length,
});

if (isForkExecution(fork)) {
const safeBlockHash = this.forkChoice.getJustifiedBlock().executionPayloadBlockHash ?? ZERO_HASH_HEX;
const finalizedBlockHash = this.forkChoice.getFinalizedBlock().executionPayloadBlockHash ?? ZERO_HASH_HEX;
const feeRecipient = requestedFeeRecipient ?? this.beaconProposerCache.getOrDefault(proposerIndex);
const feeRecipientType = requestedFeeRecipient
? "requested"
: this.beaconProposerCache.get(proposerIndex)
? "cached"
: "default";

Object.assign(logMeta, {feeRecipientType, feeRecipient});

if (blockType === BlockType.Blinded) {
if (!this.executionBuilder) throw Error("Execution Builder not available");
Expand Down Expand Up @@ -184,6 +203,8 @@ export async function produceBlockBody<T extends BlockType>(
}
(blockBody as deneb.BlindedBeaconBlockBody).blobKzgCommitments = blobKzgCommitments;
blobsResult = {type: BlobsResultType.blinded};

Object.assign(logMeta, {blobs: blobKzgCommitments.length});
} else {
blobsResult = {type: BlobsResultType.preDeneb};
}
Expand Down Expand Up @@ -267,6 +288,8 @@ export async function produceBlockBody<T extends BlockType>(
return blobSidecar;
}) as deneb.BlobSidecars;
blobsResult = {type: BlobsResultType.produced, blobSidecars, blockHash};

Object.assign(logMeta, {blobs: blobSidecars.length});
} else {
blobsResult = {type: BlobsResultType.preDeneb};
}
Expand Down Expand Up @@ -301,8 +324,13 @@ export async function produceBlockBody<T extends BlockType>(
if (ForkSeq[fork] >= ForkSeq.capella) {
// TODO: blsToExecutionChanges should be passed in the produceBlock call
(blockBody as capella.BeaconBlockBody).blsToExecutionChanges = blsToExecutionChanges;
Object.assign({
blsToExecutionChanges: blsToExecutionChanges.length,
withdrawals: (blockBody as capella.BeaconBlockBody).executionPayload.withdrawals.length,
});
}

this.logger.verbose("Produced beacon block body", logMeta);
return {body: blockBody as AssembledBodyType<T>, blobs: blobsResult, blockValue};
}

Expand Down

0 comments on commit 0940b6f

Please sign in to comment.