Skip to content

Commit

Permalink
add check for hash scheme, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
manav2401 committed Apr 14, 2024
1 parent 8dbde87 commit ac681be
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
6 changes: 6 additions & 0 deletions internal/cli/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,12 @@ func (c *PruneBlockCommand) accessDb(stack *node.Node, dbHandles int) error {
return nil
}

// Check if we're in hash scheme and not path scheme
if rawdb.ReadStateScheme(chaindb) != rawdb.HashScheme {
log.Warn("Snapshot and MPT check is only supported for hash scheme, skipping")
return nil
}

headBlock := rawdb.ReadHeadBlock(chaindb)
if headBlock == nil {
return errors.New("failed to load head block")
Expand Down
28 changes: 24 additions & 4 deletions internal/cli/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"

"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -79,7 +80,17 @@ func testOfflineBlockPruneWithAmountReserved(t *testing.T, amountReserved uint64
err = testBlockPruner.BlockPruneBackup(chaindbPath, 512, dbHandles, "", false, false)
require.NoError(t, err, "failed to backup block")

dbBack, err := rawdb.NewLevelDBDatabaseWithFreezer(chaindbPath, 0, 0, newAncientPath, "", false, true, false)
dbBack, err := rawdb.Open(rawdb.OpenOptions{
Type: node.Config().DBEngine,
Directory: chaindbPath,
AncientsDirectory: newAncientPath,
Namespace: "",
Cache: 0,
Handles: 0,
ReadOnly: false,
DisableFreeze: true,
IsLastOffset: false,
})
require.NoError(t, err, "failed to create db with ancient backend")

defer dbBack.Close()
Expand Down Expand Up @@ -133,14 +144,23 @@ func BlockchainCreator(t *testing.T, chaindbPath, AncientPath string, blockRemai
t.Helper()

// Create a database with ancient freezer
db, err := rawdb.NewLevelDBDatabaseWithFreezer(chaindbPath, 0, 0, AncientPath, "", false, false, false)
db, err := rawdb.Open(rawdb.OpenOptions{
Directory: chaindbPath,
AncientsDirectory: AncientPath,
Namespace: "",
Cache: 0,
Handles: 0,
ReadOnly: false,
DisableFreeze: false,
IsLastOffset: false,
})
require.NoError(t, err, "failed to create db with ancient backend")

defer db.Close()

genesis := gspec.MustCommit(db)
genesis := gspec.MustCommit(db, trie.NewDatabase(db, trie.HashDefaults))
// Initialize a fresh chain with only a genesis block
blockchain, err := core.NewBlockChain(db, config, gspec.Config, engine, vm.Config{}, nil, nil, nil)
blockchain, err := core.NewBlockChain(db, config, gspec, nil, engine, vm.Config{}, nil, nil, nil)
require.NoError(t, err, "failed to create chain")

// Make chain starting from genesis
Expand Down

0 comments on commit ac681be

Please sign in to comment.