aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-10-08 18:29:49 +0800
committerobscuren <geffobscura@gmail.com>2014-10-08 18:29:49 +0800
commit4de3ad1712ce0fdc62b1acc27a3922b192e943c6 (patch)
treea7de24c746a0c6d3531f1fab925d4e8b48a76cd2
parent9d86a49a7327199c01977f3372c8adf748252c32 (diff)
downloaddexon-4de3ad1712ce0fdc62b1acc27a3922b192e943c6.tar
dexon-4de3ad1712ce0fdc62b1acc27a3922b192e943c6.tar.gz
dexon-4de3ad1712ce0fdc62b1acc27a3922b192e943c6.tar.bz2
dexon-4de3ad1712ce0fdc62b1acc27a3922b192e943c6.tar.lz
dexon-4de3ad1712ce0fdc62b1acc27a3922b192e943c6.tar.xz
dexon-4de3ad1712ce0fdc62b1acc27a3922b192e943c6.tar.zst
dexon-4de3ad1712ce0fdc62b1acc27a3922b192e943c6.zip
New block message
-rw-r--r--block_pool.go23
-rw-r--r--ethereum.go4
-rw-r--r--ethpipe/js_pipe.go2
-rw-r--r--ethwire/messaging.go1
-rw-r--r--peer.go3
5 files changed, 23 insertions, 10 deletions
diff --git a/block_pool.go b/block_pool.go
index ea1f3633a..6ad2f5269 100644
--- a/block_pool.go
+++ b/block_pool.go
@@ -124,6 +124,14 @@ func (self *BlockPool) AddHash(hash []byte, peer *Peer) {
}
func (self *BlockPool) Add(b *ethchain.Block, peer *Peer) {
+ self.addBlock(b, peer, false)
+}
+
+func (self *BlockPool) AddNew(b *ethchain.Block, peer *Peer) {
+ self.addBlock(b, peer, true)
+}
+
+func (self *BlockPool) addBlock(b *ethchain.Block, peer *Peer, newBlock bool) {
self.mut.Lock()
defer self.mut.Unlock()
@@ -135,12 +143,15 @@ func (self *BlockPool) Add(b *ethchain.Block, peer *Peer) {
self.hashes = append(self.hashes, b.Hash())
self.pool[hash] = &block{peer, peer, b, time.Now(), 0}
- fmt.Println("1.", !self.eth.BlockChain().HasBlock(b.PrevHash), ethutil.Bytes2Hex(b.Hash()[0:4]), ethutil.Bytes2Hex(b.PrevHash[0:4]))
- fmt.Println("2.", self.pool[string(b.PrevHash)] == nil)
- fmt.Println("3.", !self.fetchingHashes)
- if !self.eth.BlockChain().HasBlock(b.PrevHash) && self.pool[string(b.PrevHash)] == nil && !self.fetchingHashes {
- poollogger.Infof("Unknown chain, requesting (%x...)\n", b.PrevHash[0:4])
- peer.QueueMessage(ethwire.NewMessage(ethwire.MsgGetBlockHashesTy, []interface{}{b.Hash(), uint32(256)}))
+ // The following is only performed on an unrequested new block
+ if newBlock {
+ fmt.Println("1.", !self.eth.BlockChain().HasBlock(b.PrevHash), ethutil.Bytes2Hex(b.Hash()[0:4]), ethutil.Bytes2Hex(b.PrevHash[0:4]))
+ fmt.Println("2.", self.pool[string(b.PrevHash)] == nil)
+ fmt.Println("3.", !self.fetchingHashes)
+ if !self.eth.BlockChain().HasBlock(b.PrevHash) && self.pool[string(b.PrevHash)] == nil && !self.fetchingHashes {
+ poollogger.Infof("Unknown chain, requesting (%x...)\n", b.PrevHash[0:4])
+ peer.QueueMessage(ethwire.NewMessage(ethwire.MsgGetBlockHashesTy, []interface{}{b.Hash(), uint32(256)}))
+ }
}
} else if self.pool[hash] != nil {
self.pool[hash].block = b
diff --git a/ethereum.go b/ethereum.go
index 987cd2016..b83ceb12f 100644
--- a/ethereum.go
+++ b/ethereum.go
@@ -385,7 +385,7 @@ func (s *Ethereum) RemovePeer(p *Peer) {
})
}
-func (s *Ethereum) ReapDeadPeerHandler() {
+func (s *Ethereum) reapDeadPeerHandler() {
reapTimer := time.NewTicker(processReapingTimeout * time.Second)
for {
@@ -420,7 +420,7 @@ func (s *Ethereum) Start(seed bool) {
}
// Start the reaping processes
- go s.ReapDeadPeerHandler()
+ go s.reapDeadPeerHandler()
go s.update()
go s.filterLoop()
diff --git a/ethpipe/js_pipe.go b/ethpipe/js_pipe.go
index 17c2261c7..24a553dad 100644
--- a/ethpipe/js_pipe.go
+++ b/ethpipe/js_pipe.go
@@ -3,7 +3,6 @@ package ethpipe
import (
"bytes"
"encoding/json"
- "fmt"
"sync/atomic"
"github.com/ethereum/eth-go/ethchain"
@@ -93,7 +92,6 @@ func (self *JSPipe) NumberToHuman(balance string) string {
}
func (self *JSPipe) StorageAt(addr, storageAddr string) string {
- fmt.Println("get", addr, storageAddr)
storage := self.World().SafeGet(ethutil.Hex2Bytes(addr)).Storage(ethutil.Hex2Bytes(storageAddr))
return ethutil.Bytes2Hex(storage.Bytes())
diff --git a/ethwire/messaging.go b/ethwire/messaging.go
index 2ef53c003..5013f1a97 100644
--- a/ethwire/messaging.go
+++ b/ethwire/messaging.go
@@ -40,6 +40,7 @@ const (
MsgBlockHashesTy = 0x14
MsgGetBlocksTy = 0x15
MsgBlockTy = 0x16
+ MsgNewBlockTy = 0x17
)
var msgTypeToString = map[MsgType]string{
diff --git a/peer.go b/peer.go
index 7ed152696..24dbe88d3 100644
--- a/peer.go
+++ b/peer.go
@@ -538,7 +538,10 @@ func (p *Peer) HandleInbound() {
p.lastBlockReceived = time.Now()
}
+ case ethwire.MsgNewBlockTy:
+ p.ethereum.blockPool.AddNew(ethchain.NewBlockFromRlpValue(msg.Data), p)
}
+
}
}
}