Propagate known transactions to new peers on connect

This commit is contained in:
obscuren
2015-02-04 17:28:54 -08:00
parent 292f7ada8e
commit 1d519854e2
6 changed files with 30 additions and 22 deletions

View File

@ -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...))
}