mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
node, internal/cli: add pruner options back, fix db creation in tests
This commit is contained in:
parent
f959873629
commit
4b7ace0ba6
2 changed files with 11 additions and 26 deletions
|
|
@ -65,11 +65,11 @@ func testOfflineBlockPruneWithAmountReserved(t *testing.T, amountReserved uint64
|
||||||
oldAncientPath := filepath.Join(chaindbPath, "ancient")
|
oldAncientPath := filepath.Join(chaindbPath, "ancient")
|
||||||
newAncientPath := filepath.Join(chaindbPath, "ancient_back")
|
newAncientPath := filepath.Join(chaindbPath, "ancient_back")
|
||||||
|
|
||||||
_, _, blockList, receiptsList, externTdList, startBlockNumber, _ := BlockchainCreator(t, chaindbPath, oldAncientPath, amountReserved)
|
|
||||||
|
|
||||||
node := startEthService(t, chaindbPath)
|
node := startEthService(t, chaindbPath)
|
||||||
defer node.Close()
|
defer node.Close()
|
||||||
|
|
||||||
|
_, _, blockList, receiptsList, externTdList, startBlockNumber, _ := BlockchainCreator(t, node, chaindbPath, oldAncientPath, amountReserved)
|
||||||
|
|
||||||
// Initialize a block pruner for pruning, only remain amountReserved blocks backward.
|
// Initialize a block pruner for pruning, only remain amountReserved blocks backward.
|
||||||
testBlockPruner := pruner.NewBlockPruner(node, oldAncientPath, newAncientPath, amountReserved)
|
testBlockPruner := pruner.NewBlockPruner(node, oldAncientPath, newAncientPath, amountReserved)
|
||||||
dbHandles, err := server.MakeDatabaseHandles(0)
|
dbHandles, err := server.MakeDatabaseHandles(0)
|
||||||
|
|
@ -78,17 +78,7 @@ func testOfflineBlockPruneWithAmountReserved(t *testing.T, amountReserved uint64
|
||||||
err = testBlockPruner.BlockPruneBackup(chaindbPath, 512, dbHandles, "", false, false)
|
err = testBlockPruner.BlockPruneBackup(chaindbPath, 512, dbHandles, "", false, false)
|
||||||
require.NoError(t, err, "failed to backup block")
|
require.NoError(t, err, "failed to backup block")
|
||||||
|
|
||||||
dbBack, err := rawdb.Open(rawdb.OpenOptions{
|
dbBack, err := node.OpenDatabaseWithFreezer(chaindbPath, 0, 0, newAncientPath, "", false, true, false)
|
||||||
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")
|
require.NoError(t, err, "failed to create db with ancient backend")
|
||||||
|
|
||||||
defer dbBack.Close()
|
defer dbBack.Close()
|
||||||
|
|
@ -138,20 +128,11 @@ func testOfflineBlockPruneWithAmountReserved(t *testing.T, amountReserved uint64
|
||||||
require.NoError(t, err, "failed to replace ancientDb")
|
require.NoError(t, err, "failed to replace ancientDb")
|
||||||
}
|
}
|
||||||
|
|
||||||
func BlockchainCreator(t *testing.T, chaindbPath, AncientPath string, blockRemain uint64) (ethdb.Database, []*types.Block, []*types.Block, []types.Receipts, []*big.Int, uint64, *core.BlockChain) {
|
func BlockchainCreator(t *testing.T, node *node.Node, chaindbPath, AncientPath string, blockRemain uint64) (ethdb.Database, []*types.Block, []*types.Block, []types.Receipts, []*big.Int, uint64, *core.BlockChain) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
// Create a database with ancient freezer
|
// Create a database with ancient freezer.
|
||||||
db, err := rawdb.Open(rawdb.OpenOptions{
|
db, err := node.OpenDatabaseWithFreezer(chaindbPath, 0, 0, AncientPath, "", false, false, false)
|
||||||
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")
|
require.NoError(t, err, "failed to create db with ancient backend")
|
||||||
|
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,10 @@ type openOptions struct {
|
||||||
Cache int // the capacity(in megabytes) of the data caching
|
Cache int // the capacity(in megabytes) of the data caching
|
||||||
Handles int // number of files to be open simultaneously
|
Handles int // number of files to be open simultaneously
|
||||||
ReadOnly bool
|
ReadOnly bool
|
||||||
|
|
||||||
|
// Ancient pruner related fields
|
||||||
|
DisableFreeze bool
|
||||||
|
IsLastOffset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// openDatabase opens both a disk-based key-value database such as leveldb or pebble, but also
|
// openDatabase opens both a disk-based key-value database such as leveldb or pebble, but also
|
||||||
|
|
@ -51,7 +55,7 @@ func openDatabase(o openOptions) (ethdb.Database, error) {
|
||||||
if len(o.AncientsDirectory) == 0 {
|
if len(o.AncientsDirectory) == 0 {
|
||||||
return kvdb, nil
|
return kvdb, nil
|
||||||
}
|
}
|
||||||
frdb, err := rawdb.NewDatabaseWithFreezer(kvdb, o.AncientsDirectory, o.Namespace, o.ReadOnly)
|
frdb, err := rawdb.NewDatabaseWithFreezer(kvdb, o.AncientsDirectory, o.Namespace, o.ReadOnly, o.DisableFreeze, o.IsLastOffset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
kvdb.Close()
|
kvdb.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue