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(beacon): remove soft blocks implementation #366

Merged
merged 3 commits into from
Jan 10, 2025
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
8 changes: 4 additions & 4 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: "Push multi-arch docker image to GAR"

on:
push:
branches: [taiko]
branches: [ taiko ]
tags:
- "v*"

Expand All @@ -19,9 +19,9 @@ jobs:
platform: linux/amd64
- runner: arc-runner-set-arm64
platform: linux/arm64

runs-on: ${{ matrix.runner }}

steps:
- name: Prepare Environment
run: |
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
with:
context: .
cache-from: type=gha
cache-to: type=gha,mode=max
cache-to: type=gha,mode=max
platforms: ${{ matrix.platform }}
push: true
tags: ${{ env.REGISTRY_IMAGE }}
Expand Down
2 changes: 1 addition & 1 deletion cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func init() {
metricsFlags,
)
// CHANGE(taiko): append Taiko flags into the original GETH flags
app.Flags = append(app.Flags, utils.TaikoFlag)
app.Flags = append(app.Flags, &utils.TaikoFlag)

flags.AutoEnvVars(app.Flags, "GETH")

Expand Down
8 changes: 3 additions & 5 deletions cmd/utils/taiko_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@ import (

"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/internal/flags"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
"github.com/urfave/cli/v2"
)

