From 28b470cb0d1b02331387c0071d914a044094f633 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Mon, 16 Dec 2019 22:15:06 -0800 Subject: [PATCH] blocksync tagging --- chain/blocksync/blocksync_client.go | 11 ++++++++++- node/builder.go | 4 +++- node/modules/lp2p/libp2p.go | 8 +++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/chain/blocksync/blocksync_client.go b/chain/blocksync/blocksync_client.go index c86a71801..de0a3a96e 100644 --- a/chain/blocksync/blocksync_client.go +++ b/chain/blocksync/blocksync_client.go @@ -101,8 +101,13 @@ func (bs *BlockSync) GetBlocks(ctx context.Context, tsk types.TipSetKey, count i } 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)) - return bs.processBlocksResponse(req, res) + bs.host.ConnManager().TagPeer(p, "bsync", 2) + return resp, nil } oerr = bs.processStatus(req, res) 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) { + if len(res.Chain) == 0 { + return nil, xerrors.Errorf("got no blocks in successful blocksync response") + } + cur, err := types.NewTipSet(res.Chain[0].Blocks) if err != nil { return nil, err diff --git a/node/builder.go b/node/builder.go index 96599df8c..ba7a7daa0 100644 --- a/node/builder.go +++ b/node/builder.go @@ -155,7 +155,9 @@ func libp2p() Option { Override(new(routing.Routing), lp2p.Routing), 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()), diff --git a/node/modules/lp2p/libp2p.go b/node/modules/lp2p/libp2p.go index e50c8a922..ab616ce59 100644 --- a/node/modules/lp2p/libp2p.go +++ b/node/modules/lp2p/libp2p.go @@ -69,13 +69,15 @@ func ConnectionManager(low, high int, grace time.Duration, protected []string) f for _, p := range protected { pid, err := peer.IDFromString(p) 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") } - opts.Opts = append(opts.Opts, libp2p.ConnectionManager(cm)) - return + + return Libp2pOpts{ + Opts: []libp2p.Option{libp2p.ConnectionManager(cm)}, + }, nil } }