From 17e7668ffb97bf46c2a5af54bf2aa00bb57d39c0 Mon Sep 17 00:00:00 2001 From: maskpp Date: Sun, 17 Nov 2024 14:43:48 +0800 Subject: [PATCH] add rlp optional flag --- consensus/taiko/consensus.go | 2 +- core/rawdb/taiko_l1_origin.go | 21 ++++++++------------- core/rawdb/taiko_l1_origin_test.go | 1 + ethclient/taiko_api_test.go | 4 ++-- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/consensus/taiko/consensus.go b/consensus/taiko/consensus.go index b2a38faef85e..96f18b9ba892 100644 --- a/consensus/taiko/consensus.go +++ b/consensus/taiko/consensus.go @@ -177,7 +177,7 @@ func (t *Taiko) verifyHeader(header, parent *types.Header, unixNow int64) error } // If the current block is not a soft block, then check the timestamp. - if l1Origin != nil && !l1Origin.IsSoftblock() && header.Time > uint64(unixNow) { + if l1Origin != nil && !l1Origin.IsSoftBlock() && header.Time > uint64(unixNow) { return consensus.ErrFutureBlock } diff --git a/core/rawdb/taiko_l1_origin.go b/core/rawdb/taiko_l1_origin.go index c5a3ff5f5246..eeb25c34f622 100644 --- a/core/rawdb/taiko_l1_origin.go +++ b/core/rawdb/taiko_l1_origin.go @@ -33,10 +33,10 @@ type L1Origin struct { L2BlockHash common.Hash `json:"l2BlockHash"` L1BlockHeight *big.Int `json:"l1BlockHeight"` L1BlockHash common.Hash `json:"l1BlockHash"` - BatchID *big.Int `json:"batchID"` - EndOfBlock bool `json:"endOfBlock"` - EndOfPreconf bool `json:"endOfPreconf"` - Preconfer common.Address `json:"preconfer"` + BatchID *big.Int `json:"batchID" rlp:"optional"` + EndOfBlock bool `json:"endOfBlock" rlp:"optional"` + EndOfPreconf bool `json:"endOfPreconf" rlp:"optional"` + Preconfer common.Address `json:"preconfer" rlp:"optional"` } type l1OriginMarshaling struct { @@ -44,17 +44,12 @@ type l1OriginMarshaling struct { L1BlockHeight *math.HexOrDecimal256 } -// IsSoftblock returns true if the L1Origin is a softblock. -func (l *L1Origin) IsSoftblock() bool { - if l.BatchID == nil { +// IsSoftBlock returns true if the L1Origin is a softblock. +func (l *L1Origin) IsSoftBlock() bool { + if l.BatchID != nil { return true } - - if l.BatchID.Cmp(common.Big0) == 0 && l.Preconfer == (common.Address{}) { - return false - } - - return true + return false } // WriteL1Origin stores a L1Origin into the database. diff --git a/core/rawdb/taiko_l1_origin_test.go b/core/rawdb/taiko_l1_origin_test.go index dae37a354fa5..e101d3708a85 100644 --- a/core/rawdb/taiko_l1_origin_test.go +++ b/core/rawdb/taiko_l1_origin_test.go @@ -42,6 +42,7 @@ func TestL1Origin(t *testing.T) { l1Origin, err := ReadL1Origin(db, testL1Origin.BlockID) require.Nil(t, err) require.NotNil(t, l1Origin) + assert.Equal(t, testL1Origin.BatchID, l1Origin.BatchID) assert.Equal(t, testL1Origin.BlockID, l1Origin.BlockID) assert.Equal(t, testL1Origin.L2BlockHash, l1Origin.L2BlockHash) assert.Equal(t, testL1Origin.L1BlockHeight, l1Origin.L1BlockHeight) diff --git a/ethclient/taiko_api_test.go b/ethclient/taiko_api_test.go index 839918046036..e44d6ae4e043 100644 --- a/ethclient/taiko_api_test.go +++ b/ethclient/taiko_api_test.go @@ -82,7 +82,7 @@ func TestHeadL1Origin(t *testing.T) { require.Nil(t, err) require.Equal(t, testL1Origin, l1OriginFound) - require.False(t, l1OriginFound.IsSoftblock()) + require.False(t, l1OriginFound.IsSoftBlock()) } func TestL1OriginByID(t *testing.T) { @@ -111,7 +111,7 @@ func TestL1OriginByID(t *testing.T) { require.Nil(t, err) require.Equal(t, testL1Origin, l1OriginFound) - require.True(t, l1OriginFound.IsSoftblock()) + require.True(t, l1OriginFound.IsSoftBlock()) } // randomHash generates a random blob of data and returns it as a hash.