fix(blockchain): handle sync setup errors explicitly
Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
parent
2f3f46e8c5
commit
7e01df15fe
1 changed files with 11 additions and 6 deletions
17
sync_loop.go
17
sync_loop.go
|
|
@ -60,13 +60,18 @@ func runChainSyncOnce(ctx context.Context, blockchain *chain.Chain, chainConfig
|
|||
}
|
||||
defer conn.Close()
|
||||
|
||||
levinConnection := levin.NewConnection(conn)
|
||||
p2pConn := levin.NewConnection(conn)
|
||||
|
||||
var peerIDBytes [8]byte
|
||||
rand.Read(peerIDBytes[:])
|
||||
if _, err := rand.Read(peerIDBytes[:]); err != nil {
|
||||
return coreerr.E("runChainSyncOnce", "generate peer id", err)
|
||||
}
|
||||
peerID := binary.LittleEndian.Uint64(peerIDBytes[:])
|
||||
|
||||
localHeight, _ := blockchain.Height()
|
||||
localHeight, err := blockchain.Height()
|
||||
if err != nil {
|
||||
return coreerr.E("runChainSyncOnce", "get local height", err)
|
||||
}
|
||||
|
||||
handshakeRequest := p2p.HandshakeRequest{
|
||||
NodeData: p2p.NodeData{
|
||||
|
|
@ -85,11 +90,11 @@ func runChainSyncOnce(ctx context.Context, blockchain *chain.Chain, chainConfig
|
|||
if err != nil {
|
||||
return coreerr.E("runChainSyncOnce", "encode handshake", err)
|
||||
}
|
||||
if err := levinConnection.WritePacket(p2p.CommandHandshake, payload, true); err != nil {
|
||||
if err := p2pConn.WritePacket(p2p.CommandHandshake, payload, true); err != nil {
|
||||
return coreerr.E("runChainSyncOnce", "write handshake", err)
|
||||
}
|
||||
|
||||
packetHeader, packetData, err := levinConnection.ReadPacket()
|
||||
packetHeader, packetData, err := p2pConn.ReadPacket()
|
||||
if err != nil {
|
||||
return coreerr.E("runChainSyncOnce", "read handshake", err)
|
||||
}
|
||||
|
|
@ -111,7 +116,7 @@ func runChainSyncOnce(ctx context.Context, blockchain *chain.Chain, chainConfig
|
|||
ClientVersion: config.ClientVersion,
|
||||
NonPruningMode: true,
|
||||
}
|
||||
p2pConnection := chain.NewLevinP2PConn(levinConnection, handshakeResponse.PayloadData.CurrentHeight, localSyncData)
|
||||
p2pConnection := chain.NewLevinP2PConn(p2pConn, handshakeResponse.PayloadData.CurrentHeight, localSyncData)
|
||||
|
||||
return blockchain.P2PSync(ctx, p2pConnection, opts)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue