Skip to content

Commit

Permalink
eth/catalyst: prettier output on bad new payloads (ethereum#29259)
Browse files Browse the repository at this point in the history
When we receive a bad NewPayload, we currently emit a lot of data to the logging facilities. This PR makes it so we print less data.
  • Loading branch information
holiman authored Mar 15, 2024
1 parent 95715fd commit 40cac1d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
11 changes: 11 additions & 0 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,3 +475,14 @@ func (d *Decimal) UnmarshalJSON(input []byte) error {
return err
}
}

type PrettyBytes []byte

// TerminalString implements log.TerminalStringer, formatting a string for console
// output during logging.
func (b PrettyBytes) TerminalString() string {
if len(b) < 7 {
return fmt.Sprintf("%x", b)
}
return fmt.Sprintf("%#x...%x (%dB)", b[:3], b[len(b)-3:], len(b))
}
29 changes: 28 additions & 1 deletion eth/catalyst/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package catalyst
import (
"errors"
"fmt"
"strconv"
"sync"
"time"

Expand Down Expand Up @@ -540,7 +541,33 @@ func (api *ConsensusAPI) newPayload(params engine.ExecutableData, versionedHashe
log.Trace("Engine API request received", "method", "NewPayload", "number", params.Number, "hash", params.BlockHash)
block, err := engine.ExecutableDataToBlock(params, versionedHashes, beaconRoot)
if err != nil {
log.Warn("Invalid NewPayload params", "params", params, "error", err)
bgu := "nil"
if params.BlobGasUsed != nil {
bgu = strconv.Itoa(int(*params.BlobGasUsed))
}
ebg := "nil"
if params.BlobGasUsed != nil {
ebg = strconv.Itoa(int(*params.ExcessBlobGas))
}
log.Warn("Invalid NewPayload params",
"params.Number", params.Number,
"params.ParentHash", params.ParentHash,
"params.BlockHash", params.BlockHash,
"params.StateRoot", params.StateRoot,
"params.FeeRecipient", params.FeeRecipient,
"params.LogsBloom", common.PrettyBytes(params.LogsBloom),
"params.Random", params.Random,
"params.GasLimit", params.GasLimit,
"params.GasUsed", params.GasUsed,
"params.Timestamp", params.Timestamp,
"params.ExtraData", common.PrettyBytes(params.ExtraData),
"params.BaseFeePerGas", params.BaseFeePerGas,
"params.BlobGasUsed", bgu,
"params.ExcessBlobGas", ebg,
"len(params.Transactions)", len(params.Transactions),
"len(params.Withdrawals)", len(params.Withdrawals),
"beaconRoot", beaconRoot,
"error", err)
return api.invalid(err, nil), nil
}
// Stash away the last update to warn the user if the beacon client goes offline
Expand Down

0 comments on commit 40cac1d

Please sign in to comment.