From 57c06a1375c8ceb5881535bbd84da4148eb7fd96 Mon Sep 17 00:00:00 2001 From: Artem Vorotnikov Date: Mon, 5 Apr 2021 10:10:46 +0300 Subject: [PATCH] 5 --- cmd/rpcdaemon/commands/eth_call.go | 2 +- cmd/rpcdaemon/commands/trace_adhoc.go | 4 ++-- cmd/rpcdaemon/commands/tracing.go | 2 +- core/state/plain_state_reader.go | 18 +++++++++--------- eth/stagedsync/stage_interhashes.go | 3 +-- turbo/transactions/call.go | 2 +- 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/cmd/rpcdaemon/commands/eth_call.go b/cmd/rpcdaemon/commands/eth_call.go index 061bef46e84..402bb4f382b 100644 --- a/cmd/rpcdaemon/commands/eth_call.go +++ b/cmd/rpcdaemon/commands/eth_call.go @@ -122,7 +122,7 @@ func (api *APIImpl) EstimateGas(ctx context.Context, args ethapi.CallArgs, block // Recap the highest gas limit with account's available balance. if args.GasPrice != nil && args.GasPrice.ToInt().Uint64() != 0 { - stateReader := state.NewPlainStateReader(ethdb.NewRoTxDb(dbtx)) + stateReader := state.NewPlainStateReader(dbtx) state := state.New(stateReader) if state == nil { return 0, fmt.Errorf("can't get the current state") diff --git a/cmd/rpcdaemon/commands/trace_adhoc.go b/cmd/rpcdaemon/commands/trace_adhoc.go index b0e0a46cce5..ce9617cbd64 100644 --- a/cmd/rpcdaemon/commands/trace_adhoc.go +++ b/cmd/rpcdaemon/commands/trace_adhoc.go @@ -457,7 +457,7 @@ func (api *TraceAPIImpl) Call(ctx context.Context, args TraceCallParam, traceTyp } var stateReader state.StateReader if num, ok := blockNrOrHash.Number(); ok && num == rpc.LatestBlockNumber { - stateReader = state.NewPlainStateReader(ethdb.NewRoTxDb(dbtx)) + stateReader = state.NewPlainStateReader(dbtx) } else { stateReader = state.NewPlainDBState(ethdb.NewRoTxDb(dbtx), blockNumber) } @@ -568,7 +568,7 @@ func (api *TraceAPIImpl) CallMany(ctx context.Context, calls json.RawMessage, bl } var stateReader state.StateReader if num, ok := blockNrOrHash.Number(); ok && num == rpc.LatestBlockNumber { - stateReader = state.NewPlainStateReader(ethdb.NewRoTxDb(dbtx)) + stateReader = state.NewPlainStateReader(dbtx) } else { stateReader = state.NewPlainDBState(ethdb.NewRoTxDb(dbtx), blockNumber) } diff --git a/cmd/rpcdaemon/commands/tracing.go b/cmd/rpcdaemon/commands/tracing.go index f512effdac4..28301eb2c5b 100644 --- a/cmd/rpcdaemon/commands/tracing.go +++ b/cmd/rpcdaemon/commands/tracing.go @@ -63,7 +63,7 @@ func (api *PrivateDebugAPIImpl) TraceCall(ctx context.Context, args ethapi.CallA } var stateReader state.StateReader if num, ok := blockNrOrHash.Number(); ok && num == rpc.LatestBlockNumber { - stateReader = state.NewPlainStateReader(ethdb.NewRoTxDb(dbtx)) + stateReader = state.NewPlainStateReader(dbtx) } else { stateReader = state.NewPlainDBState(ethdb.NewRoTxDb(dbtx), blockNumber) } diff --git a/core/state/plain_state_reader.go b/core/state/plain_state_reader.go index acfe75a2bd9..a3b79f4490f 100644 --- a/core/state/plain_state_reader.go +++ b/core/state/plain_state_reader.go @@ -3,7 +3,6 @@ package state import ( "bytes" "encoding/binary" - "errors" "github.com/ledgerwatch/turbo-geth/common" "github.com/ledgerwatch/turbo-geth/common/dbutils" @@ -17,10 +16,10 @@ var _ StateReader = (*PlainStateReader)(nil) // Data in the plain state is stored using un-hashed account/storage items // as opposed to the "normal" state that uses hashes of merkle paths to store items. type PlainStateReader struct { - db ethdb.Getter + db ethdb.KVGetter } -func NewPlainStateReader(db ethdb.Getter) *PlainStateReader { +func NewPlainStateReader(db ethdb.KVGetter) *PlainStateReader { return &PlainStateReader{ db: db, } @@ -57,7 +56,7 @@ func (r *PlainStateReader) ReadAccountCode(address common.Address, incarnation u if bytes.Equal(codeHash.Bytes(), emptyCodeHash) { return nil, nil } - code, err := r.db.Get(dbutils.CodeBucket, codeHash.Bytes()) + code, err := r.db.GetOne(dbutils.CodeBucket, codeHash.Bytes()) if len(code) == 0 { return nil, nil } @@ -70,11 +69,12 @@ func (r *PlainStateReader) ReadAccountCodeSize(address common.Address, incarnati } func (r *PlainStateReader) ReadAccountIncarnation(address common.Address) (uint64, error) { - if b, err := r.db.Get(dbutils.IncarnationMapBucket, address.Bytes()); err == nil { - return binary.BigEndian.Uint64(b), nil - } else if errors.Is(err, ethdb.ErrKeyNotFound) { - return 0, nil - } else { + b, err := r.db.GetOne(dbutils.IncarnationMapBucket, address.Bytes()) + if err != nil { return 0, err } + if len(b) == 0 { + return 0, nil + } + return binary.BigEndian.Uint64(b), nil } diff --git a/eth/stagedsync/stage_interhashes.go b/eth/stagedsync/stage_interhashes.go index fc006be8b69..3a4f2a6f4ff 100644 --- a/eth/stagedsync/stage_interhashes.go +++ b/eth/stagedsync/stage_interhashes.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "encoding/binary" - "errors" "fmt" "math/bits" "os" @@ -292,7 +291,7 @@ func (p *HashPromoter) Unwind(logPrefix string, s *StageState, u *UnwindState, s } // Plain state not unwind yet, it means - if key not-exists in PlainState but has value from ChangeSets - then need mark it as "created" in RetainList value, err := p.db.GetOne(dbutils.PlainStateBucket, k) - if err != nil && !errors.Is(err, ethdb.ErrKeyNotFound) { + if err != nil { return err } diff --git a/turbo/transactions/call.go b/turbo/transactions/call.go index 39db87ac909..9cfa3cfacc8 100644 --- a/turbo/transactions/call.go +++ b/turbo/transactions/call.go @@ -37,7 +37,7 @@ func DoCall(ctx context.Context, args ethapi.CallArgs, tx ethdb.Tx, blockNrOrHas } var stateReader state.StateReader if num, ok := blockNrOrHash.Number(); ok && num == rpc.LatestBlockNumber { - stateReader = state.NewPlainStateReader(ethdb.NewRoTxDb(tx)) + stateReader = state.NewPlainStateReader(tx) } else { stateReader = state.NewPlainDBState(ethdb.NewRoTxDb(tx), blockNumber) }