Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): add rlp optional flag #353

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,28 +33,23 @@ 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 {
BlockID *math.HexOrDecimal256
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.
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