Updated when FIRE INIT is actually printed

The tracer will now keep the state of wheter the init has been sent or not and will emit it prior sending the very first block out.
This commit is contained in:
Matthieu Vachon 2024-01-17 11:17:21 -05:00
parent b6c53b7ada
commit 213e30cebe

View file

@ -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))