blocksync tagging
This commit is contained in:
parent
eb4077b1af
commit
28b470cb0d
@ -101,8 +101,13 @@ func (bs *BlockSync) GetBlocks(ctx context.Context, tsk types.TipSetKey, count i
|
|||||||
}
|
}
|
||||||
|
|
||||||
if res.Status == 0 {
|
if res.Status == 0 {
|
||||||
|
resp, err := bs.processBlocksResponse(req, res)
|
||||||
|
if err != nil {
|
||||||
|
return nil, xerrors.Errorf("success response from peer failed to process: %w", err)
|
||||||
|
}
|
||||||
bs.syncPeers.logGlobalSuccess(time.Since(start))
|
bs.syncPeers.logGlobalSuccess(time.Since(start))
|
||||||
return bs.processBlocksResponse(req, res)
|
bs.host.ConnManager().TagPeer(p, "bsync", 2)
|
||||||
|
return resp, nil
|
||||||
}
|
}
|
||||||
oerr = bs.processStatus(req, res)
|
oerr = bs.processStatus(req, res)
|
||||||
if oerr != nil {
|
if oerr != nil {
|
||||||
@ -264,6 +269,10 @@ func (bs *BlockSync) sendRequestToPeer(ctx context.Context, p peer.ID, req *Bloc
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (bs *BlockSync) processBlocksResponse(req *BlockSyncRequest, res *BlockSyncResponse) ([]*types.TipSet, error) {
|
func (bs *BlockSync) processBlocksResponse(req *BlockSyncRequest, res *BlockSyncResponse) ([]*types.TipSet, error) {
|
||||||
|
if len(res.Chain) == 0 {
|
||||||
|
return nil, xerrors.Errorf("got no blocks in successful blocksync response")
|
||||||
|
}
|
||||||
|
|
||||||
cur, err := types.NewTipSet(res.Chain[0].Blocks)
|
cur, err := types.NewTipSet(res.Chain[0].Blocks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -155,7 +155,9 @@ func libp2p() Option {
|
|||||||
Override(new(routing.Routing), lp2p.Routing),
|
Override(new(routing.Routing), lp2p.Routing),
|
||||||
|
|
||||||
Override(NatPortMapKey, lp2p.NatPortMap),
|
Override(NatPortMapKey, lp2p.NatPortMap),
|
||||||
Override(ConnectionManagerKey, lp2p.ConnectionManager(50, 200, 20*time.Second)),
|
|
||||||
|
// TODO: how do i pass config.Libp2p.ProtectedPeers here?
|
||||||
|
Override(ConnectionManagerKey, lp2p.ConnectionManager(50, 200, 20*time.Second, nil)),
|
||||||
|
|
||||||
Override(new(*pubsub.PubSub), lp2p.GossipSub()),
|
Override(new(*pubsub.PubSub), lp2p.GossipSub()),
|
||||||
|
|
||||||
|
@ -69,13 +69,15 @@ func ConnectionManager(low, high int, grace time.Duration, protected []string) f
|
|||||||
for _, p := range protected {
|
for _, p := range protected {
|
||||||
pid, err := peer.IDFromString(p)
|
pid, err := peer.IDFromString(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("failed to parse peer ID in protected peers array: %w", err)
|
return Libp2pOpts{}, xerrors.Errorf("failed to parse peer ID in protected peers array: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cm.Protect(pid, "config-prot")
|
cm.Protect(pid, "config-prot")
|
||||||
}
|
}
|
||||||
opts.Opts = append(opts.Opts, libp2p.ConnectionManager(cm))
|
|
||||||
return
|
return Libp2pOpts{
|
||||||
|
Opts: []libp2p.Option{libp2p.ConnectionManager(cm)},
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user