Skip to content

Commit

Permalink
Merge pull request #293 from koinos/disconnect-on-no-rpc-protocol
Browse files Browse the repository at this point in the history
Assign chain ID mismatch naughty points if we cannot retrieve the pee…
  • Loading branch information
sgerbino authored Jun 7, 2024
2 parents 442fa37 + af75774 commit 0b2f271
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/koinos-p2p/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const (
// Version display values
const (
DisplayAppName = "Koinos P2P"
Version = "v1.1.0"
Version = "v1.1.1"
)

// Gets filled in by the linker
Expand Down
8 changes: 4 additions & 4 deletions internal/p2p/connection_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (c *ConnectionManager) handleConnected(ctx context.Context, msg connectionM
pid := msg.conn.RemotePeer()
s := fmt.Sprintf("%s/p2p/%s", msg.conn.RemoteMultiaddr(), pid)

log.Infof("Connected to peer: %s", s)
log.Debugf("Connected to peer: %s", s)

if _, ok := c.connectedPeers[pid]; !ok {
childCtx, cancel := context.WithCancel(ctx)
Expand Down Expand Up @@ -200,16 +200,16 @@ func (c *ConnectionManager) handleDisconnected(ctx context.Context, msg connecti
}

s := fmt.Sprintf("%s/p2p/%s", msg.conn.RemoteMultiaddr(), msg.conn.RemotePeer())
log.Infof("Disconnected from peer: %s", s)
log.Debugf("Disconnected from peer: %s", s)

if addr, ok := c.initialPeers[pid]; ok {
go func() {
sleepTimeSeconds := 1
for {
log.Infof("Attempting to connect to peer %v", addr.ID)
log.Infof("Attempting to connect to seed %v", addr.ID)
err := c.host.Connect(ctx, addr)
if err != nil {
log.Infof("Error connecting to peer %v: %s", addr.ID, err)
log.Infof("Error connecting to seed %v: %s", addr.ID, err)
} else {
return
}
Expand Down
4 changes: 3 additions & 1 deletion internal/p2p/error_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ func (p *PeerErrorHandler) handleError(ctx context.Context, peerErr PeerError) {
}
}

log.Infof("Encountered peer error: %s, %s. Current error score: %v", peerErr.id, peerErr.err.Error(), p.errorScores[ipAddr].score)
if !errors.Is(peerErr.err, p2perrors.ErrChainIDMismatch) {
log.Infof("Encountered peer error: %s, %s. Current error score: %v", peerErr.id, peerErr.err.Error(), p.errorScores[ipAddr].score)
}

if p.errorScores[ipAddr].score >= p.opts.ErrorScoreThreshold {
go func() {
Expand Down
2 changes: 1 addition & 1 deletion internal/p2p/peer_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (p *PeerConnection) handshake(ctx context.Context) error {
defer cancelPeerGetChainID()
peerChainID, err := p.peerRPC.GetChainID(rpcContext)
if err != nil {
return err
return p2perrors.ErrChainIDMismatch
}

if !bytes.Equal(myChainID.ChainId, peerChainID) {
Expand Down

0 comments on commit 0b2f271

Please sign in to comment.