aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-07-02 23:48:10 +0800
committerobscuren <geffobscura@gmail.com>2014-07-02 23:48:10 +0800
commit35ae9e3aa89dc0e3be1cabed313996a7d49f6628 (patch)
tree58cc607c27fbb068ba4f7c8750ddf8b9c699810c /ethchain
parent2f9bc2ab754ff85235ebb0b0b41b9b36ef30253a (diff)
downloadgo-tangerine-35ae9e3aa89dc0e3be1cabed313996a7d49f6628.tar
go-tangerine-35ae9e3aa89dc0e3be1cabed313996a7d49f6628.tar.gz
go-tangerine-35ae9e3aa89dc0e3be1cabed313996a7d49f6628.tar.bz2
go-tangerine-35ae9e3aa89dc0e3be1cabed313996a7d49f6628.tar.lz
go-tangerine-35ae9e3aa89dc0e3be1cabed313996a7d49f6628.tar.xz
go-tangerine-35ae9e3aa89dc0e3be1cabed313996a7d49f6628.tar.zst
go-tangerine-35ae9e3aa89dc0e3be1cabed313996a7d49f6628.zip
Paranoia check
Diffstat (limited to 'ethchain')
-rw-r--r--ethchain/state_manager.go9
-rw-r--r--ethchain/state_transition.go16
2 files changed, 13 insertions, 12 deletions
diff --git a/ethchain/state_manager.go b/ethchain/state_manager.go
index dea82cae3..c42238e5c 100644
--- a/ethchain/state_manager.go
+++ b/ethchain/state_manager.go
@@ -6,6 +6,7 @@ import (
"fmt"
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethlog"
+ "github.com/ethereum/eth-go/ethtrie"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethwire"
"math/big"
@@ -204,7 +205,15 @@ func (sm *StateManager) Process(block *Block, dontReact bool) (err error) {
return err
}
+ if ethutil.Config.Paranoia {
+ valid, _ := ethtrie.ParanoiaCheck(state.trie)
+ if !valid {
+ err = fmt.Errorf("PARANOIA: World state trie comparison failed")
+ }
+ }
+
if !block.State().Cmp(state) {
+
err = fmt.Errorf("Invalid merkle root.\nrec: %x\nis: %x", block.State().trie.Root, state.trie.Root)
return
}
diff --git a/ethchain/state_transition.go b/ethchain/state_transition.go
index 9e7ef3efd..898344c2e 100644
--- a/ethchain/state_transition.go
+++ b/ethchain/state_transition.go
@@ -1,7 +1,6 @@
package ethchain
import (
- "bytes"
"fmt"
"github.com/ethereum/eth-go/ethtrie"
"github.com/ethereum/eth-go/ethutil"
@@ -264,23 +263,16 @@ func Call(vm *Vm, closure *Closure, data []byte) (ret []byte, err error, deepErr
ret, _, err = closure.Call(vm, data)
deepErr = vm.err != nil
- Paranoia := ethutil.Config.Paranoia
- if Paranoia {
+ if ethutil.Config.Paranoia {
var (
context = closure.object
trie = context.state.trie
- trie2 = ethtrie.NewTrie(ethutil.Config.Db, "")
)
- trie.NewIterator().Each(func(key string, v *ethutil.Value) {
- trie2.Update(key, v.Str())
- })
-
- a := ethutil.NewValue(trie2.Root).Bytes()
- b := ethutil.NewValue(context.state.trie.Root).Bytes()
- if bytes.Compare(a, b) != 0 {
+ valid, t2 := ethtrie.ParanoiaCheck(trie)
+ if !valid {
// TODO FIXME ASAP
- context.state.trie = trie2
+ context.state.trie = t2
/*
statelogger.Debugf("(o): %x\n", trie.Root)
trie.NewIterator().Each(func(key string, v *ethutil.Value) {