Fix mining with no peers
This commit is contained in:
parent
236aa6107a
commit
5ef145463a
@ -207,20 +207,18 @@ func (bs *BlockSync) getPeers() []peer.ID {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bs *BlockSync) processStatus(req *BlockSyncRequest, res *BlockSyncResponse) ([]*types.TipSet, error) {
|
func (bs *BlockSync) processStatus(req *BlockSyncRequest, res *BlockSyncResponse) error {
|
||||||
switch res.Status {
|
switch res.Status {
|
||||||
case 0: // Success
|
|
||||||
return bs.processBlocksResponse(req, res)
|
|
||||||
case 101: // Partial Response
|
case 101: // Partial Response
|
||||||
panic("not handled")
|
panic("not handled")
|
||||||
case 201: // req.Start not found
|
case 201: // req.Start not found
|
||||||
return nil, fmt.Errorf("not found")
|
return fmt.Errorf("not found")
|
||||||
case 202: // Go Away
|
case 202: // Go Away
|
||||||
panic("not handled")
|
panic("not handled")
|
||||||
case 203: // Internal Error
|
case 203: // Internal Error
|
||||||
return nil, fmt.Errorf("block sync peer errored: %s", res.Message)
|
return fmt.Errorf("block sync peer errored: %s", res.Message)
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unrecognized response code")
|
return fmt.Errorf("unrecognized response code")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,18 +234,17 @@ func (bs *BlockSync) GetBlocks(ctx context.Context, tipset []cid.Cid, count int)
|
|||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
var res *BlockSyncResponse
|
|
||||||
for _, p := range perm {
|
for _, p := range perm {
|
||||||
res, err = bs.sendRequestToPeer(ctx, peers[p], req)
|
res, err := bs.sendRequestToPeer(ctx, peers[p], req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("BlockSync request failed for peer %s: %s", peers[p].String(), err)
|
log.Warnf("BlockSync request failed for peer %s: %s", peers[p].String(), err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
ts, err := bs.processStatus(req, res)
|
if res.Status == 0 {
|
||||||
if err == nil {
|
return bs.processBlocksResponse(req, res)
|
||||||
return ts, nil
|
|
||||||
}
|
}
|
||||||
|
err = bs.processStatus(req, res)
|
||||||
}
|
}
|
||||||
return nil, xerrors.Errorf("GetBlocks failed with all peers: %w", err)
|
return nil, xerrors.Errorf("GetBlocks failed with all peers: %w", err)
|
||||||
}
|
}
|
||||||
@ -298,25 +295,22 @@ func (bs *BlockSync) GetChainMessages(ctx context.Context, h *types.TipSet, coun
|
|||||||
Options: BSOptMessages,
|
Options: BSOptMessages,
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := bs.sendRequestToPeer(ctx, peers[perm[0]], req)
|
var err error
|
||||||
if err != nil {
|
for _, p := range perm {
|
||||||
return nil, err
|
res, err := bs.sendRequestToPeer(ctx, peers[p], req)
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("BlockSync request failed for peer %s: %s", peers[p].String(), err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if res.Status == 0 {
|
||||||
|
return res.Chain, nil
|
||||||
|
}
|
||||||
|
err = bs.processStatus(req, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch res.Status {
|
// TODO: What if we have no peers (and err is nil)?
|
||||||
case 0: // Success
|
return nil, xerrors.Errorf("GetChainMessages failed with all peers: %w", err)
|
||||||
return res.Chain, nil
|
|
||||||
case 101: // Partial Response
|
|
||||||
panic("not handled")
|
|
||||||
case 201: // req.Start not found
|
|
||||||
return nil, fmt.Errorf("not found")
|
|
||||||
case 202: // Go Away
|
|
||||||
panic("not handled")
|
|
||||||
case 203: // Internal Error
|
|
||||||
return nil, fmt.Errorf("block sync peer errored: %s", res.Message)
|
|
||||||
default:
|
|
||||||
return nil, fmt.Errorf("unrecognized response code")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func bstsToFullTipSet(bts *BSTipSet) (*store.FullTipSet, error) {
|
func bstsToFullTipSet(bts *BSTipSet) (*store.FullTipSet, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user