Skip to content

Commit

Permalink
add rlp optional flag (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
mask-pp authored Nov 17, 2024
1 parent ca660bd commit 51d42ec
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
2 changes: 1 addition & 1 deletion consensus/taiko/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
21 changes: 8 additions & 13 deletions core/rawdb/taiko_l1_origin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

// L1OriginLegacy represents the legacy L1Origin structure of a L2 block.
Expand All @@ -52,17 +52,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 {

Check failure on line 57 in core/rawdb/taiko_l1_origin.go

View workflow job for this annotation

GitHub Actions / test

S1008: should use 'return l.BatchID != nil' instead of 'if l.BatchID != nil { return true }; return false' (gosimple)
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.
Expand Down
1 change: 1 addition & 0 deletions core/rawdb/taiko_l1_origin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions ethclient/taiko_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 51d42ec

Please sign in to comment.