aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Wilcke <geffobscura@gmail.com>2015-06-29 18:42:47 +0800
committerJeffrey Wilcke <geffobscura@gmail.com>2015-06-29 19:31:49 +0800
commitb39042db5672e830ddec41ea97c642d93be61c30 (patch)
tree1c0a9ac2c1c6b616b1ea14e9b4cd1e847472e6d7
parentd1e93db3ebc218044339a6c5c95b4907e6351ede (diff)
downloaddexon-b39042db5672e830ddec41ea97c642d93be61c30.tar
dexon-b39042db5672e830ddec41ea97c642d93be61c30.tar.gz
dexon-b39042db5672e830ddec41ea97c642d93be61c30.tar.bz2
dexon-b39042db5672e830ddec41ea97c642d93be61c30.tar.lz
dexon-b39042db5672e830ddec41ea97c642d93be61c30.tar.xz
dexon-b39042db5672e830ddec41ea97c642d93be61c30.tar.zst
dexon-b39042db5672e830ddec41ea97c642d93be61c30.zip
core, miner: implemented canary
-rw-r--r--core/canary.go28
-rw-r--r--miner/worker.go6
2 files changed, 34 insertions, 0 deletions
diff --git a/core/canary.go b/core/canary.go
new file mode 100644
index 000000000..de77c4bba
--- /dev/null
+++ b/core/canary.go
@@ -0,0 +1,28 @@
+package core
+
+import (
+ "math/big"
+
+ "github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/core/state"
+)
+
+var (
+ jeff = common.HexToAddress("9d38997c624a71b21278389ea2fdc460d000e4b2")
+ vitalik = common.HexToAddress("b1e570be07eaa673e4fd0c8265b64ef739385709")
+ christoph = common.HexToAddress("529bc43a5d93789fa28de1961db6a07e752204ae")
+ gav = common.HexToAddress("e3e942b2aa524293c84ff6c7f87a6635790ad5e4")
+)
+
+// Canary will check the 0'd address of the 4 contracts above.
+// If two or more are set to anything other than a 0 the canary
+// dies a horrible death.
+func Canary(statedb *state.StateDB) bool {
+ r := new(big.Int)
+ r.Add(r, statedb.GetState(jeff, common.Hash{}).Big())
+ r.Add(r, statedb.GetState(vitalik, common.Hash{}).Big())
+ r.Add(r, statedb.GetState(christoph, common.Hash{}).Big())
+ r.Add(r, statedb.GetState(gav, common.Hash{}).Big())
+
+ return r.Cmp(big.NewInt(1)) > 0
+}
diff --git a/miner/worker.go b/miner/worker.go
index ab01ba09e..1e5d47965 100644
--- a/miner/worker.go
+++ b/miner/worker.go
@@ -267,6 +267,12 @@ func (self *worker) wait() {
func (self *worker) push() {
if atomic.LoadInt32(&self.mining) == 1 {
+ if core.Canary(self.current.state) {
+ glog.Infoln("Toxicity levels rising to deadly levels. Your canary has died. You can go back or continue down the mineshaft --more--")
+ glog.Infoln("You turn back and abort mining")
+ return
+ }
+
self.current.state.Sync()
self.current.block.SetRoot(self.current.state.Root())