Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missed this commit #292

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions service/tbc/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"time"

"github.com/btcsuite/btcd/wire"

"github.com/hemilabs/heminetwork/version"
)

// XXX wire could use some contexts,
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 11 additions & 3 deletions service/tbc/tbc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down