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

Geth sync nits #1157

Merged
merged 6 commits into from
Apr 19, 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
5 changes: 0 additions & 5 deletions core/blockchain_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"fmt"
"math/big"
"os"
"path"
"strings"
"testing"

Expand All @@ -60,7 +59,6 @@ type snapshotTestBasic struct {

// share fields, set in runtime
datadir string
ancient string
db ethdb.Database
genDb ethdb.Database
engine consensus.Engine
Expand All @@ -72,7 +70,6 @@ type snapshotTestBasic struct {
func (basic *snapshotTestBasic) prepare(t *testing.T) (*BlockChain, []*types.Block) {
// Create a temporary persistent database
datadir := t.TempDir()
ancient := path.Join(datadir, "ancient")

db, err := rawdb.Open(rawdb.OpenOptions{
Directory: datadir,
Expand Down Expand Up @@ -130,7 +127,6 @@ func (basic *snapshotTestBasic) prepare(t *testing.T) (*BlockChain, []*types.Blo

// Set runtime fields
basic.datadir = datadir
basic.ancient = ancient
basic.db = db
basic.genDb = genDb
basic.engine = engine
Expand Down Expand Up @@ -212,7 +208,6 @@ func (basic *snapshotTestBasic) teardown() {
basic.db.Close()
basic.genDb.Close()
os.RemoveAll(basic.datadir)
os.RemoveAll(basic.ancient)
}

// snapshotTest is a test case type for normal snapshot recovery.
Expand Down
23 changes: 12 additions & 11 deletions core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ func TestUngracefulAsyncShutdown(t *testing.T) {

func TestTransactionIndices(t *testing.T) {
// Configure and generate a sample block chain
require := require.New(t)
var (
key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
key2, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a")
Expand All @@ -553,17 +554,17 @@ func TestTransactionIndices(t *testing.T) {
)
genDb, blocks, _, err := GenerateChainWithGenesis(gspec, dummy.NewFaker(), 128, 10, func(i int, block *BlockGen) {
tx, err := types.SignTx(types.NewTransaction(block.TxNonce(addr1), addr2, big.NewInt(10000), params.TxGas, nil, nil), signer, key1)
require.NoError(t, err)
require.NoError(err)
block.AddTx(tx)
})
require.NoError(t, err)
require.NoError(err)

blocks2, _, err := GenerateChain(gspec.Config, blocks[len(blocks)-1], dummy.NewFaker(), genDb, 10, 10, func(i int, block *BlockGen) {
tx, err := types.SignTx(types.NewTransaction(block.TxNonce(addr1), addr2, big.NewInt(10000), params.TxGas, nil, nil), signer, key1)
require.NoError(t, err)
require.NoError(err)
block.AddTx(tx)
})
require.NoError(t, err)
require.NoError(err)

conf := &CacheConfig{
TrieCleanLimit: 256,
Expand All @@ -580,19 +581,19 @@ func TestTransactionIndices(t *testing.T) {
// Init block chain and check all needed indices has been indexed.
chainDB := rawdb.NewMemoryDatabase()
chain, err := createBlockChain(chainDB, conf, gspec, common.Hash{})
require.NoError(t, err)
require.NoError(err)

_, err = chain.InsertChain(blocks)
require.NoError(t, err)
require.NoError(err)

for _, block := range blocks {
err := chain.Accept(block)
require.NoError(t, err)
require.NoError(err)
}
chain.DrainAcceptorQueue()

lastAcceptedBlock := blocks[len(blocks)-1]
require.Equal(t, lastAcceptedBlock.Hash(), chain.CurrentHeader().Hash())
require.Equal(lastAcceptedBlock.Hash(), chain.CurrentHeader().Hash())

CheckTxIndices(t, nil, lastAcceptedBlock.NumberU64(), chain.db, false) // check all indices has been indexed
chain.Stop()
Expand All @@ -611,19 +612,19 @@ func TestTransactionIndices(t *testing.T) {
conf.TxLookupLimit = l

chain, err := createBlockChain(chainDB, conf, gspec, lastAcceptedBlock.Hash())
require.NoError(t, err)
require.NoError(err)

tail := getTail(l, lastAcceptedBlock.NumberU64())
// check if startup indices are correct
CheckTxIndices(t, tail, lastAcceptedBlock.NumberU64(), chain.db, false)

newBlks := blocks2[i : i+1]
_, err = chain.InsertChain(newBlks) // Feed chain a higher block to trigger indices updater.
require.NoError(t, err)
require.NoError(err)

lastAcceptedBlock = newBlks[0]
err = chain.Accept(lastAcceptedBlock) // Accept the block to trigger indices updater.
require.NoError(t, err)
require.NoError(err)
chain.DrainAcceptorQueue()

tail = getTail(l, lastAcceptedBlock.NumberU64())
Expand Down
5 changes: 3 additions & 2 deletions tests/utils/tmpnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import (
)

var DefaultChainConfig = tmpnet.FlagsMap{
"log-level": "debug",
"warp-api-enabled": true,
"log-level": "debug",
"warp-api-enabled": true,
"local-txs-enabled": true,
darioush marked this conversation as resolved.
Show resolved Hide resolved
}

func NewTmpnetNodes(count int) []*tmpnet.Node {
Expand Down
Loading