Skip to content

Commit 1ac9c79

Browse files
committed
add NewBlockChainArbitrum
1 parent e47297e commit 1ac9c79

34 files changed

+124
-115
lines changed

accounts/abi/bind/backends/simulated.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func NewSimulatedBackendWithDatabase(database ethdb.Database, alloc core.Genesis
8383
GasLimit: gasLimit,
8484
Alloc: alloc,
8585
}
86-
blockchain, _ := core.NewBlockChain(database, nil, nil, &genesis, nil, ethash.NewFaker(), vm.Config{}, nil, nil, nil)
86+
blockchain, _ := core.NewBlockChain(database, nil, nil, &genesis, nil, ethash.NewFaker(), vm.Config{}, nil)
8787

8888
backend := &SimulatedBackend{
8989
database: database,

arbitrum/sync_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func TestSimpleSync(t *testing.T) {
194194
testUser2Address: {Balance: new(big.Int).Lsh(big.NewInt(1), 250)},
195195
},
196196
}
197-
sourceChain, _ := core.NewBlockChain(sourceDb, nil, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil, nil)
197+
sourceChain, _ := core.NewBlockChainArbitrum(sourceDb, nil, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil, nil)
198198
signer := types.MakeSigner(sourceChain.Config(), big.NewInt(1), 0)
199199

