diff options
Diffstat (limited to 'eth')
-rw-r--r-- | eth/backend.go | 15 | ||||
-rw-r--r-- | eth/block_pool.go | 6 | ||||
-rw-r--r-- | eth/protocol.go | 14 | ||||
-rw-r--r-- | eth/protocol_test.go | 2 |
4 files changed, 23 insertions, 14 deletions
diff --git a/eth/backend.go b/eth/backend.go index b7b5c5f85..43e757435 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -17,10 +17,6 @@ import ( "github.com/ethereum/go-ethereum/whisper" ) -const ( - seedNodeAddress = "poc-8.ethdev.com:30303" -) - type Config struct { Name string Version string @@ -141,14 +137,13 @@ func New(config *Config) (*Ethereum, error) { if err != nil { return nil, err } - fmt.Println(nat) eth.net = &p2p.Server{ Identity: clientId, MaxPeers: config.MaxPeers, Protocols: protocols, Blacklist: eth.blacklist, - NAT: p2p.UPNP(), + NAT: nat, NoDial: !config.Dial, } @@ -224,7 +219,7 @@ func (s *Ethereum) Coinbase() []byte { } // Start the ethereum -func (s *Ethereum) Start(seed bool) error { +func (s *Ethereum) Start(seedNode string) error { err := s.net.Start() if err != nil { return err @@ -247,9 +242,9 @@ func (s *Ethereum) Start(seed bool) error { go s.blockBroadcastLoop() // TODO: read peers here - if seed { - logger.Infof("Connect to seed node %v", seedNodeAddress) - if err := s.SuggestPeer(seedNodeAddress); err != nil { + if len(seedNode) > 0 { + logger.Infof("Connect to seed node %v", seedNode) + if err := s.SuggestPeer(seedNode); err != nil { logger.Infoln(err) } } diff --git a/eth/block_pool.go b/eth/block_pool.go index b624d064a..13016c694 100644 --- a/eth/block_pool.go +++ b/eth/block_pool.go @@ -636,12 +636,12 @@ func (self *BlockPool) AddBlock(block *types.Block, peerId string) { // validate block for PoW if !self.verifyPoW(block) { - poolLogger.Warnf("invalid pow on block [%s] by peer %s", name(hash), peerId) + poolLogger.Warnf("invalid pow on block [%s %v] by peer %s", name(hash), block.Number(), peerId) self.peerError(peerId, ErrInvalidPoW, "%x", hash) return } } - poolLogger.Debugf("added block [%s] sent by peer %s", name(hash), peerId) + poolLogger.DebugDetailf("added block [%s] sent by peer %s", name(hash), peerId) node.block = block node.blockBy = peerId @@ -1098,7 +1098,7 @@ func (self *BlockPool) requestBlocks(attempts int, hashes [][]byte) { poolLogger.Debugf("request %v missing blocks from %v/%v peers: chosen %v", len(hashes), repetitions, peerCount, indexes) for _, peer := range self.peers { if i == indexes[0] { - poolLogger.Debugf("request %v missing blocks from peer %s", len(hashes), peer.id) + poolLogger.Debugf("request %v missing blocks [%x/%x] from peer %s", len(hashes), hashes[0][:4], hashes[len(hashes)-1][:4], peer.id) peer.requestBlocks(hashes) indexes = indexes[1:] if len(indexes) == 0 { diff --git a/eth/protocol.go b/eth/protocol.go index 24a0f0a8e..d7a7fa910 100644 --- a/eth/protocol.go +++ b/eth/protocol.go @@ -13,7 +13,7 @@ import ( ) const ( - ProtocolVersion = 51 + ProtocolVersion = 52 NetworkId = 0 ProtocolLength = uint64(8) ProtocolMaxMsgSize = 10 * 1024 * 1024 @@ -46,6 +46,7 @@ type ethProtocol struct { // used as an argument to EthProtocol type txPool interface { AddTransactions([]*types.Transaction) + GetTransactions() types.Transactions } type chainManager interface { @@ -101,6 +102,7 @@ func runEthProtocol(txPool txPool, chainManager chainManager, blockPool blockPoo } err = self.handleStatus() if err == nil { + self.propagateTxs() for { err = self.handle() if err != nil { @@ -324,3 +326,13 @@ func (self *ethProtocol) protoErrorDisconnect(code int, format string, params .. } } + +func (self *ethProtocol) propagateTxs() { + transactions := self.txPool.GetTransactions() + iface := make([]interface{}, len(transactions)) + for i, transaction := range transactions { + iface[i] = transaction + } + + self.rw.WriteMsg(p2p.NewMsg(TxMsg, iface...)) +} diff --git a/eth/protocol_test.go b/eth/protocol_test.go index 224b59abd..1fe6d8f6b 100644 --- a/eth/protocol_test.go +++ b/eth/protocol_test.go @@ -80,6 +80,8 @@ func (self *testTxPool) AddTransactions(txs []*types.Transaction) { } } +func (self *testTxPool) GetTransactions() types.Transactions { return nil } + func (self *testChainManager) GetBlockHashesFromHash(hash []byte, amount uint64) (hashes [][]byte) { if self.getBlockHashes != nil { hashes = self.getBlockHashes(hash, amount) |