Commit 2b91cc6d authored by protolambda's avatar protolambda

batch Epoch() method, improve logging of batch filter

parent df4d4eea
...@@ -7,6 +7,8 @@ import ( ...@@ -7,6 +7,8 @@ import (
"io" "io"
"sync" "sync"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/rollup" "github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
...@@ -45,6 +47,10 @@ type BatchData struct { ...@@ -45,6 +47,10 @@ type BatchData struct {
// batches may contain additional data with new upgrades // batches may contain additional data with new upgrades
} }
func (b *BatchV1) Epoch() eth.BlockID {
return eth.BlockID{Hash: b.EpochHash, Number: uint64(b.EpochNum)}
}
// EncodeRLP implements rlp.Encoder // EncodeRLP implements rlp.Encoder
func (b *BatchData) EncodeRLP(w io.Writer) error { func (b *BatchData) EncodeRLP(w io.Writer) error {
buf := encodeBufferPool.Get().(*bytes.Buffer) buf := encodeBufferPool.Get().(*bytes.Buffer)
......
...@@ -17,15 +17,17 @@ func FilterBatches(log log.Logger, config *rollup.Config, epoch eth.BlockID, min ...@@ -17,15 +17,17 @@ func FilterBatches(log log.Logger, config *rollup.Config, epoch eth.BlockID, min
for _, batch := range batches { for _, batch := range batches {
if err := ValidBatch(batch, config, epoch, minL2Time, maxL2Time); err != nil { if err := ValidBatch(batch, config, epoch, minL2Time, maxL2Time); err != nil {
if err == DifferentEpoch { if err == DifferentEpoch {
log.Trace("ignoring batch of different epoch", "epoch", batch.EpochNum, "expected_epoch", epoch, "timestamp", batch.Timestamp, "txs", len(batch.Transactions)) log.Trace("ignoring batch of different epoch", "expected_epoch", epoch,
"epoch", batch.Epoch(), "timestamp", batch.Timestamp, "txs", len(batch.Transactions))
} else { } else {
log.Warn("filtered batch", "epoch", batch.EpochNum, "timestamp", batch.Timestamp, "txs", len(batch.Transactions), "err", err) log.Warn("filtered batch", "expected_epoch", epoch, "min", minL2Time, "max", maxL2Time,
"epoch", batch.Epoch(), "timestamp", batch.Timestamp, "txs", len(batch.Transactions), "err", err)
} }
continue continue
} }
// Check if we have already seen a batch for this L2 block // Check if we have already seen a batch for this L2 block
if _, ok := uniqueTime[batch.Timestamp]; ok { if _, ok := uniqueTime[batch.Timestamp]; ok {
log.Warn("duplicate batch", "epoch", batch.EpochNum, "timestamp", batch.Timestamp, "txs", len(batch.Transactions)) log.Warn("duplicate batch", "epoch", batch.Epoch(), "timestamp", batch.Timestamp, "txs", len(batch.Transactions))
// block already exists, batch is duplicate (first batch persists, others are ignored) // block already exists, batch is duplicate (first batch persists, others are ignored)
continue continue
} }
...@@ -36,11 +38,15 @@ func FilterBatches(log log.Logger, config *rollup.Config, epoch eth.BlockID, min ...@@ -36,11 +38,15 @@ func FilterBatches(log log.Logger, config *rollup.Config, epoch eth.BlockID, min
} }
func ValidBatch(batch *BatchData, config *rollup.Config, epoch eth.BlockID, minL2Time uint64, maxL2Time uint64) error { func ValidBatch(batch *BatchData, config *rollup.Config, epoch eth.BlockID, minL2Time uint64, maxL2Time uint64) error {
if batch.EpochNum != rollup.Epoch(epoch.Number) || batch.EpochHash != epoch.Hash { if batch.EpochNum != rollup.Epoch(epoch.Number) {
// Batch was tagged for past or future epoch, // Batch was tagged for past or future epoch,
// i.e. it was included too late or depends on the given L1 block to be processed first. // i.e. it was included too late or depends on the given L1 block to be processed first.
// This is a very common error, batches may just be buffered for a later epoch.
return DifferentEpoch return DifferentEpoch
} }
if batch.EpochHash != epoch.Hash {
return fmt.Errorf("batch was meant for alternative L1 chain")
}
if (batch.Timestamp-config.Genesis.L2Time)%config.BlockTime != 0 { if (batch.Timestamp-config.Genesis.L2Time)%config.BlockTime != 0 {
return fmt.Errorf("bad timestamp %d, not a multiple of the block time", batch.Timestamp) return fmt.Errorf("bad timestamp %d, not a multiple of the block time", batch.Timestamp)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment