mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
BUG: Unclear block start
This commit is contained in:
parent
9ba4611433
commit
04ffb08423
2 changed files with 43 additions and 6 deletions
|
|
@ -192,9 +192,10 @@ type Firehose struct {
|
||||||
testingIgnoreGenesisBlock bool
|
testingIgnoreGenesisBlock bool
|
||||||
|
|
||||||
// Worker queue for block printing
|
// Worker queue for block printing
|
||||||
blockPrintQueue chan *blockPrintJob
|
blockPrintQueue chan *blockPrintJob
|
||||||
flushDone sync.WaitGroup
|
blockOutputQueue chan *blockOutput
|
||||||
closeOnce sync.Once
|
flushDone sync.WaitGroup
|
||||||
|
closeOnce sync.Once
|
||||||
}
|
}
|
||||||
|
|
||||||
const FirehoseProtocolVersion = "3.0"
|
const FirehoseProtocolVersion = "3.0"
|
||||||
|
|
@ -261,11 +262,32 @@ func NewFirehose(config *FirehoseConfig) *Firehose {
|
||||||
log.Info("Concurrent block flushing enabled: starting goroutine...")
|
log.Info("Concurrent block flushing enabled: starting goroutine...")
|
||||||
const numWorkers = 10 // TODO: This becomes a parameter
|
const numWorkers = 10 // TODO: This becomes a parameter
|
||||||
firehose.blockPrintQueue = make(chan *blockPrintJob, 100) // TODO: Optimal buffer size tbd
|
firehose.blockPrintQueue = make(chan *blockPrintJob, 100) // TODO: Optimal buffer size tbd
|
||||||
|
firehose.blockOutputQueue = make(chan *blockOutput, 100)
|
||||||
|
|
||||||
for i := 0; i < numWorkers; i++ {
|
for i := 0; i < numWorkers; i++ {
|
||||||
firehose.flushDone.Add(1)
|
firehose.flushDone.Add(1)
|
||||||
go firehose.blockPrintWorker()
|
go firehose.blockPrintWorker()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Output channel to order the flushing linearly
|
||||||
|
go func() {
|
||||||
|
expected := uint64(1000) // TODO: We will need to determine at which block it starts
|
||||||
|
buffer := make(map[uint64][]byte)
|
||||||
|
|
||||||
|
for result := range firehose.blockOutputQueue {
|
||||||
|
buffer[result.blockNum] = result.data
|
||||||
|
|
||||||
|
for {
|
||||||
|
data, ok := buffer[expected]
|
||||||
|
if !ok {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
firehose.flushToFirehose(data)
|
||||||
|
delete(buffer, expected)
|
||||||
|
expected++ // TODO: Assuming block numbers are linear
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
return firehose
|
return firehose
|
||||||
|
|
@ -1859,13 +1881,13 @@ func (f *Firehose) panicInvalidState(msg string, callerSkip int) string {
|
||||||
|
|
||||||
// printBlockToFirehose is a helper function to print a block to Firehose protocl format.
|
// printBlockToFirehose is a helper function to print a block to Firehose protocl format.
|
||||||
func (f *Firehose) printBlockToFirehose(block *pbeth.Block, finalityStatus *FinalityStatus) {
|
func (f *Firehose) printBlockToFirehose(block *pbeth.Block, finalityStatus *FinalityStatus) {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
|
||||||
marshalled, err := proto.Marshal(block)
|
marshalled, err := proto.Marshal(block)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Errorf("failed to marshal block: %w", err))
|
panic(fmt.Errorf("failed to marshal block: %w", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
var buf bytes.Buffer
|
|
||||||
|
|
||||||
previousHash := block.PreviousID()
|
previousHash := block.PreviousID()
|
||||||
previousNum := 0
|
previousNum := 0
|
||||||
if block.Number > 0 {
|
if block.Number > 0 {
|
||||||
|
|
@ -1897,7 +1919,14 @@ func (f *Firehose) printBlockToFirehose(block *pbeth.Block, finalityStatus *Fina
|
||||||
|
|
||||||
buf.WriteString("\n")
|
buf.WriteString("\n")
|
||||||
|
|
||||||
f.flushToFirehose(buf.Bytes())
|
if f.concurrentBlockFlushing {
|
||||||
|
f.blockOutputQueue <- &blockOutput{
|
||||||
|
blockNum: block.Number,
|
||||||
|
data: buf.Bytes(),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
f.flushToFirehose(buf.Bytes())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// printToFirehose is an easy way to print to Firehose format, it essentially
|
// printToFirehose is an easy way to print to Firehose format, it essentially
|
||||||
|
|
@ -2852,3 +2881,8 @@ func (f *Firehose) CloseBlockPrintQueue() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type blockOutput struct {
|
||||||
|
blockNum uint64
|
||||||
|
data []byte
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFirehose_BlockPrintsToFirehose_SingleBlock(t *testing.T) {
|
func TestFirehose_BlockPrintsToFirehose_SingleBlock(t *testing.T) {
|
||||||
|
|
@ -92,6 +93,8 @@ func TestFirehose_BlocksPrintToFirehose_MultipleBlocksInOrder(t *testing.T) {
|
||||||
f.OnBlockEnd(nil)
|
f.OnBlockEnd(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
|
||||||
f.OnClose()
|
f.OnClose()
|
||||||
|
|
||||||
output := f.InternalTestingBuffer().String()
|
output := f.InternalTestingBuffer().String()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue