|
|
@ -4,6 +4,8 @@ import ( |
|
|
|
"bytes" |
|
|
|
"bytes" |
|
|
|
"container/list" |
|
|
|
"container/list" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
|
|
|
|
"math" |
|
|
|
|
|
|
|
"math/big" |
|
|
|
"net" |
|
|
|
"net" |
|
|
|
"strconv" |
|
|
|
"strconv" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
@ -22,7 +24,7 @@ const ( |
|
|
|
// The size of the output buffer for writing messages
|
|
|
|
// The size of the output buffer for writing messages
|
|
|
|
outputBufferSize = 50 |
|
|
|
outputBufferSize = 50 |
|
|
|
// Current protocol version
|
|
|
|
// Current protocol version
|
|
|
|
ProtocolVersion = 26 |
|
|
|
ProtocolVersion = 27 |
|
|
|
// Interval for ping/pong message
|
|
|
|
// Interval for ping/pong message
|
|
|
|
pingPongTimer = 2 * time.Second |
|
|
|
pingPongTimer = 2 * time.Second |
|
|
|
) |
|
|
|
) |
|
|
@ -125,9 +127,13 @@ type Peer struct { |
|
|
|
lastPong int64 |
|
|
|
lastPong int64 |
|
|
|
lastBlockReceived time.Time |
|
|
|
lastBlockReceived time.Time |
|
|
|
|
|
|
|
|
|
|
|
host []byte |
|
|
|
host []byte |
|
|
|
port uint16 |
|
|
|
port uint16 |
|
|
|
caps Caps |
|
|
|
caps Caps |
|
|
|
|
|
|
|
td *big.Int |
|
|
|
|
|
|
|
bestHash []byte |
|
|
|
|
|
|
|
lastReceivedHash []byte |
|
|
|
|
|
|
|
requestedHashes [][]byte |
|
|
|
|
|
|
|
|
|
|
|
// This peer's public key
|
|
|
|
// This peer's public key
|
|
|
|
pubkey []byte |
|
|
|
pubkey []byte |
|
|
@ -345,7 +351,6 @@ func (p *Peer) HandleInbound() { |
|
|
|
for _, msg := range msgs { |
|
|
|
for _, msg := range msgs { |
|
|
|
peerlogger.DebugDetailf("(%v) => %v %v\n", p.conn.RemoteAddr(), msg.Type, msg.Data) |
|
|
|
peerlogger.DebugDetailf("(%v) => %v %v\n", p.conn.RemoteAddr(), msg.Type, msg.Data) |
|
|
|
|
|
|
|
|
|
|
|
nextMsg: |
|
|
|
|
|
|
|
switch msg.Type { |
|
|
|
switch msg.Type { |
|
|
|
case ethwire.MsgHandshakeTy: |
|
|
|
case ethwire.MsgHandshakeTy: |
|
|
|
// Version message
|
|
|
|
// Version message
|
|
|
@ -354,6 +359,7 @@ func (p *Peer) HandleInbound() { |
|
|
|
if p.caps.IsCap(CapPeerDiscTy) { |
|
|
|
if p.caps.IsCap(CapPeerDiscTy) { |
|
|
|
p.QueueMessage(ethwire.NewMessage(ethwire.MsgGetPeersTy, "")) |
|
|
|
p.QueueMessage(ethwire.NewMessage(ethwire.MsgGetPeersTy, "")) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
case ethwire.MsgDiscTy: |
|
|
|
case ethwire.MsgDiscTy: |
|
|
|
p.Stop() |
|
|
|
p.Stop() |
|
|
|
peerlogger.Infoln("Disconnect peer: ", DiscReason(msg.Data.Get(0).Uint())) |
|
|
|
peerlogger.Infoln("Disconnect peer: ", DiscReason(msg.Data.Get(0).Uint())) |
|
|
@ -366,117 +372,6 @@ func (p *Peer) HandleInbound() { |
|
|
|
// active.
|
|
|
|
// active.
|
|
|
|
p.lastPong = time.Now().Unix() |
|
|
|
p.lastPong = time.Now().Unix() |
|
|
|
p.pingTime = time.Since(p.pingStartTime) |
|
|
|
p.pingTime = time.Since(p.pingStartTime) |
|
|
|
case ethwire.MsgBlockTy: |
|
|
|
|
|
|
|
// Get all blocks and process them
|
|
|
|
|
|
|
|
//var block, lastBlock *ethchain.Block
|
|
|
|
|
|
|
|
//var err error
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
|
|
|
|
block, lastBlock *ethchain.Block |
|
|
|
|
|
|
|
blockChain = p.ethereum.BlockChain() |
|
|
|
|
|
|
|
err error |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Make sure we are actually receiving anything
|
|
|
|
|
|
|
|
if msg.Data.Len()-1 > 1 && p.diverted { |
|
|
|
|
|
|
|
// We requested blocks and now we need to make sure we have a common ancestor somewhere in these blocks so we can find
|
|
|
|
|
|
|
|
// common ground to start syncing from
|
|
|
|
|
|
|
|
lastBlock = ethchain.NewBlockFromRlpValue(msg.Data.Get(msg.Data.Len() - 1)) |
|
|
|
|
|
|
|
if p.lastRequestedBlock != nil && bytes.Compare(lastBlock.Hash(), p.lastRequestedBlock.Hash()) == 0 { |
|
|
|
|
|
|
|
p.catchingUp = false |
|
|
|
|
|
|
|
continue |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
p.lastRequestedBlock = lastBlock |
|
|
|
|
|
|
|
peerlogger.Infof("Last block: %x. Checking if we have it locally.\n", lastBlock.Hash()) |
|
|
|
|
|
|
|
for i := msg.Data.Len() - 1; i >= 0; i-- { |
|
|
|
|
|
|
|
block = ethchain.NewBlockFromRlpValue(msg.Data.Get(i)) |
|
|
|
|
|
|
|
// Do we have this block on our chain? If so we can continue
|
|
|
|
|
|
|
|
if !blockChain.HasBlock(block.Hash()) { |
|
|
|
|
|
|
|
// We don't have this block, but we do have a block with the same prevHash, diversion time!
|
|
|
|
|
|
|
|
if blockChain.HasBlockWithPrevHash(block.PrevHash) { |
|
|
|
|
|
|
|
p.diverted = false |
|
|
|
|
|
|
|
if !blockChain.FindCanonicalChainFromMsg(msg, block.PrevHash) { |
|
|
|
|
|
|
|
p.SyncWithPeerToLastKnown() |
|
|
|
|
|
|
|
break nextMsg |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if !blockChain.HasBlock(lastBlock.Hash()) { |
|
|
|
|
|
|
|
// If we can't find a common ancenstor we need to request more blocks.
|
|
|
|
|
|
|
|
// FIXME: At one point this won't scale anymore since we are not asking for an offset
|
|
|
|
|
|
|
|
// we just keep increasing the amount of blocks.
|
|
|
|
|
|
|
|
p.blocksRequested = p.blocksRequested * 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
peerlogger.Infof("No common ancestor found, requesting %d more blocks.\n", p.blocksRequested) |
|
|
|
|
|
|
|
p.FindCommonParentBlock() |
|
|
|
|
|
|
|
break nextMsg |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p.catchingUp = false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for i := msg.Data.Len() - 1; i >= 0; i-- { |
|
|
|
|
|
|
|
block = ethchain.NewBlockFromRlpValue(msg.Data.Get(i)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err = p.ethereum.StateManager().Process(block, false) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
if ethutil.Config.Debug { |
|
|
|
|
|
|
|
peerlogger.Infof("Block %x failed\n", block.Hash()) |
|
|
|
|
|
|
|
peerlogger.Infof("%v\n", err) |
|
|
|
|
|
|
|
peerlogger.Debugln(block) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
lastBlock = block |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p.lastBlockReceived = time.Now() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if msg.Data.Len() <= 1 { |
|
|
|
|
|
|
|
// Set catching up to false if
|
|
|
|
|
|
|
|
// the peer has nothing left to give
|
|
|
|
|
|
|
|
p.catchingUp = false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
// If the parent is unknown try to catch up with this peer
|
|
|
|
|
|
|
|
if ethchain.IsParentErr(err) { |
|
|
|
|
|
|
|
b := ethchain.NewBlockFromRlpValue(msg.Data.Get(0)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
peerlogger.Infof("Attempting to catch (%x). Parent unknown\n", b.Hash()) |
|
|
|
|
|
|
|
p.catchingUp = false |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p.CatchupWithPeer(b.PrevHash) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
peerlogger.Infoln(b) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
peerlogger.Infoln("Attempting to catch. Parent known") |
|
|
|
|
|
|
|
p.catchingUp = false |
|
|
|
|
|
|
|
p.CatchupWithPeer(p.ethereum.BlockChain().CurrentBlock.Hash()) |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
} else if ethchain.IsValidationErr(err) { |
|
|
|
|
|
|
|
fmt.Println("Err:", err) |
|
|
|
|
|
|
|
p.catchingUp = false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// If we're catching up, try to catch up further.
|
|
|
|
|
|
|
|
if p.catchingUp && msg.Data.Len() > 1 { |
|
|
|
|
|
|
|
if lastBlock != nil { |
|
|
|
|
|
|
|
blockInfo := lastBlock.BlockInfo() |
|
|
|
|
|
|
|
peerlogger.DebugDetailf("Synced chain to #%d %x %x\n", blockInfo.Number, lastBlock.Hash(), blockInfo.Hash) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p.catchingUp = false |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hash := p.ethereum.BlockChain().CurrentBlock.Hash() |
|
|
|
|
|
|
|
p.CatchupWithPeer(hash) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case ethwire.MsgTxTy: |
|
|
|
case ethwire.MsgTxTy: |
|
|
|
// If the message was a transaction queue the transaction
|
|
|
|
// If the message was a transaction queue the transaction
|
|
|
|
// in the TxPool where it will undergo validation and
|
|
|
|
// in the TxPool where it will undergo validation and
|
|
|
@ -501,78 +396,114 @@ func (p *Peer) HandleInbound() { |
|
|
|
|
|
|
|
|
|
|
|
// Connect to the list of peers
|
|
|
|
// Connect to the list of peers
|
|
|
|
p.ethereum.ProcessPeerList(peers) |
|
|
|
p.ethereum.ProcessPeerList(peers) |
|
|
|
case ethwire.MsgGetChainTy: |
|
|
|
case ethwire.MsgGetTxsTy: |
|
|
|
var parent *ethchain.Block |
|
|
|
// Get the current transactions of the pool
|
|
|
|
// Length minus one since the very last element in the array is a count
|
|
|
|
txs := p.ethereum.TxPool().CurrentTransactions() |
|
|
|
l := msg.Data.Len() - 1 |
|
|
|
// Get the RlpData values from the txs
|
|
|
|
// Ignore empty get chains
|
|
|
|
txsInterface := make([]interface{}, len(txs)) |
|
|
|
if l == 0 { |
|
|
|
for i, tx := range txs { |
|
|
|
break |
|
|
|
txsInterface[i] = tx.RlpData() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Broadcast it back to the peer
|
|
|
|
|
|
|
|
p.QueueMessage(ethwire.NewMessage(ethwire.MsgTxTy, txsInterface)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case ethwire.MsgGetBlockHashesTy: |
|
|
|
|
|
|
|
if msg.Data.Len() < 2 { |
|
|
|
|
|
|
|
peerlogger.Debugln("err: argument length invalid ", msg.Data.Len()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Amount of parents in the canonical chain
|
|
|
|
hash := msg.Data.Get(0).Bytes() |
|
|
|
//amountOfBlocks := msg.Data.Get(l).AsUint()
|
|
|
|
amount := msg.Data.Get(1).Uint() |
|
|
|
amountOfBlocks := uint64(100) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check each SHA block hash from the message and determine whether
|
|
|
|
hashes := p.ethereum.BlockChain().GetChainHashesFromHash(hash, amount) |
|
|
|
// the SHA is in the database
|
|
|
|
|
|
|
|
for i := 0; i < l; i++ { |
|
|
|
p.QueueMessage(ethwire.NewMessage(ethwire.MsgBlockHashesTy, ethutil.ByteSliceToInterface(hashes))) |
|
|
|
if data := msg.Data.Get(i).Bytes(); p.ethereum.StateManager().BlockChain().HasBlock(data) { |
|
|
|
|
|
|
|
parent = p.ethereum.BlockChain().GetBlock(data) |
|
|
|
case ethwire.MsgGetBlocksTy: |
|
|
|
break |
|
|
|
// Limit to max 300 blocks
|
|
|
|
|
|
|
|
max := int(math.Min(float64(msg.Data.Len()), 300.0)) |
|
|
|
|
|
|
|
var blocks []interface{} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for i := 0; i < max; i++ { |
|
|
|
|
|
|
|
hash := msg.Data.Get(i).Bytes() |
|
|
|
|
|
|
|
block := p.ethereum.BlockChain().GetBlock(hash) |
|
|
|
|
|
|
|
if block != nil { |
|
|
|
|
|
|
|
blocks = append(blocks, block.Value().Raw()) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// If a parent is found send back a reply
|
|
|
|
p.QueueMessage(ethwire.NewMessage(ethwire.MsgBlockTy, blocks)) |
|
|
|
if parent != nil { |
|
|
|
|
|
|
|
peerlogger.DebugDetailf("Found canonical block, returning chain from: %x ", parent.Hash()) |
|
|
|
|
|
|
|
chain := p.ethereum.BlockChain().GetChainFromHash(parent.Hash(), amountOfBlocks) |
|
|
|
|
|
|
|
if len(chain) > 0 { |
|
|
|
|
|
|
|
//peerlogger.Debugf("Returning %d blocks: %x ", len(chain), parent.Hash())
|
|
|
|
|
|
|
|
p.QueueMessage(ethwire.NewMessage(ethwire.MsgBlockTy, chain)) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
p.QueueMessage(ethwire.NewMessage(ethwire.MsgBlockTy, []interface{}{})) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
case ethwire.MsgBlockHashesTy: |
|
|
|
//peerlogger.Debugf("Could not find a similar block")
|
|
|
|
blockPool := p.ethereum.blockPool |
|
|
|
// If no blocks are found we send back a reply with msg not in chain
|
|
|
|
|
|
|
|
// and the last hash from get chain
|
|
|
|
foundCommonHash := false |
|
|
|
if l > 0 { |
|
|
|
|
|
|
|
lastHash := msg.Data.Get(l - 1) |
|
|
|
it := msg.Data.NewIterator() |
|
|
|
//log.Printf("Sending not in chain with hash %x\n", lastHash.AsRaw())
|
|
|
|
for it.Next() { |
|
|
|
p.QueueMessage(ethwire.NewMessage(ethwire.MsgNotInChainTy, []interface{}{lastHash.Raw()})) |
|
|
|
hash := it.Value().Bytes() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if blockPool.HasCommonHash(hash) { |
|
|
|
|
|
|
|
foundCommonHash = true |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
blockPool.AddHash(hash) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p.lastReceivedHash = hash |
|
|
|
} |
|
|
|
} |
|
|
|
case ethwire.MsgNotInChainTy: |
|
|
|
|
|
|
|
peerlogger.DebugDetailf("Not in chain: %x\n", msg.Data.Get(0).Bytes()) |
|
|
|
if foundCommonHash { |
|
|
|
if p.diverted == true { |
|
|
|
p.FetchBlocks() |
|
|
|
// If were already looking for a common parent and we get here again we need to go deeper
|
|
|
|
} else { |
|
|
|
p.blocksRequested = p.blocksRequested * 2 |
|
|
|
p.FetchHashes() |
|
|
|
} |
|
|
|
} |
|
|
|
p.diverted = true |
|
|
|
case ethwire.MsgBlockTy: |
|
|
|
p.catchingUp = false |
|
|
|
blockPool := p.ethereum.blockPool |
|
|
|
p.FindCommonParentBlock() |
|
|
|
|
|
|
|
case ethwire.MsgGetTxsTy: |
|
|
|
it := msg.Data.NewIterator() |
|
|
|
// Get the current transactions of the pool
|
|
|
|
|
|
|
|
txs := p.ethereum.TxPool().CurrentTransactions() |
|
|
|
for it.Next() { |
|
|
|
// Get the RlpData values from the txs
|
|
|
|
block := ethchain.NewBlockFromRlpValue(it.Value()) |
|
|
|
txsInterface := make([]interface{}, len(txs)) |
|
|
|
blockPool.SetBlock(block) |
|
|
|
for i, tx := range txs { |
|
|
|
|
|
|
|
txsInterface[i] = tx.RlpData() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
// Broadcast it back to the peer
|
|
|
|
|
|
|
|
p.QueueMessage(ethwire.NewMessage(ethwire.MsgTxTy, txsInterface)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Unofficial but fun nonetheless
|
|
|
|
linked := blockPool.CheckLinkAndProcess(func(block *ethchain.Block) { |
|
|
|
case ethwire.MsgTalkTy: |
|
|
|
p.ethereum.StateManager().Process(block, false) |
|
|
|
peerlogger.Infoln("%v says: %s\n", p.conn.RemoteAddr(), msg.Data.Str()) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !linked { |
|
|
|
|
|
|
|
p.FetchBlocks() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
p.Stop() |
|
|
|
p.Stop() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (self *Peer) FetchBlocks() { |
|
|
|
|
|
|
|
blockPool := self.ethereum.blockPool |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hashes := blockPool.Take(100, self) |
|
|
|
|
|
|
|
if len(hashes) > 0 { |
|
|
|
|
|
|
|
self.QueueMessage(ethwire.NewMessage(ethwire.MsgGetBlocksTy, ethutil.ByteSliceToInterface(hashes))) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (self *Peer) FetchHashes() { |
|
|
|
|
|
|
|
blockPool := self.ethereum.blockPool |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self.td.Cmp(blockPool.td) >= 0 { |
|
|
|
|
|
|
|
peerlogger.Debugf("Requesting hashes from %x\n", self.lastReceivedHash) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !blockPool.HasLatestHash() { |
|
|
|
|
|
|
|
self.QueueMessage(ethwire.NewMessage(ethwire.MsgGetBlockHashesTy, []interface{}{self.lastReceivedHash, uint32(200)})) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// General update method
|
|
|
|
// General update method
|
|
|
|
func (self *Peer) update() { |
|
|
|
func (self *Peer) update() { |
|
|
|
serviceTimer := time.NewTicker(5 * time.Second) |
|
|
|
serviceTimer := time.NewTicker(5 * time.Second) |
|
|
@ -643,6 +574,7 @@ func (p *Peer) pushHandshake() error { |
|
|
|
pubkey := p.ethereum.KeyManager().PublicKey() |
|
|
|
pubkey := p.ethereum.KeyManager().PublicKey() |
|
|
|
msg := ethwire.NewMessage(ethwire.MsgHandshakeTy, []interface{}{ |
|
|
|
msg := ethwire.NewMessage(ethwire.MsgHandshakeTy, []interface{}{ |
|
|
|
uint32(ProtocolVersion), uint32(0), []byte(p.version), byte(p.caps), p.port, pubkey[1:], |
|
|
|
uint32(ProtocolVersion), uint32(0), []byte(p.version), byte(p.caps), p.port, pubkey[1:], |
|
|
|
|
|
|
|
p.ethereum.BlockChain().TD.Uint64(), p.ethereum.BlockChain().CurrentBlock.Hash(), |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
p.QueueMessage(msg) |
|
|
|
p.QueueMessage(msg) |
|
|
@ -728,10 +660,15 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) { |
|
|
|
p.SetVersion(c.Get(2).Str()) |
|
|
|
p.SetVersion(c.Get(2).Str()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get the td and last hash
|
|
|
|
|
|
|
|
p.td = c.Get(6).BigInt() |
|
|
|
|
|
|
|
p.bestHash = c.Get(7).Bytes() |
|
|
|
|
|
|
|
p.lastReceivedHash = p.bestHash |
|
|
|
|
|
|
|
|
|
|
|
p.ethereum.PushPeer(p) |
|
|
|
p.ethereum.PushPeer(p) |
|
|
|
p.ethereum.reactor.Post("peerList", p.ethereum.Peers()) |
|
|
|
p.ethereum.reactor.Post("peerList", p.ethereum.Peers()) |
|
|
|
|
|
|
|
|
|
|
|
ethlogger.Infof("Added peer (%s) %d / %d\n", p.conn.RemoteAddr(), p.ethereum.Peers().Len(), p.ethereum.MaxPeers) |
|
|
|
ethlogger.Infof("Added peer (%s) %d / %d (TD = %v ~ %x)\n", p.conn.RemoteAddr(), p.ethereum.Peers().Len(), p.ethereum.MaxPeers, p.td, p.bestHash) |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
/* |
|
|
|
// Catch up with the connected peer
|
|
|
|
// Catch up with the connected peer
|
|
|
@ -740,7 +677,12 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) { |
|
|
|
time.Sleep(10 * time.Second) |
|
|
|
time.Sleep(10 * time.Second) |
|
|
|
} |
|
|
|
} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
p.SyncWithPeerToLastKnown() |
|
|
|
//p.SyncWithPeerToLastKnown()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if p.td.Cmp(p.ethereum.BlockChain().TD) > 0 { |
|
|
|
|
|
|
|
p.ethereum.blockPool.AddHash(p.lastReceivedHash) |
|
|
|
|
|
|
|
p.FetchHashes() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
peerlogger.Debugln(p) |
|
|
|
peerlogger.Debugln(p) |
|
|
|
} |
|
|
|
} |
|
|
|