mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 03:30:37 +00:00
CL lightclient to create memdb in the tmpdir which gets cleaned up on… (#6829)
… startup --------- Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local> Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro-2.local>
This commit is contained in:
parent
c6f6aab542
commit
ee83447fa1
@ -117,7 +117,7 @@ func main() {
|
||||
|
||||
printNotice(&nodeKey.PublicKey, *realaddr)
|
||||
|
||||
db, err := enode.OpenDB("")
|
||||
db, err := enode.OpenDB("" /* path */, "" /* tmpDir */)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ func main() {
|
||||
maxReceiveSize := 500 * datasize.MB
|
||||
|
||||
s := grpc.NewServer(grpc.MaxRecvMsgSize(int(maxReceiveSize)))
|
||||
execution.RegisterExecutionServer(s, NewEth1Execution(memdb.New()))
|
||||
execution.RegisterExecutionServer(s, NewEth1Execution(memdb.New("" /* tmpDir */)))
|
||||
log.Info("Serving mock Execution layer.")
|
||||
if err := s.Serve(lis); err != nil {
|
||||
log.Error("failed to serve", "err", err)
|
||||
|
@ -193,7 +193,7 @@ func NewBackend(stack *node.Node, config *ethconfig.Config, logger log.Logger) (
|
||||
genesisSpec = nil
|
||||
}
|
||||
var genesisErr error
|
||||
chainConfig, genesis, genesisErr = core.WriteGenesisBlock(tx, genesisSpec, config.OverrideShanghaiTime)
|
||||
chainConfig, genesis, genesisErr = core.WriteGenesisBlock(tx, genesisSpec, config.OverrideShanghaiTime, tmpdir)
|
||||
if _, ok := genesisErr.(*chain.ConfigCompatError); genesisErr != nil && !ok {
|
||||
return genesisErr
|
||||
}
|
||||
@ -325,6 +325,7 @@ func NewBackend(stack *node.Node, config *ethconfig.Config, logger log.Logger) (
|
||||
for _, protocol := range refCfg.ProtocolVersion {
|
||||
cfg := refCfg
|
||||
cfg.NodeDatabase = filepath.Join(stack.Config().Dirs.Nodes, eth.ProtocolToString[protocol])
|
||||
cfg.TmpDir = stack.Config().Dirs.Tmp
|
||||
|
||||
// pick port from allowed list
|
||||
var picked bool
|
||||
|
@ -281,7 +281,7 @@ func Main(ctx *cli.Context) error {
|
||||
}
|
||||
return h
|
||||
}
|
||||
db := memdb.New()
|
||||
db := memdb.New("" /* tmpDir */)
|
||||
|
||||
tx, err := db.BeginRw(context.Background())
|
||||
if err != nil {
|
||||
|
@ -146,10 +146,10 @@ func runCmd(ctx *cli.Context) error {
|
||||
} else {
|
||||
debugLogger = logger.NewStructLogger(logconfig)
|
||||
}
|
||||
db := memdb.New()
|
||||
db := memdb.New("")
|
||||
if ctx.String(GenesisFlag.Name) != "" {
|
||||
gen := readGenesis(ctx.String(GenesisFlag.Name))
|
||||
gen.MustCommit(db)
|
||||
gen.MustCommit(db, "")
|
||||
genesisConfig = gen
|
||||
chainConfig = gen.Config
|
||||
} else {
|
||||
|
@ -114,7 +114,7 @@ func aggregateResultsFromStateTests(
|
||||
Tracer: tracer,
|
||||
Debug: ctx.Bool(DebugFlag.Name) || ctx.Bool(MachineFlag.Name),
|
||||
}
|
||||
db := memdb.New()
|
||||
db := memdb.New("")
|
||||
defer db.Close()
|
||||
|
||||
tx, txErr := db.BeginRw(context.Background())
|
||||
|
@ -35,7 +35,7 @@ var cmdResetState = &cobra.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
err := reset2.ResetState(db, ctx, chain)
|
||||
err := reset2.ResetState(db, ctx, chain, "")
|
||||
if err != nil {
|
||||
log.Error(err.Error())
|
||||
return err
|
||||
|
@ -685,7 +685,7 @@ func stageExec(db kv.RwDB, ctx context.Context) error {
|
||||
return reset2.WarmupExec(ctx, db)
|
||||
}
|
||||
if reset {
|
||||
return reset2.ResetExec(ctx, db, chain)
|
||||
return reset2.ResetExec(ctx, db, chain, "")
|
||||
}
|
||||
|
||||
if txtrace {
|
||||
@ -1197,7 +1197,7 @@ func newSync(ctx context.Context, db kv.RwDB, miningConfig *params.MiningConfig)
|
||||
events := shards.NewEvents()
|
||||
|
||||
genesis := core.DefaultGenesisBlockByChainName(chain)
|
||||
chainConfig, genesisBlock, genesisErr := core.CommitGenesisBlock(db, genesis)
|
||||
chainConfig, genesisBlock, genesisErr := core.CommitGenesisBlock(db, genesis, "")
|
||||
if _, ok := genesisErr.(*chain2.ConfigCompatError); genesisErr != nil && !ok {
|
||||
panic(genesisErr)
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ func runLightClientNode(cliCtx *cli.Context) error {
|
||||
var db kv.RwDB
|
||||
if cfg.Chaindata == "" {
|
||||
log.Info("chaindata is in-memory")
|
||||
db = memdb.New()
|
||||
db = memdb.New("" /* tmpDir */)
|
||||
} else {
|
||||
db, err = mdbx.Open(cfg.Chaindata, log.Root(), false)
|
||||
if err != nil {
|
||||
|
@ -87,7 +87,7 @@ func NewServer(flags CommandFlags) (*Server, error) {
|
||||
}
|
||||
|
||||
func makeLocalNode(nodeDBPath string, privateKey *ecdsa.PrivateKey, chain string) (*enode.LocalNode, error) {
|
||||
db, err := enode.OpenDB(nodeDBPath)
|
||||
db, err := enode.OpenDB(nodeDBPath, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -421,7 +421,7 @@ func initialState1() error {
|
||||
return err
|
||||
}
|
||||
|
||||
emptyKv := memdb.New()
|
||||
emptyKv := memdb.New("")
|
||||
if err = stateDatabaseComparison(emptyKv, m.DB, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
|
||||
func TestGetChainConfig(t *testing.T) {
|
||||
db := memdb.NewTestDB(t)
|
||||
config, _, err := core.CommitGenesisBlock(db, core.DefaultGenesisBlock())
|
||||
config, _, err := core.CommitGenesisBlock(db, core.DefaultGenesisBlock(), "")
|
||||
if err != nil {
|
||||
t.Fatalf("setting up genensis block: %v", err)
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ type SentinelConfig struct {
|
||||
HostAddress string
|
||||
HostDNS string
|
||||
NoDiscovery bool
|
||||
TmpDir string
|
||||
}
|
||||
|
||||
func convertToCryptoPrivkey(privkey *ecdsa.PrivateKey) (crypto.PrivKey, error) {
|
||||
|
@ -61,8 +61,9 @@ func (s *Sentinel) createLocalNode(
|
||||
privKey *ecdsa.PrivateKey,
|
||||
ipAddr net.IP,
|
||||
udpPort, tcpPort int,
|
||||
tmpDir string,
|
||||
) (*enode.LocalNode, error) {
|
||||
db, err := enode.OpenDB("")
|
||||
db, err := enode.OpenDB("", tmpDir)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not open node's peer database: %w", err)
|
||||
}
|
||||
@ -125,7 +126,7 @@ func (s *Sentinel) createListener() (*discover.UDPv5, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
localNode, err := s.createLocalNode(discCfg.PrivateKey, ip, port, int(s.cfg.TCPPort))
|
||||
localNode, err := s.createLocalNode(discCfg.PrivateKey, ip, port, int(s.cfg.TCPPort), s.cfg.TmpDir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -73,8 +73,8 @@ func testForkIDSplit(t *testing.T, protocol uint) {
|
||||
gspecNoFork = &core.Genesis{Config: configNoFork}
|
||||
gspecProFork = &core.Genesis{Config: configProFork}
|
||||
|
||||
genesisNoFork = gspecNoFork.MustCommit(dbNoFork)
|
||||
genesisProFork = gspecProFork.MustCommit(dbProFork)
|
||||
genesisNoFork = gspecNoFork.MustCommit(dbNoFork, "")
|
||||
genesisProFork = gspecProFork.MustCommit(dbProFork, "")
|
||||
)
|
||||
|
||||
var s1, s2 *GrpcServer
|
||||
@ -162,7 +162,7 @@ func TestSentryServerImpl_SetStatusInitPanic(t *testing.T) {
|
||||
configNoFork := &chain.Config{HomesteadBlock: big.NewInt(1), ChainID: big.NewInt(1)}
|
||||
dbNoFork := memdb.NewTestDB(t)
|
||||
gspecNoFork := &core.Genesis{Config: configNoFork}
|
||||
genesisNoFork := gspecNoFork.MustCommit(dbNoFork)
|
||||
genesisNoFork := gspecNoFork.MustCommit(dbNoFork, "")
|
||||
ss := &GrpcServer{p2p: &p2p.Config{}}
|
||||
|
||||
_, err := ss.SetStatus(context.Background(), &proto_sentry.StatusData{
|
||||
|
@ -172,7 +172,7 @@ func Erigon2(genesis *core.Genesis, chainConfig *chain2.Config, logger log.Logge
|
||||
w := agg.MakeStateWriter(changesets /* beforeOn */)
|
||||
var rootHash []byte
|
||||
if block == 0 {
|
||||
genBlock, genesisIbs, err4 := genesis.ToBlock()
|
||||
genBlock, genesisIbs, err4 := genesis.ToBlock("")
|
||||
if err4 != nil {
|
||||
return err4
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ func Erigon4(genesis *core.Genesis, chainConfig *chain2.Config, logger log.Logge
|
||||
|
||||
interrupt := false
|
||||
if startTxNum == 0 {
|
||||
genBlock, genesisIbs, err := genesis.ToBlock()
|
||||
genBlock, genesisIbs, err := genesis.ToBlock("")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ func StateRoot(genesis *core.Genesis, logger log.Logger, blockNum uint64, datadi
|
||||
if rwTx, err = db.BeginRw(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
_, genesisIbs, err4 := genesis.ToBlock()
|
||||
_, genesisIbs, err4 := genesis.ToBlock("")
|
||||
if err4 != nil {
|
||||
return err4
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ func (rw *Worker) RunTxTask(txTask *exec22.TxTask) {
|
||||
if txTask.BlockNum == 0 && txTask.TxIndex == -1 {
|
||||
//fmt.Printf("txNum=%d, blockNum=%d, Genesis\n", txTask.TxNum, txTask.BlockNum)
|
||||
// Genesis block
|
||||
_, ibs, err = rw.genesis.ToBlock()
|
||||
_, ibs, err = rw.genesis.ToBlock("")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -297,7 +297,7 @@ func (rw *ReconWorker) runTxTask(txTask *exec22.TxTask) {
|
||||
if txTask.BlockNum == 0 && txTask.TxIndex == -1 {
|
||||
//fmt.Printf("txNum=%d, blockNum=%d, Genesis\n", txTask.TxNum, txTask.BlockNum)
|
||||
// Genesis block
|
||||
_, ibs, err = rw.genesis.ToBlock()
|
||||
_, ibs, err = rw.genesis.ToBlock("")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -908,6 +908,7 @@ func NewP2PConfig(
|
||||
Log: log.New(),
|
||||
NodeDatabase: enodeDBPath,
|
||||
AllowedPorts: allowedPorts,
|
||||
TmpDir: dirs.Tmp,
|
||||
}
|
||||
if netRestrict != "" {
|
||||
cfg.NetRestrict = new(netutil.Netlist)
|
||||
|
@ -203,7 +203,7 @@ func TestEmptyBlock(t *testing.T) {
|
||||
|
||||
require := require.New(t)
|
||||
genesis := core.DefaultGnosisGenesisBlock()
|
||||
genesisBlock, _, err := genesis.ToBlock()
|
||||
genesisBlock, _, err := genesis.ToBlock("")
|
||||
require.NoError(err)
|
||||
|
||||
genesis.Config.TerminalTotalDifficultyPassed = false
|
||||
|
@ -93,12 +93,7 @@ type AuthorityRoundSeal struct {
|
||||
}
|
||||
|
||||
var genesisTmpDB kv.RwDB
|
||||
var genesisDBLock *sync.Mutex
|
||||
|
||||
func init() {
|
||||
genesisTmpDB = mdbx.NewMDBX(log.New()).InMem("").MapSize(2 * datasize.GB).PageSize(2 * 4096).MustOpen()
|
||||
genesisDBLock = &sync.Mutex{}
|
||||
}
|
||||
var genesisDBLock sync.Mutex
|
||||
|
||||
func (ga *GenesisAlloc) UnmarshalJSON(data []byte) error {
|
||||
m := make(map[common.UnprefixedAddress]GenesisAccount)
|
||||
@ -192,17 +187,17 @@ func (e *GenesisMismatchError) Error() string {
|
||||
// error is a *params.ConfigCompatError and the new, unwritten config is returned.
|
||||
//
|
||||
// The returned chain configuration is never nil.
|
||||
func CommitGenesisBlock(db kv.RwDB, genesis *Genesis) (*chain.Config, *types.Block, error) {
|
||||
return CommitGenesisBlockWithOverride(db, genesis, nil)
|
||||
func CommitGenesisBlock(db kv.RwDB, genesis *Genesis, tmpDir string) (*chain.Config, *types.Block, error) {
|
||||
return CommitGenesisBlockWithOverride(db, genesis, nil, tmpDir)
|
||||
}
|
||||
|
||||
func CommitGenesisBlockWithOverride(db kv.RwDB, genesis *Genesis, overrideShanghaiTime *big.Int) (*chain.Config, *types.Block, error) {
|
||||
func CommitGenesisBlockWithOverride(db kv.RwDB, genesis *Genesis, overrideShanghaiTime *big.Int, tmpDir string) (*chain.Config, *types.Block, error) {
|
||||
tx, err := db.BeginRw(context.Background())
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
c, b, err := WriteGenesisBlock(tx, genesis, overrideShanghaiTime)
|
||||
c, b, err := WriteGenesisBlock(tx, genesis, overrideShanghaiTime, tmpDir)
|
||||
if err != nil {
|
||||
return c, b, err
|
||||
}
|
||||
@ -213,15 +208,15 @@ func CommitGenesisBlockWithOverride(db kv.RwDB, genesis *Genesis, overrideShangh
|
||||
return c, b, nil
|
||||
}
|
||||
|
||||
func MustCommitGenesisBlock(db kv.RwDB, genesis *Genesis) (*chain.Config, *types.Block) {
|
||||
c, b, err := CommitGenesisBlock(db, genesis)
|
||||
func MustCommitGenesisBlock(db kv.RwDB, genesis *Genesis, tmpDir string) (*chain.Config, *types.Block) {
|
||||
c, b, err := CommitGenesisBlock(db, genesis, tmpDir)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return c, b
|
||||
}
|
||||
|
||||
func WriteGenesisBlock(db kv.RwTx, genesis *Genesis, overrideShanghaiTime *big.Int) (*chain.Config, *types.Block, error) {
|
||||
func WriteGenesisBlock(db kv.RwTx, genesis *Genesis, overrideShanghaiTime *big.Int, tmpDir string) (*chain.Config, *types.Block, error) {
|
||||
if genesis != nil && genesis.Config == nil {
|
||||
return params.AllProtocolChanges, nil, ErrGenesisNoConfig
|
||||
}
|
||||
@ -245,7 +240,7 @@ func WriteGenesisBlock(db kv.RwTx, genesis *Genesis, overrideShanghaiTime *big.I
|
||||
custom = false
|
||||
}
|
||||
applyOverrides(genesis.Config)
|
||||
block, _, err1 := genesis.Write(db)
|
||||
block, _, err1 := genesis.Write(db, tmpDir)
|
||||
if err1 != nil {
|
||||
return genesis.Config, nil, err1
|
||||
}
|
||||
@ -257,7 +252,7 @@ func WriteGenesisBlock(db kv.RwTx, genesis *Genesis, overrideShanghaiTime *big.I
|
||||
|
||||
// Check whether the genesis block is already written.
|
||||
if genesis != nil {
|
||||
block, _, err1 := genesis.ToBlock()
|
||||
block, _, err1 := genesis.ToBlock(tmpDir)
|
||||
if err1 != nil {
|
||||
return genesis.Config, nil, err1
|
||||
}
|
||||
@ -336,7 +331,7 @@ func sortedAllocKeys(m GenesisAlloc) []string {
|
||||
|
||||
// ToBlock creates the genesis block and writes state of a genesis specification
|
||||
// to the given database (or discards it if nil).
|
||||
func (g *Genesis) ToBlock() (*types.Block, *state.IntraBlockState, error) {
|
||||
func (g *Genesis) ToBlock(tmpDir string) (*types.Block, *state.IntraBlockState, error) {
|
||||
_ = g.Alloc //nil-check
|
||||
|
||||
head := &types.Header{
|
||||
@ -377,14 +372,18 @@ func (g *Genesis) ToBlock() (*types.Block, *state.IntraBlockState, error) {
|
||||
var statedb *state.IntraBlockState
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(1)
|
||||
var err error
|
||||
go func() { // we may run inside write tx, can't open 2nd write tx in same goroutine
|
||||
// TODO(yperbasis): use memdb.MemoryMutation instead
|
||||
defer wg.Done()
|
||||
genesisDBLock.Lock()
|
||||
defer genesisDBLock.Unlock()
|
||||
tx, err := genesisTmpDB.BeginRw(context.Background())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
if genesisTmpDB == nil {
|
||||
genesisTmpDB = mdbx.NewMDBX(log.New()).InMem(tmpDir).MapSize(2 * datasize.GB).PageSize(2 * 4096).MustOpen()
|
||||
}
|
||||
var tx kv.RwTx
|
||||
if tx, err = genesisTmpDB.BeginRw(context.Background()); err != nil {
|
||||
return
|
||||
}
|
||||
defer tx.Rollback()
|
||||
r, w := state.NewDbStateReader(tx), state.NewDbStateWriter(tx, 0)
|
||||
@ -421,9 +420,8 @@ func (g *Genesis) ToBlock() (*types.Block, *state.IntraBlockState, error) {
|
||||
}
|
||||
|
||||
if len(account.Constructor) > 0 {
|
||||
_, err := SysCreate(addr, account.Constructor, *g.Config, statedb, head)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
if _, err = SysCreate(addr, account.Constructor, *g.Config, statedb, head); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@ -431,23 +429,25 @@ func (g *Genesis) ToBlock() (*types.Block, *state.IntraBlockState, error) {
|
||||
statedb.SetIncarnation(addr, state.FirstContractIncarnation)
|
||||
}
|
||||
}
|
||||
if err := statedb.FinalizeTx(&chain.Rules{}, w); err != nil {
|
||||
panic(err)
|
||||
if err = statedb.FinalizeTx(&chain.Rules{}, w); err != nil {
|
||||
return
|
||||
}
|
||||
root, err = trie.CalcRoot("genesis", tx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
if root, err = trie.CalcRoot("genesis", tx); err != nil {
|
||||
return
|
||||
}
|
||||
}()
|
||||
wg.Wait()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
head.Root = root
|
||||
|
||||
return types.NewBlock(head, nil, nil, nil, withdrawals), statedb, nil
|
||||
}
|
||||
|
||||
func (g *Genesis) WriteGenesisState(tx kv.RwTx) (*types.Block, *state.IntraBlockState, error) {
|
||||
block, statedb, err := g.ToBlock()
|
||||
func (g *Genesis) WriteGenesisState(tx kv.RwTx, tmpDir string) (*types.Block, *state.IntraBlockState, error) {
|
||||
block, statedb, err := g.ToBlock(tmpDir)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@ -480,8 +480,8 @@ func (g *Genesis) WriteGenesisState(tx kv.RwTx) (*types.Block, *state.IntraBlock
|
||||
return block, statedb, nil
|
||||
}
|
||||
|
||||
func (g *Genesis) MustWrite(tx kv.RwTx, history bool) (*types.Block, *state.IntraBlockState) {
|
||||
b, s, err := g.Write(tx)
|
||||
func (g *Genesis) MustWrite(tx kv.RwTx, tmpDir string, history bool) (*types.Block, *state.IntraBlockState) {
|
||||
b, s, err := g.Write(tx, tmpDir)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -490,8 +490,8 @@ func (g *Genesis) MustWrite(tx kv.RwTx, history bool) (*types.Block, *state.Intr
|
||||
|
||||
// Write writes the block and state of a genesis specification to the database.
|
||||
// The block is committed as the canonical head block.
|
||||
func (g *Genesis) Write(tx kv.RwTx) (*types.Block, *state.IntraBlockState, error) {
|
||||
block, statedb, err2 := g.WriteGenesisState(tx)
|
||||
func (g *Genesis) Write(tx kv.RwTx, tmpDir string) (*types.Block, *state.IntraBlockState, error) {
|
||||
block, statedb, err2 := g.WriteGenesisState(tx, tmpDir)
|
||||
if err2 != nil {
|
||||
return block, statedb, err2
|
||||
}
|
||||
@ -553,13 +553,13 @@ func (g *Genesis) Write(tx kv.RwTx) (*types.Block, *state.IntraBlockState, error
|
||||
|
||||
// MustCommit writes the genesis block and state to db, panicking on error.
|
||||
// The block is committed as the canonical head block.
|
||||
func (g *Genesis) MustCommit(db kv.RwDB) *types.Block {
|
||||
func (g *Genesis) MustCommit(db kv.RwDB, tmpDir string) *types.Block {
|
||||
tx, err := db.BeginRw(context.Background())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer tx.Rollback()
|
||||
block, _ := g.MustWrite(tx, true)
|
||||
block, _ := g.MustWrite(tx, tmpDir, true)
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -568,9 +568,9 @@ func (g *Genesis) MustCommit(db kv.RwDB) *types.Block {
|
||||
}
|
||||
|
||||
// GenesisBlockForTesting creates and writes a block in which addr has the given wei balance.
|
||||
func GenesisBlockForTesting(db kv.RwDB, addr libcommon.Address, balance *big.Int) *types.Block {
|
||||
func GenesisBlockForTesting(db kv.RwDB, addr libcommon.Address, balance *big.Int, tmpDir string) *types.Block {
|
||||
g := Genesis{Alloc: GenesisAlloc{addr: {Balance: balance}}, Config: params.TestChainConfig}
|
||||
block := g.MustCommit(db)
|
||||
block := g.MustCommit(db, tmpDir)
|
||||
return block
|
||||
}
|
||||
|
||||
@ -579,14 +579,14 @@ type GenAccount struct {
|
||||
Balance *big.Int
|
||||
}
|
||||
|
||||
func GenesisWithAccounts(db kv.RwDB, accs []GenAccount) *types.Block {
|
||||
func GenesisWithAccounts(db kv.RwDB, accs []GenAccount, tmpDir string) *types.Block {
|
||||
g := Genesis{Config: params.TestChainConfig}
|
||||
allocs := make(map[libcommon.Address]GenesisAccount)
|
||||
for _, acc := range accs {
|
||||
allocs[acc.Addr] = GenesisAccount{Balance: acc.Balance}
|
||||
}
|
||||
g.Alloc = allocs
|
||||
block := g.MustCommit(db)
|
||||
block := g.MustCommit(db, tmpDir)
|
||||
return block
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ func TestDefaultGenesisBlockHashes(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer tx.Rollback()
|
||||
_, block, err := core.WriteGenesisBlock(tx, genesis, nil)
|
||||
_, block, err := core.WriteGenesisBlock(tx, genesis, nil, "")
|
||||
require.NoError(t, err)
|
||||
expect := params.GenesisHashByChainName(network)
|
||||
require.NotNil(t, expect, network)
|
||||
@ -46,12 +46,12 @@ func TestDefaultGenesisBlockRoots(t *testing.T) {
|
||||
require := require.New(t)
|
||||
var err error
|
||||
|
||||
block, _, _ := core.DefaultGenesisBlock().ToBlock()
|
||||
block, _, _ := core.DefaultGenesisBlock().ToBlock("")
|
||||
if block.Hash() != params.MainnetGenesisHash {
|
||||
t.Errorf("wrong mainnet genesis hash, got %v, want %v", block.Hash(), params.MainnetGenesisHash)
|
||||
}
|
||||
|
||||
block, _, err = core.DefaultSokolGenesisBlock().ToBlock()
|
||||
block, _, err = core.DefaultSokolGenesisBlock().ToBlock("")
|
||||
require.NoError(err)
|
||||
if block.Root() != params.SokolGenesisStateRoot {
|
||||
t.Errorf("wrong Sokol genesis state root, got %v, want %v", block.Root(), params.SokolGenesisStateRoot)
|
||||
@ -60,7 +60,7 @@ func TestDefaultGenesisBlockRoots(t *testing.T) {
|
||||
t.Errorf("wrong Sokol genesis hash, got %v, want %v", block.Hash(), params.SokolGenesisHash)
|
||||
}
|
||||
|
||||
block, _, err = core.DefaultGnosisGenesisBlock().ToBlock()
|
||||
block, _, err = core.DefaultGnosisGenesisBlock().ToBlock("")
|
||||
require.NoError(err)
|
||||
if block.Root() != params.GnosisGenesisStateRoot {
|
||||
t.Errorf("wrong Gnosis Chain genesis state root, got %v, want %v", block.Root(), params.GnosisGenesisStateRoot)
|
||||
@ -69,7 +69,7 @@ func TestDefaultGenesisBlockRoots(t *testing.T) {
|
||||
t.Errorf("wrong Gnosis Chain genesis hash, got %v, want %v", block.Hash(), params.GnosisGenesisHash)
|
||||
}
|
||||
|
||||
block, _, err = core.DefaultChiadoGenesisBlock().ToBlock()
|
||||
block, _, err = core.DefaultChiadoGenesisBlock().ToBlock("")
|
||||
require.NoError(err)
|
||||
if block.Root() != params.ChiadoGenesisStateRoot {
|
||||
t.Errorf("wrong Chiado genesis state root, got %v, want %v", block.Root(), params.ChiadoGenesisStateRoot)
|
||||
@ -82,13 +82,13 @@ func TestDefaultGenesisBlockRoots(t *testing.T) {
|
||||
func TestCommitGenesisIdempotency(t *testing.T) {
|
||||
_, tx := memdb.NewTestTx(t)
|
||||
genesis := core.DefaultGenesisBlockByChainName(networkname.MainnetChainName)
|
||||
_, _, err := core.WriteGenesisBlock(tx, genesis, nil)
|
||||
_, _, err := core.WriteGenesisBlock(tx, genesis, nil, "")
|
||||
require.NoError(t, err)
|
||||
seq, err := tx.ReadSequence(kv.EthTx)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, uint64(2), seq)
|
||||
|
||||
_, _, err = core.WriteGenesisBlock(tx, genesis, nil)
|
||||
_, _, err = core.WriteGenesisBlock(tx, genesis, nil, "")
|
||||
require.NoError(t, err)
|
||||
seq, err = tx.ReadSequence(kv.EthTx)
|
||||
require.NoError(t, err)
|
||||
@ -99,7 +99,7 @@ func TestSokolHeaderRLP(t *testing.T) {
|
||||
require := require.New(t)
|
||||
{ //sokol
|
||||
expect := common.FromHex("f9020da00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0fad4af258fd11939fae0c6c6eec9d340b1caac0b0196fd9a1bc3f489c5bf00b3a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830200008083663be080808080b8410000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
|
||||
block, _, err := core.DefaultSokolGenesisBlock().ToBlock()
|
||||
block, _, err := core.DefaultSokolGenesisBlock().ToBlock("")
|
||||
require.NoError(err)
|
||||
b, err := rlp.EncodeToBytes(block.Header())
|
||||
require.NoError(err)
|
||||
@ -162,7 +162,7 @@ func TestAllocConstructor(t *testing.T) {
|
||||
}
|
||||
db := memdb.NewTestDB(t)
|
||||
defer db.Close()
|
||||
_, _, err := core.CommitGenesisBlock(db, genSpec)
|
||||
_, _, err := core.CommitGenesisBlock(db, genSpec, "")
|
||||
require.NoError(err)
|
||||
|
||||
tx, err := db.BeginRo(context.Background())
|
||||
|
@ -26,7 +26,7 @@ import (
|
||||
"github.com/ledgerwatch/erigon/turbo/snapshotsync"
|
||||
)
|
||||
|
||||
func ResetState(db kv.RwDB, ctx context.Context, chain string) error {
|
||||
func ResetState(db kv.RwDB, ctx context.Context, chain string, tmpDir string) error {
|
||||
// don't reset senders here
|
||||
if err := Reset(ctx, db, stages.HashState); err != nil {
|
||||
return err
|
||||
@ -50,7 +50,7 @@ func ResetState(db kv.RwDB, ctx context.Context, chain string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := ResetExec(ctx, db, chain); err != nil {
|
||||
if err := ResetExec(ctx, db, chain, tmpDir); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@ -137,7 +137,7 @@ func WarmupExec(ctx context.Context, db kv.RwDB) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func ResetExec(ctx context.Context, db kv.RwDB, chain string) (err error) {
|
||||
func ResetExec(ctx context.Context, db kv.RwDB, chain string, tmpDir string) (err error) {
|
||||
historyV3 := kvcfg.HistoryV3.FromDB(db)
|
||||
if historyV3 {
|
||||
stateHistoryBuckets = append(stateHistoryBuckets, stateHistoryV3Buckets...)
|
||||
@ -162,7 +162,7 @@ func ResetExec(ctx context.Context, db kv.RwDB, chain string) (err error) {
|
||||
}
|
||||
if !historyV3 {
|
||||
genesis := core.DefaultGenesisBlockByChainName(chain)
|
||||
if _, _, err := genesis.WriteGenesisState(tx); err != nil {
|
||||
if _, _, err := genesis.WriteGenesisState(tx, tmpDir); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -34,8 +34,8 @@ import (
|
||||
"github.com/ledgerwatch/erigon/rlp"
|
||||
)
|
||||
|
||||
func getBlock(transactions int, uncles int, dataSize int) *types.Block {
|
||||
db := memdb.New()
|
||||
func getBlock(transactions int, uncles int, dataSize int, tmpDir string) *types.Block {
|
||||
db := memdb.New(tmpDir)
|
||||
defer db.Close()
|
||||
var (
|
||||
aa = libcommon.HexToAddress("0x000000000000000000000000000000000000aaaa")
|
||||
@ -49,7 +49,7 @@ func getBlock(transactions int, uncles int, dataSize int) *types.Block {
|
||||
Config: params.TestChainConfig,
|
||||
Alloc: GenesisAlloc{address: {Balance: funds}},
|
||||
}
|
||||
genesis = gspec.MustCommit(db)
|
||||
genesis = gspec.MustCommit(db, tmpDir)
|
||||
)
|
||||
|
||||
// We need to generate as many blocks +1 as uncles
|
||||
@ -91,7 +91,7 @@ func TestRlpIterator(t *testing.T) {
|
||||
|
||||
func testRlpIterator(t *testing.T, txs, uncles, datasize int) {
|
||||
desc := fmt.Sprintf("%d txs [%d datasize] and %d uncles", txs, datasize, uncles)
|
||||
bodyRlp, _ := rlp.EncodeToBytes(getBlock(txs, uncles, datasize).Body())
|
||||
bodyRlp, _ := rlp.EncodeToBytes(getBlock(txs, uncles, datasize, "").Body())
|
||||
it, err := rlp.NewListIterator(bodyRlp)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -150,7 +150,7 @@ func BenchmarkHashing(b *testing.B) {
|
||||
blockRlp []byte
|
||||
)
|
||||
{
|
||||
block := getBlock(200, 2, 50)
|
||||
block := getBlock(200, 2, 50, "")
|
||||
bodyRlp, _ = rlp.EncodeToBytes(block.Body())
|
||||
blockRlp, _ = rlp.EncodeToBytes(block)
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ func (s *StateSuite) TestDump(c *checker.C) {
|
||||
}
|
||||
|
||||
func (s *StateSuite) SetUpTest(c *checker.C) {
|
||||
s.kv = memdb.New()
|
||||
s.kv = memdb.New("")
|
||||
tx, err := s.kv.BeginRw(context.Background()) //nolint
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
@ -119,7 +119,7 @@ func Execute(code, input []byte, cfg *Config, blockNr uint64) ([]byte, *state.In
|
||||
setDefaults(cfg)
|
||||
|
||||
if cfg.State == nil {
|
||||
db := olddb.NewObjectDatabase(memdb.New())
|
||||
db := olddb.NewObjectDatabase(memdb.New(""))
|
||||
defer db.Close()
|
||||
cfg.r = state.NewDbStateReader(db)
|
||||
cfg.w = state.NewDbStateWriter(db, 0)
|
||||
@ -158,7 +158,7 @@ func Create(input []byte, cfg *Config, blockNr uint64) ([]byte, libcommon.Addres
|
||||
setDefaults(cfg)
|
||||
|
||||
if cfg.State == nil {
|
||||
db := olddb.NewObjectDatabase(memdb.New())
|
||||
db := olddb.NewObjectDatabase(memdb.New(""))
|
||||
defer db.Close()
|
||||
cfg.r = state.NewDbStateReader(db)
|
||||
cfg.w = state.NewDbStateWriter(db, 0)
|
||||
|
@ -224,7 +224,7 @@ func New(stack *node.Node, config *ethconfig.Config, logger log.Logger) (*Ethere
|
||||
genesisSpec = nil
|
||||
}
|
||||
var genesisErr error
|
||||
chainConfig, genesis, genesisErr = core.WriteGenesisBlock(tx, genesisSpec, config.OverrideShanghaiTime)
|
||||
chainConfig, genesis, genesisErr = core.WriteGenesisBlock(tx, genesisSpec, config.OverrideShanghaiTime, tmpdir)
|
||||
if _, ok := genesisErr.(*chain.ConfigCompatError); genesisErr != nil && !ok {
|
||||
return genesisErr
|
||||
}
|
||||
@ -573,12 +573,13 @@ func New(stack *node.Node, config *ethconfig.Config, logger log.Logger) (*Ethere
|
||||
GenesisConfig: genesisCfg,
|
||||
NetworkConfig: networkCfg,
|
||||
BeaconConfig: beaconCfg,
|
||||
TmpDir: tmpdir,
|
||||
}, chainKv, &service.ServerConfig{Network: "tcp", Addr: fmt.Sprintf("%s:%d", config.SentinelAddr, config.SentinelPort)}, creds, nil, handshake.LightClientRule)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
lc, err := lightclient.NewLightClient(ctx, memdb.New(), genesisCfg, beaconCfg, ethBackendRPC, nil, client, currentBlockNumber, false)
|
||||
lc, err := lightclient.NewLightClient(ctx, memdb.New(tmpdir), genesisCfg, beaconCfg, ethBackendRPC, nil, client, currentBlockNumber, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module github.com/ledgerwatch/erigon
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/ledgerwatch/erigon-lib v0.0.0-20230210064100-682cdfca7799
|
||||
github.com/ledgerwatch/erigon-lib v0.0.0-20230211200854-aa2b5617412b
|
||||
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230211023518-6233ff68c4ca
|
||||
github.com/ledgerwatch/log/v3 v3.7.0
|
||||
github.com/ledgerwatch/secp256k1 v1.0.0
|
||||
|
4
go.sum
4
go.sum
@ -556,8 +556,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758 h1:0D5M2HQSGD3PYPwICLl+/9oulQauOuETfgFvhBDffs0=
|
||||
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
|
||||
github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8=
|
||||
github.com/ledgerwatch/erigon-lib v0.0.0-20230210064100-682cdfca7799 h1:vfTDc788s26oW/U8ui6/Jb5Jj2AnTwPa1FxcwKZmDGg=
|
||||
github.com/ledgerwatch/erigon-lib v0.0.0-20230210064100-682cdfca7799/go.mod h1:OXgMDuUo2lZ3NpH29ZvMYbk+LxFd5ffDl2Z2mGMuY/I=
|
||||
github.com/ledgerwatch/erigon-lib v0.0.0-20230211200854-aa2b5617412b h1:EG1UQaC1Kxo7gHI2B2SFQ+FkHXNfgZAJnn1/HjJkn3A=
|
||||
github.com/ledgerwatch/erigon-lib v0.0.0-20230211200854-aa2b5617412b/go.mod h1:OXgMDuUo2lZ3NpH29ZvMYbk+LxFd5ffDl2Z2mGMuY/I=
|
||||
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230211023518-6233ff68c4ca h1:fCwX4mJf2/fEQZ9GU/QTIxa6WQd39MbwlC6aKkL4Ip8=
|
||||
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230211023518-6233ff68c4ca/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo=
|
||||
github.com/ledgerwatch/log/v3 v3.7.0 h1:aFPEZdwZx4jzA3+/Pf8wNDN5tCI0cIolq/kfvgcM+og=
|
||||
|
@ -312,7 +312,7 @@ func OpenDatabase(config *nodecfg.Config, logger log.Logger, label kv.Label) (kv
|
||||
}
|
||||
var db kv.RwDB
|
||||
if config.Dirs.DataDir == "" {
|
||||
db = memdb.New()
|
||||
db = memdb.New("")
|
||||
return db, nil
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,8 @@ func TestTable_pingReplace(t *testing.T) {
|
||||
|
||||
func testPingReplace(t *testing.T, newNodeIsResponding, lastInBucketIsResponding bool) {
|
||||
transport := newPingRecorder()
|
||||
tab, db := newTestTable(transport)
|
||||
tmpDir := t.TempDir()
|
||||
tab, db := newTestTable(transport, tmpDir)
|
||||
defer db.Close()
|
||||
defer tab.close()
|
||||
|
||||
@ -116,7 +117,8 @@ func testTableBumpNoDuplicatesRun(t *testing.T, bucketCountGen byte, bumpCountGe
|
||||
bumps := generateRandomBumpPositions(bumpCountGen, len(nodes), randGen)
|
||||
|
||||
if len(bumps) > 0 {
|
||||
tab, db := newTestTable(newPingRecorder())
|
||||
tmpDir := t.TempDir()
|
||||
tab, db := newTestTable(newPingRecorder(), tmpDir)
|
||||
defer db.Close()
|
||||
defer tab.close()
|
||||
|
||||
@ -167,7 +169,8 @@ func TestTable_bumpNoDuplicates_examples(t *testing.T) {
|
||||
// This checks that the table-wide IP limit is applied correctly.
|
||||
func TestTable_IPLimit(t *testing.T) {
|
||||
transport := newPingRecorder()
|
||||
tab, db := newTestTable(transport)
|
||||
tmpDir := t.TempDir()
|
||||
tab, db := newTestTable(transport, tmpDir)
|
||||
defer db.Close()
|
||||
defer tab.close()
|
||||
|
||||
@ -184,7 +187,8 @@ func TestTable_IPLimit(t *testing.T) {
|
||||
// This checks that the per-bucket IP limit is applied correctly.
|
||||
func TestTable_BucketIPLimit(t *testing.T) {
|
||||
transport := newPingRecorder()
|
||||
tab, db := newTestTable(transport)
|
||||
tmpDir := t.TempDir()
|
||||
tab, db := newTestTable(transport, tmpDir)
|
||||
defer db.Close()
|
||||
defer tab.close()
|
||||
|
||||
@ -219,7 +223,8 @@ func testTableFindNodeByIDRun(t *testing.T, nodesCountGen uint16, resultsCountGe
|
||||
if !t.Skipped() {
|
||||
// for any node table, Target and N
|
||||
transport := newPingRecorder()
|
||||
tab, db := newTestTable(transport)
|
||||
tmpDir := t.TempDir()
|
||||
tab, db := newTestTable(transport, tmpDir)
|
||||
defer db.Close()
|
||||
defer tab.close()
|
||||
|
||||
@ -322,7 +327,8 @@ func testTableReadRandomNodesGetAllRun(t *testing.T, nodesCountGen uint16, rand
|
||||
if nodesCount > 0 {
|
||||
buf := make([]*enode.Node, nodesCount)
|
||||
transport := newPingRecorder()
|
||||
tab, db := newTestTable(transport)
|
||||
tmpDir := t.TempDir()
|
||||
tab, db := newTestTable(transport, tmpDir)
|
||||
defer db.Close()
|
||||
defer tab.close()
|
||||
<-tab.initDone
|
||||
@ -385,7 +391,8 @@ func generateNode(rand *rand.Rand) *node {
|
||||
}
|
||||
|
||||
func TestTable_addVerifiedNode(t *testing.T) {
|
||||
tab, db := newTestTable(newPingRecorder())
|
||||
tmpDir := t.TempDir()
|
||||
tab, db := newTestTable(newPingRecorder(), tmpDir)
|
||||
<-tab.initDone
|
||||
defer db.Close()
|
||||
defer tab.close()
|
||||
@ -417,7 +424,8 @@ func TestTable_addVerifiedNode(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTable_addSeenNode(t *testing.T) {
|
||||
tab, db := newTestTable(newPingRecorder())
|
||||
tmpDir := t.TempDir()
|
||||
tab, db := newTestTable(newPingRecorder(), tmpDir)
|
||||
<-tab.initDone
|
||||
defer db.Close()
|
||||
defer tab.close()
|
||||
@ -451,7 +459,8 @@ func TestTable_addSeenNode(t *testing.T) {
|
||||
// announces a new sequence number, the new record should be pulled.
|
||||
func TestTable_revalidateSyncRecord(t *testing.T) {
|
||||
transport := newPingRecorder()
|
||||
tab, db := newTestTable(transport)
|
||||
tmpDir := t.TempDir()
|
||||
tab, db := newTestTable(transport, tmpDir)
|
||||
<-tab.initDone
|
||||
defer db.Close()
|
||||
defer tab.close()
|
||||
|
@ -42,8 +42,8 @@ func init() {
|
||||
nullNode = enode.SignNull(&r, enode.ID{})
|
||||
}
|
||||
|
||||
func newTestTable(t transport) (*Table, *enode.DB) {
|
||||
db, err := enode.OpenDB("")
|
||||
func newTestTable(t transport, tmpDir string) (*Table, *enode.DB) {
|
||||
db, err := enode.OpenDB("", tmpDir)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -79,9 +79,10 @@ func newUDPTestContext(ctx context.Context, t *testing.T) *udpTest {
|
||||
remotekey: newkey(),
|
||||
remoteaddr: &net.UDPAddr{IP: net.IP{10, 0, 1, 99}, Port: 30303},
|
||||
}
|
||||
tmpDir := t.TempDir()
|
||||
|
||||
var err error
|
||||
test.db, err = enode.OpenDB("")
|
||||
test.db, err = enode.OpenDB("", tmpDir)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -607,7 +608,8 @@ func startLocalhostV4(ctx context.Context, t *testing.T, cfg Config) *UDPv4 {
|
||||
t.Helper()
|
||||
|
||||
cfg.PrivateKey = newkey()
|
||||
db, err := enode.OpenDB("")
|
||||
tmpDir := t.TempDir()
|
||||
db, err := enode.OpenDB("", tmpDir)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -40,7 +40,8 @@ import (
|
||||
|
||||
func startLocalhostV5(t *testing.T, cfg Config) *UDPv5 {
|
||||
cfg.PrivateKey = newkey()
|
||||
db, err := enode.OpenDB("")
|
||||
tmpDir := t.TempDir()
|
||||
db, err := enode.OpenDB("", tmpDir)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -602,7 +603,8 @@ func newUDPV5TestContext(ctx context.Context, t *testing.T) *udpV5Test {
|
||||
}
|
||||
t.Cleanup(test.close)
|
||||
var err error
|
||||
test.db, err = enode.OpenDB("")
|
||||
tmpDir := t.TempDir()
|
||||
test.db, err = enode.OpenDB("", tmpDir)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -655,7 +657,8 @@ func (test *udpV5Test) getNode(key *ecdsa.PrivateKey, addr *net.UDPAddr) *enode.
|
||||
id := enode.PubkeyToIDV4(&key.PublicKey)
|
||||
ln := test.nodesByID[id]
|
||||
if ln == nil {
|
||||
db, err := enode.OpenDB("")
|
||||
tmpDir := test.t.TempDir()
|
||||
db, err := enode.OpenDB("", tmpDir)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ func TestVector_KDF(t *testing.T) {
|
||||
var (
|
||||
ephKey = hexPrivkey("0xfb757dc581730490a1d7a00deea65e9b1936924caaea8f44d476014856b68736")
|
||||
cdata = hexutil.MustDecode("0x000000000000000000000000000000006469736376350001010102030405060708090a0b0c00180102030405060708090a0b0c0d0e0f100000000000000000")
|
||||
net = newHandshakeTest()
|
||||
net = newHandshakeTest(t.TempDir())
|
||||
)
|
||||
defer net.close()
|
||||
|
||||
|
@ -69,7 +69,8 @@ func TestMinSizes(t *testing.T) {
|
||||
// This test checks the basic handshake flow where A talks to B and A has no secrets.
|
||||
func TestHandshake(t *testing.T) {
|
||||
t.Parallel()
|
||||
net := newHandshakeTest()
|
||||
tmpDir := t.TempDir()
|
||||
net := newHandshakeTest(tmpDir)
|
||||
defer net.close()
|
||||
|
||||
// A -> B RANDOM PACKET
|
||||
@ -100,7 +101,8 @@ func TestHandshake(t *testing.T) {
|
||||
// This test checks that handshake attempts are removed within the timeout.
|
||||
func TestHandshake_timeout(t *testing.T) {
|
||||
t.Parallel()
|
||||
net := newHandshakeTest()
|
||||
tmpDir := t.TempDir()
|
||||
net := newHandshakeTest(tmpDir)
|
||||
defer net.close()
|
||||
|
||||
// A -> B RANDOM PACKET
|
||||
@ -125,7 +127,8 @@ func TestHandshake_timeout(t *testing.T) {
|
||||
// This test checks handshake behavior when no record is sent in the auth response.
|
||||
func TestHandshake_norecord(t *testing.T) {
|
||||
t.Parallel()
|
||||
net := newHandshakeTest()
|
||||
tmpDir := t.TempDir()
|
||||
net := newHandshakeTest(tmpDir)
|
||||
defer net.close()
|
||||
|
||||
// A -> B RANDOM PACKET
|
||||
@ -165,7 +168,8 @@ func TestHandshake_rekey(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Parallel()
|
||||
net := newHandshakeTest()
|
||||
tmpDir := t.TempDir()
|
||||
net := newHandshakeTest(tmpDir)
|
||||
defer net.close()
|
||||
|
||||
session := &session{
|
||||
@ -204,7 +208,8 @@ func TestHandshake_rekey(t *testing.T) {
|
||||
// In this test A and B have different keys before the handshake.
|
||||
func TestHandshake_rekey2(t *testing.T) {
|
||||
t.Parallel()
|
||||
net := newHandshakeTest()
|
||||
tmpDir := t.TempDir()
|
||||
net := newHandshakeTest(tmpDir)
|
||||
defer net.close()
|
||||
|
||||
initKeysA := &session{
|
||||
@ -238,7 +243,8 @@ func TestHandshake_rekey2(t *testing.T) {
|
||||
|
||||
func TestHandshake_BadHandshakeAttack(t *testing.T) {
|
||||
t.Parallel()
|
||||
net := newHandshakeTest()
|
||||
tmpDir := t.TempDir()
|
||||
net := newHandshakeTest(tmpDir)
|
||||
defer net.close()
|
||||
|
||||
// A -> B RANDOM PACKET
|
||||
@ -278,7 +284,8 @@ func TestHandshake_BadHandshakeAttack(t *testing.T) {
|
||||
// This test checks some malformed packets.
|
||||
func TestDecodeErrorsV5(t *testing.T) {
|
||||
t.Parallel()
|
||||
net := newHandshakeTest()
|
||||
tmpDir := t.TempDir()
|
||||
net := newHandshakeTest(tmpDir)
|
||||
defer net.close()
|
||||
|
||||
net.nodeA.expectDecodeErr(t, errTooShort, []byte{})
|
||||
@ -307,7 +314,8 @@ func TestTestVectorsV5(t *testing.T) {
|
||||
}
|
||||
challenge0A, challenge1A, challenge0B = c, c, c
|
||||
challenge1A.RecordSeq = 1
|
||||
net := newHandshakeTest()
|
||||
tmpDir := t.TempDir()
|
||||
net := newHandshakeTest(tmpDir)
|
||||
challenge0A.Node = net.nodeA.n()
|
||||
challenge0B.Node = net.nodeB.n()
|
||||
challenge1A.Node = net.nodeA.n()
|
||||
@ -366,7 +374,7 @@ func TestTestVectorsV5(t *testing.T) {
|
||||
for _, test := range tests {
|
||||
test := test
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
net := newHandshakeTest()
|
||||
net := newHandshakeTest(tmpDir)
|
||||
defer net.close()
|
||||
|
||||
// Override all random inputs.
|
||||
@ -434,7 +442,8 @@ func testVectorComment(net *handshakeTest, p Packet, challenge *Whoareyou, nonce
|
||||
|
||||
// This benchmark checks performance of handshake packet decoding.
|
||||
func BenchmarkV5_DecodeHandshakePingSecp256k1(b *testing.B) {
|
||||
net := newHandshakeTest()
|
||||
tmpDir := b.TempDir()
|
||||
net := newHandshakeTest(tmpDir)
|
||||
defer net.close()
|
||||
|
||||
var (
|
||||
@ -462,7 +471,8 @@ func BenchmarkV5_DecodeHandshakePingSecp256k1(b *testing.B) {
|
||||
|
||||
// This benchmark checks how long it takes to decode an encrypted ping packet.
|
||||
func BenchmarkV5_DecodePing(b *testing.B) {
|
||||
net := newHandshakeTest()
|
||||
tmpDir := b.TempDir()
|
||||
net := newHandshakeTest(tmpDir)
|
||||
defer net.close()
|
||||
|
||||
session := &session{
|
||||
@ -501,10 +511,10 @@ type handshakeTestNode struct {
|
||||
c *Codec
|
||||
}
|
||||
|
||||
func newHandshakeTest() *handshakeTest {
|
||||
func newHandshakeTest(tmpDir string) *handshakeTest {
|
||||
t := new(handshakeTest)
|
||||
t.nodeA.init(testKeyA, net.IP{127, 0, 0, 1}, &t.clock)
|
||||
t.nodeB.init(testKeyB, net.IP{127, 0, 0, 1}, &t.clock)
|
||||
t.nodeA.init(testKeyA, net.IP{127, 0, 0, 1}, &t.clock, tmpDir)
|
||||
t.nodeB.init(testKeyB, net.IP{127, 0, 0, 1}, &t.clock, tmpDir)
|
||||
return t
|
||||
}
|
||||
|
||||
@ -513,8 +523,8 @@ func (t *handshakeTest) close() {
|
||||
t.nodeB.ln.Database().Close()
|
||||
}
|
||||
|
||||
func (n *handshakeTestNode) init(key *ecdsa.PrivateKey, ip net.IP, clock mclock.Clock) {
|
||||
db, err := enode.OpenDB("")
|
||||
func (n *handshakeTestNode) init(key *ecdsa.PrivateKey, ip net.IP, clock mclock.Clock, tmpDir string) {
|
||||
db, err := enode.OpenDB("", tmpDir)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -26,8 +26,8 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func newLocalNodeForTesting() (*LocalNode, *DB) {
|
||||
db, err := OpenDB("")
|
||||
func newLocalNodeForTesting(tmpDir string) (*LocalNode, *DB) {
|
||||
db, err := OpenDB("", tmpDir)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -36,7 +36,8 @@ func newLocalNodeForTesting() (*LocalNode, *DB) {
|
||||
}
|
||||
|
||||
func TestLocalNode(t *testing.T) {
|
||||
ln, db := newLocalNodeForTesting()
|
||||
tmpDir := t.TempDir()
|
||||
ln, db := newLocalNodeForTesting(tmpDir)
|
||||
defer db.Close()
|
||||
|
||||
if ln.Node().ID() != ln.ID() {
|
||||
@ -53,7 +54,8 @@ func TestLocalNode(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLocalNodeSeqPersist(t *testing.T) {
|
||||
ln, db := newLocalNodeForTesting()
|
||||
tmpDir := t.TempDir()
|
||||
ln, db := newLocalNodeForTesting(tmpDir)
|
||||
defer db.Close()
|
||||
|
||||
if s := ln.Node().Seq(); s != 1 {
|
||||
@ -88,7 +90,8 @@ func TestLocalNodeEndpoint(t *testing.T) {
|
||||
predicted = &net.UDPAddr{IP: net.IP{127, 0, 1, 2}, Port: 81}
|
||||
staticIP = net.IP{127, 0, 1, 2}
|
||||
)
|
||||
ln, db := newLocalNodeForTesting()
|
||||
tmpDir := t.TempDir()
|
||||
ln, db := newLocalNodeForTesting(tmpDir)
|
||||
defer db.Close()
|
||||
|
||||
// Nothing is set initially.
|
||||
|
@ -83,10 +83,10 @@ type DB struct {
|
||||
|
||||
// OpenDB opens a node database for storing and retrieving infos about known peers in the
|
||||
// network. If no path is given an in-memory, temporary database is constructed.
|
||||
func OpenDB(path string) (*DB, error) {
|
||||
func OpenDB(path string, tmpDir string) (*DB, error) {
|
||||
logger := log.New() //TODO: move higher
|
||||
if path == "" {
|
||||
return newMemoryDB(logger)
|
||||
return newMemoryDB(logger, tmpDir)
|
||||
}
|
||||
return newPersistentDB(logger, path)
|
||||
}
|
||||
@ -99,10 +99,10 @@ func bucketsConfig(_ kv.TableCfg) kv.TableCfg {
|
||||
}
|
||||
|
||||
// newMemoryNodeDB creates a new in-memory node database without a persistent backend.
|
||||
func newMemoryDB(logger log.Logger) (*DB, error) {
|
||||
func newMemoryDB(logger log.Logger, tmpDir string) (*DB, error) {
|
||||
db := &DB{quit: make(chan struct{})}
|
||||
var err error
|
||||
db.kv, err = mdbx.NewMDBX(logger).InMem("").Label(kv.SentryDB).WithTableCfg(bucketsConfig).Open()
|
||||
db.kv, err = mdbx.NewMDBX(logger).InMem(tmpDir).Label(kv.SentryDB).WithTableCfg(bucketsConfig).Open()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -87,7 +87,8 @@ var nodeDBInt64Tests = []struct {
|
||||
}
|
||||
|
||||
func TestDBInt64(t *testing.T) {
|
||||
db, err := OpenDB("")
|
||||
tmpDir := t.TempDir()
|
||||
db, err := OpenDB("", tmpDir)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -119,10 +120,11 @@ func TestDBFetchStore(t *testing.T) {
|
||||
30303,
|
||||
30303,
|
||||
)
|
||||
tmpDir := t.TempDir()
|
||||
inst := time.Now()
|
||||
num := 314
|
||||
|
||||
db, err := OpenDB("")
|
||||
db, err := OpenDB("", tmpDir)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -253,8 +255,9 @@ func TestDBSeedQuery(t *testing.T) {
|
||||
// times to avoid flakes.
|
||||
const attempts = 15
|
||||
var err error
|
||||
tmpDir := t.TempDir()
|
||||
for i := 0; i < attempts; i++ {
|
||||
if err = testSeedQuery(); err == nil {
|
||||
if err = testSeedQuery(tmpDir); err == nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -263,8 +266,8 @@ func TestDBSeedQuery(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testSeedQuery() error {
|
||||
db, err := OpenDB("")
|
||||
func testSeedQuery(tmpDir string) error {
|
||||
db, err := OpenDB("", tmpDir)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -314,7 +317,7 @@ func TestDBPersistency(t *testing.T) {
|
||||
)
|
||||
|
||||
// Create a persistent database and store some values
|
||||
db, err := OpenDB(filepath.Join(root, "database"))
|
||||
db, err := OpenDB(filepath.Join(root, "database"), root)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create persistent database: %v", err)
|
||||
}
|
||||
@ -325,7 +328,7 @@ func TestDBPersistency(t *testing.T) {
|
||||
db.Close()
|
||||
|
||||
// ReopenSegments the database and check the value
|
||||
db, err = OpenDB(filepath.Join(root, "database"))
|
||||
db, err = OpenDB(filepath.Join(root, "database"), root)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open persistent database: %v", err)
|
||||
}
|
||||
@ -427,7 +430,8 @@ var nodeDBExpirationNodes = []struct {
|
||||
}
|
||||
|
||||
func TestDBExpiration(t *testing.T) {
|
||||
db, err := OpenDB("")
|
||||
tmpDir := t.TempDir()
|
||||
db, err := OpenDB("", tmpDir)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -473,7 +477,8 @@ func TestDBExpiration(t *testing.T) {
|
||||
// This test checks that expiration works when discovery v5 data is present
|
||||
// in the database.
|
||||
func TestDBExpireV5(t *testing.T) {
|
||||
db, err := OpenDB("")
|
||||
tmpDir := t.TempDir()
|
||||
db, err := OpenDB("", tmpDir)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -169,6 +169,8 @@ type Config struct {
|
||||
|
||||
// it is actually used but a linter got confused
|
||||
clock mclock.Clock //nolint:structcheck
|
||||
|
||||
TmpDir string
|
||||
}
|
||||
|
||||
// Server manages all peer connections.
|
||||
@ -533,7 +535,7 @@ func (srv *Server) setupLocalNode() error {
|
||||
}
|
||||
sort.Sort(capsByNameAndVersion(srv.ourHandshake.Caps))
|
||||
// Create the local node
|
||||
db, err := enode.OpenDB(srv.Config.NodeDatabase)
|
||||
db, err := enode.OpenDB(srv.Config.NodeDatabase, srv.Config.TmpDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -191,7 +191,7 @@ func (t *StateTest) RunNoVerify(tx kv.RwTx, subtest StateSubtest, vmconfig vm.Co
|
||||
return nil, libcommon.Hash{}, UnsupportedForkError{subtest.Fork}
|
||||
}
|
||||
vmconfig.ExtraEips = eips
|
||||
block, _, err := t.genesis(config).ToBlock()
|
||||
block, _, err := t.genesis(config).ToBlock("")
|
||||
if err != nil {
|
||||
return nil, libcommon.Hash{}, UnsupportedForkError{subtest.Fork}
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ func initGenesis(ctx *cli.Context) error {
|
||||
if err != nil {
|
||||
utils.Fatalf("Failed to open database: %v", err)
|
||||
}
|
||||
_, hash, err := core.CommitGenesisBlock(chaindb, genesis)
|
||||
_, hash, err := core.CommitGenesisBlock(chaindb, genesis, "")
|
||||
if err != nil {
|
||||
utils.Fatalf("Failed to write genesis block: %v", err)
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ func TestSetupGenesis(t *testing.T) {
|
||||
},
|
||||
}
|
||||
oldcustomg = customg
|
||||
tmpdir = t.TempDir()
|
||||
)
|
||||
oldcustomg.Config = &chain.Config{ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(2)}
|
||||
tests := []struct {
|
||||
@ -58,7 +59,7 @@ func TestSetupGenesis(t *testing.T) {
|
||||
{
|
||||
name: "genesis without ChainConfig",
|
||||
fn: func(db kv.RwDB) (*chain.Config, *types.Block, error) {
|
||||
return core.CommitGenesisBlock(db, new(core.Genesis))
|
||||
return core.CommitGenesisBlock(db, new(core.Genesis), tmpdir)
|
||||
},
|
||||
wantErr: core.ErrGenesisNoConfig,
|
||||
wantConfig: params.AllProtocolChanges,
|
||||
@ -66,7 +67,7 @@ func TestSetupGenesis(t *testing.T) {
|
||||
{
|
||||
name: "no block in DB, genesis == nil",
|
||||
fn: func(db kv.RwDB) (*chain.Config, *types.Block, error) {
|
||||
return core.CommitGenesisBlock(db, nil)
|
||||
return core.CommitGenesisBlock(db, nil, tmpdir)
|
||||
},
|
||||
wantHash: params.MainnetGenesisHash,
|
||||
wantConfig: params.MainnetChainConfig,
|
||||
@ -74,7 +75,7 @@ func TestSetupGenesis(t *testing.T) {
|
||||
{
|
||||
name: "mainnet block in DB, genesis == nil",
|
||||
fn: func(db kv.RwDB) (*chain.Config, *types.Block, error) {
|
||||
return core.CommitGenesisBlock(db, nil)
|
||||
return core.CommitGenesisBlock(db, nil, tmpdir)
|
||||
},
|
||||
wantHash: params.MainnetGenesisHash,
|
||||
wantConfig: params.MainnetChainConfig,
|
||||
@ -82,8 +83,8 @@ func TestSetupGenesis(t *testing.T) {
|
||||
{
|
||||
name: "custom block in DB, genesis == nil",
|
||||
fn: func(db kv.RwDB) (*chain.Config, *types.Block, error) {
|
||||
customg.MustCommit(db)
|
||||
return core.CommitGenesisBlock(db, nil)
|
||||
customg.MustCommit(db, tmpdir)
|
||||
return core.CommitGenesisBlock(db, nil, tmpdir)
|
||||
},
|
||||
wantHash: customghash,
|
||||
wantConfig: customg.Config,
|
||||
@ -91,8 +92,8 @@ func TestSetupGenesis(t *testing.T) {
|
||||
{
|
||||
name: "custom block in DB, genesis == sepolia",
|
||||
fn: func(db kv.RwDB) (*chain.Config, *types.Block, error) {
|
||||
customg.MustCommit(db)
|
||||
return core.CommitGenesisBlock(db, core.DefaultSepoliaGenesisBlock())
|
||||
customg.MustCommit(db, tmpdir)
|
||||
return core.CommitGenesisBlock(db, core.DefaultSepoliaGenesisBlock(), tmpdir)
|
||||
},
|
||||
wantErr: &core.GenesisMismatchError{Stored: customghash, New: params.SepoliaGenesisHash},
|
||||
wantHash: params.SepoliaGenesisHash,
|
||||
@ -101,8 +102,8 @@ func TestSetupGenesis(t *testing.T) {
|
||||
{
|
||||
name: "compatible config in DB",
|
||||
fn: func(db kv.RwDB) (*chain.Config, *types.Block, error) {
|
||||
oldcustomg.MustCommit(db)
|
||||
return core.CommitGenesisBlock(db, &customg)
|
||||
oldcustomg.MustCommit(db, tmpdir)
|
||||
return core.CommitGenesisBlock(db, &customg, tmpdir)
|
||||
},
|
||||
wantHash: customghash,
|
||||
wantConfig: customg.Config,
|
||||
@ -123,7 +124,7 @@ func TestSetupGenesis(t *testing.T) {
|
||||
return nil, nil, err
|
||||
}
|
||||
// This should return a compatibility error.
|
||||
return core.CommitGenesisBlock(m.DB, &customg)
|
||||
return core.CommitGenesisBlock(m.DB, &customg, tmpdir)
|
||||
},
|
||||
wantHash: customghash,
|
||||
wantConfig: customg.Config,
|
||||
|
@ -28,7 +28,7 @@ func TestInserter1(t *testing.T) {
|
||||
}
|
||||
db := memdb.NewTestDB(t)
|
||||
defer db.Close()
|
||||
_, genesis, err := core.CommitGenesisBlock(db, gspec)
|
||||
_, genesis, err := core.CommitGenesisBlock(db, gspec, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ func MockWithEverything(t *testing.T, gspec *core.Genesis, key *ecdsa.PrivateKey
|
||||
if t != nil {
|
||||
db = memdb.NewTestDB(t)
|
||||
} else {
|
||||
db = memdb.New()
|
||||
db = memdb.New(tmpdir)
|
||||
}
|
||||
ctx, ctxCancel := context.WithCancel(context.Background())
|
||||
_ = db.Update(ctx, func(tx kv.RwTx) error {
|
||||
@ -313,7 +313,7 @@ func MockWithEverything(t *testing.T, gspec *core.Genesis, key *ecdsa.PrivateKey
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mock.txPoolDB = memdb.NewPoolDB()
|
||||
mock.txPoolDB = memdb.NewPoolDB(tmpdir)
|
||||
|
||||
stateChangesClient := direct.NewStateDiffClientDirect(erigonGrpcServeer)
|
||||
|
||||
@ -331,7 +331,7 @@ func MockWithEverything(t *testing.T, gspec *core.Genesis, key *ecdsa.PrivateKey
|
||||
}
|
||||
|
||||
// Committed genesis will be shared between download and mock sentry
|
||||
_, mock.Genesis, err = core.CommitGenesisBlock(mock.DB, gspec)
|
||||
_, mock.Genesis, err = core.CommitGenesisBlock(mock.DB, gspec, "")
|
||||
if _, ok := err.(*chain.ConfigCompatError); err != nil && !ok {
|
||||
if t != nil {
|
||||
t.Fatal(err)
|
||||
|
Loading…
Reference in New Issue
Block a user