aboutsummaryrefslogtreecommitdiffstats
path: root/les/odr_test.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@users.noreply.github.com>2017-06-27 21:57:06 +0800
committerGitHub <noreply@github.com>2017-06-27 21:57:06 +0800
commit9e5f03b6c487175cc5aa1224e5e12fd573f483a7 (patch)
tree475e573ff6c7e77cd069a2f6238afdb27d4bce43 /les/odr_test.go
parentbb366271fe33cf87b462dc5a25ac6c448ac6d2e1 (diff)
downloadgo-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/odr_test.go')
-rw-r--r--les/odr_test.go53
1 files changed, 22 insertions, 31 deletions
diff --git a/les/odr_test.go b/les/odr_test.go
index 7b34996ce..3a0fd6738 100644
--- a/les/odr_test.go
+++ b/les/odr_test.go
@@ -75,24 +75,23 @@ func odrAccounts(ctx context.Context, db ethdb.Database, config *params.ChainCon
dummyAddr := common.HexToAddress("1234567812345678123456781234567812345678")
acc := []common.Address{testBankAddress, acc1Addr, acc2Addr, dummyAddr}
- var res []byte
+ var (
+ res []byte
+ st *state.StateDB
+ err error
+ )
for _, addr := range acc {
if bc != nil {
header := bc.GetHeaderByHash(bhash)
- st, err := state.New(header.Root, db)
- if err == nil {
- bal := st.GetBalance(addr)
- rlp, _ := rlp.EncodeToBytes(bal)
- res = append(res, rlp...)
- }
+ st, err = state.New(header.Root, state.NewDatabase(db))
} else {
header := lc.GetHeaderByHash(bhash)
- st := light.NewLightState(light.StateTrieID(header), lc.Odr())
- bal, err := st.GetBalance(ctx, addr)
- if err == nil {
- rlp, _ := rlp.EncodeToBytes(bal)
- res = append(res, rlp...)
- }
+ st = light.NewState(ctx, header, lc.Odr())
+ }
+ if err == nil {
+ bal := st.GetBalance(addr)
+ rlp, _ := rlp.EncodeToBytes(bal)
+ res = append(res, rlp...)
}
}
@@ -115,7 +114,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai
data[35] = byte(i)
if bc != nil {
header := bc.GetHeaderByHash(bhash)
- statedb, err := state.New(header.Root, db)
+ statedb, err := state.New(header.Root, state.NewDatabase(db))
if err == nil {
from := statedb.GetOrNewStateObject(testBankAddress)
@@ -133,23 +132,15 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai
}
} else {
header := lc.GetHeaderByHash(bhash)
- state := light.NewLightState(light.StateTrieID(header), lc.Odr())
- vmstate := light.NewVMState(ctx, state)
- from, err := state.GetOrNewStateObject(ctx, testBankAddress)
- if err == nil {
- from.SetBalance(math.MaxBig256)
-
- msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), big.NewInt(100000), new(big.Int), data, false)}
-
- context := core.NewEVMContext(msg, header, lc, nil)
- vmenv := vm.NewEVM(context, vmstate, config, vm.Config{})
-
- //vmenv := light.NewEnv(ctx, state, config, lc, msg, header, vm.Config{})
- gp := new(core.GasPool).AddGas(math.MaxBig256)
- ret, _, _ := core.ApplyMessage(vmenv, msg, gp)
- if vmstate.Error() == nil {
- res = append(res, ret...)
- }
+ state := light.NewState(ctx, header, lc.Odr())
+ state.SetBalance(testBankAddress, math.MaxBig256)
+ msg := callmsg{types.NewMessage(testBankAddress, &testContractAddr, 0, new(big.Int), big.NewInt(100000), new(big.Int), data, false)}
+ context := core.NewEVMContext(msg, header, lc, nil)
+ vmenv := vm.NewEVM(context, state, config, vm.Config{})
+ gp := new(core.GasPool).AddGas(math.MaxBig256)
+ ret, _, _ := core.ApplyMessage(vmenv, msg, gp)
+ if state.Error() == nil {
+ res = append(res, ret...)
}
}
}