Merge pull request #1548 from chaosma/state_sync

close connection after pushnewblock error
pull/1552/head
chaosma 5 years ago committed by GitHub
commit 370b8fc2ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      api/service/syncing/downloader/client.go
  2. 7
      node/node_syncing.go

@ -89,7 +89,7 @@ func (client *Client) Register(hash []byte, ip, port string) *pb.DownloaderRespo
} }
// PushNewBlock will send the lastest verified block to registered nodes // PushNewBlock will send the lastest verified block to registered nodes
func (client *Client) PushNewBlock(selfPeerHash [20]byte, blockHash []byte, timeout bool) *pb.DownloaderResponse { func (client *Client) PushNewBlock(selfPeerHash [20]byte, blockHash []byte, timeout bool) (*pb.DownloaderResponse, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel() defer cancel()
@ -107,7 +107,7 @@ func (client *Client) PushNewBlock(selfPeerHash [20]byte, blockHash []byte, time
if err != nil { if err != nil {
utils.Logger().Error().Err(err).Str("target", client.conn.Target()).Msg("[SYNC] unable to send new block to unsync node") utils.Logger().Error().Err(err).Str("target", client.conn.Target()).Msg("[SYNC] unable to send new block to unsync node")
} }
return response return response, err
} }
// GetBlockChainHeight gets the blockheight from peer // GetBlockChainHeight gets the blockheight from peer

@ -296,7 +296,12 @@ func (node *Node) SendNewBlockToUnsync() {
delete(node.peerRegistrationRecord, peerID) delete(node.peerRegistrationRecord, peerID)
continue continue
} }
response := config.client.PushNewBlock(node.GetSyncID(), blockHash, false) response, err := config.client.PushNewBlock(node.GetSyncID(), blockHash, false)
// close the connection if cannot push new block to unsync node
if err != nil {
node.peerRegistrationRecord[peerID].client.Close()
delete(node.peerRegistrationRecord, peerID)
}
if response != nil && response.Type == downloader_pb.DownloaderResponse_INSYNC { if response != nil && response.Type == downloader_pb.DownloaderResponse_INSYNC {
node.peerRegistrationRecord[peerID].client.Close() node.peerRegistrationRecord[peerID].client.Close()
delete(node.peerRegistrationRecord, peerID) delete(node.peerRegistrationRecord, peerID)

Loading…
Cancel
Save