diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2016-10-20 19:36:29 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2016-11-13 17:44:04 +0800 |
commit | 445feaeef58bd89a113743dccf6fd5df55cde6fa (patch) | |
tree | 6c692a0989800f005a94bde2d372fcbe1f7630a1 /tests/state_test_util.go | |
parent | 932d973e36ff0d41a6005b93d2d4ff1b4430fb04 (diff) | |
download | dexon-445feaeef58bd89a113743dccf6fd5df55cde6fa.tar dexon-445feaeef58bd89a113743dccf6fd5df55cde6fa.tar.gz dexon-445feaeef58bd89a113743dccf6fd5df55cde6fa.tar.bz2 dexon-445feaeef58bd89a113743dccf6fd5df55cde6fa.tar.lz dexon-445feaeef58bd89a113743dccf6fd5df55cde6fa.tar.xz dexon-445feaeef58bd89a113743dccf6fd5df55cde6fa.tar.zst dexon-445feaeef58bd89a113743dccf6fd5df55cde6fa.zip |
core, core/state, trie: EIP158, reprice & skip empty account write
This commit implements EIP158 part 1, 2, 3 & 4
1. If an account is empty it's no longer written to the trie. An empty
account is defined as (balance=0, nonce=0, storage=0, code=0).
2. Delete an empty account if it's touched
3. An empty account is redefined as either non-existent or empty.
4. Zero value calls and zero value suicides no longer consume the 25k
reation costs.
params: moved core/config to params
Signed-off-by: Jeffrey Wilcke <jeffrey@ethereum.org>
Diffstat (limited to 'tests/state_test_util.go')
-rw-r--r-- | tests/state_test_util.go | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/tests/state_test_util.go b/tests/state_test_util.go index 985271500..6427537b4 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -33,28 +33,29 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/params" ) -func RunStateTestWithReader(ruleSet RuleSet, r io.Reader, skipTests []string) error { +func RunStateTestWithReader(chainConfig *params.ChainConfig, r io.Reader, skipTests []string) error { tests := make(map[string]VmTest) if err := readJson(r, &tests); err != nil { return err } - if err := runStateTests(ruleSet, tests, skipTests); err != nil { + if err := runStateTests(chainConfig, tests, skipTests); err != nil { return err } return nil } -func RunStateTest(ruleSet RuleSet, p string, skipTests []string) error { +func RunStateTest(chainConfig *params.ChainConfig, p string, skipTests []string) error { tests := make(map[string]VmTest) if err := readJsonFile(p, &tests); err != nil { return err } - if err := runStateTests(ruleSet, tests, skipTests); err != nil { + if err := runStateTests(chainConfig, tests, skipTests); err != nil { return err } @@ -62,7 +63,7 @@ func RunStateTest(ruleSet RuleSet, p string, skipTests []string) error { } -func BenchStateTest(ruleSet RuleSet, p string, conf bconf, b *testing.B) error { +func BenchStateTest(chainConfig *params.ChainConfig, p string, conf bconf, b *testing.B) error { tests := make(map[string]VmTest) if err := readJsonFile(p, &tests); err != nil { return err @@ -87,22 +88,22 @@ func BenchStateTest(ruleSet RuleSet, p string, conf bconf, b *testing.B) error { b.ResetTimer() for i := 0; i < b.N; i++ { - benchStateTest(ruleSet, test, env, b) + benchStateTest(chainConfig, test, env, b) } return nil } -func benchStateTest(ruleSet RuleSet, test VmTest, env map[string]string, b *testing.B) { +func benchStateTest(chainConfig *params.ChainConfig, test VmTest, env map[string]string, b *testing.B) { b.StopTimer() db, _ := ethdb.NewMemDatabase() statedb := makePreState(db, test.Pre) b.StartTimer() - RunState(ruleSet, statedb, env, test.Exec) + RunState(chainConfig, statedb, env, test.Exec) } -func runStateTests(ruleSet RuleSet, tests map[string]VmTest, skipTests []string) error { +func runStateTests(chainConfig *params.ChainConfig, tests map[string]VmTest, skipTests []string) error { skipTest := make(map[string]bool, len(skipTests)) for _, name := range skipTests { skipTest[name] = true @@ -115,7 +116,7 @@ func runStateTests(ruleSet RuleSet, tests map[string]VmTest, skipTests []string) } //fmt.Println("StateTest:", name) - if err := runStateTest(ruleSet, test); err != nil { + if err := runStateTest(chainConfig, test); err != nil { return fmt.Errorf("%s: %s\n", name, err.Error()) } @@ -126,7 +127,7 @@ func runStateTests(ruleSet RuleSet, tests map[string]VmTest, skipTests []string) } -func runStateTest(ruleSet RuleSet, test VmTest) error { +func runStateTest(chainConfig *params.ChainConfig, test VmTest) error { db, _ := ethdb.NewMemDatabase() statedb := makePreState(db, test.Pre) @@ -150,7 +151,7 @@ func runStateTest(ruleSet RuleSet, test VmTest) error { logs vm.Logs ) - ret, logs, _, _ = RunState(ruleSet, statedb, env, test.Transaction) + ret, logs, _, _ = RunState(chainConfig, statedb, env, test.Transaction) // Compare expected and actual return var rexp []byte @@ -189,7 +190,7 @@ func runStateTest(ruleSet RuleSet, test VmTest) error { } } - root, _ := statedb.Commit() + root, _ := statedb.Commit(false) if common.HexToHash(test.PostStateRoot) != root { return fmt.Errorf("Post state root error. Expected: %s have: %x", test.PostStateRoot, root) } @@ -204,7 +205,7 @@ func runStateTest(ruleSet RuleSet, test VmTest) error { return nil } -func RunState(ruleSet RuleSet, statedb *state.StateDB, env, tx map[string]string) ([]byte, vm.Logs, *big.Int, error) { +func RunState(chainConfig *params.ChainConfig, statedb *state.StateDB, env, tx map[string]string) ([]byte, vm.Logs, *big.Int, error) { var ( data = common.FromHex(tx["data"]) gas = common.Big(tx["gasLimit"]) @@ -226,13 +227,13 @@ func RunState(ruleSet RuleSet, statedb *state.StateDB, env, tx map[string]string key, _ := hex.DecodeString(tx["secretKey"]) addr := crypto.PubkeyToAddress(crypto.ToECDSA(key).PublicKey) message := NewMessage(addr, to, data, value, gas, price, nonce) - vmenv := NewEnvFromMap(ruleSet, statedb, env, tx) + vmenv := NewEnvFromMap(chainConfig, statedb, env, tx) vmenv.origin = addr ret, _, err := core.ApplyMessage(vmenv, message, gaspool) if core.IsNonceErr(err) || core.IsInvalidTxErr(err) || core.IsGasLimitErr(err) { statedb.RevertToSnapshot(snapshot) } - statedb.Commit() + statedb.Commit(chainConfig.IsEIP158(vmenv.BlockNumber())) return ret, vmenv.state.Logs(), vmenv.Gas, err } |