From 1b475ba6fe29fb7b403107b26b44f45dea4c4363 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Wed, 4 Dec 2019 17:18:30 -0800 Subject: [PATCH] some fixes from staticcheck in ./chain --- chain/sync.go | 70 +--------------------------------------- chain/sync_manager.go | 25 +++++++------- storage/sector_states.go | 1 - 3 files changed, 12 insertions(+), 84 deletions(-) diff --git a/chain/sync.go b/chain/sync.go index 06b0c71f0..9d9e799f1 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -6,7 +6,6 @@ import ( "crypto/sha256" "errors" "fmt" - "sync" "time" "github.com/Gurpartap/async" @@ -61,8 +60,6 @@ type Syncer struct { self peer.ID - syncLock sync.Mutex - syncmgr *SyncManager incoming *pubsub.PubSub @@ -242,14 +239,6 @@ func (syncer *Syncer) InformNewBlock(from peer.ID, blk *types.FullBlock) { syncer.InformNewHead(from, fts) } -func reverse(tips []*types.TipSet) []*types.TipSet { - out := make([]*types.TipSet, len(tips)) - for i := 0; i < len(tips); i++ { - out[i] = tips[len(tips)-(i+1)] - } - return out -} - func copyBlockstore(from, to bstore.Blockstore) error { cids, err := from.AllKeysChan(context.TODO()) if err != nil { @@ -340,59 +329,6 @@ func computeMsgMeta(bs amt.Blocks, bmsgCids, smsgCids []cbg.CBORMarshaler) (cid. return mrcid, nil } -func (syncer *Syncer) selectHead(ctx context.Context, heads map[peer.ID]*types.TipSet) (*types.TipSet, error) { - var headsArr []*types.TipSet - for _, ts := range heads { - headsArr = append(headsArr, ts) - } - - sel := headsArr[0] - for i := 1; i < len(headsArr); i++ { - cur := headsArr[i] - - yes, err := syncer.store.IsAncestorOf(cur, sel) - if err != nil { - return nil, err - } - if yes { - continue - } - - yes, err = syncer.store.IsAncestorOf(sel, cur) - if err != nil { - return nil, err - } - if yes { - sel = cur - continue - } - - nca, err := syncer.store.NearestCommonAncestor(cur, sel) - if err != nil { - return nil, err - } - - if sel.Height()-nca.Height() > build.ForkLengthThreshold { - // TODO: handle this better than refusing to sync - return nil, fmt.Errorf("Conflict exists in heads set") - } - - curw, err := syncer.store.Weight(ctx, cur) - if err != nil { - return nil, err - } - selw, err := syncer.store.Weight(ctx, sel) - if err != nil { - return nil, err - } - - if curw.GreaterThan(selw) { - sel = cur - } - } - return sel, nil -} - func (syncer *Syncer) FetchTipSet(ctx context.Context, p peer.ID, cids []cid.Cid) (*store.FullTipSet, error) { if fts, err := syncer.tryLoadFullTipSet(cids); err == nil { return fts, nil @@ -521,10 +457,6 @@ func (syncer *Syncer) minerIsValid(ctx context.Context, maddr address.Address, b return nil } -func (syncer *Syncer) validateTicket(ctx context.Context, maddr, mworker address.Address, ticket *types.Ticket, base *types.TipSet) error { - return gen.VerifyVRF(ctx, mworker, maddr, gen.DSepTicket, base.MinTicket().VRFProof, ticket.VRFProof) -} - var ErrTemporal = errors.New("temporal error") // Should match up with 'Semantical Validation' in validation.md in the spec @@ -829,7 +761,7 @@ func (syncer *Syncer) checkBlockMessages(ctx context.Context, b *types.FullBlock } func (syncer *Syncer) verifyBlsAggregate(ctx context.Context, sig types.Signature, msgs []cid.Cid, pubks []bls.PublicKey) error { - ctx, span := trace.StartSpan(ctx, "syncer.verifyBlsAggregate") + _, span := trace.StartSpan(ctx, "syncer.verifyBlsAggregate") defer span.End() span.AddAttributes( trace.Int64Attribute("msgCount", int64(len(msgs))), diff --git a/chain/sync_manager.go b/chain/sync_manager.go index 104ca674c..8a81e4781 100644 --- a/chain/sync_manager.go +++ b/chain/sync_manager.go @@ -6,7 +6,7 @@ import ( "sync" "github.com/filecoin-project/lotus/chain/types" - peer "github.com/libp2p/go-libp2p-peer" + peer "github.com/libp2p/go-libp2p-core/peer" ) const BootstrapPeerThreshold = 2 @@ -100,6 +100,14 @@ type syncBucketSet struct { buckets []*syncTargetBucket } +func newSyncTargetBucket(tipsets ...*types.TipSet) *syncTargetBucket { + var stb syncTargetBucket + for _, ts := range tipsets { + stb.add(ts) + } + return &stb +} + func (sbs *syncBucketSet) Insert(ts *types.TipSet) { for _, b := range sbs.buckets { if b.sameChainAs(ts) { @@ -107,10 +115,7 @@ func (sbs *syncBucketSet) Insert(ts *types.TipSet) { return } } - sbs.buckets = append(sbs.buckets, &syncTargetBucket{ - tips: []*types.TipSet{ts}, - count: 1, - }) + sbs.buckets = append(sbs.buckets, newSyncTargetBucket(ts)) } func (sbs *syncBucketSet) Pop() *syncTargetBucket { @@ -166,14 +171,6 @@ type syncTargetBucket struct { count int } -func newSyncTargetBucket(tipsets ...*types.TipSet) *syncTargetBucket { - var stb syncTargetBucket - for _, ts := range tipsets { - stb.add(ts) - } - return &stb -} - func (stb *syncTargetBucket) sameChainAs(ts *types.TipSet) bool { for _, t := range stb.tips { if ts.Equals(t) { @@ -231,7 +228,7 @@ func (sm *SyncManager) selectSyncTarget() (*types.TipSet, error) { } if len(buckets.buckets) > 1 { - log.Warning("caution, multiple distinct chains seen during head selections") + log.Warn("caution, multiple distinct chains seen during head selections") // TODO: we *could* refuse to sync here without user intervention. // For now, just select the best cluster } diff --git a/storage/sector_states.go b/storage/sector_states.go index ef555a061..4790447e9 100644 --- a/storage/sector_states.go +++ b/storage/sector_states.go @@ -84,7 +84,6 @@ func (m *Miner) handleUnsealed(ctx context.Context, sector SectorInfo) *sectorUp TicketBytes: ticket.TicketBytes[:], } }) - } func (m *Miner) handlePreCommitting(ctx context.Context, sector SectorInfo) *sectorUpdate {