diff --git a/eth/tracers/firehose.go b/eth/tracers/firehose.go index 2341dc67de..4d7be9052b 100644 --- a/eth/tracers/firehose.go +++ b/eth/tracers/firehose.go @@ -14,6 +14,7 @@ import ( "runtime/debug" "strconv" "strings" + "sync/atomic" "time" "github.com/ethereum/go-ethereum/common" @@ -56,6 +57,7 @@ func newFirehoseTracer() (core.BlockchainLogger, error) { type Firehose struct { // Global state outputBuffer *bytes.Buffer + initSent *atomic.Bool // Block state block *pbeth.Block @@ -78,12 +80,10 @@ type Firehose struct { const FirehoseProtocolVersion = "3.0" func NewFirehoseLogger() *Firehose { - // FIXME: Where should we put our actual INIT line? - printToFirehose("INIT", FirehoseProtocolVersion, "geth", params.Version) - return &Firehose{ // Global state outputBuffer: bytes.NewBuffer(make([]byte, 0, 100*1024*1024)), + initSent: new(atomic.Bool), // Block state blockOrdinal: &Ordinal{}, @@ -978,6 +978,10 @@ func (f *Firehose) panicNotInState(msg string) string { // // It flushes this through [flushToFirehose] to the `os.Stdout` writer. func (f *Firehose) printBlockToFirehose(block *pbeth.Block, finalityStatus *FinalityStatus) { + if wasNeverSent := f.initSent.CompareAndSwap(false, true); wasNeverSent { + printToFirehose("INIT", FirehoseProtocolVersion, "geth", params.Version) + } + marshalled, err := proto.Marshal(block) if err != nil { panic(fmt.Errorf("failed to marshal block: %w", err))