Commit 59d40347 authored by Tei Im's avatar Tei Im

Improve span batch logging

parent 05deae54
...@@ -207,7 +207,9 @@ func (s *channelManager) ensureChannelWithSpace(l1Head eth.BlockID) error { ...@@ -207,7 +207,9 @@ func (s *channelManager) ensureChannelWithSpace(l1Head eth.BlockID) error {
s.log.Info("Created channel", s.log.Info("Created channel",
"id", pc.ID(), "id", pc.ID(),
"l1Head", l1Head, "l1Head", l1Head,
"blocks_pending", len(s.blocks)) "blocks_pending", len(s.blocks),
"batch_type", s.cfg.BatchType,
)
s.metr.RecordChannelOpened(pc.ID(), len(s.blocks)) s.metr.RecordChannelOpened(pc.ID(), len(s.blocks))
return nil return nil
......
...@@ -86,6 +86,7 @@ func (bq *BatchQueue) popNextBatch(parent eth.L2BlockRef) *SingularBatch { ...@@ -86,6 +86,7 @@ func (bq *BatchQueue) popNextBatch(parent eth.L2BlockRef) *SingularBatch {
bq.nextSpan = bq.nextSpan[1:] bq.nextSpan = bq.nextSpan[1:]
// Must set ParentHash before return. we can use parent because the parentCheck is verified in CheckBatch(). // Must set ParentHash before return. we can use parent because the parentCheck is verified in CheckBatch().
nextBatch.ParentHash = parent.Hash nextBatch.ParentHash = parent.Hash
bq.log.Debug("pop next batch from the cached span batch")
return nextBatch return nextBatch
} }
...@@ -103,6 +104,7 @@ func (bq *BatchQueue) NextBatch(ctx context.Context, parent eth.L2BlockRef) (*Si ...@@ -103,6 +104,7 @@ func (bq *BatchQueue) NextBatch(ctx context.Context, parent eth.L2BlockRef) (*Si
} else { } else {
// Given parent block does not match the next batch. It means the previously returned batch is invalid. // Given parent block does not match the next batch. It means the previously returned batch is invalid.
// Drop cached batches and find another batch. // Drop cached batches and find another batch.
bq.log.Warn("parent block does not match the next batch. dropped cached batches", "parent", parent.ID(), "nextBatchTime", bq.nextSpan[0].GetTimestamp())
bq.nextSpan = bq.nextSpan[:0] bq.nextSpan = bq.nextSpan[:0]
} }
} }
...@@ -115,6 +117,11 @@ func (bq *BatchQueue) NextBatch(ctx context.Context, parent eth.L2BlockRef) (*Si ...@@ -115,6 +117,11 @@ func (bq *BatchQueue) NextBatch(ctx context.Context, parent eth.L2BlockRef) (*Si
for i, l1Block := range bq.l1Blocks { for i, l1Block := range bq.l1Blocks {
if parent.L1Origin.Number == l1Block.Number { if parent.L1Origin.Number == l1Block.Number {
bq.l1Blocks = bq.l1Blocks[i:] bq.l1Blocks = bq.l1Blocks[i:]
if len(bq.l1Blocks) > 0 {
bq.log.Debug("Advancing internal L1 blocks", "next_epoch", bq.l1Blocks[0].ID(), "next_epoch_time", bq.l1Blocks[0].Time)
} else {
bq.log.Debug("Advancing internal L1 blocks. No L1 blocks left")
}
break break
} }
} }
......
...@@ -187,7 +187,7 @@ func checkSpanBatch(ctx context.Context, cfg *rollup.Config, log log.Logger, l1B ...@@ -187,7 +187,7 @@ func checkSpanBatch(ctx context.Context, cfg *rollup.Config, log log.Logger, l1B
batchOrigin = l1Blocks[1] batchOrigin = l1Blocks[1]
} }
if !cfg.IsDelta(batchOrigin.Time) { if !cfg.IsDelta(batchOrigin.Time) {
log.Warn("received SpanBatch with L1 origin before Delta hard fork") log.Warn("received SpanBatch with L1 origin before Delta hard fork", "l1_origin", batchOrigin.ID(), "l1_origin_time", batchOrigin.Time)
return BatchDrop return BatchDrop
} }
......
...@@ -96,6 +96,7 @@ func (cr *ChannelInReader) NextBatch(ctx context.Context) (Batch, error) { ...@@ -96,6 +96,7 @@ func (cr *ChannelInReader) NextBatch(ctx context.Context) (Batch, error) {
if !ok { if !ok {
return nil, NewCriticalError(errors.New("failed type assertion to SingularBatch")) return nil, NewCriticalError(errors.New("failed type assertion to SingularBatch"))
} }
cr.log.Debug("decoded singular batch from channel")
return singularBatch, nil return singularBatch, nil
case SpanBatchType: case SpanBatchType:
if origin := cr.Origin(); !cr.cfg.IsDelta(origin.Time) { if origin := cr.Origin(); !cr.cfg.IsDelta(origin.Time) {
...@@ -113,6 +114,7 @@ func (cr *ChannelInReader) NextBatch(ctx context.Context) (Batch, error) { ...@@ -113,6 +114,7 @@ func (cr *ChannelInReader) NextBatch(ctx context.Context) (Batch, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
cr.log.Debug("decoded span batch from channel")
return spanBatch, nil return spanBatch, nil
default: default:
// error is bubbled up to user, but pipeline can skip the batch and continue after. // error is bubbled up to user, but pipeline can skip the batch and continue after.
......
...@@ -44,6 +44,7 @@ func (b *SingularBatch) GetEpochNum() rollup.Epoch { ...@@ -44,6 +44,7 @@ func (b *SingularBatch) GetEpochNum() rollup.Epoch {
// LogContext creates a new log context that contains information of the batch // LogContext creates a new log context that contains information of the batch
func (b *SingularBatch) LogContext(log log.Logger) log.Logger { func (b *SingularBatch) LogContext(log log.Logger) log.Logger {
return log.New( return log.New(
"batch_type", "SingularBatch",
"batch_timestamp", b.Timestamp, "batch_timestamp", b.Timestamp,
"parent_hash", b.ParentHash, "parent_hash", b.ParentHash,
"batch_epoch", b.Epoch(), "batch_epoch", b.Epoch(),
......
...@@ -230,10 +230,10 @@ func (b *RawSpanBatch) decode(r *bytes.Reader) error { ...@@ -230,10 +230,10 @@ func (b *RawSpanBatch) decode(r *bytes.Reader) error {
return ErrTooBigSpanBatchSize return ErrTooBigSpanBatchSize
} }
if err := b.decodePrefix(r); err != nil { if err := b.decodePrefix(r); err != nil {
return err return fmt.Errorf("failed to decode span batch prefix: %w", err)
} }
if err := b.decodePayload(r); err != nil { if err := b.decodePayload(r); err != nil {
return err return fmt.Errorf("failed to decode span batch payload: %w", err)
} }
return nil return nil
} }
...@@ -460,6 +460,7 @@ func (b *SpanBatch) LogContext(log log.Logger) log.Logger { ...@@ -460,6 +460,7 @@ func (b *SpanBatch) LogContext(log log.Logger) log.Logger {
return log.New("block_count", 0) return log.New("block_count", 0)
} }
return log.New( return log.New(
"batch_type", "SpanBatch",
"batch_timestamp", b.batches[0].Timestamp, "batch_timestamp", b.batches[0].Timestamp,
"parent_check", hexutil.Encode(b.parentCheck[:]), "parent_check", hexutil.Encode(b.parentCheck[:]),
"origin_check", hexutil.Encode(b.l1OriginCheck[:]), "origin_check", hexutil.Encode(b.l1OriginCheck[:]),
......
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