Skip to content

Commit

Permalink
5
Browse files Browse the repository at this point in the history
  • Loading branch information
vorot93 committed Apr 5, 2021
1 parent 26568db commit 57c06a1
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cmd/rpcdaemon/commands/eth_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions cmd/rpcdaemon/commands/trace_adhoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/rpcdaemon/commands/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
18 changes: 9 additions & 9 deletions core/state/plain_state_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package state
import (
"bytes"
"encoding/binary"
"errors"

"github.com/ledgerwatch/turbo-geth/common"
"github.com/ledgerwatch/turbo-geth/common/dbutils"
Expand All @@ -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,
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
3 changes: 1 addition & 2 deletions eth/stagedsync/stage_interhashes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"encoding/binary"
"errors"
"fmt"
"math/bits"
"os"
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion turbo/transactions/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 57c06a1

Please sign in to comment.