var (
TaikoFlag = &cli.BoolFlag{
Name: "taiko",
Usage: "Taiko network",
Category: flags.TaikoCategory,
TaikoFlag = cli.BoolFlag{
Name: "taiko",
Usage: "Taiko network",
}
)

Expand Down
26 changes: 8 additions & 18 deletions consensus/taiko/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/tracing"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
Expand All @@ -42,13 +40,12 @@ var (
// Taiko is a consensus engine used by L2 rollup.
type Taiko struct {
chainConfig *params.ChainConfig
chainDB ethdb.Database
taikoL2Address common.Address
}

var _ = new(Taiko)

func New(chainConfig *params.ChainConfig, chainDB ethdb.Database) *Taiko {
func New(chainConfig *params.ChainConfig) *Taiko {
taikoL2AddressPrefix := strings.TrimPrefix(chainConfig.ChainID.String(), "0")

return &Taiko{
Expand All @@ -59,7 +56,6 @@ func New(chainConfig *params.ChainConfig, chainDB ethdb.Database) *Taiko {
strings.Repeat("0", common.AddressLength*2-len(taikoL2AddressPrefix)-len(TaikoL2AddressSuffix)) +
TaikoL2AddressSuffix,
),
chainDB: chainDB,
}
}

Expand All @@ -86,7 +82,7 @@ func (t *Taiko) VerifyHeader(chain consensus.ChainHeaderReader, header *types.He
return consensus.ErrUnknownAncestor
}
// Sanity checks passed, do a proper verification
return t.verifyHeader(header, parent, time.Now().Unix())
return t.verifyHeader(chain, header, parent, time.Now().Unix())
}

// VerifyHeaders is similar to VerifyHeader, but verifies a batch of headers
Expand All @@ -113,7 +109,7 @@ func (t *Taiko) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*type
if parent == nil {
err = consensus.ErrUnknownAncestor
} else {
err = t.verifyHeader(header, parent, unixNow)
err = t.verifyHeader(chain, header, parent, unixNow)
}
select {
case <-abort:
Expand All @@ -125,7 +121,11 @@ func (t *Taiko) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*type
return abort, results
}

func (t *Taiko) verifyHeader(header, parent *types.Header, unixNow int64) error {
func (t *Taiko) verifyHeader(chain consensus.ChainHeaderReader, header, parent *types.Header, unixNow int64) error {
if header.Time > uint64(unixNow) {
return consensus.ErrFutureBlock
}

// Ensure that the header's extra-data section is of a reasonable size (<= 32 bytes)
if uint64(len(header.Extra)) > params.MaximumExtraDataSize {
return fmt.Errorf("extra-data too long: %d > %d", len(header.Extra), params.MaximumExtraDataSize)
Expand Down Expand Up @@ -171,16 +171,6 @@ func (t *Taiko) verifyHeader(header, parent *types.Header, unixNow int64) error
return ErrEmptyWithdrawalsHash
}

l1Origin, err := rawdb.ReadL1Origin(t.chainDB, header.Number)
if err != nil {
return err
}

// If the current block is not a soft block, then check the timestamp.
if l1Origin != nil && !l1Origin.IsSoftBlock() && header.Time > uint64(unixNow) {
return consensus.ErrFutureBlock
}

return nil
}

Expand Down
81 changes: 39 additions & 42 deletions consensus/taiko/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func init() {
config.ArrowGlacierBlock = nil
config.Ethash = nil
config.Taiko = true
testEngine = taiko.New(config, rawdb.NewMemoryDatabase())
testEngine = taiko.New(config)

taikoL2AddressPrefix := strings.TrimPrefix(config.ChainID.String(), "0")

Expand Down Expand Up @@ -93,73 +93,70 @@ func init() {
}
}

func generateTestChain(t *testing.T) ([]*types.Block, *eth.Ethereum) {
generate := func(i int, g *core.BlockGen) {
g.OffsetTime(5)

g.SetExtra([]byte("test_taiko"))
g.SetDifficulty(common.Big0)

for i, tx := range txs {
if i == 0 {
if err := tx.MarkAsAnchor(); err != nil {
panic(err)
}
}
g.AddTx(tx)
}
}
func newTestBackend(t *testing.T) (*eth.Ethereum, []*types.Block) {
// Generate test chain.
blocks := generateTestChain()

// Create node
n, err := node.New(&node.Config{
DataDir: t.TempDir(),
})
n, err := node.New(&node.Config{})
if err != nil {
t.Fatalf("can't create new node: %v", err)
}

// Create Ethereum Service
ethService, err := eth.New(n, &ethconfig.Config{
config := &ethconfig.Config{
Genesis: genesis,
})
if err != nil {
t.Fatalf("can't create new ethereum service: %v", err)
}

db := ethService.ChainDb()

gblock := genesis.MustCommit(db, triedb.NewDatabase(db, triedb.HashDefaults))
blocks, _ := core.GenerateChain(genesis.Config, gblock, testEngine, db, 1, generate)
blocks = append([]*types.Block{gblock}, blocks...)

// Insert L1Origins.
for _, block := range blocks {
rawdb.WriteL1Origin(db, block.Number(), &rawdb.L1Origin{
BlockID: block.Number(),
L1BlockHeight: block.Number(),
L1BlockHash: block.Hash(),
})
ethservice, err := eth.New(n, config)
if err != nil {
t.Fatalf("can't create new ethereum service: %v", err)
}

// Import the test chain.
if err := n.Start(); err != nil {
t.Fatalf("can't start test node: %v", err)
}

if _, err := ethService.BlockChain().InsertChain(blocks[1:]); err != nil {
if _, err := ethservice.BlockChain().InsertChain(blocks[1:]); err != nil {
t.Fatalf("can't import test blocks: %v", err)
}

if _, ok := ethService.Engine().(*taiko.Taiko); !ok {
if _, ok := ethservice.Engine().(*taiko.Taiko); !ok {
t.Fatalf("not use taiko engine")
}

return blocks, ethService
return ethservice, blocks
}

func generateTestChain() []*types.Block {
db := rawdb.NewMemoryDatabase()
generate := func(i int, g *core.BlockGen) {
g.OffsetTime(5)

g.SetExtra([]byte("test_taiko"))
g.SetDifficulty(common.Big0)

for i, tx := range txs {
if i == 0 {
if err := tx.MarkAsAnchor(); err != nil {
panic(err)
}
}
g.AddTx(tx)
}
}

gblock := genesis.MustCommit(db, triedb.NewDatabase(db, triedb.HashDefaults))

blocks, _ := core.GenerateChain(genesis.Config, gblock, testEngine, db, 1, generate)

blocks = append([]*types.Block{gblock}, blocks...)
return blocks
}

func TestVerifyHeader(t *testing.T) {
// Generate test chain.
blocks, ethService := generateTestChain(t)
ethService, blocks := newTestBackend(t)

for _, b := range blocks {
err := testEngine.VerifyHeader(ethService.BlockChain(), b.Header())
Expand Down
7 changes: 1 addition & 6 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2269,12 +2269,7 @@ func (bc *BlockChain) reorg(oldHead *types.Header, newHead *types.Block) error {
} else {
// len(newChain) == 0 && len(oldChain) > 0
// rewind the canonical chain to a lower point.
// CHANGE(taiko): use debug log level to avoid logging too many logs when frequently soft block rollback.
if bc.chainConfig.Taiko {
log.Debug("Impossible reorg, please file an issue", "oldnum", oldBlock.Number(), "oldhash", oldBlock.Hash(), "oldblocks", len(oldChain), "newnum", newBlock.Number(), "newhash", newBlock.Hash(), "newblocks", len(newChain))
} else {
log.Error("Impossible reorg, please file an issue", "oldnum", oldBlock.Number(), "oldhash", oldBlock.Hash(), "oldblocks", len(oldChain), "newnum", newBlock.Number(), "newhash", newBlock.Hash(), "newblocks", len(newChain))
}
log.Error("Impossible reorg, please file an issue", "oldnum", oldBlock.Number(), "oldhash", oldBlock.Hash(), "oldblocks", len(oldChain), "newnum", newBlock.Number(), "newhash", newBlock.Hash(), "newblocks", len(newChain))
}
// Acquire the tx-lookup lock before mutation. This step is essential
// as the txlookups should be changed atomically, and all subsequent
Expand Down
42 changes: 10 additions & 32 deletions core/rawdb/gen_taiko_l1_origin.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading