forked from cerc-io/plugeth
New block message
This commit is contained in:
parent
9d86a49a73
commit
4de3ad1712
@ -124,6 +124,14 @@ func (self *BlockPool) AddHash(hash []byte, peer *Peer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *BlockPool) Add(b *ethchain.Block, 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()
|
self.mut.Lock()
|
||||||
defer self.mut.Unlock()
|
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.hashes = append(self.hashes, b.Hash())
|
||||||
self.pool[hash] = &block{peer, peer, b, time.Now(), 0}
|
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]))
|
// The following is only performed on an unrequested new block
|
||||||
fmt.Println("2.", self.pool[string(b.PrevHash)] == nil)
|
if newBlock {
|
||||||
fmt.Println("3.", !self.fetchingHashes)
|
fmt.Println("1.", !self.eth.BlockChain().HasBlock(b.PrevHash), ethutil.Bytes2Hex(b.Hash()[0:4]), ethutil.Bytes2Hex(b.PrevHash[0:4]))
|
||||||
if !self.eth.BlockChain().HasBlock(b.PrevHash) && self.pool[string(b.PrevHash)] == nil && !self.fetchingHashes {
|
fmt.Println("2.", self.pool[string(b.PrevHash)] == nil)
|
||||||
poollogger.Infof("Unknown chain, requesting (%x...)\n", b.PrevHash[0:4])
|
fmt.Println("3.", !self.fetchingHashes)
|
||||||
peer.QueueMessage(ethwire.NewMessage(ethwire.MsgGetBlockHashesTy, []interface{}{b.Hash(), uint32(256)}))
|
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 {
|
} else if self.pool[hash] != nil {
|
||||||
self.pool[hash].block = b
|
self.pool[hash].block = b
|
||||||
|
@ -385,7 +385,7 @@ func (s *Ethereum) RemovePeer(p *Peer) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Ethereum) ReapDeadPeerHandler() {
|
func (s *Ethereum) reapDeadPeerHandler() {
|
||||||
reapTimer := time.NewTicker(processReapingTimeout * time.Second)
|
reapTimer := time.NewTicker(processReapingTimeout * time.Second)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
@ -420,7 +420,7 @@ func (s *Ethereum) Start(seed bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start the reaping processes
|
// Start the reaping processes
|
||||||
go s.ReapDeadPeerHandler()
|
go s.reapDeadPeerHandler()
|
||||||
go s.update()
|
go s.update()
|
||||||
go s.filterLoop()
|
go s.filterLoop()
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ package ethpipe
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/ethereum/eth-go/ethchain"
|
"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 {
|
func (self *JSPipe) StorageAt(addr, storageAddr string) string {
|
||||||
fmt.Println("get", addr, storageAddr)
|
|
||||||
storage := self.World().SafeGet(ethutil.Hex2Bytes(addr)).Storage(ethutil.Hex2Bytes(storageAddr))
|
storage := self.World().SafeGet(ethutil.Hex2Bytes(addr)).Storage(ethutil.Hex2Bytes(storageAddr))
|
||||||
|
|
||||||
return ethutil.Bytes2Hex(storage.Bytes())
|
return ethutil.Bytes2Hex(storage.Bytes())
|
||||||
|
@ -40,6 +40,7 @@ const (
|
|||||||
MsgBlockHashesTy = 0x14
|
MsgBlockHashesTy = 0x14
|
||||||
MsgGetBlocksTy = 0x15
|
MsgGetBlocksTy = 0x15
|
||||||
MsgBlockTy = 0x16
|
MsgBlockTy = 0x16
|
||||||
|
MsgNewBlockTy = 0x17
|
||||||
)
|
)
|
||||||
|
|
||||||
var msgTypeToString = map[MsgType]string{
|
var msgTypeToString = map[MsgType]string{
|
||||||
|
Loading…
Reference in New Issue
Block a user