Commit 8e9baf53 authored by zhiqiangxu's avatar zhiqiangxu Committed by GitHub

op-batcher: log oldest l1 origin when channel close (#10676)

* output oldest l1 origin in channel

* also log l2 range when channel close

* use eth.ToBlockID

* fix a bug

* add testcase for 3 new fields
parent c9fd3b49
...@@ -226,6 +226,21 @@ func (c *channel) LatestL1Origin() eth.BlockID { ...@@ -226,6 +226,21 @@ func (c *channel) LatestL1Origin() eth.BlockID {
return c.channelBuilder.LatestL1Origin() return c.channelBuilder.LatestL1Origin()
} }
// OldestL1Origin returns the oldest L1 block origin from all the L2 blocks that have been added to the channel
func (c *channel) OldestL1Origin() eth.BlockID {
return c.channelBuilder.OldestL1Origin()
}
// LatestL2 returns the latest L2 block from all the L2 blocks that have been added to the channel
func (c *channel) LatestL2() eth.BlockID {
return c.channelBuilder.LatestL2()
}
// OldestL2 returns the oldest L2 block from all the L2 blocks that have been added to the channel
func (c *channel) OldestL2() eth.BlockID {
return c.channelBuilder.OldestL2()
}
func (s *channel) Close() { func (s *channel) Close() {
s.channelBuilder.Close() s.channelBuilder.Close()
} }
...@@ -68,6 +68,12 @@ type ChannelBuilder struct { ...@@ -68,6 +68,12 @@ type ChannelBuilder struct {
blocks []*types.Block blocks []*types.Block
// latestL1Origin is the latest L1 origin of all the L2 blocks that have been added to the channel // latestL1Origin is the latest L1 origin of all the L2 blocks that have been added to the channel
latestL1Origin eth.BlockID latestL1Origin eth.BlockID
// oldestL1Origin is the oldest L1 origin of all the L2 blocks that have been added to the channel
oldestL1Origin eth.BlockID
// latestL2 is the latest L2 block of all the L2 blocks that have been added to the channel
latestL2 eth.BlockID
// oldestL2 is the oldest L2 block of all the L2 blocks that have been added to the channel
oldestL2 eth.BlockID
// frames data queue, to be send as txs // frames data queue, to be send as txs
frames []frameData frames []frameData
// total frames counter // total frames counter
...@@ -135,6 +141,21 @@ func (c *ChannelBuilder) LatestL1Origin() eth.BlockID { ...@@ -135,6 +141,21 @@ func (c *ChannelBuilder) LatestL1Origin() eth.BlockID {
return c.latestL1Origin return c.latestL1Origin
} }
// OldestL1Origin returns the oldest L1 block origin from all the L2 blocks that have been added to the channel
func (c *ChannelBuilder) OldestL1Origin() eth.BlockID {
return c.oldestL1Origin
}
// LatestL2 returns the latest L2 block from all the L2 blocks that have been added to the channel
func (c *ChannelBuilder) LatestL2() eth.BlockID {
return c.latestL2
}
// OldestL2 returns the oldest L2 block from all the L2 blocks that have been added to the channel
func (c *ChannelBuilder) OldestL2() eth.BlockID {
return c.oldestL2
}
// AddBlock adds a block to the channel compression pipeline. IsFull should be // AddBlock adds a block to the channel compression pipeline. IsFull should be
// called afterwards to test whether the channel is full. If full, a new channel // called afterwards to test whether the channel is full. If full, a new channel
// must be started. // must be started.
...@@ -172,6 +193,18 @@ func (c *ChannelBuilder) AddBlock(block *types.Block) (*derive.L1BlockInfo, erro ...@@ -172,6 +193,18 @@ func (c *ChannelBuilder) AddBlock(block *types.Block) (*derive.L1BlockInfo, erro
Number: l1info.Number, Number: l1info.Number,
} }
} }
if c.oldestL1Origin.Number == 0 || l1info.Number < c.latestL1Origin.Number {
c.oldestL1Origin = eth.BlockID{
Hash: l1info.BlockHash,
Number: l1info.Number,
}
}
if block.NumberU64() > c.latestL2.Number {
c.latestL2 = eth.ToBlockID(block)
}
if c.oldestL2.Number == 0 || block.NumberU64() < c.oldestL2.Number {
c.oldestL2 = eth.ToBlockID(block)
}
if err = c.co.FullErr(); err != nil { if err = c.co.FullErr(); err != nil {
c.setFullErr(err) c.setFullErr(err)
......
...@@ -712,6 +712,72 @@ func TestChannelBuilder_LatestL1Origin(t *testing.T) { ...@@ -712,6 +712,72 @@ func TestChannelBuilder_LatestL1Origin(t *testing.T) {
require.Equal(t, uint64(2), cb.LatestL1Origin().Number) require.Equal(t, uint64(2), cb.LatestL1Origin().Number)
} }
func TestChannelBuilder_OldestL1Origin(t *testing.T) {
cb, err := NewChannelBuilder(defaultTestChannelConfig(), defaultTestRollupConfig, latestL1BlockOrigin)
require.NoError(t, err)
require.Equal(t, eth.BlockID{}, cb.OldestL1Origin())
_, err = cb.AddBlock(newMiniL2BlockWithNumberParentAndL1Information(0, big.NewInt(1), common.Hash{}, 1, 100))
require.NoError(t, err)
require.Equal(t, uint64(1), cb.OldestL1Origin().Number)
_, err = cb.AddBlock(newMiniL2BlockWithNumberParentAndL1Information(0, big.NewInt(2), common.Hash{}, 1, 100))
require.NoError(t, err)
require.Equal(t, uint64(1), cb.OldestL1Origin().Number)
_, err = cb.AddBlock(newMiniL2BlockWithNumberParentAndL1Information(0, big.NewInt(3), common.Hash{}, 2, 110))
require.NoError(t, err)
require.Equal(t, uint64(1), cb.OldestL1Origin().Number)
_, err = cb.AddBlock(newMiniL2BlockWithNumberParentAndL1Information(0, big.NewInt(3), common.Hash{}, 1, 110))
require.NoError(t, err)
require.Equal(t, uint64(1), cb.OldestL1Origin().Number)
}
func TestChannelBuilder_LatestL2(t *testing.T) {
cb, err := NewChannelBuilder(defaultTestChannelConfig(), defaultTestRollupConfig, latestL1BlockOrigin)
require.NoError(t, err)
require.Equal(t, eth.BlockID{}, cb.LatestL2())
_, err = cb.AddBlock(newMiniL2BlockWithNumberParentAndL1Information(0, big.NewInt(1), common.Hash{}, 1, 100))
require.NoError(t, err)
require.Equal(t, uint64(1), cb.LatestL2().Number)
_, err = cb.AddBlock(newMiniL2BlockWithNumberParentAndL1Information(0, big.NewInt(2), common.Hash{}, 1, 100))
require.NoError(t, err)
require.Equal(t, uint64(2), cb.LatestL2().Number)
_, err = cb.AddBlock(newMiniL2BlockWithNumberParentAndL1Information(0, big.NewInt(3), common.Hash{}, 2, 110))
require.NoError(t, err)
require.Equal(t, uint64(3), cb.LatestL2().Number)
_, err = cb.AddBlock(newMiniL2BlockWithNumberParentAndL1Information(0, big.NewInt(3), common.Hash{}, 1, 110))
require.NoError(t, err)
require.Equal(t, uint64(3), cb.LatestL2().Number)
}
func TestChannelBuilder_OldestL2(t *testing.T) {
cb, err := NewChannelBuilder(defaultTestChannelConfig(), defaultTestRollupConfig, latestL1BlockOrigin)
require.NoError(t, err)
require.Equal(t, eth.BlockID{}, cb.OldestL2())
_, err = cb.AddBlock(newMiniL2BlockWithNumberParentAndL1Information(0, big.NewInt(1), common.Hash{}, 1, 100))
require.NoError(t, err)
require.Equal(t, uint64(1), cb.OldestL2().Number)
_, err = cb.AddBlock(newMiniL2BlockWithNumberParentAndL1Information(0, big.NewInt(2), common.Hash{}, 1, 100))
require.NoError(t, err)
require.Equal(t, uint64(1), cb.OldestL2().Number)
_, err = cb.AddBlock(newMiniL2BlockWithNumberParentAndL1Information(0, big.NewInt(3), common.Hash{}, 2, 110))
require.NoError(t, err)
require.Equal(t, uint64(1), cb.OldestL2().Number)
_, err = cb.AddBlock(newMiniL2BlockWithNumberParentAndL1Information(0, big.NewInt(3), common.Hash{}, 1, 110))
require.NoError(t, err)
require.Equal(t, uint64(1), cb.OldestL2().Number)
}
func ChannelBuilder_PendingFrames_TotalFrames(t *testing.T, batchType uint) { func ChannelBuilder_PendingFrames_TotalFrames(t *testing.T, batchType uint) {
const tnf = 9 const tnf = 9
rng := rand.New(rand.NewSource(94572314)) rng := rand.New(rand.NewSource(94572314))
......
...@@ -320,7 +320,10 @@ func (s *channelManager) outputFrames() error { ...@@ -320,7 +320,10 @@ func (s *channelManager) outputFrames() error {
"num_frames", s.currentChannel.TotalFrames(), "num_frames", s.currentChannel.TotalFrames(),
"input_bytes", inBytes, "input_bytes", inBytes,
"output_bytes", outBytes, "output_bytes", outBytes,
"oldest_l1_origin", s.currentChannel.OldestL1Origin(),
"l1_origin", lastClosedL1Origin, "l1_origin", lastClosedL1Origin,
"oldest_l2", s.currentChannel.OldestL2(),
"latest_l2", s.currentChannel.LatestL2(),
"full_reason", s.currentChannel.FullErr(), "full_reason", s.currentChannel.FullErr(),
"compr_ratio", comprRatio, "compr_ratio", comprRatio,
"latest_l1_origin", s.l1OriginLastClosedChannel, "latest_l1_origin", s.l1OriginLastClosedChannel,
......
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