Skip to content

Commit

Permalink
Move bucket constants into kv package, move kv interface to kv package (
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored Jul 28, 2021
1 parent 63a6c45 commit 838e5f9
Show file tree
Hide file tree
Showing 232 changed files with 3,275 additions and 3,474 deletions.
15 changes: 8 additions & 7 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"github.com/ledgerwatch/erigon/eth/filters"
"github.com/ledgerwatch/erigon/ethdb"
"github.com/ledgerwatch/erigon/ethdb/kv"
"github.com/ledgerwatch/erigon/ethdb/olddb"
"github.com/ledgerwatch/erigon/event"
"github.com/ledgerwatch/erigon/log"
"github.com/ledgerwatch/erigon/params"
Expand Down Expand Up @@ -95,7 +96,7 @@ func NewSimulatedBackendWithConfig(alloc core.GenesisAlloc, config *params.Chain
m: m,
prependBlock: m.Genesis,
getHeader: func(hash common.Hash, number uint64) (h *types.Header) {
if err := m.DB.View(context.Background(), func(tx ethdb.Tx) error {
if err := m.DB.View(context.Background(), func(tx kv.Tx) error {
h = rawdb.ReadHeader(tx, hash, number)
return nil
}); err != nil {
Expand All @@ -104,7 +105,7 @@ func NewSimulatedBackendWithConfig(alloc core.GenesisAlloc, config *params.Chain
return h
},
}
backend.checkTEVM = ethdb.GetCheckTEVM(kv.NewObjectDatabase(m.DB))
backend.checkTEVM = ethdb.GetCheckTEVM(olddb.NewObjectDatabase(m.DB))
backend.events = filters.NewEventSystem(&filterBackend{m.DB, backend})
backend.emptyPendingBlock()
return backend
Expand All @@ -119,7 +120,7 @@ func NewSimulatedBackend(t *testing.T, alloc core.GenesisAlloc, gasLimit uint64)
return b
}

func (b *SimulatedBackend) DB() ethdb.RwKV {
func (b *SimulatedBackend) DB() kv.RwDB {
return b.m.DB
}

Expand Down Expand Up @@ -166,12 +167,12 @@ func (b *SimulatedBackend) emptyPendingBlock() {
b.pendingReceipts = chain.Receipts[0]
b.pendingHeader = chain.Headers[0]
b.gasPool = new(core.GasPool).AddGas(b.pendingHeader.GasLimit)
b.pendingReader = state.NewPlainStateReader(kv.NewObjectDatabase(b.m.DB))
b.pendingReader = state.NewPlainStateReader(olddb.NewObjectDatabase(b.m.DB))
b.pendingState = state.New(b.pendingReader)
}

// stateByBlockNumber retrieves a state by a given blocknumber.
func (b *SimulatedBackend) stateByBlockNumber(db ethdb.Tx, blockNumber *big.Int) *state.IntraBlockState {
func (b *SimulatedBackend) stateByBlockNumber(db kv.Tx, blockNumber *big.Int) *state.IntraBlockState {
if blockNumber == nil || blockNumber.Cmp(b.pendingBlock.Number()) == 0 {
return state.New(state.NewPlainState(db, b.pendingBlock.NumberU64()))
}
Expand Down Expand Up @@ -490,7 +491,7 @@ func (b *SimulatedBackend) CallContract(ctx context.Context, call ethereum.CallM
return nil, errBlockNumberUnsupported
}
var res *core.ExecutionResult
if err := b.m.DB.View(context.Background(), func(tx ethdb.Tx) (err error) {
if err := b.m.DB.View(context.Background(), func(tx kv.Tx) (err error) {
s := state.New(state.NewPlainStateReader(tx))
res, err = b.callContract(ctx, call, b.pendingBlock, s)
if err != nil {
Expand Down Expand Up @@ -846,7 +847,7 @@ func (m callMsg) AccessList() types.AccessList { return m.CallMsg.AccessList }
// filterBackend implements filters.Backend to support filtering for logs without
// taking bloom-bits acceleration structures into account.
type filterBackend struct {
db ethdb.RwKV
db kv.RwDB
b *SimulatedBackend
}

Expand Down
4 changes: 2 additions & 2 deletions accounts/abi/bind/backends/simulated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
"github.com/ledgerwatch/erigon/core/state"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/crypto"
"github.com/ledgerwatch/erigon/ethdb"
"github.com/ledgerwatch/erigon/ethdb/kv"
"github.com/ledgerwatch/erigon/params"
)

Expand Down Expand Up @@ -140,7 +140,7 @@ func TestNewSimulatedBackend(t *testing.T) {
defer tx.Rollback()

var num uint64
if err := sim.m.DB.View(context.Background(), func(tx ethdb.Tx) error {
if err := sim.m.DB.View(context.Background(), func(tx kv.Tx) error {
num = rawdb.ReadCurrentHeader(tx).Number.Uint64()
return nil
}); err != nil {
Expand Down
11 changes: 6 additions & 5 deletions cmd/cons/commands/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/ledgerwatch/erigon/consensus/clique"
"github.com/ledgerwatch/erigon/core"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/ethdb"
"github.com/ledgerwatch/erigon/ethdb/kv"
"github.com/ledgerwatch/erigon/log"
"github.com/ledgerwatch/erigon/metrics"
"github.com/ledgerwatch/erigon/params"
Expand All @@ -50,11 +50,12 @@ var cliqueCmd = &cobra.Command{
Short: "Run clique consensus engine",
RunE: func(cmd *cobra.Command, args []string) error {
ctx, _ := utils.RootContext()
return cliqueEngine(ctx)
logger := log.New()
return cliqueEngine(ctx, logger)
},
}

func cliqueEngine(ctx context.Context) error {
func cliqueEngine(ctx context.Context, logger log.Logger) error {
var server *CliqueServerImpl
var err error
if config == "test" {
Expand Down Expand Up @@ -85,7 +86,7 @@ func cliqueEngine(ctx context.Context) error {
return err
}
}
server.db = openDatabase(filepath.Join(datadir, "clique", "db"))
server.db = openDB(filepath.Join(datadir, "clique", "db"), logger)
server.c = clique.New(server.chainConfig, &params.SnapshotConfig{}, server.db)
<-ctx.Done()
return nil
Expand Down Expand Up @@ -151,7 +152,7 @@ type CliqueServerImpl struct {
genesis *core.Genesis
chainConfig *params.ChainConfig
c *clique.Clique
db ethdb.RwKV
db kv.RwDB
}

func NewCliqueServer(_ context.Context) *CliqueServerImpl {
Expand Down
15 changes: 4 additions & 11 deletions cmd/cons/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (

"github.com/ledgerwatch/erigon/cmd/utils"
"github.com/ledgerwatch/erigon/common/paths"
"github.com/ledgerwatch/erigon/ethdb"
"github.com/ledgerwatch/erigon/ethdb/kv"
"github.com/ledgerwatch/erigon/ethdb/mdbx"
"github.com/ledgerwatch/erigon/internal/debug"
"github.com/ledgerwatch/erigon/log"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -62,14 +63,6 @@ func withConfig(cmd *cobra.Command) {
cmd.Flags().StringVar(&config, "config", "", "`file:<path>` to specify config file in file system, `embed:<path>` to use embedded file, `test` to register test interface and receive config from test driver")
}

func openDatabase(path string) ethdb.RwKV {
return openKV(path, false)
}

func openKV(path string, exclusive bool) ethdb.RwKV {
opts := kv.NewMDBX().Path(path)
if exclusive {
opts = opts.Exclusive()
}
return opts.MustOpen()
func openDB(path string, logger log.Logger) kv.RwDB {
return mdbx.NewMDBX(logger).Path(path).MustOpen()
}
12 changes: 6 additions & 6 deletions cmd/erigon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/common/debug"
"github.com/ledgerwatch/erigon/core/rawdb"
"github.com/ledgerwatch/erigon/ethdb"
"github.com/ledgerwatch/erigon/ethdb/kv"
"github.com/ledgerwatch/erigon/log"
"github.com/ledgerwatch/erigon/params"
erigoncli "github.com/ledgerwatch/erigon/turbo/cli"
Expand All @@ -19,7 +19,6 @@ import (

func main() {
defer debug.LogPanic()
// creating a erigon-api app with all defaults
app := erigoncli.MakeApp(runErigon, erigoncli.DefaultFlags)
if err := app.Run(os.Args); err != nil {
fmt.Fprintln(os.Stderr, err)
Expand All @@ -28,15 +27,16 @@ func main() {
}

func runErigon(cliCtx *cli.Context) {
logger := log.New()
// initializing the node and providing the current git commit there
log.Info("Build info", "git_branch", params.GitBranch, "git_tag", params.GitTag, "git_commit", params.GitCommit)
logger.Info("Build info", "git_branch", params.GitBranch, "git_tag", params.GitTag, "git_commit", params.GitCommit)
nodeCfg := node.NewNodConfigUrfave(cliCtx)
ethCfg := node.NewEthConfigUrfave(cliCtx, nodeCfg)
if cliCtx.GlobalIsSet(utils.DataDirFlag.Name) {
// Check if we have an already initialized chain and fall back to
// that if so. Otherwise we need to generate a new genesis spec.
chaindb := utils.MakeChainDatabase(nodeCfg)
if err := chaindb.View(context.Background(), func(tx ethdb.Tx) error {
chaindb := utils.MakeChainDatabase(logger, nodeCfg)
if err := chaindb.View(context.Background(), func(tx kv.Tx) error {
h, err := rawdb.ReadCanonicalHash(tx, 0)
if err != nil {
panic(err)
Expand All @@ -51,7 +51,7 @@ func runErigon(cliCtx *cli.Context) {
chaindb.Close()
}

err := node.New(nodeCfg, ethCfg).Serve()
err := node.New(nodeCfg, ethCfg, logger).Serve()
if err != nil {
log.Error("error while serving a Erigon node", "err", err)
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/evm/internal/t8ntool/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import (
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/core/vm"
"github.com/ledgerwatch/erigon/crypto"
"github.com/ledgerwatch/erigon/ethdb"
"github.com/ledgerwatch/erigon/ethdb/kv"
"github.com/ledgerwatch/erigon/ethdb/memdb"
"github.com/ledgerwatch/erigon/log"
"github.com/ledgerwatch/erigon/params"
"github.com/ledgerwatch/erigon/rlp"
Expand Down Expand Up @@ -90,7 +90,7 @@ type stEnvMarshaling struct {
// Apply applies a set of transactions to a pre-state
func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
txs types.Transactions, miningReward int64,
getTracerFn func(txIndex int, txHash common.Hash) (tracer vm.Tracer, err error)) (ethdb.RwKV, *ExecutionResult, error) {
getTracerFn func(txIndex int, txHash common.Hash) (tracer vm.Tracer, err error)) (kv.RwDB, *ExecutionResult, error) {

// Capture errors for BLOCKHASH operation, if we haven't been supplied the
// required blockhashes
Expand All @@ -106,7 +106,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
}
return h
}
db := kv.NewMemKV()
db := memdb.New()

tx, err := db.BeginRw(context.Background())
if err != nil {
Expand Down Expand Up @@ -265,7 +265,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
return db, execRs, nil
}

func MakePreState(chainRules params.Rules, tx ethdb.RwTx, accounts core.GenesisAlloc) *state.IntraBlockState {
func MakePreState(chainRules params.Rules, tx kv.RwTx, accounts core.GenesisAlloc) *state.IntraBlockState {
var blockNr uint64 = 0
r, _ := state.NewPlainStateReader(tx), state.NewPlainStateWriter(tx, tx, blockNr)
statedb := state.New(r)
Expand Down
4 changes: 2 additions & 2 deletions cmd/evm/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"time"

"github.com/holiman/uint256"
"github.com/ledgerwatch/erigon/ethdb/kv"
"github.com/ledgerwatch/erigon/ethdb/memdb"
"github.com/urfave/cli"

"github.com/ledgerwatch/erigon/cmd/evm/internal/compiler"
Expand Down Expand Up @@ -135,7 +135,7 @@ func runCmd(ctx *cli.Context) error {
} else {
debugLogger = vm.NewStructLogger(logconfig)
}
db := kv.NewMemKV()
db := memdb.New()
if ctx.GlobalString(GenesisFlag.Name) != "" {
gen := readGenesis(ctx.GlobalString(GenesisFlag.Name))
gen.MustCommit(db)
Expand Down
4 changes: 2 additions & 2 deletions cmd/evm/staterunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/core/state"
"github.com/ledgerwatch/erigon/core/vm"
"github.com/ledgerwatch/erigon/ethdb/kv"
"github.com/ledgerwatch/erigon/ethdb/memdb"
"github.com/ledgerwatch/erigon/log"
"github.com/ledgerwatch/erigon/params"
"github.com/ledgerwatch/erigon/tests"
Expand Down Expand Up @@ -98,7 +98,7 @@ func stateTestCmd(ctx *cli.Context) error {
Debug: ctx.GlobalBool(DebugFlag.Name) || ctx.GlobalBool(MachineFlag.Name),
}
results := make([]StatetestResult, 0, len(tests))
db := kv.NewMemKV()
db := memdb.New()
defer db.Close()

tx, txErr := db.BeginRw(context.Background())
Expand Down
Loading

0 comments on commit 838e5f9

Please sign in to comment.