200200
firstAddress := common.Address{}
@@ -302,7 +302,7 @@ func TestSimpleSync(t *testing.T) {
302302
if err != nil {
303303
t.Fatal(err)
304304
}
305-
badChain, _ := core.NewBlockChain(badDb, nil, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil, nil)
305+
badChain, _ := core.NewBlockChainArbitrum(badDb, nil, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil, nil)
306306
if _, err := badChain.InsertChain(badBlocks[:pivotBlockNum]); err != nil {
307307
t.Fatal(err)
308308
}
@@ -344,7 +344,7 @@ func TestSimpleSync(t *testing.T) {
344344
if err != nil {
345345
t.Fatal(err)
346346
}
347-
destChain, _ := core.NewBlockChain(destDb, nil, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil, nil)
347+
destChain, _ := core.NewBlockChainArbitrum(destDb, nil, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil, nil)
348348
destHandler := NewProtocolHandler(destDb, destChain, &dummySyncHelper{syncBlock.Header(), nil}, true)
349349
destStack.RegisterProtocols(destHandler.MakeProtocols(iter))
350350

cmd/utils/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2136,7 +2136,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh
21362136
vmcfg := vm.Config{EnablePreimageRecording: ctx.Bool(VMEnableDebugFlag.Name)}
21372137

21382138
// Disable transaction indexing/unindexing by default.
2139-
chain, err := core.NewBlockChain(chainDb, cache, nil, gspec, nil, engine, vmcfg, nil, nil, nil)
2139+
chain, err := core.NewBlockChain(chainDb, cache, nil, gspec, nil, engine, vmcfg, nil)
21402140
if err != nil {
21412141
Fatalf("Can't create BlockChain: %v", err)
21422142
}

consensus/clique/clique_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func TestReimportMirroredState(t *testing.T) {
5555
copy(genspec.ExtraData[extraVanity:], addr[:])
5656

5757
// Generate a batch of blocks, each properly signed
58-
chain, _ := core.NewBlockChain(rawdb.NewMemoryDatabase(), nil, nil, genspec, nil, engine, vm.Config{}, nil, nil, nil)
58+
chain, _ := core.NewBlockChain(rawdb.NewMemoryDatabase(), nil, nil, genspec, nil, engine, vm.Config{}, nil)
5959
defer chain.Stop()
6060

6161
_, blocks, _ := core.GenerateChainWithGenesis(genspec, engine, 3, func(i int, block *core.BlockGen) {
@@ -87,7 +87,7 @@ func TestReimportMirroredState(t *testing.T) {
8787
}
8888
// Insert the first two blocks and make sure the chain is valid
8989
db = rawdb.NewMemoryDatabase()
90-
chain, _ = core.NewBlockChain(db, nil, nil, genspec, nil, engine, vm.Config{}, nil, nil, nil)
90+
chain, _ = core.NewBlockChain(db, nil, nil, genspec, nil, engine, vm.Config{}, nil)
9191
defer chain.Stop()
9292

9393
if _, err := chain.InsertChain(blocks[:2]); err != nil {
@@ -100,7 +100,7 @@ func TestReimportMirroredState(t *testing.T) {
100100
// Simulate a crash by creating a new chain on top of the database, without
101101
// flushing the dirty states out. Insert the last block, triggering a sidechain
102102
// reimport.
103-
chain, _ = core.NewBlockChain(db, nil, nil, genspec, nil, engine, vm.Config{}, nil, nil, nil)
103+
chain, _ = core.NewBlockChain(db, nil, nil, genspec, nil, engine, vm.Config{}, nil)
104104
defer chain.Stop()
105105

106106
if _, err := chain.InsertChain(blocks[2:]); err != nil {

consensus/clique/snapshot_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ func (tt *cliqueTest) run(t *testing.T) {
458458
batches[len(batches)-1] = append(batches[len(batches)-1], block)
459459
}
460460
// Pass all the headers through clique and ensure tallying succeeds
461-
chain, err := core.NewBlockChain(rawdb.NewMemoryDatabase(), nil, nil, genesis, nil, engine, vm.Config{}, nil, nil, nil)
461+
chain, err := core.NewBlockChain(rawdb.NewMemoryDatabase(), nil, nil, genesis, nil, engine, vm.Config{}, nil)
462462
if err != nil {
463463
t.Fatalf("failed to create test chain: %v", err)
464464
}

core/bench_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func benchInsertChain(b *testing.B, disk bool, gen func(int, *BlockGen)) {
195195

196196
// Time the insertion of the new chain.
197197
// State and blocks are stored in the same DB.
198-
chainman, _ := NewBlockChain(db, nil, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil, nil)
198+
chainman, _ := NewBlockChain(db, nil, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil)
199199
defer chainman.Stop()
200200
b.ReportAllocs()
201201
b.ResetTimer()
@@ -307,7 +307,7 @@ func benchReadChain(b *testing.B, full bool, count uint64) {
307307
if err != nil {
308308
b.Fatalf("error opening database at %v: %v", dir, err)
309309
}
310-
chain, err := NewBlockChain(db, &cacheConfig, nil, nil, nil, ethash.NewFaker(), vm.Config{}, nil, nil, nil)
310+
chain, err := NewBlockChain(db, &cacheConfig, nil, nil, nil, ethash.NewFaker(), vm.Config{}, nil)
311311
if err != nil {
312312
b.Fatalf("error creating chain: %v", err)
313313
}

core/block_validator_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestHeaderVerification(t *testing.T) {
4545
headers[i] = block.Header()
4646
}
4747
// Run the header checker for blocks one-by-one, checking for both valid and invalid nonces
48-
chain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), nil, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil, nil)
48+
chain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), nil, nil, gspec, nil, ethash.NewFaker(), vm.Config{}, nil)
4949
defer chain.Stop()
5050

5151
for i := 0; i < len(blocks); i++ {
@@ -158,7 +158,7 @@ func testHeaderVerificationForMerging(t *testing.T, isClique bool) {
158158
t.Logf("Post-merge header: %d", block.NumberU64())
159159
}
160160
// Run the header checker for blocks one-by-one, checking for both valid and invalid nonces
161-
chain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), nil, nil, gspec, nil, engine, vm.Config{}, nil, nil, nil)
161+
chain, _ := NewBlockChain(rawdb.NewMemoryDatabase(), nil, nil, gspec, nil, engine, vm.Config{}, nil)
162162
defer chain.Stop()
163163

164164
// Verify the blocks before the merging

core/blockchain.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,26 @@ type trieGcEntry struct {
258258
GasUsed uint64
259259
}
260260

261+
func NewBlockChainArbitrum(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *params.ChainConfig, genesis *Genesis, overrides *ChainOverrides, engine consensus.Engine, vmConfig vm.Config, shouldPreserve func(header *types.Header) bool, txLookupLimit *uint64, forceTriedbCommitHook ForceTriedbCommitHook) (*BlockChain, error) {
262+
bc, err := NewBlockChain(db, cacheConfig, chainConfig, genesis, overrides, engine, vmConfig, shouldPreserve)
263+
if err != nil {
264+
return nil, err
265+
}
266+
// Start tx indexer/unindexer if required.
267+
if txLookupLimit != nil {
268+
bc.txLookupLimit = *txLookupLimit
269+
270+
bc.wg.Add(1)
271+
go bc.maintainTxIndex()
272+
}
273+
bc.forceTriedbCommitHook = forceTriedbCommitHook
274+
return bc, nil
275+
}
276+
261277
// NewBlockChain returns a fully initialised block chain using information
262278
// available in the database. It initialises the default Ethereum Validator
263279
// and Processor.
264-
func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *params.ChainConfig, genesis *Genesis, overrides *ChainOverrides, engine consensus.Engine, vmConfig vm.Config, shouldPreserve func(header *types.Header) bool, txLookupLimit *uint64, forceTriedbCommitHook ForceTriedbCommitHook) (*BlockChain, error) {
280+
func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *params.ChainConfig, genesis *Genesis, overrides *ChainOverrides, engine consensus.Engine, vmConfig vm.Config, shouldPreserve func(header *types.Header) bool) (*BlockChain, error) {
265281
if cacheConfig == nil {
266282
cacheConfig = defaultCacheConfig
267283
}
@@ -468,14 +484,6 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
468484
}
469485
rawdb.WriteChainConfig(db, genesisHash, chainConfig)
470486
}
471-
// Start tx indexer/unindexer if required.
472-
if txLookupLimit != nil {
473-
bc.txLookupLimit = *txLookupLimit
474-
475-
bc.wg.Add(1)
476-
go bc.maintainTxIndex()
477-
}
478-
bc.forceTriedbCommitHook = forceTriedbCommitHook
479487
return bc, nil
480488
}
481489

@@ -961,6 +969,7 @@ func (bc *BlockChain) ExportN(w io.Writer, first uint64, last uint64) error {
961969
//
962970
// Note, this function assumes that the `mu` mutex is held!
963971
func (bc *BlockChain) writeHeadBlock(block *types.Block) {
972+
log.Warn("YYY writeBlockHead", "number", block.NumberU64())
964973
// Add the block to the canonical chain number scheme and mark as the head
965974
batch := bc.db.NewBatch()
966975
rawdb.WriteHeadHeaderHash(batch, block.Hash())
@@ -1030,7 +1039,7 @@ func (bc *BlockChain) Stop() {
10301039
// - HEAD: So we don't need to reprocess any blocks in the general case
10311040
// - HEAD-1: So we don't do large reorgs if our HEAD becomes an uncle
10321041
// - HEAD-127: So we have a hard limit on the number of blocks reexecuted
1033-
if !bc.cacheConfig.TrieDirtyDisabled {
1042+
if !bc.cacheConfig.TrieDirtyDisabled || bc.cacheConfig.MaxAmountOfGasToSkipStateSaving > 0 || bc.cacheConfig.MaxNumberOfBlocksToSkipStateSaving > 0 {
10341043
triedb := bc.triedb
10351044

10361045
for _, offset := range []uint64{0, 1, bc.cacheConfig.TriesInMemory - 1, math.MaxUint64} {

core/blockchain_repair_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,7 +1788,7 @@ func testRepair(t *testing.T, tt *rewindTest, snapshots bool) {
17881788
config.SnapshotLimit = 256
17891789
config.SnapshotWait = true
17901790
}
1791-
chain, err := NewBlockChain(db, config, nil, gspec, nil, engine, vm.Config{}, nil, nil, nil)
1791+
chain, err := NewBlockChain(db, config, nil, gspec, nil, engine, vm.Config{}, nil)
17921792
if err != nil {
17931793
t.Fatalf("Failed to create chain: %v", err)
17941794
}
@@ -1846,7 +1846,7 @@ func testRepair(t *testing.T, tt *rewindTest, snapshots bool) {
18461846
}
18471847
defer db.Close()
18481848

1849-
newChain, err := NewBlockChain(db, nil, nil, gspec, nil, engine, vm.Config{}, nil, nil, nil)
1849+
newChain, err := NewBlockChain(db, nil, nil, gspec, nil, engine, vm.Config{}, nil)
18501850
if err != nil {
18511851
t.Fatalf("Failed to recreate chain: %v", err)
18521852
}
@@ -1924,7 +1924,7 @@ func TestIssue23496(t *testing.T) {
19241924
TrieRetention: 30 * time.Minute,
19251925
}
19261926
)
1927-
chain, err := NewBlockChain(db, config, nil, gspec, nil, engine, vm.Config{}, nil, nil, nil)
1927+
chain, err := NewBlockChain(db, config, nil, gspec, nil, engine, vm.Config{}, nil)
19281928
if err != nil {
19291929
t.Fatalf("Failed to create chain: %v", err)
19301930
}
@@ -1972,7 +1972,7 @@ func TestIssue23496(t *testing.T) {
19721972
}
19731973
defer db.Close()
19741974

1975-
chain, err = NewBlockChain(db, nil, nil, gspec, nil, engine, vm.Config{}, nil, nil, nil)
1975+
chain, err = NewBlockChain(db, nil, nil, gspec, nil, engine, vm.Config{}, nil)
19761976
if err != nil {
19771977
t.Fatalf("Failed to recreate chain: %v", err)
19781978
}

core/blockchain_sethead_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1987,7 +1987,7 @@ func testSetHead(t *testing.T, tt *rewindTest, snapshots bool) {
19871987
config.SnapshotLimit = 256
19881988
config.SnapshotWait = true
19891989
}
1990-
chain, err := NewBlockChain(db, config, nil, gspec, nil, engine, vm.Config{}, nil, nil, nil)
1990+
chain, err := NewBlockChain(db, config, nil, gspec, nil, engine, vm.Config{}, nil)
19911991
if err != nil {
19921992
t.Fatalf("Failed to create chain: %v", err)
19931993
}

core/blockchain_snapshot_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (basic *snapshotTestBasic) prepare(t *testing.T) (*BlockChain, []*types.Blo
8181
// will happen during the block insertion.
8282
cacheConfig = defaultCacheConfig
8383
)
84-
chain, err := NewBlockChain(db, cacheConfig, nil, gspec, nil, engine, vm.Config{}, nil, nil, nil)
84+
chain, err := NewBlockChain(db, cacheConfig, nil, gspec, nil, engine, vm.Config{}, nil)
8585
if err != nil {
8686
t.Fatalf("Failed to create chain: %v", err)
8787
}
@@ -226,7 +226,7 @@ func (snaptest *snapshotTest) test(t *testing.T) {
226226

227227
// Restart the chain normally
228228
chain.Stop()
229-
newchain, err := NewBlockChain(snaptest.db, nil, nil, snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil, nil)
229+
newchain, err := NewBlockChain(snaptest.db, nil, nil, snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil)
230230
if err != nil {
231231
t.Fatalf("Failed to recreate chain: %v", err)
232232
}
@@ -267,13 +267,13 @@ func (snaptest *crashSnapshotTest) test(t *testing.T) {
267267
// the crash, we do restart twice here: one after the crash and one
268268
// after the normal stop. It's used to ensure the broken snapshot
269269
// can be detected all the time.
270-
newchain, err := NewBlockChain(newdb, nil, nil, snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil, nil)
270+
newchain, err := NewBlockChain(newdb, nil, nil, snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil)
271271
if err != nil {
272272
t.Fatalf("Failed to recreate chain: %v", err)
273273
}
274274
newchain.Stop()
275275

276-
newchain, err = NewBlockChain(newdb, nil, nil, snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil, nil)
276+
newchain, err = NewBlockChain(newdb, nil, nil, snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil)
277277
if err != nil {
278278
t.Fatalf("Failed to recreate chain: %v", err)
279279
}
@@ -314,15 +314,15 @@ func (snaptest *gappedSnapshotTest) test(t *testing.T) {
314314
TrieTimeLimit: 5 * time.Minute,
315315
SnapshotLimit: 0,
316316
}
317-
newchain, err := NewBlockChain(snaptest.db, cacheConfig, nil, snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil, nil)
317+
newchain, err := NewBlockChain(snaptest.db, cacheConfig, nil, snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil)
318318
if err != nil {
319319
t.Fatalf("Failed to recreate chain: %v", err)
320320
}
321321
newchain.InsertChain(gappedBlocks)
322322
newchain.Stop()
323323

324324
// Restart the chain with enabling the snapshot
325-
newchain, err = NewBlockChain(snaptest.db, nil, nil, snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil, nil)
325+
newchain, err = NewBlockChain(snaptest.db, nil, nil, snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil)
326326
if err != nil {
327327
t.Fatalf("Failed to recreate chain: %v", err)
328328
}
@@ -350,7 +350,7 @@ func (snaptest *setHeadSnapshotTest) test(t *testing.T) {
350350
chain.SetHead(snaptest.setHead)
351351
chain.Stop()
352352

353-
newchain, err := NewBlockChain(snaptest.db, nil, nil, snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil, nil)
353+
newchain, err := NewBlockChain(snaptest.db, nil, nil, snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil)
354354
if err != nil {
355355
t.Fatalf("Failed to recreate chain: %v", err)
356356
}
@@ -390,7 +390,7 @@ func (snaptest *wipeCrashSnapshotTest) test(t *testing.T) {
390390
TrieTimeLimit: 5 * time.Minute,
391391
SnapshotLimit: 0,
392392
}
393-
newchain, err := NewBlockChain(snaptest.db, config, nil, snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil, nil)
393+
newchain, err := NewBlockChain(snaptest.db, config, nil, snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil)
394394
if err != nil {
395395
t.Fatalf("Failed to recreate chain: %v", err)
396396
}
@@ -411,15 +411,15 @@ func (snaptest *wipeCrashSnapshotTest) test(t *testing.T) {
411411
SnapshotLimit: 256,
412412
SnapshotWait: false, // Don't wait rebuild
413413
}
414-
tmp, err := NewBlockChain(snaptest.db, config, nil, snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil, nil)
414+
tmp, err := NewBlockChain(snaptest.db, config, nil, snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil)
415415
if err != nil {
416416
t.Fatalf("Failed to recreate chain: %v", err)
417417
}
418418

419419
// Simulate the blockchain crash.
420420
tmp.stopWithoutSaving()
421421

422-
newchain, err = NewBlockChain(snaptest.db, nil, nil, snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil, nil, nil)
422+
newchain, err = NewBlockChain(snaptest.db, nil, nil, snaptest.gspec, nil, snaptest.engine, vm.Config{}, nil)
423423
if err != nil {
424424
t.Fatalf("Failed to recreate chain: %v", err)
425425
}

0 commit comments

Comments
 (0)