Skip to content

Commit 3b30523

Browse files
feat(beacon): remove soft blocks implementation (#366)
* Revert "chore(cmd): add `--taiko` flag (#365)" This reverts commit ca784a2. * Revert "chore(cmd): remove `--taiko.preconfirmationForwardingUrl` flag (#362)" This reverts commit 283fedd. * Revert "feat(beacon): introduce soft blocks (#342)" This reverts commit a2cbf90.
1 parent ca784a2 commit 3b30523

File tree

19 files changed

+74
-417
lines changed

19 files changed

+74
-417
lines changed

.github/workflows/docker.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: "Push multi-arch docker image to GAR"
22

33
on:
44
push:
5-
branches: [taiko]
5+
branches: [ taiko ]
66
tags:
77
- "v*"
88

@@ -19,9 +19,9 @@ jobs:
1919
platform: linux/amd64
2020
- runner: arc-runner-set-arm64
2121
platform: linux/arm64
22-
22+
2323
runs-on: ${{ matrix.runner }}
24-
24+
2525
steps:
2626
- name: Prepare Environment
2727
run: |
@@ -80,7 +80,7 @@ jobs:
8080
with:
8181
context: .
8282
cache-from: type=gha
83-
cache-to: type=gha,mode=max
83+
cache-to: type=gha,mode=max
8484
platforms: ${{ matrix.platform }}
8585
push: true
8686
tags: ${{ env.REGISTRY_IMAGE }}

cmd/geth/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func init() {
261261
metricsFlags,
262262
)
263263
// CHANGE(taiko): append Taiko flags into the original GETH flags
264-
app.Flags = append(app.Flags, utils.TaikoFlag)
264+
app.Flags = append(app.Flags, &utils.TaikoFlag)
265265

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

cmd/utils/taiko_flags.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,16 @@ import (
55

66
"github.com/ethereum/go-ethereum/eth"
77
"github.com/ethereum/go-ethereum/eth/ethconfig"
8-
"github.com/ethereum/go-ethereum/internal/flags"
98
"github.com/ethereum/go-ethereum/node"
109
"github.com/ethereum/go-ethereum/params"
1110
"github.com/ethereum/go-ethereum/rpc"
1211
"github.com/urfave/cli/v2"
1312
)
1413

1514
var (
16-
TaikoFlag = &cli.BoolFlag{
17-
Name: "taiko",
18-
Usage: "Taiko network",
19-
Category: flags.TaikoCategory,
15+
TaikoFlag = cli.BoolFlag{
16+
Name: "taiko",
17+
Usage: "Taiko network",
2018
}
2119
)
2220

consensus/taiko/consensus.go

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ import (
1010

1111
"github.com/ethereum/go-ethereum/common"
1212
"github.com/ethereum/go-ethereum/consensus"
13-
"github.com/ethereum/go-ethereum/core/rawdb"
1413
"github.com/ethereum/go-ethereum/core/state"
1514
"github.com/ethereum/go-ethereum/core/tracing"
1615
"github.com/ethereum/go-ethereum/core/types"
1716
"github.com/ethereum/go-ethereum/crypto"
18-
"github.com/ethereum/go-ethereum/ethdb"
1917
"github.com/ethereum/go-ethereum/log"
2018
"github.com/ethereum/go-ethereum/params"
2119
"github.com/ethereum/go-ethereum/rpc"
@@ -42,13 +40,12 @@ var (
4240
// Taiko is a consensus engine used by L2 rollup.
4341
type Taiko struct {
4442
chainConfig *params.ChainConfig
45-
chainDB ethdb.Database
4643
taikoL2Address common.Address
4744
}
4845

4946
var _ = new(Taiko)
5047

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

5451
return &Taiko{
@@ -59,7 +56,6 @@ func New(chainConfig *params.ChainConfig, chainDB ethdb.Database) *Taiko {
5956
strings.Repeat("0", common.AddressLength*2-len(taikoL2AddressPrefix)-len(TaikoL2AddressSuffix)) +
6057
TaikoL2AddressSuffix,
6158
),
62-
chainDB: chainDB,
6359
}
6460
}
6561

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

9288
// VerifyHeaders is similar to VerifyHeader, but verifies a batch of headers
@@ -113,7 +109,7 @@ func (t *Taiko) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*type
113109
if parent == nil {
114110
err = consensus.ErrUnknownAncestor
115111
} else {
116-
err = t.verifyHeader(header, parent, unixNow)
112+
err = t.verifyHeader(chain, header, parent, unixNow)
117113
}
118114
select {
119115
case <-abort:
@@ -125,7 +121,11 @@ func (t *Taiko) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*type
125121
return abort, results
126122
}
127123

128-
func (t *Taiko) verifyHeader(header, parent *types.Header, unixNow int64) error {
124+
func (t *Taiko) verifyHeader(chain consensus.ChainHeaderReader, header, parent *types.Header, unixNow int64) error {
125+
if header.Time > uint64(unixNow) {
126+
return consensus.ErrFutureBlock
127+
}
128+
129129
// Ensure that the header's extra-data section is of a reasonable size (<= 32 bytes)
130130
if uint64(len(header.Extra)) > params.MaximumExtraDataSize {
131131
return fmt.Errorf("extra-data too long: %d > %d", len(header.Extra), params.MaximumExtraDataSize)
@@ -171,16 +171,6 @@ func (t *Taiko) verifyHeader(header, parent *types.Header, unixNow int64) error
171171
return ErrEmptyWithdrawalsHash
172172
}
173173

174-
l1Origin, err := rawdb.ReadL1Origin(t.chainDB, header.Number)
175-
if err != nil {
176-
return err
177-
}
178-
179-
// If the current block is not a soft block, then check the timestamp.
180-
if l1Origin != nil && !l1Origin.IsSoftBlock() && header.Time > uint64(unixNow) {
181-
return consensus.ErrFutureBlock
182-
}
183-
184174
return nil
185175
}
186176

consensus/taiko/consensus_test.go

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func init() {
3939
config.ArrowGlacierBlock = nil
4040
config.Ethash = nil
4141
config.Taiko = true
42-
testEngine = taiko.New(config, rawdb.NewMemoryDatabase())
42+
testEngine = taiko.New(config)
4343

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

@@ -93,73 +93,70 @@ func init() {
9393
}
9494
}
9595

96-
func generateTestChain(t *testing.T) ([]*types.Block, *eth.Ethereum) {
97-
generate := func(i int, g *core.BlockGen) {
98-
g.OffsetTime(5)
99-
100-
g.SetExtra([]byte("test_taiko"))
101-
g.SetDifficulty(common.Big0)
102-
103-
for i, tx := range txs {
104-
if i == 0 {
105-
if err := tx.MarkAsAnchor(); err != nil {
106-
panic(err)
107-
}
108-
}
109-
g.AddTx(tx)
110-
}
111-
}
96+
func newTestBackend(t *testing.T) (*eth.Ethereum, []*types.Block) {
97+
// Generate test chain.
98+
blocks := generateTestChain()
11299

113100
// Create node
114-
n, err := node.New(&node.Config{
115-
DataDir: t.TempDir(),
116-
})
101+
n, err := node.New(&node.Config{})
117102
if err != nil {
118103
t.Fatalf("can't create new node: %v", err)
119104
}
120105

121106
// Create Ethereum Service
122-
ethService, err := eth.New(n, &ethconfig.Config{
107+
config := &ethconfig.Config{
123108
Genesis: genesis,
124-
})
125-
if err != nil {
126-
t.Fatalf("can't create new ethereum service: %v", err)
127109
}
128110

129-
db := ethService.ChainDb()
130-
131-
gblock := genesis.MustCommit(db, triedb.NewDatabase(db, triedb.HashDefaults))
132-
blocks, _ := core.GenerateChain(genesis.Config, gblock, testEngine, db, 1, generate)
133-
blocks = append([]*types.Block{gblock}, blocks...)
134-
135-
// Insert L1Origins.
136-
for _, block := range blocks {
137-
rawdb.WriteL1Origin(db, block.Number(), &rawdb.L1Origin{
138-
BlockID: block.Number(),
139-
L1BlockHeight: block.Number(),
140-
L1BlockHash: block.Hash(),
141-
})
111+
ethservice, err := eth.New(n, config)
112+
if err != nil {
113+
t.Fatalf("can't create new ethereum service: %v", err)
142114
}
143115

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

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

153-
if _, ok := ethService.Engine().(*taiko.Taiko); !ok {
125+
if _, ok := ethservice.Engine().(*taiko.Taiko); !ok {
154126
t.Fatalf("not use taiko engine")
155127
}
156128

157-
return blocks, ethService
129+
return ethservice, blocks
130+
}
131+
132+
func generateTestChain() []*types.Block {
133+
db := rawdb.NewMemoryDatabase()
134+
generate := func(i int, g *core.BlockGen) {
135+
g.OffsetTime(5)
136+
137+
g.SetExtra([]byte("test_taiko"))
138+
g.SetDifficulty(common.Big0)
139+
140+
for i, tx := range txs {
141+
if i == 0 {
142+
if err := tx.MarkAsAnchor(); err != nil {
143+
panic(err)
144+
}
145+
}
146+
g.AddTx(tx)
147+
}
148+
}
149+
150+
gblock := genesis.MustCommit(db, triedb.NewDatabase(db, triedb.HashDefaults))
151+
152+
blocks, _ := core.GenerateChain(genesis.Config, gblock, testEngine, db, 1, generate)
153+
154+
blocks = append([]*types.Block{gblock}, blocks...)
155+
return blocks
158156
}
159157

160158
func TestVerifyHeader(t *testing.T) {
161-
// Generate test chain.
162-
blocks, ethService := generateTestChain(t)
159+
ethService, blocks := newTestBackend(t)
163160

164161
for _, b := range blocks {
165162
err := testEngine.VerifyHeader(ethService.BlockChain(), b.Header())

core/blockchain.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,12 +2269,7 @@ func (bc *BlockChain) reorg(oldHead *types.Header, newHead *types.Block) error {
22692269
} else {
22702270
// len(newChain) == 0 && len(oldChain) > 0
22712271
// rewind the canonical chain to a lower point.
2272-
// CHANGE(taiko): use debug log level to avoid logging too many logs when frequently soft block rollback.
2273-
if bc.chainConfig.Taiko {
2274-
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))
2275-
} else {
2276-
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))
2277-
}
2272+
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))
22782273
}
22792274
// Acquire the tx-lookup lock before mutation. This step is essential
22802275
// as the txlookups should be changed atomically, and all subsequent

core/rawdb/gen_taiko_l1_origin.go

Lines changed: 10 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)