Merge pull request #739 from filecoin-project/feat/static-check
some fixes from staticcheck
This commit is contained in:
commit
a45fe8a7f9
@ -6,7 +6,6 @@ import (
|
|||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Gurpartap/async"
|
"github.com/Gurpartap/async"
|
||||||
@ -61,8 +60,6 @@ type Syncer struct {
|
|||||||
|
|
||||||
self peer.ID
|
self peer.ID
|
||||||
|
|
||||||
syncLock sync.Mutex
|
|
||||||
|
|
||||||
syncmgr *SyncManager
|
syncmgr *SyncManager
|
||||||
|
|
||||||
incoming *pubsub.PubSub
|
incoming *pubsub.PubSub
|
||||||
@ -242,14 +239,6 @@ func (syncer *Syncer) InformNewBlock(from peer.ID, blk *types.FullBlock) {
|
|||||||
syncer.InformNewHead(from, fts)
|
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 {
|
func copyBlockstore(from, to bstore.Blockstore) error {
|
||||||
cids, err := from.AllKeysChan(context.TODO())
|
cids, err := from.AllKeysChan(context.TODO())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -340,59 +329,6 @@ func computeMsgMeta(bs amt.Blocks, bmsgCids, smsgCids []cbg.CBORMarshaler) (cid.
|
|||||||
return mrcid, nil
|
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) {
|
func (syncer *Syncer) FetchTipSet(ctx context.Context, p peer.ID, cids []cid.Cid) (*store.FullTipSet, error) {
|
||||||
if fts, err := syncer.tryLoadFullTipSet(cids); err == nil {
|
if fts, err := syncer.tryLoadFullTipSet(cids); err == nil {
|
||||||
return fts, nil
|
return fts, nil
|
||||||
@ -521,10 +457,6 @@ func (syncer *Syncer) minerIsValid(ctx context.Context, maddr address.Address, b
|
|||||||
return nil
|
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")
|
var ErrTemporal = errors.New("temporal error")
|
||||||
|
|
||||||
// Should match up with 'Semantical Validation' in validation.md in the spec
|
// 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 {
|
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()
|
defer span.End()
|
||||||
span.AddAttributes(
|
span.AddAttributes(
|
||||||
trace.Int64Attribute("msgCount", int64(len(msgs))),
|
trace.Int64Attribute("msgCount", int64(len(msgs))),
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"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
|
const BootstrapPeerThreshold = 2
|
||||||
@ -100,6 +100,14 @@ type syncBucketSet struct {
|
|||||||
buckets []*syncTargetBucket
|
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) {
|
func (sbs *syncBucketSet) Insert(ts *types.TipSet) {
|
||||||
for _, b := range sbs.buckets {
|
for _, b := range sbs.buckets {
|
||||||
if b.sameChainAs(ts) {
|
if b.sameChainAs(ts) {
|
||||||
@ -107,10 +115,7 @@ func (sbs *syncBucketSet) Insert(ts *types.TipSet) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sbs.buckets = append(sbs.buckets, &syncTargetBucket{
|
sbs.buckets = append(sbs.buckets, newSyncTargetBucket(ts))
|
||||||
tips: []*types.TipSet{ts},
|
|
||||||
count: 1,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sbs *syncBucketSet) Pop() *syncTargetBucket {
|
func (sbs *syncBucketSet) Pop() *syncTargetBucket {
|
||||||
@ -166,14 +171,6 @@ type syncTargetBucket struct {
|
|||||||
count int
|
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 {
|
func (stb *syncTargetBucket) sameChainAs(ts *types.TipSet) bool {
|
||||||
for _, t := range stb.tips {
|
for _, t := range stb.tips {
|
||||||
if ts.Equals(t) {
|
if ts.Equals(t) {
|
||||||
@ -231,7 +228,7 @@ func (sm *SyncManager) selectSyncTarget() (*types.TipSet, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(buckets.buckets) > 1 {
|
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.
|
// TODO: we *could* refuse to sync here without user intervention.
|
||||||
// For now, just select the best cluster
|
// For now, just select the best cluster
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,6 @@ func (m *Miner) handleUnsealed(ctx context.Context, sector SectorInfo) *sectorUp
|
|||||||
TicketBytes: ticket.TicketBytes[:],
|
TicketBytes: ticket.TicketBytes[:],
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Miner) handlePreCommitting(ctx context.Context, sector SectorInfo) *sectorUpdate {
|
func (m *Miner) handlePreCommitting(ctx context.Context, sector SectorInfo) *sectorUpdate {
|
||||||
|
Loading…
Reference in New Issue
Block a user