diff --git a/service/tbc/peer.go b/service/tbc/peer.go index 582258f0..98d8101a 100644 --- a/service/tbc/peer.go +++ b/service/tbc/peer.go @@ -14,6 +14,8 @@ import ( "time" "github.com/btcsuite/btcd/wire" + + "github.com/hemilabs/heminetwork/version" ) // XXX wire could use some contexts, @@ -118,6 +120,7 @@ func (p *peer) handshake(ctx context.Context, conn net.Conn) error { us := &wire.NetAddress{Timestamp: time.Now()} them := &wire.NetAddress{Timestamp: time.Now()} msg := wire.NewMsgVersion(us, them, rand.Uint64(), 0) + msg.UserAgent = fmt.Sprintf("/%v:%v/", version.Component, version.String()) err := writeTimeout(defaultHandshakeTimeout, conn, msg, p.protocolVersion, p.network) if err != nil { return fmt.Errorf("could not write version message: %w", err) diff --git a/service/tbc/tbc.go b/service/tbc/tbc.go index 878c8618..79230182 100644 --- a/service/tbc/tbc.go +++ b/service/tbc/tbc.go @@ -282,6 +282,11 @@ func (s *Server) mempoolPeer(ctx context.Context, p *peer) { return } + // Don't ask for mempool if the other end does not advertise it. + if !p.remoteVersion.HasService(wire.SFNodeBloom) { + return + } + err := p.write(defaultCmdTimeout, wire.NewMsgMemPool()) if err != nil { log.Debugf("mempool %v: %v", p, err) @@ -694,8 +699,9 @@ func (s *Server) handlePeer(ctx context.Context, p *peer) error { return err } - // If we are caught up and start collecting mempool data. - if s.cfg.MempoolEnabled && s.Synced(ctx).Synced { + // If we are caught up start collecting mempool data. + if s.cfg.MempoolEnabled && p.remoteVersion.HasService(wire.SFNodeBloom) && + s.Synced(ctx).Synced { err := p.write(defaultCmdTimeout, wire.NewMsgMemPool()) if err != nil { return fmt.Errorf("mempool %v: %w", p, err) @@ -707,7 +713,9 @@ func (s *Server) handlePeer(ctx context.Context, p *peer) error { // Only now can we consider the peer connected verbose := false - log.Infof("connected: %v", p) + log.Infof("connected: %v version %v agent %v", p, + p.remoteVersion.ProtocolVersion, + p.remoteVersion.UserAgent) defer log.Debugf("disconnect: %v", p) for { // See if we were interrupted, for the love of pete add ctx to wire