diff options
author | Felix Lange <fjl@users.noreply.github.com> | 2017-06-27 21:57:06 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-27 21:57:06 +0800 |
commit | 9e5f03b6c487175cc5aa1224e5e12fd573f483a7 (patch) | |
tree | 475e573ff6c7e77cd069a2f6238afdb27d4bce43 /les/api_backend.go | |
parent | bb366271fe33cf87b462dc5a25ac6c448ac6d2e1 (diff) | |
download | go-tangerine-9e5f03b6c487175cc5aa1224e5e12fd573f483a7.tar go-tangerine-9e5f03b6c487175cc5aa1224e5e12fd573f483a7.tar.gz go-tangerine-9e5f03b6c487175cc5aa1224e5e12fd573f483a7.tar.bz2 go-tangerine-9e5f03b6c487175cc5aa1224e5e12fd573f483a7.tar.lz go-tangerine-9e5f03b6c487175cc5aa1224e5e12fd573f483a7.tar.xz go-tangerine-9e5f03b6c487175cc5aa1224e5e12fd573f483a7.tar.zst go-tangerine-9e5f03b6c487175cc5aa1224e5e12fd573f483a7.zip |
core/state: access trie through Database interface, track errors (#14589)
With this commit, core/state's access to the underlying key/value database is
mediated through an interface. Database errors are tracked in StateDB and
returned by CommitTo or the new Error method.
Motivation for this change: We can remove the light client's duplicated copy of
core/state. The light client now supports node iteration, so tracing and storage
enumeration can work with the light client (not implemented in this commit).
Diffstat (limited to 'les/api_backend.go')
-rw-r--r-- | les/api_backend.go | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/les/api_backend.go b/les/api_backend.go index 7d69046de..7a3c2447c 100644 --- a/les/api_backend.go +++ b/les/api_backend.go @@ -24,13 +24,13 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/eth/downloader" "github.com/ethereum/go-ethereum/eth/gasprice" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" - "github.com/ethereum/go-ethereum/internal/ethapi" "github.com/ethereum/go-ethereum/light" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rpc" @@ -70,12 +70,12 @@ func (b *LesApiBackend) BlockByNumber(ctx context.Context, blockNr rpc.BlockNumb return b.GetBlock(ctx, header.Hash()) } -func (b *LesApiBackend) StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (ethapi.State, *types.Header, error) { +func (b *LesApiBackend) StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*state.StateDB, *types.Header, error) { header, err := b.HeaderByNumber(ctx, blockNr) if header == nil || err != nil { return nil, nil, err } - return light.NewLightState(light.StateTrieID(header), b.eth.odr), header, nil + return light.NewState(ctx, header, b.eth.odr), header, nil } func (b *LesApiBackend) GetBlock(ctx context.Context, blockHash common.Hash) (*types.Block, error) { @@ -90,18 +90,10 @@ func (b *LesApiBackend) GetTd(blockHash common.Hash) *big.Int { return b.eth.blockchain.GetTdByHash(blockHash) } -func (b *LesApiBackend) GetEVM(ctx context.Context, msg core.Message, state ethapi.State, header *types.Header, vmCfg vm.Config) (*vm.EVM, func() error, error) { - stateDb := state.(*light.LightState).Copy() - addr := msg.From() - from, err := stateDb.GetOrNewStateObject(ctx, addr) - if err != nil { - return nil, nil, err - } - from.SetBalance(math.MaxBig256) - - vmstate := light.NewVMState(ctx, stateDb) +func (b *LesApiBackend) GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, vmCfg vm.Config) (*vm.EVM, func() error, error) { + state.SetBalance(msg.From(), math.MaxBig256) context := core.NewEVMContext(msg, header, b.eth.blockchain, nil) - return vm.NewEVM(context, vmstate, b.eth.chainConfig, vmCfg), vmstate.Error, nil + return vm.NewEVM(context, state, b.eth.chainConfig, vmCfg), state.Error, nil } func (b *LesApiBackend) SendTx(ctx context.Context, signedTx *types.Transaction) error { |