aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-07-25 16:43:59 +0800
committerobscuren <geffobscura@gmail.com>2014-07-25 16:43:59 +0800
commit92ffc1cc4c7227de93d933181a30c57c5730c41f (patch)
tree6fe0805649ddf38b2b90e77c5fb2000a4bdab536
parent702cf5a3e19e33616e7e98ec8ab7a00d56dd7e85 (diff)
parent54f9ea14e197ad805f24592153f1b9e69f3bc5c3 (diff)
downloadgo-tangerine-92ffc1cc4c7227de93d933181a30c57c5730c41f.tar
go-tangerine-92ffc1cc4c7227de93d933181a30c57c5730c41f.tar.gz
go-tangerine-92ffc1cc4c7227de93d933181a30c57c5730c41f.tar.bz2
go-tangerine-92ffc1cc4c7227de93d933181a30c57c5730c41f.tar.lz
go-tangerine-92ffc1cc4c7227de93d933181a30c57c5730c41f.tar.xz
go-tangerine-92ffc1cc4c7227de93d933181a30c57c5730c41f.tar.zst
go-tangerine-92ffc1cc4c7227de93d933181a30c57c5730c41f.zip
Merge branch 'release/0.6.0' into develop
-rw-r--r--ethvm/vm.go43
-rw-r--r--peer.go29
2 files changed, 41 insertions, 31 deletions
diff --git a/ethvm/vm.go b/ethvm/vm.go
index b81c8a189..a93b56e60 100644
--- a/ethvm/vm.go
+++ b/ethvm/vm.go
@@ -282,20 +282,15 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
case SDIV:
require(2)
x, y := stack.Popn()
- // n > 2**255
- if x.Cmp(Pow256) > 0 {
- x.Sub(Pow256, x)
- }
- if y.Cmp(Pow256) > 0 {
- y.Sub(Pow256, y)
- }
- z := new(big.Int)
- z.Div(x, y)
- if z.Cmp(Pow256) > 0 {
- z.Sub(Pow256, z)
+ self.Printf(" %v / %v", y, x)
+
+ if x.Cmp(ethutil.Big0) != 0 {
+ base.Div(y, x)
}
- // Push result on to the stack
- stack.Push(z)
+
+ self.Printf(" = %v", base)
+ // Pop result back on the stack
+ stack.Push(base)
case MOD:
require(2)
x, y := stack.Popn()
@@ -309,20 +304,14 @@ func (self *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
case SMOD:
require(2)
x, y := stack.Popn()
- // n > 2**255
- if x.Cmp(Pow256) > 0 {
- x.Sub(Pow256, x)
- }
- if y.Cmp(Pow256) > 0 {
- y.Sub(Pow256, y)
- }
- z := new(big.Int)
- z.Mod(x, y)
- if z.Cmp(Pow256) > 0 {
- z.Sub(Pow256, z)
- }
- // Push result on to the stack
- stack.Push(z)
+
+ self.Printf(" %v %% %v", y, x)
+
+ base.Mod(y, x)
+
+ self.Printf(" = %v", base)
+ stack.Push(base)
+
case EXP:
require(2)
x, y := stack.Popn()
diff --git a/peer.go b/peer.go
index c73617ed5..ffba695ca 100644
--- a/peer.go
+++ b/peer.go
@@ -121,7 +121,8 @@ type Peer struct {
versionKnown bool
// Last received pong message
- lastPong int64
+ lastPong int64
+ lastBlockReceived time.Time
host []byte
port uint16
@@ -408,10 +409,7 @@ func (p *Peer) HandleInbound() {
for i := msg.Data.Len() - 1; i >= 0; i-- {
block = ethchain.NewBlockFromRlpValue(msg.Data.Get(i))
- //p.ethereum.StateManager().PrepareDefault(block)
- //state := p.ethereum.StateManager().CurrentState()
err = p.ethereum.StateManager().Process(block, false)
-
if err != nil {
if ethutil.Config.Debug {
peerlogger.Infof("Block %x failed\n", block.Hash())
@@ -422,6 +420,8 @@ func (p *Peer) HandleInbound() {
} else {
lastBlock = block
}
+
+ p.lastBlockReceived = time.Now()
}
if msg.Data.Len() <= 1 {
@@ -561,6 +561,25 @@ func (p *Peer) HandleInbound() {
p.Stop()
}
+// General update method
+func (self *Peer) update() {
+ serviceTimer := time.NewTicker(5 * time.Second)
+
+out:
+ for {
+ select {
+ case <-serviceTimer.C:
+ if time.Since(self.lastBlockReceived) > 10*time.Second {
+ self.catchingUp = false
+ }
+ case <-self.quit:
+ break out
+ }
+ }
+
+ serviceTimer.Stop()
+}
+
func (p *Peer) Start() {
peerHost, peerPort, _ := net.SplitHostPort(p.conn.LocalAddr().String())
servHost, servPort, _ := net.SplitHostPort(p.conn.RemoteAddr().String())
@@ -583,6 +602,8 @@ func (p *Peer) Start() {
go p.HandleOutbound()
// Run the inbound handler in a new goroutine
go p.HandleInbound()
+ // Run the general update handler
+ go p.update()
// Wait a few seconds for startup and then ask for an initial ping
time.Sleep(2 * time.Second)