From 613a0a05a0577eec8d969d67b5dd17cbb986887e Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Wed, 4 Dec 2019 18:04:09 -0800 Subject: [PATCH] more of that sweet staticcheck goodness --- chain/actors/actor_storagepower.go | 4 ++-- chain/actors/actors.go | 2 +- chain/blocksync/blocksync.go | 2 +- chain/blocksync/blocksync_client.go | 5 ++--- chain/gen/gen.go | 4 +--- chain/gen/utils.go | 2 +- chain/messagepool/messagepool.go | 12 ++++-------- chain/vm/vm.go | 2 +- cmd/lotus/main.go | 1 - miner/miner.go | 2 +- node/repo/fsrepo.go | 1 - peermgr/peermgr.go | 2 +- retrieval/client.go | 3 +++ storage/miner.go | 5 ----- 14 files changed, 18 insertions(+), 29 deletions(-) diff --git a/chain/actors/actor_storagepower.go b/chain/actors/actor_storagepower.go index c3ee5530c..53d021b11 100644 --- a/chain/actors/actor_storagepower.go +++ b/chain/actors/actor_storagepower.go @@ -747,10 +747,10 @@ func MinerSetRemove(ctx context.Context, vmctx types.VMContext, rcid cid.Cid, ma mkey := string(maddr.Bytes()) switch nd.Delete(ctx, mkey) { - case hamt.ErrNotFound: - return cid.Undef, aerrors.New(1, "miner not found in set on delete") default: return cid.Undef, aerrors.HandleExternalError(err, "failed to delete miner from set") + case hamt.ErrNotFound: + return cid.Undef, aerrors.New(1, "miner not found in set on delete") case nil: } diff --git a/chain/actors/actors.go b/chain/actors/actors.go index 19de6a383..5208286a3 100644 --- a/chain/actors/actors.go +++ b/chain/actors/actors.go @@ -32,7 +32,7 @@ func mustIDAddress(i uint64) address.Address { } func init() { - pref := cid.NewPrefixV1(cid.Raw, mh.ID) + pref := cid.NewPrefixV1(cid.Raw, mh.IDENTITY) mustSum := func(s string) cid.Cid { c, err := pref.Sum([]byte(s)) if err != nil { diff --git a/chain/blocksync/blocksync.go b/chain/blocksync/blocksync.go index 873426d0b..a16bc78b0 100644 --- a/chain/blocksync/blocksync.go +++ b/chain/blocksync/blocksync.go @@ -108,7 +108,7 @@ func (bss *BlockSyncService) HandleStream(s inet.Stream) { } func (bss *BlockSyncService) processRequest(ctx context.Context, req *BlockSyncRequest) (*BlockSyncResponse, error) { - ctx, span := trace.StartSpan(ctx, "blocksync.ProcessRequest") + _, span := trace.StartSpan(ctx, "blocksync.ProcessRequest") defer span.End() opts := ParseBSOptions(req.Options) diff --git a/chain/blocksync/blocksync_client.go b/chain/blocksync/blocksync_client.go index 32c810511..127808092 100644 --- a/chain/blocksync/blocksync_client.go +++ b/chain/blocksync/blocksync_client.go @@ -12,9 +12,9 @@ import ( blocks "github.com/ipfs/go-block-format" bserv "github.com/ipfs/go-blockservice" "github.com/ipfs/go-cid" + host "github.com/libp2p/go-libp2p-core/host" inet "github.com/libp2p/go-libp2p-core/network" "github.com/libp2p/go-libp2p-core/peer" - host "github.com/libp2p/go-libp2p-host" "go.opencensus.io/trace" "golang.org/x/xerrors" @@ -28,8 +28,7 @@ type BlockSync struct { bserv bserv.BlockService host host.Host - syncPeersLk sync.Mutex - syncPeers *bsPeerTracker + syncPeers *bsPeerTracker } func NewBlockSyncClient(bserv dtypes.ChainBlockService, h host.Host) *BlockSync { diff --git a/chain/gen/gen.go b/chain/gen/gen.go index 059db2be5..9c8bfadfb 100644 --- a/chain/gen/gen.go +++ b/chain/gen/gen.go @@ -15,7 +15,7 @@ import ( "github.com/ipfs/go-car" offline "github.com/ipfs/go-ipfs-exchange-offline" "github.com/ipfs/go-merkledag" - peer "github.com/libp2p/go-libp2p-peer" + peer "github.com/libp2p/go-libp2p-core/peer" "go.opencensus.io/trace" "golang.org/x/xerrors" @@ -42,8 +42,6 @@ var log = logging.Logger("gen") const msgsPerBlock = 20 type ChainGen struct { - accounts []address.Address - msgsPerBlock int bs blockstore.Blockstore diff --git a/chain/gen/utils.go b/chain/gen/utils.go index dc4589585..34cdce95b 100644 --- a/chain/gen/utils.go +++ b/chain/gen/utils.go @@ -11,7 +11,7 @@ import ( hamt "github.com/ipfs/go-hamt-ipld" blockstore "github.com/ipfs/go-ipfs-blockstore" bstore "github.com/ipfs/go-ipfs-blockstore" - peer "github.com/libp2p/go-libp2p-peer" + peer "github.com/libp2p/go-libp2p-core/peer" cbg "github.com/whyrusleeping/cbor-gen" "golang.org/x/xerrors" diff --git a/chain/messagepool/messagepool.go b/chain/messagepool/messagepool.go index 369be86f6..1d0f3eb45 100644 --- a/chain/messagepool/messagepool.go +++ b/chain/messagepool/messagepool.go @@ -59,8 +59,7 @@ type MessagePool struct { localAddrs map[address.Address]struct{} - pending map[address.Address]*msgSet - pendingCount int + pending map[address.Address]*msgSet curTsLk sync.Mutex // DO NOT LOCK INSIDE lk curTs *types.TipSet @@ -79,9 +78,8 @@ type MessagePool struct { } type msgSet struct { - msgs map[uint64]*types.SignedMessage - nextNonce uint64 - curBalance types.BigInt + msgs map[uint64]*types.SignedMessage + nextNonce uint64 } func newMsgSet() *msgSet { @@ -572,9 +570,7 @@ func (mp *MessagePool) MessagesForBlocks(blks []*types.BlockHeader) ([]*types.Si if err != nil { return nil, xerrors.Errorf("failed to get messages for apply block %s(height %d) (msgroot = %s): %w", b.Cid(), b.Height, b.Messages, err) } - for _, msg := range smsgs { - out = append(out, msg) - } + out = append(out, smsgs...) for _, msg := range bmsgs { smsg := mp.RecoverSig(msg) diff --git a/chain/vm/vm.go b/chain/vm/vm.go index 932488fd7..1eed0f895 100644 --- a/chain/vm/vm.go +++ b/chain/vm/vm.go @@ -521,7 +521,7 @@ func (vm *VM) ActorBalance(addr address.Address) (types.BigInt, aerrors.ActorErr } func (vm *VM) Flush(ctx context.Context) (cid.Cid, error) { - ctx, span := trace.StartSpan(ctx, "vm.Flush") + _, span := trace.StartSpan(ctx, "vm.Flush") defer span.End() from := vm.buf diff --git a/cmd/lotus/main.go b/cmd/lotus/main.go index e2f32c0a0..fb90b178a 100644 --- a/cmd/lotus/main.go +++ b/cmd/lotus/main.go @@ -72,5 +72,4 @@ func main() { log.Warnf("%+v", err) os.Exit(1) } - return } diff --git a/miner/miner.go b/miner/miner.go index df2b3cdaa..307a495d2 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -191,7 +191,7 @@ eventLoop: time.Sleep(time.Until(btime)) } else { log.Warnw("mined block in the past", "block-time", btime, - "time", time.Now(), "duration", time.Now().Sub(btime)) + "time", time.Now(), "duration", time.Since(btime)) } mWon := make(map[address.Address]struct{}) diff --git a/node/repo/fsrepo.go b/node/repo/fsrepo.go index b75138835..b41024e5d 100644 --- a/node/repo/fsrepo.go +++ b/node/repo/fsrepo.go @@ -29,7 +29,6 @@ const ( fsAPIToken = "token" fsConfig = "config.toml" fsDatastore = "datastore" - fsLibp2pKey = "libp2p.priv" fsLock = "repo.lock" fsKeystore = "keystore" ) diff --git a/peermgr/peermgr.go b/peermgr/peermgr.go index 60714f219..624fcfcc5 100644 --- a/peermgr/peermgr.go +++ b/peermgr/peermgr.go @@ -27,7 +27,7 @@ type PeerMgr struct { // peerLeads is a set of peers we hear about through the network // and who may be good peers to connect to for expanding our peer set - peerLeads map[peer.ID]time.Time + //peerLeads map[peer.ID]time.Time // TODO: unused peersLk sync.Mutex peers map[peer.ID]struct{} diff --git a/retrieval/client.go b/retrieval/client.go index 8936fbafb..405320a46 100644 --- a/retrieval/client.go +++ b/retrieval/client.go @@ -231,6 +231,9 @@ func (cst *clientStream) consumeBlockMessage(block Block, out io.Writer) (uint64 } cid, err := prefix.Sum(block.Data) + if err != nil { + return 0, err + } blk, err := blocks.NewBlockWithCid(block.Data, cid) if err != nil { diff --git a/storage/miner.go b/storage/miner.go index dcb6b1155..7026ce1f8 100644 --- a/storage/miner.go +++ b/storage/miner.go @@ -3,7 +3,6 @@ package storage import ( "context" "errors" - "sync" "time" "github.com/ipfs/go-cid" @@ -36,10 +35,6 @@ type Miner struct { maddr address.Address worker address.Address - // PoSt - postLk sync.Mutex - schedPost uint64 - // Sealing sb *sectorbuilder.SectorBuilder sectors *statestore.StateStore