From 5733c71c50cf2416e529adc1298073b49cb63380 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 19 Aug 2020 21:49:10 -0700 Subject: [PATCH] Lint everything We were ignoring quite a few error cases, and had one case where we weren't actually updating state where we wanted to. Unfortunately, if the linter doesn't pass, nobody has any reason to actually check lint failures in CI. There are three remaining XXXs marked in the code for lint. --- .circleci/config.yml | 6 +- .golangci.yml | 21 +++++ api/docgen/docgen.go | 4 +- api/test/deals.go | 8 +- api/test/mining.go | 1 + api/test/paych.go | 3 + api/test/window_post.go | 11 ++- chain/block_receipt_tracker.go | 4 +- chain/blocksync/client.go | 4 +- chain/blocksync/protocol.go | 3 +- chain/events/state/diff_adt.go | 1 + chain/events/state/predicates.go | 1 + chain/events/state/predicates_test.go | 18 ++-- chain/gen/gen.go | 7 +- chain/gen/genesis/miners.go | 10 +- chain/gen/genesis/util.go | 4 - chain/market/fundmgr_test.go | 1 + chain/messagepool/block_proba.go | 2 +- chain/messagepool/provider.go | 2 +- chain/metrics/consensus.go | 3 +- chain/state/statetree.go | 4 +- chain/store/index_test.go | 2 +- chain/store/store.go | 4 +- chain/sub/incoming.go | 5 +- chain/sync_manager.go | 10 +- chain/sync_test.go | 26 ++--- chain/types/signedmessage.go | 4 +- chain/types/tipset.go | 4 + chain/validation/factories.go | 1 + chain/validation/keymanager.go | 3 +- chain/vectors/vectors_test.go | 2 +- chain/vm/runtime.go | 12 ++- chain/vm/vm.go | 3 + cli/auth.go | 1 + cli/chain.go | 4 +- cli/client.go | 94 +++++++++---------- cli/helper.go | 2 +- cli/mpool.go | 2 +- cli/net.go | 2 +- cli/pprof.go | 2 +- cli/state.go | 14 ++- cli/wallet.go | 5 +- cmd/lotus-bench/import.go | 34 ++----- cmd/lotus-chainwatch/processor/reward.go | 2 +- cmd/lotus-chainwatch/run.go | 2 +- .../refresh_top_miners_by_base_reward.go | 4 +- cmd/lotus-chainwatch/scheduler/scheduler.go | 8 +- cmd/lotus-fountain/main.go | 69 ++++++-------- cmd/lotus-keygen/main.go | 7 +- cmd/lotus-pcr/main.go | 20 ++-- cmd/lotus-seal-worker/main.go | 9 +- cmd/lotus-seed/main.go | 3 + cmd/lotus-shed/keyinfo.go | 10 +- cmd/lotus-storage-miner/info_all.go | 4 +- cmd/lotus-storage-miner/run.go | 5 +- cmd/lotus-storage-miner/sealing.go | 3 +- cmd/lotus-storage-miner/sectors.go | 3 +- cmd/lotus-townhall/main.go | 3 +- .../sector-storage/ffiwrapper/partialfile.go | 2 +- extern/sector-storage/fsutil/statfs_unix.go | 2 + extern/sector-storage/mock/mock.go | 2 +- extern/sector-storage/tarutil/systar.go | 2 + extern/storage-sealing/fsm.go | 4 +- extern/storage-sealing/sealing.go | 7 +- extern/storage-sealing/types.go | 1 + go.mod | 1 - journal/journal.go | 16 ++-- lib/blockstore/blockstore.go | 4 +- lib/cachebs/cachebs.go | 1 + lib/rpcenc/reader.go | 2 +- lib/rpcenc/reader_test.go | 2 +- lib/sigs/bls/bls_bench_test.go | 7 +- lotuspond/api.go | 2 +- lotuspond/outmux.go | 2 +- markets/storageadapter/client.go | 6 +- markets/storageadapter/provider.go | 6 +- miner/miner.go | 11 +-- node/builder.go | 1 + node/impl/client/client.go | 6 +- node/impl/full/mpool.go | 7 +- node/impl/full/multisig.go | 2 +- node/impl/full/state.go | 16 ++-- node/impl/full/sync.go | 3 +- node/impl/full/wallet.go | 14 ++- node/modules/client.go | 3 +- node/modules/core.go | 4 +- node/modules/graphsync.go | 2 +- node/modules/services.go | 4 +- storage/adapter_storage_miner.go | 2 +- storage/addresses.go | 1 + storage/wdpost_run.go | 2 +- tools/stats/head_buffer.go | 6 +- tools/stats/head_buffer_test.go | 40 ++++---- tools/stats/metrics.go | 9 +- tools/stats/rpc.go | 11 ++- 95 files changed, 372 insertions(+), 347 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8b304da90..0b2329954 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -288,9 +288,6 @@ jobs: command: | $HOME/.local/bin/golangci-lint run -v --timeout 2m \ --concurrency << parameters.concurrency >> << parameters.args >> - lint-changes: - <<: *lint - lint-all: <<: *lint @@ -319,8 +316,7 @@ workflows: version: 2.1 ci: jobs: - - lint-changes: - args: "--new-from-rev origin/next" + - lint-all - mod-tidy-check - gofmt - test: diff --git a/.golangci.yml b/.golangci.yml index 76bbc1949..8bdba64f0 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -23,6 +23,14 @@ issues: - "Potential file inclusion via variable" - "should have( a package)? comment" - "Error return value of `logging.SetLogLevel` is not checked" + - "comment on exported" + - "(func|method) \\w+ should be \\w+" + - "(type|var|struct field|(method|func) parameter) `\\w+` should be `\\w+`" + - "(G306|G301|G307|G108|G302|G204|G104)" + - "don't use ALL_CAPS in Go names" + - "string .* has .* occurrences, make it a constant" + - "a blank import should be only in a main or test package, or have a comment justifying it" + - "package comment should be of the form" exclude-use-default: false exclude-rules: @@ -46,6 +54,19 @@ issues: linters: - gosec + - path: chain/vectors/gen/.* + linters: + - gosec + + - path: cmd/lotus-bench/.* + linters: + - gosec + + - path: api/test/.* + text: "context.Context should be the first parameter" + linters: + - golint + linters-settings: goconst: min-occurrences: 6 diff --git a/api/docgen/docgen.go b/api/docgen/docgen.go index c9d8e8aa4..f9e614677 100644 --- a/api/docgen/docgen.go +++ b/api/docgen/docgen.go @@ -26,7 +26,7 @@ import ( "github.com/ipfs/go-cid" "github.com/ipfs/go-filestore" "github.com/libp2p/go-libp2p-core/network" - peer "github.com/libp2p/go-libp2p-peer" + "github.com/libp2p/go-libp2p-core/peer" "github.com/multiformats/go-multiaddr" ) @@ -66,7 +66,7 @@ func init() { ExampleValues[reflect.TypeOf(addr)] = addr - pid, err := peer.IDB58Decode("12D3KooWGzxzKZYveHXtpG6AsrUJBcWxHBFS2HsEoGTxrMLvKXtf") + pid, err := peer.Decode("12D3KooWGzxzKZYveHXtpG6AsrUJBcWxHBFS2HsEoGTxrMLvKXtf") if err != nil { panic(err) } diff --git a/api/test/deals.go b/api/test/deals.go index d36f57eb5..fc469da15 100644 --- a/api/test/deals.go +++ b/api/test/deals.go @@ -141,7 +141,7 @@ func makeDeal(t *testing.T, ctx context.Context, rseed int, client *impl.FullNod info, err := client.ClientGetDealInfo(ctx, *deal) require.NoError(t, err) - testRetrieval(t, ctx, err, client, fcid, &info.PieceCID, carExport, data) + testRetrieval(t, ctx, client, fcid, &info.PieceCID, carExport, data) } func TestFastRetrievalDealFlow(t *testing.T, b APIBuilder, blocktime time.Duration) { @@ -193,7 +193,7 @@ func TestFastRetrievalDealFlow(t *testing.T, b APIBuilder, blocktime time.Durati info, err := client.ClientGetDealInfo(ctx, *deal) require.NoError(t, err) - testRetrieval(t, ctx, err, client, fcid, &info.PieceCID, false, data) + testRetrieval(t, ctx, client, fcid, &info.PieceCID, false, data) atomic.AddInt64(&mine, -1) fmt.Println("shutting down mining") <-done @@ -267,7 +267,7 @@ func TestSenondDealRetrieval(t *testing.T, b APIBuilder, blocktime time.Duration rf, _ := miner.SectorsRefs(ctx) fmt.Printf("refs: %+v\n", rf) - testRetrieval(t, ctx, err, client, fcid2, &info.PieceCID, false, data2) + testRetrieval(t, ctx, client, fcid2, &info.PieceCID, false, data2) } atomic.AddInt64(&mine, -1) @@ -373,7 +373,7 @@ func startSealingWaiting(t *testing.T, ctx context.Context, miner TestStorageNod } } -func testRetrieval(t *testing.T, ctx context.Context, err error, client *impl.FullNodeAPI, fcid cid.Cid, piece *cid.Cid, carExport bool, data []byte) { +func testRetrieval(t *testing.T, ctx context.Context, client *impl.FullNodeAPI, fcid cid.Cid, piece *cid.Cid, carExport bool, data []byte) { offers, err := client.ClientFindData(ctx, fcid, piece) if err != nil { t.Fatal(err) diff --git a/api/test/mining.go b/api/test/mining.go index ee1268ed2..07070101b 100644 --- a/api/test/mining.go +++ b/api/test/mining.go @@ -20,6 +20,7 @@ import ( "github.com/filecoin-project/lotus/node/impl" ) +//nolint:deadcode,varcheck var log = logging.Logger("apitest") func (ts *testSuite) testMining(t *testing.T) { diff --git a/api/test/paych.go b/api/test/paych.go index 09e6f5d96..faa0bf8d9 100644 --- a/api/test/paych.go +++ b/api/test/paych.go @@ -153,6 +153,9 @@ func TestPaymentChannels(t *testing.T, b APIBuilder, blocktime time.Duration) { }, int(build.MessageConfidence)+1, build.SealRandomnessLookbackLimit, func(oldTs, newTs *types.TipSet) (bool, events.StateChange, error) { return preds.OnPaymentChannelActorChanged(channel, preds.OnToSendAmountChanges())(ctx, oldTs.Key(), newTs.Key()) }) + if err != nil { + t.Fatal(err) + } select { case <-finished: diff --git a/api/test/window_post.go b/api/test/window_post.go index e2a553c21..7dd4a0742 100644 --- a/api/test/window_post.go +++ b/api/test/window_post.go @@ -24,9 +24,14 @@ import ( "github.com/filecoin-project/lotus/node/impl" ) -func TestPledgeSector(t *testing.T, b APIBuilder, blocktime time.Duration, nSectors int) { - os.Setenv("BELLMAN_NO_GPU", "1") +func init() { + err := os.Setenv("BELLMAN_NO_GPU", "1") + if err != nil { + panic(fmt.Sprintf("failed to set BELLMAN_NO_GPU env variable: %s", err)) + } +} +func TestPledgeSector(t *testing.T, b APIBuilder, blocktime time.Duration, nSectors int) { ctx := context.Background() n, sn := b(t, 1, OneMiner) client := n[0].FullNode.(*impl.FullNodeAPI) @@ -110,8 +115,6 @@ func pledgeSectors(t *testing.T, ctx context.Context, miner TestStorageNode, n, } func TestWindowPost(t *testing.T, b APIBuilder, blocktime time.Duration, nSectors int) { - os.Setenv("BELLMAN_NO_GPU", "1") - ctx := context.Background() n, sn := b(t, 1, OneMiner) client := n[0].FullNode.(*impl.FullNodeAPI) diff --git a/chain/block_receipt_tracker.go b/chain/block_receipt_tracker.go index 466adef9d..a4a6743d1 100644 --- a/chain/block_receipt_tracker.go +++ b/chain/block_receipt_tracker.go @@ -7,8 +7,8 @@ import ( "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/types" - "github.com/hashicorp/golang-lru" - peer "github.com/libp2p/go-libp2p-core/peer" + lru "github.com/hashicorp/golang-lru" + "github.com/libp2p/go-libp2p-core/peer" ) type blockReceiptTracker struct { diff --git a/chain/blocksync/client.go b/chain/blocksync/client.go index bc1826527..f5a88a525 100644 --- a/chain/blocksync/client.go +++ b/chain/blocksync/client.go @@ -172,7 +172,7 @@ func (client *BlockSync) processResponse( resLength, req.Length) } if resLength < int(req.Length) && res.Status != Partial { - return nil, xerrors.Errorf("got less than requested without a proper status: %s", res.Status) + return nil, xerrors.Errorf("got less than requested without a proper status: %d", res.Status) } validRes := &validatedResponse{} @@ -205,7 +205,7 @@ func (client *BlockSync) processResponse( validRes.messages = make([]*CompactedMessages, resLength) for i := 0; i < resLength; i++ { if res.Chain[i].Messages == nil { - return nil, xerrors.Errorf("no messages included for tipset at height (head - %d): %w", i) + return nil, xerrors.Errorf("no messages included for tipset at height (head - %d)", i) } validRes.messages[i] = res.Chain[i].Messages } diff --git a/chain/blocksync/protocol.go b/chain/blocksync/protocol.go index 5a499f367..6a2861b80 100644 --- a/chain/blocksync/protocol.go +++ b/chain/blocksync/protocol.go @@ -1,9 +1,10 @@ package blocksync import ( + "time" + "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/store" - "time" "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log" diff --git a/chain/events/state/diff_adt.go b/chain/events/state/diff_adt.go index 1b921dd9e..39d7e8556 100644 --- a/chain/events/state/diff_adt.go +++ b/chain/events/state/diff_adt.go @@ -2,6 +2,7 @@ package state import ( "bytes" + "github.com/filecoin-project/specs-actors/actors/util/adt" typegen "github.com/whyrusleeping/cbor-gen" ) diff --git a/chain/events/state/predicates.go b/chain/events/state/predicates.go index bf85f1f1a..2019a38eb 100644 --- a/chain/events/state/predicates.go +++ b/chain/events/state/predicates.go @@ -3,6 +3,7 @@ package state import ( "bytes" "context" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi/big" diff --git a/chain/events/state/predicates_test.go b/chain/events/state/predicates_test.go index 27354105e..944b7e61c 100644 --- a/chain/events/state/predicates_test.go +++ b/chain/events/state/predicates_test.go @@ -114,10 +114,10 @@ func TestMarketPredicates(t *testing.T) { } oldBalances := map[address.Address]balance{ - tutils.NewIDAddr(t, 1): balance{abi.NewTokenAmount(1000), abi.NewTokenAmount(1000)}, - tutils.NewIDAddr(t, 2): balance{abi.NewTokenAmount(2000), abi.NewTokenAmount(500)}, - tutils.NewIDAddr(t, 3): balance{abi.NewTokenAmount(3000), abi.NewTokenAmount(2000)}, - tutils.NewIDAddr(t, 5): balance{abi.NewTokenAmount(3000), abi.NewTokenAmount(1000)}, + tutils.NewIDAddr(t, 1): {abi.NewTokenAmount(1000), abi.NewTokenAmount(1000)}, + tutils.NewIDAddr(t, 2): {abi.NewTokenAmount(2000), abi.NewTokenAmount(500)}, + tutils.NewIDAddr(t, 3): {abi.NewTokenAmount(3000), abi.NewTokenAmount(2000)}, + tutils.NewIDAddr(t, 5): {abi.NewTokenAmount(3000), abi.NewTokenAmount(1000)}, } oldStateC := createMarketState(ctx, t, store, oldDeals, oldProps, oldBalances) @@ -162,10 +162,10 @@ func TestMarketPredicates(t *testing.T) { // NB: DealProposals cannot be modified, so don't test that case. } newBalances := map[address.Address]balance{ - tutils.NewIDAddr(t, 1): balance{abi.NewTokenAmount(3000), abi.NewTokenAmount(0)}, - tutils.NewIDAddr(t, 2): balance{abi.NewTokenAmount(2000), abi.NewTokenAmount(500)}, - tutils.NewIDAddr(t, 4): balance{abi.NewTokenAmount(5000), abi.NewTokenAmount(0)}, - tutils.NewIDAddr(t, 5): balance{abi.NewTokenAmount(1000), abi.NewTokenAmount(3000)}, + tutils.NewIDAddr(t, 1): {abi.NewTokenAmount(3000), abi.NewTokenAmount(0)}, + tutils.NewIDAddr(t, 2): {abi.NewTokenAmount(2000), abi.NewTokenAmount(500)}, + tutils.NewIDAddr(t, 4): {abi.NewTokenAmount(5000), abi.NewTokenAmount(0)}, + tutils.NewIDAddr(t, 5): {abi.NewTokenAmount(1000), abi.NewTokenAmount(3000)}, } newStateC := createMarketState(ctx, t, store, newDeals, newProps, newBalances) @@ -505,6 +505,7 @@ func createBalanceTable(ctx context.Context, t *testing.T, store adt.Store, bala lockedMapRootCid, err := lockedMapRoot.Root() require.NoError(t, err) lockedRoot, err := adt.AsBalanceTable(store, lockedMapRootCid) + require.NoError(t, err) for addr, balance := range balances { err := escrowRoot.Add(addr, big.Add(balance.available, balance.locked)) @@ -542,6 +543,7 @@ func createEmptyMinerState(ctx context.Context, t *testing.T, store adt.Store, o emptyVestingFunds := miner.ConstructVestingFunds() emptyVestingFundsCid, err := store.Put(store.Context(), emptyVestingFunds) + require.NoError(t, err) emptyDeadlines := miner.ConstructDeadlines(emptyDeadline) emptyDeadlinesCid, err := store.Put(store.Context(), emptyDeadlines) diff --git a/chain/gen/gen.go b/chain/gen/gen.go index e34bb586b..551c3703f 100644 --- a/chain/gen/gen.go +++ b/chain/gen/gen.go @@ -41,10 +41,11 @@ import ( "github.com/filecoin-project/lotus/node/repo" ) -var log = logging.Logger("gen") - const msgsPerBlock = 20 +//nolint:deadcode,varcheck +var log = logging.Logger("gen") + var ValidWpostForTesting = []abi.PoStProof{{ ProofBytes: []byte("valid proof"), }} @@ -605,7 +606,7 @@ func IsRoundWinner(ctx context.Context, ts *types.TipSet, round abi.ChainEpoch, buf := new(bytes.Buffer) if err := miner.MarshalCBOR(buf); err != nil { - return nil, xerrors.Errorf("failed to cbor marshal address: %w") + return nil, xerrors.Errorf("failed to cbor marshal address: %w", err) } electionRand, err := store.DrawRandomness(brand.Data, crypto.DomainSeparationTag_ElectionProofProduction, round, buf.Bytes()) diff --git a/chain/gen/genesis/miners.go b/chain/gen/genesis/miners.go index 04c121d41..770581238 100644 --- a/chain/gen/genesis/miners.go +++ b/chain/gen/genesis/miners.go @@ -129,6 +129,9 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid return nil }) + if err != nil { + return cid.Undef, xerrors.Errorf("mutating state: %w", err) + } } // Add market funds @@ -217,9 +220,12 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid } err = vm.MutateState(ctx, builtin.RewardActorAddr, func(sct cbor.IpldStore, st *reward.State) error { - st = reward.ConstructState(qaPow) + *st = *reward.ConstructState(qaPow) return nil }) + if err != nil { + return cid.Undef, xerrors.Errorf("mutating state: %w", err) + } } for i, m := range miners { @@ -244,7 +250,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid // we've added fake power for this sector above, remove it now err = vm.MutateState(ctx, builtin.StoragePowerActorAddr, func(cst cbor.IpldStore, st *power.State) error { - st.TotalQualityAdjPower = types.BigSub(st.TotalQualityAdjPower, sectorWeight) + st.TotalQualityAdjPower = types.BigSub(st.TotalQualityAdjPower, sectorWeight) //nolint:scopelint st.TotalRawBytePower = types.BigSub(st.TotalRawBytePower, types.NewInt(uint64(m.SectorSize))) return nil }) diff --git a/chain/gen/genesis/util.go b/chain/gen/genesis/util.go index e78f6a0d2..10081c763 100644 --- a/chain/gen/genesis/util.go +++ b/chain/gen/genesis/util.go @@ -21,10 +21,6 @@ func mustEnc(i cbg.CBORMarshaler) []byte { return enc } -func doExec(ctx context.Context, vm *vm.VM, to, from address.Address, method abi.MethodNum, params []byte) ([]byte, error) { - return doExecValue(ctx, vm, to, from, types.NewInt(0), method, params) -} - func doExecValue(ctx context.Context, vm *vm.VM, to, from address.Address, value types.BigInt, method abi.MethodNum, params []byte) ([]byte, error) { act, err := vm.StateTree().GetActor(from) if err != nil { diff --git a/chain/market/fundmgr_test.go b/chain/market/fundmgr_test.go index d1b0fb7e6..5e8800528 100644 --- a/chain/market/fundmgr_test.go +++ b/chain/market/fundmgr_test.go @@ -147,6 +147,7 @@ func TestAddFunds(t *testing.T) { } for testCase, data := range testCases { + //nolint:scopelint t.Run(testCase, func(t *testing.T) { ctx, cancel := context.WithTimeout(ctx, 5*time.Second) defer cancel() diff --git a/chain/messagepool/block_proba.go b/chain/messagepool/block_proba.go index 6634f5b46..61bb018d7 100644 --- a/chain/messagepool/block_proba.go +++ b/chain/messagepool/block_proba.go @@ -56,7 +56,7 @@ func binomialCoefficient(n, k float64) float64 { for d := 1.0; d <= k; d++ { r *= n r /= d - n -= 1 + n-- } return r } diff --git a/chain/messagepool/provider.go b/chain/messagepool/provider.go index a6aa79ef6..fa8b8ea83 100644 --- a/chain/messagepool/provider.go +++ b/chain/messagepool/provider.go @@ -43,7 +43,7 @@ func (mpp *mpoolProvider) PutMessage(m types.ChainMsg) (cid.Cid, error) { } func (mpp *mpoolProvider) PubSubPublish(k string, v []byte) error { - return mpp.ps.Publish(k, v) + return mpp.ps.Publish(k, v) //nolint } func (mpp *mpoolProvider) StateGetActor(addr address.Address, ts *types.TipSet) (*types.Actor, error) { diff --git a/chain/metrics/consensus.go b/chain/metrics/consensus.go index 7d19d5bd6..25e299247 100644 --- a/chain/metrics/consensus.go +++ b/chain/metrics/consensus.go @@ -44,7 +44,7 @@ func SendHeadNotifs(nickname string) func(mctx helpers.MetricsCtx, lc fx.Lifecyc } }() go func() { - sub, err := ps.Subscribe(topic) + sub, err := ps.Subscribe(topic) //nolint if err != nil { return } @@ -116,6 +116,7 @@ func sendHeadNotifs(ctx context.Context, ps *pubsub.PubSub, topic string, chain return err } + //nolint if err := ps.Publish(topic, b); err != nil { return err } diff --git a/chain/state/statetree.go b/chain/state/statetree.go index d2a98b1e4..c083f1817 100644 --- a/chain/state/statetree.go +++ b/chain/state/statetree.go @@ -246,7 +246,7 @@ func (st *StateTree) DeleteActor(addr address.Address) error { } func (st *StateTree) Flush(ctx context.Context) (cid.Cid, error) { - ctx, span := trace.StartSpan(ctx, "stateTree.Flush") + ctx, span := trace.StartSpan(ctx, "stateTree.Flush") //nolint:staticcheck defer span.End() if len(st.snaps.layers) != 1 { return cid.Undef, xerrors.Errorf("tried to flush state tree with snapshots on the stack") @@ -268,7 +268,7 @@ func (st *StateTree) Flush(ctx context.Context) (cid.Cid, error) { } func (st *StateTree) Snapshot(ctx context.Context) error { - ctx, span := trace.StartSpan(ctx, "stateTree.SnapShot") + ctx, span := trace.StartSpan(ctx, "stateTree.SnapShot") //nolint:staticcheck defer span.End() st.snaps.addLayer() diff --git a/chain/store/index_test.go b/chain/store/index_test.go index 9443b4c07..5c49c6791 100644 --- a/chain/store/index_test.go +++ b/chain/store/index_test.go @@ -42,7 +42,7 @@ func TestIndexSeeks(t *testing.T) { if err := cs.PutTipSet(ctx, mock.TipSet(gen)); err != nil { t.Fatal(err) } - cs.SetGenesis(gen) + assert.NoError(t, cs.SetGenesis(gen)) // Put 113 blocks from genesis for i := 0; i < 113; i++ { diff --git a/chain/store/store.go b/chain/store/store.go index 9c424dc3b..139444f67 100644 --- a/chain/store/store.go +++ b/chain/store/store.go @@ -925,7 +925,7 @@ func (cs *ChainStore) LoadMessagesFromCids(cids []cid.Cid) ([]*types.Message, er for i, c := range cids { m, err := cs.GetMessage(c) if err != nil { - return nil, xerrors.Errorf("failed to get message: (%s):%d: %w", err, c, i) + return nil, xerrors.Errorf("failed to get message: (%s):%d: %w", c, i, err) } msgs = append(msgs, m) @@ -939,7 +939,7 @@ func (cs *ChainStore) LoadSignedMessagesFromCids(cids []cid.Cid) ([]*types.Signe for i, c := range cids { m, err := cs.GetSignedMessage(c) if err != nil { - return nil, xerrors.Errorf("failed to get message: (%s):%d: %w", err, c, i) + return nil, xerrors.Errorf("failed to get message: (%s):%d: %w", c, i, err) } msgs = append(msgs, m) diff --git a/chain/sub/incoming.go b/chain/sub/incoming.go index 561d2c3f1..c036bf1f6 100644 --- a/chain/sub/incoming.go +++ b/chain/sub/incoming.go @@ -292,10 +292,9 @@ func (bv *BlockValidator) Validate(ctx context.Context, pid peer.ID, msg *pubsub log.Warnf("received block from unknown miner or miner that doesn't meet min power over pubsub; rejecting message") recordFailure("unknown_miner") return pubsub.ValidationReject - } else { - log.Warnf("cannot validate block message; unknown miner or miner that doesn't meet min power in unsynced chain") - return pubsub.ValidationIgnore } + log.Warnf("cannot validate block message; unknown miner or miner that doesn't meet min power in unsynced chain") + return pubsub.ValidationIgnore } err = sigs.CheckBlockSignature(ctx, blk.Header, key) diff --git a/chain/sync_manager.go b/chain/sync_manager.go index e3fbdf4e1..8c77b47c5 100644 --- a/chain/sync_manager.go +++ b/chain/sync_manager.go @@ -343,12 +343,12 @@ func (sm *SyncManager) scheduleProcessResult(res *syncResult) { sm.syncQueue.buckets = append(sm.syncQueue.buckets, relbucket) } return - } else { - // TODO: this is the case where we try to sync a chain, and - // fail, and we have more blocks on top of that chain that - // have come in since. The question is, should we try to - // sync these? or just drop them? } + // TODO: this is the case where we try to sync a chain, and + // fail, and we have more blocks on top of that chain that + // have come in since. The question is, should we try to + // sync these? or just drop them? + log.Error("failed to sync chain but have new unconnected blocks from chain") } if sm.nextSyncTarget == nil && !sm.syncQueue.Empty() { diff --git a/chain/sync_test.go b/chain/sync_test.go index 2774571b2..cf1385baa 100644 --- a/chain/sync_test.go +++ b/chain/sync_test.go @@ -3,11 +3,12 @@ package chain_test import ( "context" "fmt" - "github.com/ipfs/go-cid" "os" "testing" "time" + "github.com/ipfs/go-cid" + ds "github.com/ipfs/go-datastore" logging "github.com/ipfs/go-log/v2" "github.com/libp2p/go-libp2p-core/peer" @@ -36,7 +37,10 @@ import ( func init() { build.InsecurePoStValidation = true - os.Setenv("TRUST_PARAMS", "1") + err := os.Setenv("TRUST_PARAMS", "1") + if err != nil { + panic(err) + } miner.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg2KiBV1: {}, } @@ -212,20 +216,6 @@ func (tu *syncTestUtil) mineNewBlock(src int, miners []int) { tu.g.CurTipset = mts } -func fblkToBlkMsg(fb *types.FullBlock) *types.BlockMsg { - out := &types.BlockMsg{ - Header: fb.Header, - } - - for _, msg := range fb.BlsMessages { - out.BlsMessages = append(out.BlsMessages, msg.Cid()) - } - for _, msg := range fb.SecpkMessages { - out.SecpkMessages = append(out.SecpkMessages, msg.Cid()) - } - return out -} - func (tu *syncTestUtil) addSourceNode(gen int) { if tu.genesis != nil { tu.t.Fatal("source node already exists") @@ -454,7 +444,7 @@ func (wpp badWpp) GenerateCandidates(context.Context, abi.PoStRandomness, uint64 func (wpp badWpp) ComputeProof(context.Context, []abi.SectorInfo, abi.PoStRandomness) ([]abi.PoStProof, error) { return []abi.PoStProof{ - abi.PoStProof{ + { PoStProof: abi.RegisteredPoStProof_StackedDrgWinning2KiBV1, ProofBytes: []byte("evil"), }, @@ -587,7 +577,7 @@ func TestDuplicateNonce(t *testing.T) { msgs := make([][]*types.SignedMessage, 2) // Each miner includes a message from the banker with the same nonce, but to different addresses - for k, _ := range msgs { + for k := range msgs { msgs[k] = []*types.SignedMessage{makeMsg(tu.g.Miners[k])} } diff --git a/chain/types/signedmessage.go b/chain/types/signedmessage.go index 77374ca38..47592feb1 100644 --- a/chain/types/signedmessage.go +++ b/chain/types/signedmessage.go @@ -62,8 +62,8 @@ func (sm *SignedMessage) Serialize() ([]byte, error) { return buf.Bytes(), nil } -func (m *SignedMessage) ChainLength() int { - ser, err := m.Serialize() +func (sm *SignedMessage) ChainLength() int { + ser, err := sm.Serialize() if err != nil { panic(err) } diff --git a/chain/types/tipset.go b/chain/types/tipset.go index 271301ea6..4217d2a86 100644 --- a/chain/types/tipset.go +++ b/chain/types/tipset.go @@ -238,3 +238,7 @@ func (ts *TipSet) IsChildOf(parent *TipSet) bool { // height for their processing logic at the moment to obviate it. ts.height > parent.height } + +func (ts *TipSet) String() string { + return fmt.Sprintf("%v", ts.cids) +} diff --git a/chain/validation/factories.go b/chain/validation/factories.go index 6d5386023..b7781cacc 100644 --- a/chain/validation/factories.go +++ b/chain/validation/factories.go @@ -2,6 +2,7 @@ package validation import ( "context" + "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/specs-actors/actors/runtime" cbor "github.com/ipfs/go-ipld-cbor" diff --git a/chain/validation/keymanager.go b/chain/validation/keymanager.go index a826d5ea0..95fbf2142 100644 --- a/chain/validation/keymanager.go +++ b/chain/validation/keymanager.go @@ -2,9 +2,10 @@ package validation import ( "fmt" - "github.com/minio/blake2b-simd" "math/rand" + "github.com/minio/blake2b-simd" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-crypto" acrypto "github.com/filecoin-project/specs-actors/actors/crypto" diff --git a/chain/vectors/vectors_test.go b/chain/vectors/vectors_test.go index 77073a07e..68cc5ac45 100644 --- a/chain/vectors/vectors_test.go +++ b/chain/vectors/vectors_test.go @@ -18,7 +18,7 @@ func LoadVector(t *testing.T, f string, out interface{}) { if err != nil { t.Fatal(err) } - defer fi.Close() + defer fi.Close() //nolint:errcheck if err := json.NewDecoder(fi).Decode(out); err != nil { t.Fatal(err) diff --git a/chain/vm/runtime.go b/chain/vm/runtime.go index 772bc9750..d39c14beb 100644 --- a/chain/vm/runtime.go +++ b/chain/vm/runtime.go @@ -410,8 +410,10 @@ type shimStateHandle struct { func (ssh *shimStateHandle) Create(obj vmr.CBORMarshaler) { c := ssh.rt.Put(obj) - // TODO: handle error below - ssh.rt.stateCommit(EmptyObjectCid, c) + err := ssh.rt.stateCommit(EmptyObjectCid, c) + if err != nil { + panic(fmt.Errorf("failed to commit state after creating object: %w", err)) + } } func (ssh *shimStateHandle) Readonly(obj vmr.CBORUnmarshaler) { @@ -440,8 +442,10 @@ func (ssh *shimStateHandle) Transaction(obj vmr.CBORer, f func()) { c := ssh.rt.Put(obj) - // TODO: handle error below - ssh.rt.stateCommit(baseState, c) + err = ssh.rt.stateCommit(baseState, c) + if err != nil { + panic(fmt.Errorf("failed to commit state after transaction: %w", err)) + } } func (rt *Runtime) GetBalance(a address.Address) (types.BigInt, aerrors.ActorError) { diff --git a/chain/vm/vm.go b/chain/vm/vm.go index 42570392f..7be5417b7 100644 --- a/chain/vm/vm.go +++ b/chain/vm/vm.go @@ -254,6 +254,9 @@ func (vm *VM) send(ctx context.Context, msg *types.Message, parent *Runtime, if aerr := rt.chargeGasSafe(rt.Pricelist().OnMethodInvocation(msg.Value, msg.Method)); aerr != nil { return nil, aerrors.Wrap(aerr, "not enough gas for method invocation") } + + // not charging any gas, just logging + //nolint:errcheck defer rt.chargeGasSafe(newGasCharge("OnMethodInvocationDone", 0, 0)) if types.BigCmp(msg.Value, types.NewInt(0)) != 0 { diff --git a/cli/auth.go b/cli/auth.go index 40947d797..ba20b2bcc 100644 --- a/cli/auth.go +++ b/cli/auth.go @@ -2,6 +2,7 @@ package cli import ( "fmt" + "github.com/urfave/cli/v2" "golang.org/x/xerrors" diff --git a/cli/chain.go b/cli/chain.go index 22c35abb3..1f8339e93 100644 --- a/cli/chain.go +++ b/cli/chain.go @@ -319,7 +319,7 @@ var chainSetHeadCmd = &cli.Command{ ts, err = api.ChainGetTipSetByHeight(ctx, abi.ChainEpoch(cctx.Uint64("epoch")), types.EmptyTSK) } if ts == nil { - ts, err = parseTipSet(api, ctx, cctx.Args().Slice()) + ts, err = parseTipSet(ctx, api, cctx.Args().Slice()) } if err != nil { return err @@ -337,7 +337,7 @@ var chainSetHeadCmd = &cli.Command{ }, } -func parseTipSet(api api.FullNode, ctx context.Context, vals []string) (*types.TipSet, error) { +func parseTipSet(ctx context.Context, api api.FullNode, vals []string) (*types.TipSet, error) { var headers []*types.BlockHeader for _, c := range vals { blkc, err := cid.Decode(c) diff --git a/cli/client.go b/cli/client.go index 159fef41b..008ca8799 100644 --- a/cli/client.go +++ b/cli/client.go @@ -930,11 +930,11 @@ var clientQueryAskCmd = &cli.Command{ return xerrors.Errorf("failed to get peerID for miner: %w", err) } - if peer.ID(*mi.PeerId) == peer.ID("SETME") { + if *mi.PeerId == peer.ID("SETME") { return fmt.Errorf("the miner hasn't initialized yet") } - pid = peer.ID(*mi.PeerId) + pid = *mi.PeerId } ask, err := api.ClientQueryAsk(ctx, pid, maddr) @@ -1045,55 +1045,55 @@ var clientListDeals = &cli.Command{ fmt.Fprintf(w, "%s\t%s\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%s\n", d.LocalDeal.CreationTime.Format(time.Stamp), d.LocalDeal.ProposalCid, d.LocalDeal.DealID, d.LocalDeal.Provider, dealStateString(color, d.LocalDeal.State), onChain, slashed, d.LocalDeal.PieceCID, types.SizeStr(types.NewInt(d.LocalDeal.Size)), price, d.LocalDeal.Duration, d.LocalDeal.Message) } return w.Flush() - } else { - w := tablewriter.New(tablewriter.Col("DealCid"), - tablewriter.Col("DealId"), - tablewriter.Col("Provider"), - tablewriter.Col("State"), - tablewriter.Col("On Chain?"), - tablewriter.Col("Slashed?"), - tablewriter.Col("PieceCID"), - tablewriter.Col("Size"), - tablewriter.Col("Price"), - tablewriter.Col("Duration"), - tablewriter.NewLineCol("Message")) + } - for _, d := range deals { - propcid := d.LocalDeal.ProposalCid.String() - propcid = "..." + propcid[len(propcid)-8:] + w := tablewriter.New(tablewriter.Col("DealCid"), + tablewriter.Col("DealId"), + tablewriter.Col("Provider"), + tablewriter.Col("State"), + tablewriter.Col("On Chain?"), + tablewriter.Col("Slashed?"), + tablewriter.Col("PieceCID"), + tablewriter.Col("Size"), + tablewriter.Col("Price"), + tablewriter.Col("Duration"), + tablewriter.NewLineCol("Message")) - onChain := "N" - if d.OnChainDealState.SectorStartEpoch != -1 { - onChain = fmt.Sprintf("Y (epoch %d)", d.OnChainDealState.SectorStartEpoch) - } + for _, d := range deals { + propcid := d.LocalDeal.ProposalCid.String() + propcid = "..." + propcid[len(propcid)-8:] - slashed := "N" - if d.OnChainDealState.SlashEpoch != -1 { - slashed = fmt.Sprintf("Y (epoch %d)", d.OnChainDealState.SlashEpoch) - } - - piece := d.LocalDeal.PieceCID.String() - piece = "..." + piece[len(piece)-8:] - - price := types.FIL(types.BigMul(d.LocalDeal.PricePerEpoch, types.NewInt(d.LocalDeal.Duration))) - - w.Write(map[string]interface{}{ - "DealCid": propcid, - "DealId": d.LocalDeal.DealID, - "Provider": d.LocalDeal.Provider, - "State": dealStateString(color, d.LocalDeal.State), - "On Chain?": onChain, - "Slashed?": slashed, - "PieceCID": piece, - "Size": types.SizeStr(types.NewInt(d.LocalDeal.Size)), - "Price": price, - "Duration": d.LocalDeal.Duration, - "Message": d.LocalDeal.Message, - }) + onChain := "N" + if d.OnChainDealState.SectorStartEpoch != -1 { + onChain = fmt.Sprintf("Y (epoch %d)", d.OnChainDealState.SectorStartEpoch) } - return w.Flush(os.Stdout) + slashed := "N" + if d.OnChainDealState.SlashEpoch != -1 { + slashed = fmt.Sprintf("Y (epoch %d)", d.OnChainDealState.SlashEpoch) + } + + piece := d.LocalDeal.PieceCID.String() + piece = "..." + piece[len(piece)-8:] + + price := types.FIL(types.BigMul(d.LocalDeal.PricePerEpoch, types.NewInt(d.LocalDeal.Duration))) + + w.Write(map[string]interface{}{ + "DealCid": propcid, + "DealId": d.LocalDeal.DealID, + "Provider": d.LocalDeal.Provider, + "State": dealStateString(color, d.LocalDeal.State), + "On Chain?": onChain, + "Slashed?": slashed, + "PieceCID": piece, + "Size": types.SizeStr(types.NewInt(d.LocalDeal.Size)), + "Price": price, + "Duration": d.LocalDeal.Duration, + "Message": d.LocalDeal.Message, + }) } + + return w.Flush(os.Stdout) }, } @@ -1318,7 +1318,7 @@ func OutputDataTransferChannels(out io.Writer, channels []lapi.DataTransferChann for _, channel := range sendingChannels { w.Write(toChannelOutput(color, "Sending To", channel)) } - w.Flush(out) + w.Flush(out) //nolint:errcheck fmt.Fprintf(out, "\nReceiving Channels\n\n") w = tablewriter.New(tablewriter.Col("ID"), @@ -1332,7 +1332,7 @@ func OutputDataTransferChannels(out io.Writer, channels []lapi.DataTransferChann for _, channel := range receivingChannels { w.Write(toChannelOutput(color, "Receiving From", channel)) } - w.Flush(out) + w.Flush(out) //nolint:errcheck } func channelStatusString(useColor bool, status datatransfer.Status) string { diff --git a/cli/helper.go b/cli/helper.go index 536301e87..70a168145 100644 --- a/cli/helper.go +++ b/cli/helper.go @@ -39,7 +39,7 @@ func RunApp(app *cli.App) { } var phe *PrintHelpErr if xerrors.As(err, &phe) { - cli.ShowCommandHelp(phe.Ctx, phe.Ctx.Command.Name) + _ = cli.ShowCommandHelp(phe.Ctx, phe.Ctx.Command.Name) } os.Exit(1) } diff --git a/cli/mpool.go b/cli/mpool.go index 62ab06dae..eed507482 100644 --- a/cli/mpool.go +++ b/cli/mpool.go @@ -313,7 +313,7 @@ var mpoolReplaceCmd = &cli.Command{ if err != nil { return fmt.Errorf("parsing gas-premium: %w", err) } - // TODO: estiamte fee cap here + // TODO: estimate fee cap here msg.GasFeeCap, err = types.BigFromString(cctx.String("gas-feecap")) if err != nil { return fmt.Errorf("parsing gas-feecap: %w", err) diff --git a/cli/net.go b/cli/net.go index fb902e39c..6dd11d045 100644 --- a/cli/net.go +++ b/cli/net.go @@ -180,7 +180,7 @@ var netFindPeer = &cli.Command{ return nil } - pid, err := peer.IDB58Decode(cctx.Args().First()) + pid, err := peer.Decode(cctx.Args().First()) if err != nil { return err } diff --git a/cli/pprof.go b/cli/pprof.go index 50a67ef86..2ac4206b5 100644 --- a/cli/pprof.go +++ b/cli/pprof.go @@ -44,7 +44,7 @@ var PprofGoroutines = &cli.Command{ addr = "http://" + addr + "/debug/pprof/goroutine?debug=2" - r, err := http.Get(addr) + r, err := http.Get(addr) //nolint:gosec if err != nil { return err } diff --git a/cli/state.go b/cli/state.go index c49994e2a..1e75cc7cd 100644 --- a/cli/state.go +++ b/cli/state.go @@ -353,6 +353,9 @@ var stateReplaySetCmd = &cli.Command{ } ts, err = types.NewTipSet(headers) + if err != nil { + return err + } } else { var r *api.MsgLookup r, err = fapi.StateWaitMsg(ctx, mcid, build.MessageConfidence) @@ -365,9 +368,9 @@ var stateReplaySetCmd = &cli.Command{ return xerrors.Errorf("loading tipset: %w", err) } ts, err = fapi.ChainGetTipSet(ctx, childTs.Parents()) - } - if err != nil { - return err + if err != nil { + return err + } } } @@ -1499,7 +1502,7 @@ func parseParamsForMethod(act cid.Cid, method uint64, args []string) ([]byte, er } p.Elem().Field(i).Set(reflect.ValueOf(val)) case reflect.TypeOf(peer.ID("")): - pid, err := peer.IDB58Decode(args[i]) + pid, err := peer.Decode(args[i]) if err != nil { return nil, fmt.Errorf("failed to parse peer ID: %s", err) } @@ -1584,6 +1587,9 @@ var stateMarketBalanceCmd = &cli.Command{ } balance, err := api.StateMarketBalance(ctx, addr, ts.Key()) + if err != nil { + return err + } fmt.Printf("Escrow: %s\n", types.FIL(balance.Escrow)) fmt.Printf("Locked: %s\n", types.FIL(balance.Locked)) diff --git a/cli/wallet.go b/cli/wallet.go index 29f0b2db9..025e3a7b6 100644 --- a/cli/wallet.go +++ b/cli/wallet.go @@ -385,10 +385,9 @@ var walletVerify = &cli.Command{ if api.WalletVerify(ctx, addr, msg, &sig) { fmt.Println("valid") return nil - } else { - fmt.Println("invalid") - return NewCliError("CLI Verify called with invalid signature") } + fmt.Println("invalid") + return NewCliError("CLI Verify called with invalid signature") }, } diff --git a/cmd/lotus-bench/import.go b/cmd/lotus-bench/import.go index 9944adc0b..7400cd92e 100644 --- a/cmd/lotus-bench/import.go +++ b/cmd/lotus-bench/import.go @@ -214,7 +214,7 @@ func countGasCosts(et *types.ExecutionTrace) (int64, int64) { } for _, sub := range et.Subcalls { - c, v := countGasCosts(&sub) + c, v := countGasCosts(&sub) //nolint cgas += c vgas += v } @@ -222,24 +222,6 @@ func countGasCosts(et *types.ExecutionTrace) (int64, int64) { return cgas, vgas } -func compStats(vals []float64) (float64, float64) { - var sum float64 - - for _, v := range vals { - sum += v - } - - av := sum / float64(len(vals)) - - var varsum float64 - for _, v := range vals { - delta := av - v - varsum += delta * delta - } - - return av, math.Sqrt(varsum / float64(len(vals))) -} - type stats struct { timeTaken meanVar gasRatio meanVar @@ -264,20 +246,20 @@ func (cov1 *covar) VarianceX() float64 { return cov1.m2x / (cov1.n - 1) } -func (v1 *covar) StddevX() float64 { - return math.Sqrt(v1.VarianceX()) +func (cov1 *covar) StddevX() float64 { + return math.Sqrt(cov1.VarianceX()) } func (cov1 *covar) VarianceY() float64 { return cov1.m2y / (cov1.n - 1) } -func (v1 *covar) StddevY() float64 { - return math.Sqrt(v1.VarianceY()) +func (cov1 *covar) StddevY() float64 { + return math.Sqrt(cov1.VarianceY()) } func (cov1 *covar) AddPoint(x, y float64) { - cov1.n += 1 + cov1.n++ dx := x - cov1.meanX cov1.meanX += dx / cov1.n @@ -344,7 +326,7 @@ type meanVar struct { func (v1 *meanVar) AddPoint(value float64) { // based on https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Welford's_online_algorithm - v1.n += 1 + v1.n++ delta := value - v1.mean v1.mean += delta / v1.n delta2 := value - v1.mean @@ -481,7 +463,7 @@ var importAnalyzeCmd = &cli.Command{ } go func() { - http.ListenAndServe("localhost:6060", nil) + http.ListenAndServe("localhost:6060", nil) //nolint:errcheck }() fi, err := os.Open(cctx.Args().First()) diff --git a/cmd/lotus-chainwatch/processor/reward.go b/cmd/lotus-chainwatch/processor/reward.go index d6f2ddad0..230b3c6c1 100644 --- a/cmd/lotus-chainwatch/processor/reward.go +++ b/cmd/lotus-chainwatch/processor/reward.go @@ -159,7 +159,7 @@ func (p *Processor) persistRewardActors(ctx context.Context, rewards []rewardAct log.Debugw("Persisted Reward Actors", "duration", time.Since(start).String()) }() - grp, ctx := errgroup.WithContext(ctx) + grp, ctx := errgroup.WithContext(ctx) //nolint grp.Go(func() error { if err := p.storeChainPower(rewards); err != nil { diff --git a/cmd/lotus-chainwatch/run.go b/cmd/lotus-chainwatch/run.go index f5f1afa53..3442ec714 100644 --- a/cmd/lotus-chainwatch/run.go +++ b/cmd/lotus-chainwatch/run.go @@ -29,7 +29,7 @@ var runCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { go func() { - http.ListenAndServe(":6060", nil) + http.ListenAndServe(":6060", nil) //nolint:errcheck }() ll := cctx.String("log-level") if err := logging.SetLogLevel("*", ll); err != nil { diff --git a/cmd/lotus-chainwatch/scheduler/refresh_top_miners_by_base_reward.go b/cmd/lotus-chainwatch/scheduler/refresh_top_miners_by_base_reward.go index 550f7a2bd..b6a24507f 100644 --- a/cmd/lotus-chainwatch/scheduler/refresh_top_miners_by_base_reward.go +++ b/cmd/lotus-chainwatch/scheduler/refresh_top_miners_by_base_reward.go @@ -49,11 +49,11 @@ func setupTopMinerByBaseRewardSchema(ctx context.Context, db *sql.DB) error { order by 1 desc limit 1; `); err != nil { - return xerrors.Errorf("create top_miner_by_base_reward views", err) + return xerrors.Errorf("create top_miner_by_base_reward views: %w", err) } if err := tx.Commit(); err != nil { - return xerrors.Errorf("commiting top_miner_by_base_reward views", err) + return xerrors.Errorf("committing top_miner_by_base_reward views; %w", err) } return nil } diff --git a/cmd/lotus-chainwatch/scheduler/scheduler.go b/cmd/lotus-chainwatch/scheduler/scheduler.go index c2b02e325..936b61ce7 100644 --- a/cmd/lotus-chainwatch/scheduler/scheduler.go +++ b/cmd/lotus-chainwatch/scheduler/scheduler.go @@ -25,7 +25,7 @@ func PrepareScheduler(db *sql.DB) *Scheduler { func (s *Scheduler) setupSchema(ctx context.Context) error { if err := setupTopMinerByBaseRewardSchema(ctx, s.db); err != nil { - return xerrors.Errorf("setup top miners by reward schema", err) + return xerrors.Errorf("setup top miners by reward schema: %w", err) } return nil } @@ -35,14 +35,14 @@ func (s *Scheduler) Start(ctx context.Context) { log.Debug("Starting Scheduler") if err := s.setupSchema(ctx); err != nil { - log.Fatalw("applying scheduling schema", err) + log.Fatalw("applying scheduling schema", "error", err) } go func() { // run once on start after schema has initialized time.Sleep(5 * time.Second) if err := refreshTopMinerByBaseReward(ctx, s.db); err != nil { - log.Errorf(err.Error()) + log.Errorw("failed to refresh top miner", "error", err) } refreshTopMinerCh := time.NewTicker(30 * time.Second) defer refreshTopMinerCh.Stop() @@ -50,7 +50,7 @@ func (s *Scheduler) Start(ctx context.Context) { select { case <-refreshTopMinerCh.C: if err := refreshTopMinerByBaseReward(ctx, s.db); err != nil { - log.Errorf(err.Error()) + log.Errorw("failed to refresh top miner", "error", err) } case <-ctx.Done(): return diff --git a/cmd/lotus-fountain/main.go b/cmd/lotus-fountain/main.go index 8e3461595..021335cc3 100644 --- a/cmd/lotus-fountain/main.go +++ b/cmd/lotus-fountain/main.go @@ -47,7 +47,7 @@ var supportedSectors struct { } func init() { - for supportedSector, _ := range miner.SupportedProofTypes { + for supportedSector := range miner.SupportedProofTypes { sectorSize, err := supportedSector.SectorSize() if err != nil { panic(err) @@ -207,24 +207,24 @@ type handler struct { func (h *handler) minerhtml(w http.ResponseWriter, r *http.Request) { f, err := rice.MustFindBox("site").Open("_miner.html") if err != nil { - w.WriteHeader(500) - _, _ = w.Write([]byte(err.Error())) + http.Error(w, err.Error(), http.StatusInternalServerError) return } tmpl, err := ioutil.ReadAll(f) if err != nil { - w.WriteHeader(500) - _, _ = w.Write([]byte(err.Error())) + http.Error(w, err.Error(), http.StatusInternalServerError) return } var executedTmpl bytes.Buffer t, err := template.New("miner.html").Parse(string(tmpl)) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } if err := t.Execute(&executedTmpl, supportedSectors); err != nil { - w.WriteHeader(500) - _, _ = w.Write([]byte(err.Error())) + http.Error(w, err.Error(), http.StatusInternalServerError) return } @@ -238,8 +238,7 @@ func (h *handler) minerhtml(w http.ResponseWriter, r *http.Request) { func (h *handler) send(w http.ResponseWriter, r *http.Request) { to, err := address.NewFromString(r.FormValue("address")) if err != nil { - w.WriteHeader(400) - _, _ = w.Write([]byte(err.Error())) + http.Error(w, err.Error(), http.StatusBadRequest) return } @@ -282,8 +281,7 @@ func (h *handler) send(w http.ResponseWriter, r *http.Request) { To: to, }, nil) if err != nil { - w.WriteHeader(400) - _, _ = w.Write([]byte(err.Error())) + http.Error(w, err.Error(), http.StatusBadRequest) return } @@ -293,15 +291,15 @@ func (h *handler) send(w http.ResponseWriter, r *http.Request) { func (h *handler) mkminer(w http.ResponseWriter, r *http.Request) { owner, err := address.NewFromString(r.FormValue("address")) if err != nil { - w.WriteHeader(400) - _, _ = w.Write([]byte(err.Error())) + http.Error(w, err.Error(), http.StatusBadRequest) return } if owner.Protocol() != address.BLS { - w.WriteHeader(400) - _, _ = w.Write([]byte("Miner address must use BLS. A BLS address starts with the prefix 't3'.")) - _, _ = w.Write([]byte("Please create a BLS address by running \"lotus wallet new bls\" while connected to a Lotus node.")) + http.Error(w, + "Miner address must use BLS. A BLS address starts with the prefix 't3'."+ + "Please create a BLS address by running \"lotus wallet new bls\" while connected to a Lotus node.", + http.StatusBadRequest) return } @@ -346,16 +344,14 @@ func (h *handler) mkminer(w http.ResponseWriter, r *http.Request) { To: owner, }, nil) if err != nil { - w.WriteHeader(400) - w.Write([]byte("pushfunds: " + err.Error())) + http.Error(w, "pushfunds: "+err.Error(), http.StatusBadRequest) return } log.Infof("%s: push funds %s", owner, smsg.Cid()) spt, err := ffiwrapper.SealProofTypeFromSectorSize(abi.SectorSize(ssize)) if err != nil { - w.WriteHeader(400) - w.Write([]byte("sealprooftype: " + err.Error())) + http.Error(w, "sealprooftype: "+err.Error(), http.StatusBadRequest) return } @@ -366,8 +362,7 @@ func (h *handler) mkminer(w http.ResponseWriter, r *http.Request) { Peer: abi.PeerID(h.defaultMinerPeer), }) if err != nil { - w.WriteHeader(400) - w.Write([]byte(err.Error())) + http.Error(w, err.Error(), http.StatusBadRequest) return } @@ -382,66 +377,58 @@ func (h *handler) mkminer(w http.ResponseWriter, r *http.Request) { signed, err := h.api.MpoolPushMessage(r.Context(), createStorageMinerMsg, nil) if err != nil { - w.WriteHeader(400) - w.Write([]byte(err.Error())) + http.Error(w, err.Error(), http.StatusBadRequest) return } log.Infof("%s: create miner msg: %s", owner, signed.Cid()) - http.Redirect(w, r, fmt.Sprintf("/wait.html?f=%s&m=%s&o=%s", signed.Cid(), smsg.Cid(), owner), 303) + http.Redirect(w, r, fmt.Sprintf("/wait.html?f=%s&m=%s&o=%s", signed.Cid(), smsg.Cid(), owner), http.StatusSeeOther) } func (h *handler) msgwait(w http.ResponseWriter, r *http.Request) { c, err := cid.Parse(r.FormValue("cid")) if err != nil { - w.WriteHeader(400) - w.Write([]byte(err.Error())) + http.Error(w, err.Error(), http.StatusBadRequest) return } mw, err := h.api.StateWaitMsg(r.Context(), c, build.MessageConfidence) if err != nil { - w.WriteHeader(400) - w.Write([]byte(err.Error())) + http.Error(w, err.Error(), http.StatusBadRequest) return } if mw.Receipt.ExitCode != 0 { - w.WriteHeader(400) - w.Write([]byte(xerrors.Errorf("create miner failed: exit code %d", mw.Receipt.ExitCode).Error())) + http.Error(w, err.Error(), http.StatusBadRequest) return } - w.WriteHeader(200) + w.WriteHeader(http.StatusOK) } func (h *handler) msgwaitaddr(w http.ResponseWriter, r *http.Request) { c, err := cid.Parse(r.FormValue("cid")) if err != nil { - w.WriteHeader(400) - w.Write([]byte(err.Error())) + http.Error(w, err.Error(), http.StatusBadRequest) return } mw, err := h.api.StateWaitMsg(r.Context(), c, build.MessageConfidence) if err != nil { - w.WriteHeader(400) - w.Write([]byte(err.Error())) + http.Error(w, err.Error(), http.StatusBadRequest) return } if mw.Receipt.ExitCode != 0 { - w.WriteHeader(400) - w.Write([]byte(xerrors.Errorf("create miner failed: exit code %d", mw.Receipt.ExitCode).Error())) + http.Error(w, xerrors.Errorf("create miner failed: exit code %d", mw.Receipt.ExitCode).Error(), http.StatusBadRequest) return } - w.WriteHeader(200) + w.WriteHeader(http.StatusOK) var ma power.CreateMinerReturn if err := ma.UnmarshalCBOR(bytes.NewReader(mw.Receipt.Return)); err != nil { log.Errorf("%w", err) - w.WriteHeader(400) - w.Write([]byte(err.Error())) + http.Error(w, err.Error(), http.StatusBadRequest) return } diff --git a/cmd/lotus-keygen/main.go b/cmd/lotus-keygen/main.go index d4c7a2548..33124107e 100644 --- a/cmd/lotus-keygen/main.go +++ b/cmd/lotus-keygen/main.go @@ -54,7 +54,12 @@ func main() { if err != nil { return err } - defer fi.Close() + defer func() { + err2 := fi.Close() + if err == nil { + err = err2 + } + }() b, err := json.Marshal(ki) if err != nil { diff --git a/cmd/lotus-pcr/main.go b/cmd/lotus-pcr/main.go index 0540e843d..d86eb60e9 100644 --- a/cmd/lotus-pcr/main.go +++ b/cmd/lotus-pcr/main.go @@ -142,7 +142,7 @@ var runCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { go func() { - http.ListenAndServe(":6060", nil) + http.ListenAndServe(":6060", nil) //nolint:errcheck }() ctx := context.Background() @@ -445,7 +445,7 @@ func (r *refunder) Refund(ctx context.Context, tipset *types.TipSet, refunds *Mi // Calculate the minimum balance as the total refund we need to issue plus 5% to cover fees minBalance := types.BigAdd(refundSum, types.BigDiv(refundSum, types.NewInt(500))) if balance.LessThan(minBalance) { - log.Errorw("not sufficent funds to cover refunds", "balance", balance, "refund_sum", refundSum, "minimum_required", minBalance) + log.Errorw("not sufficient funds to cover refunds", "balance", balance, "refund_sum", refundSum, "minimum_required", minBalance) return xerrors.Errorf("wallet does not have enough balance to cover refund") } @@ -467,24 +467,24 @@ func (r *refunder) Refund(ctx context.Context, tipset *types.TipSet, refunds *Mi return nil } -type repo struct { +type Repo struct { last abi.ChainEpoch path string } -func NewRepo(path string) (*repo, error) { +func NewRepo(path string) (*Repo, error) { path, err := homedir.Expand(path) if err != nil { return nil, err } - return &repo{ + return &Repo{ last: 0, path: path, }, nil } -func (r *repo) exists() (bool, error) { +func (r *Repo) exists() (bool, error) { _, err := os.Stat(r.path) notexist := os.IsNotExist(err) if notexist { @@ -494,7 +494,7 @@ func (r *repo) exists() (bool, error) { } -func (r *repo) init() error { +func (r *Repo) init() error { exist, err := r.exists() if err != nil { return err @@ -511,7 +511,7 @@ func (r *repo) init() error { return nil } -func (r *repo) Open() (err error) { +func (r *Repo) Open() (err error) { if err = r.init(); err != nil { return } @@ -542,11 +542,11 @@ func (r *repo) Open() (err error) { return } -func (r *repo) Height() abi.ChainEpoch { +func (r *Repo) Height() abi.ChainEpoch { return r.last } -func (r *repo) SetHeight(last abi.ChainEpoch) (err error) { +func (r *Repo) SetHeight(last abi.ChainEpoch) (err error) { r.last = last var f *os.File f, err = os.OpenFile(filepath.Join(r.path, "height"), os.O_RDWR, 0644) diff --git a/cmd/lotus-seal-worker/main.go b/cmd/lotus-seal-worker/main.go index d190142e4..1b6ed2782 100644 --- a/cmd/lotus-seal-worker/main.go +++ b/cmd/lotus-seal-worker/main.go @@ -185,7 +185,7 @@ var runCmd = &cli.Command{ return err } if v.APIVersion != build.APIVersion { - return xerrors.Errorf("lotus-miner API version doesn't match: local: ", api.Version{APIVersion: build.APIVersion}) + return xerrors.Errorf("lotus-miner API version doesn't match: local: %s", api.Version{APIVersion: build.APIVersion}) } log.Infof("Remote version %s", v) @@ -420,10 +420,11 @@ func watchMinerConn(ctx context.Context, cctx *cli.Context, nodeApi api.StorageM log.Errorf("getting executable for auto-restart: %+v", err) } - log.Sync() + _ = log.Sync() // TODO: there are probably cleaner/more graceful ways to restart, // but this is good enough for now (FSM can recover from the mess this creates) + //nolint:gosec if err := syscall.Exec(exe, []string{exe, fmt.Sprintf("--worker-repo=%s", cctx.String("worker-repo")), fmt.Sprintf("--miner-repo=%s", cctx.String("miner-repo")), @@ -450,7 +451,7 @@ func extractRoutableIP(timeout time.Duration) (string, error) { env, ok := os.LookupEnv(minerMultiAddrKey) if !ok { // TODO remove after deprecation period - env, ok = os.LookupEnv(deprecatedMinerMultiAddrKey) + _, ok = os.LookupEnv(deprecatedMinerMultiAddrKey) if ok { log.Warnf("Using a deprecated env(%s) value, please use env(%s) instead.", deprecatedMinerMultiAddrKey, minerMultiAddrKey) } @@ -461,7 +462,7 @@ func extractRoutableIP(timeout time.Duration) (string, error) { if err != nil { return "", err } - defer conn.Close() + defer conn.Close() //nolint:errcheck localAddr := conn.LocalAddr().(*net.TCPAddr) diff --git a/cmd/lotus-seed/main.go b/cmd/lotus-seed/main.go index 508d1d222..48691d5ec 100644 --- a/cmd/lotus-seed/main.go +++ b/cmd/lotus-seed/main.go @@ -114,6 +114,9 @@ var preSealCmd = &cli.Command{ return err } kb, err := hex.DecodeString(string(kh)) + if err != nil { + return err + } if err := json.Unmarshal(kb, k); err != nil { return err } diff --git a/cmd/lotus-shed/keyinfo.go b/cmd/lotus-shed/keyinfo.go index b3a42e1c1..f397bd4c7 100644 --- a/cmd/lotus-shed/keyinfo.go +++ b/cmd/lotus-shed/keyinfo.go @@ -69,7 +69,7 @@ var keyinfoImportCmd = &cli.Command{ if err != nil { return err } - defer inputFile.Close() + defer inputFile.Close() //nolint:errcheck input = bufio.NewReader(inputFile) } @@ -98,7 +98,7 @@ var keyinfoImportCmd = &cli.Command{ return err } - defer lkrepo.Close() + defer lkrepo.Close() //nolint:errcheck keystore, err := lkrepo.KeyStore() if err != nil { @@ -150,7 +150,7 @@ var keyinfoInfoCmd = &cli.Command{ The 'format' flag takes a golang text/template template as its value. - The following fields can be retrived through this command + The following fields can be retrieved through this command Type Address PublicKey @@ -159,7 +159,7 @@ var keyinfoInfoCmd = &cli.Command{ Examples - Retreive the address of a lotus wallet + Retrieve the address of a lotus wallet lotus-shed keyinfo info --format '{{ .Address }}' wallet.keyinfo `, Flags: []cli.Flag{ @@ -181,7 +181,7 @@ var keyinfoInfoCmd = &cli.Command{ if err != nil { return err } - defer inputFile.Close() + defer inputFile.Close() //nolint:errcheck input = bufio.NewReader(inputFile) } diff --git a/cmd/lotus-storage-miner/info_all.go b/cmd/lotus-storage-miner/info_all.go index 78b7cb0d5..265ba78a4 100644 --- a/cmd/lotus-storage-miner/info_all.go +++ b/cmd/lotus-storage-miner/info_all.go @@ -126,7 +126,9 @@ var infoAllCmd = &cli.Command{ fs := &flag.FlagSet{} for _, f := range sectorsStatusCmd.Flags { - f.Apply(fs) + if err := f.Apply(fs); err != nil { + return err + } } if err := fs.Parse([]string{"--log", "--on-chain-info", fmt.Sprint(s)}); err != nil { return err diff --git a/cmd/lotus-storage-miner/run.go b/cmd/lotus-storage-miner/run.go index 8b10e7c1e..38fa8340e 100644 --- a/cmd/lotus-storage-miner/run.go +++ b/cmd/lotus-storage-miner/run.go @@ -53,7 +53,10 @@ var runCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { if !cctx.Bool("enable-gpu-proving") { - os.Setenv("BELLMAN_NO_GPU", "true") + err := os.Setenv("BELLMAN_NO_GPU", "true") + if err != nil { + return err + } } nodeApi, ncloser, err := lcli.GetFullNodeAPI(cctx) diff --git a/cmd/lotus-storage-miner/sealing.go b/cmd/lotus-storage-miner/sealing.go index c9ed224b3..2f966dcca 100644 --- a/cmd/lotus-storage-miner/sealing.go +++ b/cmd/lotus-storage-miner/sealing.go @@ -3,13 +3,14 @@ package main import ( "encoding/json" "fmt" - "golang.org/x/xerrors" "os" "sort" "strings" "text/tabwriter" "time" + "golang.org/x/xerrors" + "github.com/fatih/color" "github.com/urfave/cli/v2" diff --git a/cmd/lotus-storage-miner/sectors.go b/cmd/lotus-storage-miner/sectors.go index 59bb97c99..454162d87 100644 --- a/cmd/lotus-storage-miner/sectors.go +++ b/cmd/lotus-storage-miner/sectors.go @@ -2,13 +2,14 @@ package main import ( "fmt" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" "os" "sort" "strconv" "text/tabwriter" "time" + "github.com/filecoin-project/specs-actors/actors/builtin/miner" + "github.com/urfave/cli/v2" "golang.org/x/xerrors" diff --git a/cmd/lotus-townhall/main.go b/cmd/lotus-townhall/main.go index 5f9603fba..7e8f6df7f 100644 --- a/cmd/lotus-townhall/main.go +++ b/cmd/lotus-townhall/main.go @@ -106,10 +106,11 @@ func handler(ps *pubsub.PubSub) func(w http.ResponseWriter, r *http.Request) { return } - sub, err := ps.Subscribe(topic) + sub, err := ps.Subscribe(topic) //nolint if err != nil { return } + defer sub.Cancel() //nolint:errcheck fmt.Println("new conn") diff --git a/extern/sector-storage/ffiwrapper/partialfile.go b/extern/sector-storage/ffiwrapper/partialfile.go index 74992f7ba..597e33105 100644 --- a/extern/sector-storage/ffiwrapper/partialfile.go +++ b/extern/sector-storage/ffiwrapper/partialfile.go @@ -118,7 +118,7 @@ func openPartialFile(maxPieceSize abi.PaddedPieceSize, path string) (*partialFil trailerLen := binary.LittleEndian.Uint32(tlen[:]) expectLen := int64(trailerLen) + int64(len(tlen)) + int64(maxPieceSize) if expectLen != st.Size() { - return xerrors.Errorf("file '%d' has inconsistent length; has %d bytes; expected %d (%d trailer, %d sector data)", path, st.Size(), expectLen, int64(trailerLen)+int64(len(tlen)), maxPieceSize) + return xerrors.Errorf("file '%s' has inconsistent length; has %d bytes; expected %d (%d trailer, %d sector data)", path, st.Size(), expectLen, int64(trailerLen)+int64(len(tlen)), maxPieceSize) } if trailerLen > veryLargeRle { log.Warnf("Partial file '%s' has a VERY large trailer with %d bytes", path, trailerLen) diff --git a/extern/sector-storage/fsutil/statfs_unix.go b/extern/sector-storage/fsutil/statfs_unix.go index 7fcb8af37..831fd8b4f 100644 --- a/extern/sector-storage/fsutil/statfs_unix.go +++ b/extern/sector-storage/fsutil/statfs_unix.go @@ -12,6 +12,8 @@ func Statfs(path string) (FsStat, error) { return FsStat{}, xerrors.Errorf("statfs: %w", err) } + // force int64 to handle platform specific differences + //nolint:unconvert return FsStat{ Capacity: int64(stat.Blocks) * int64(stat.Bsize), Available: int64(stat.Bavail) * int64(stat.Bsize), diff --git a/extern/sector-storage/mock/mock.go b/extern/sector-storage/mock/mock.go index 783d2e19c..e3fcc3f5b 100644 --- a/extern/sector-storage/mock/mock.go +++ b/extern/sector-storage/mock/mock.go @@ -438,7 +438,7 @@ func (m mockVerif) VerifyWindowPoSt(ctx context.Context, info abi.WindowPoStVeri } if !bytes.Equal(b1, b2) { - return false, xerrors.Errorf("proven and challenged sector sets didn't match: %s != !s", string(b1), string(b2)) + return false, xerrors.Errorf("proven and challenged sector sets didn't match: %s != %s", string(b1), string(b2)) } } diff --git a/extern/sector-storage/tarutil/systar.go b/extern/sector-storage/tarutil/systar.go index 6811cb46a..2329aafc7 100644 --- a/extern/sector-storage/tarutil/systar.go +++ b/extern/sector-storage/tarutil/systar.go @@ -36,6 +36,8 @@ func ExtractTar(body io.Reader, dir string) error { return xerrors.Errorf("creating file %s: %w", filepath.Join(dir, header.Name), err) } + // This data is coming from a trusted source, no need to check the size. + //nolint:gosec if _, err := io.Copy(f, tr); err != nil { return err } diff --git a/extern/storage-sealing/fsm.go b/extern/storage-sealing/fsm.go index d9648a99d..82db5c15a 100644 --- a/extern/storage-sealing/fsm.go +++ b/extern/storage-sealing/fsm.go @@ -348,7 +348,9 @@ func (m *Sealing) restartSectors(ctx context.Context) error { timer := time.NewTimer(cfg.WaitDealsDelay) go func() { <-timer.C - m.StartPacking(sector.SectorNumber) + if err := m.StartPacking(sector.SectorNumber); err != nil { + log.Errorf("starting sector %d: %+v", sector.SectorNumber, err) + } }() } } diff --git a/extern/storage-sealing/sealing.go b/extern/storage-sealing/sealing.go index 062ade2a3..a19ada176 100644 --- a/extern/storage-sealing/sealing.go +++ b/extern/storage-sealing/sealing.go @@ -355,7 +355,9 @@ func (m *Sealing) newDealSector() (abi.SectorNumber, error) { timer := time.NewTimer(cf.WaitDealsDelay) go func() { <-timer.C - m.StartPacking(sid) + if err := m.StartPacking(sid); err != nil { + log.Errorf("starting sector %d: %+v", sid, err) + } }() } @@ -396,7 +398,6 @@ func (m *Sealing) Address() address.Address { func getDealPerSectorLimit(size abi.SectorSize) uint64 { if size < 64<<30 { return 256 - } else { - return 512 } + return 512 } diff --git a/extern/storage-sealing/types.go b/extern/storage-sealing/types.go index a9c2a7203..9d82ea2c2 100644 --- a/extern/storage-sealing/types.go +++ b/extern/storage-sealing/types.go @@ -3,6 +3,7 @@ package sealing import ( "bytes" "context" + "github.com/ipfs/go-cid" "github.com/filecoin-project/specs-actors/actors/abi" diff --git a/go.mod b/go.mod index a8a2f2e0e..813636d93 100644 --- a/go.mod +++ b/go.mod @@ -92,7 +92,6 @@ require ( github.com/libp2p/go-libp2p-kad-dht v0.8.3 github.com/libp2p/go-libp2p-mplex v0.2.4 github.com/libp2p/go-libp2p-noise v0.1.1 - github.com/libp2p/go-libp2p-peer v0.2.0 github.com/libp2p/go-libp2p-peerstore v0.2.6 github.com/libp2p/go-libp2p-pubsub v0.3.5-0.20200820194335-bfc96c2cd081 github.com/libp2p/go-libp2p-quic-transport v0.7.1 diff --git a/journal/journal.go b/journal/journal.go index 74208c62e..f043d37d6 100644 --- a/journal/journal.go +++ b/journal/journal.go @@ -5,7 +5,6 @@ import ( "fmt" "os" "path/filepath" - "sync" "time" logging "github.com/ipfs/go-log" @@ -48,8 +47,6 @@ type fsJournal struct { fi *os.File fSize int64 - lk sync.Mutex - journalDir string incoming chan *JournalEntry @@ -58,7 +55,7 @@ type fsJournal struct { closing chan struct{} } -func OpenFSJournal(dir string) (*fsJournal, error) { +func OpenFSJournal(dir string) (Journal, error) { fsj := &fsJournal{ journalDir: dir, incoming: make(chan *JournalEntry, 32), @@ -94,7 +91,7 @@ func (fsj *fsJournal) putEntry(je *JournalEntry) error { fsj.fSize += int64(n) if fsj.fSize >= fsj.journalSizeLimit { - fsj.rollJournalFile() + return fsj.rollJournalFile() } return nil @@ -104,7 +101,10 @@ const RFC3339nocolon = "2006-01-02T150405Z0700" func (fsj *fsJournal) rollJournalFile() error { if fsj.fi != nil { - fsj.fi.Close() + err := fsj.fi.Close() + if err != nil { + return err + } } nfi, err := os.Create(filepath.Join(fsj.journalDir, fmt.Sprintf("lotus-journal-%s.ndjson", build.Clock.Now().Format(RFC3339nocolon)))) @@ -125,7 +125,9 @@ func (fsj *fsJournal) runLoop() { log.Errorw("failed to write out journal entry", "entry", je, "err", err) } case <-fsj.closing: - fsj.fi.Close() + if err := fsj.fi.Close(); err != nil { + log.Errorw("failed to close journal", "err", err) + } return } } diff --git a/lib/blockstore/blockstore.go b/lib/blockstore/blockstore.go index 079338041..9e74f4373 100644 --- a/lib/blockstore/blockstore.go +++ b/lib/blockstore/blockstore.go @@ -28,12 +28,12 @@ func NewTemporary() blockstore.Blockstore { return NewBlockstore(ds.NewMapDatastore()) } -// NewTemporary returns a thread-safe temporary blockstore. +// NewTemporarySync returns a thread-safe temporary blockstore. func NewTemporarySync() blockstore.Blockstore { return NewBlockstore(dssync.MutexWrap(ds.NewMapDatastore())) } -// Wraps the underlying blockstore in an "identity" blockstore. +// WrapIDStore wraps the underlying blockstore in an "identity" blockstore. func WrapIDStore(bstore blockstore.Blockstore) blockstore.Blockstore { return blockstore.NewIdStore(bstore) } diff --git a/lib/cachebs/cachebs.go b/lib/cachebs/cachebs.go index 0880acc6e..046f100c0 100644 --- a/lib/cachebs/cachebs.go +++ b/lib/cachebs/cachebs.go @@ -11,6 +11,7 @@ import ( bstore "github.com/filecoin-project/lotus/lib/blockstore" ) +//nolint:deadcode,varcheck var log = logging.Logger("cachebs") type CacheBS struct { diff --git a/lib/rpcenc/reader.go b/lib/rpcenc/reader.go index ffb13577f..3f4d5c604 100644 --- a/lib/rpcenc/reader.go +++ b/lib/rpcenc/reader.go @@ -64,7 +64,7 @@ func ReaderParamEncoder(addr string) jsonrpc.Option { return } - defer resp.Body.Close() + defer resp.Body.Close() //nolint:errcheck if resp.StatusCode != 200 { b, _ := ioutil.ReadAll(resp.Body) diff --git a/lib/rpcenc/reader_test.go b/lib/rpcenc/reader_test.go index d33bbbd26..d6289c150 100644 --- a/lib/rpcenc/reader_test.go +++ b/lib/rpcenc/reader_test.go @@ -56,7 +56,7 @@ func TestReaderProxy(t *testing.T) { read, err := client.ReadAll(context.TODO(), strings.NewReader("pooooootato")) require.NoError(t, err) - require.Equal(t, "pooooootato", string(read), "potatos weren't equal") + require.Equal(t, "pooooootato", string(read), "potatoes weren't equal") } func TestNullReaderProxy(t *testing.T) { diff --git a/lib/sigs/bls/bls_bench_test.go b/lib/sigs/bls/bls_bench_test.go index a6c033912..118d25975 100644 --- a/lib/sigs/bls/bls_bench_test.go +++ b/lib/sigs/bls/bls_bench_test.go @@ -2,8 +2,9 @@ package bls import ( "crypto/rand" - "github.com/filecoin-project/go-address" "testing" + + "github.com/filecoin-project/go-address" ) func BenchmarkBLSSign(b *testing.B) { @@ -12,7 +13,7 @@ func BenchmarkBLSSign(b *testing.B) { b.StopTimer() pk, _ := signer.GenPrivate() randMsg := make([]byte, 32) - rand.Read(randMsg) + _, _ = rand.Read(randMsg) b.StartTimer() _, _ = signer.Sign(pk, randMsg) @@ -24,7 +25,7 @@ func BenchmarkBLSVerify(b *testing.B) { for i := 0; i < b.N; i++ { b.StopTimer() randMsg := make([]byte, 32) - rand.Read(randMsg) + _, _ = rand.Read(randMsg) priv, _ := signer.GenPrivate() pk, _ := signer.ToPublic(priv) diff --git a/lotuspond/api.go b/lotuspond/api.go index 169cec1de..e61372a87 100644 --- a/lotuspond/api.go +++ b/lotuspond/api.go @@ -17,7 +17,7 @@ import ( type NodeState int const ( - NodeUnknown = iota + NodeUnknown = iota //nolint:deadcode NodeRunning NodeStopped ) diff --git a/lotuspond/outmux.go b/lotuspond/outmux.go index 406001078..199c83ef1 100644 --- a/lotuspond/outmux.go +++ b/lotuspond/outmux.go @@ -73,7 +73,7 @@ func (m *outmux) run() { case msg := <-stdout: for k, out := range m.outs { if err := out.WriteMessage(websocket.BinaryMessage, msg); err != nil { - out.Close() + _ = out.Close() fmt.Printf("outmux write failed: %s\n", err) delete(m.outs, k) } diff --git a/markets/storageadapter/client.go b/markets/storageadapter/client.go index 576a0e98a..91fc6a054 100644 --- a/markets/storageadapter/client.go +++ b/markets/storageadapter/client.go @@ -266,7 +266,7 @@ func (c *ClientNodeAdapter) OnDealSectorCommitted(ctx context.Context, provider return false, nil } - sd, err := stmgr.GetStorageDeal(ctx, c.StateManager, abi.DealID(dealId), ts) + sd, err := stmgr.GetStorageDeal(ctx, c.StateManager, dealId, ts) if err != nil { return false, xerrors.Errorf("failed to look up deal on chain: %w", err) } @@ -303,7 +303,7 @@ func (c *ClientNodeAdapter) OnDealSectorCommitted(ctx context.Context, provider } for _, did := range params.DealIDs { - if did == abi.DealID(dealId) { + if did == dealId { sectorNumber = params.SectorNumber sectorFound = true return true, false, nil @@ -464,7 +464,7 @@ func (c *ClientNodeAdapter) ValidateAskSignature(ctx context.Context, ask *stora mi, err := c.StateMinerInfo(ctx, ask.Ask.Miner, tsk) if err != nil { - return false, xerrors.Errorf("failed to get worker for miner in ask", err) + return false, xerrors.Errorf("failed to get worker for miner in ask: %w", err) } sigb, err := cborutil.Dump(ask.Ask) diff --git a/markets/storageadapter/provider.go b/markets/storageadapter/provider.go index f796a2300..eaa2a3ae2 100644 --- a/markets/storageadapter/provider.go +++ b/markets/storageadapter/provider.go @@ -69,7 +69,7 @@ func (n *ProviderNodeAdapter) PublishDeals(ctx context.Context, deal storagemark }) if err != nil { - return cid.Undef, xerrors.Errorf("serializing PublishStorageDeals params failed: ", err) + return cid.Undef, xerrors.Errorf("serializing PublishStorageDeals params failed: %w", err) } // TODO: We may want this to happen after fetching data @@ -267,7 +267,7 @@ func (n *ProviderNodeAdapter) OnDealSectorCommitted(ctx context.Context, provide return false, nil } - sd, err := n.StateMarketStorageDeal(ctx, abi.DealID(dealID), ts.Key()) + sd, err := n.StateMarketStorageDeal(ctx, dealID, ts.Key()) if err != nil { return false, xerrors.Errorf("failed to look up deal on chain: %w", err) } @@ -305,7 +305,7 @@ func (n *ProviderNodeAdapter) OnDealSectorCommitted(ctx context.Context, provide } for _, did := range params.DealIDs { - if did == abi.DealID(dealID) { + if did == dealID { sectorNumber = params.SectorNumber sectorFound = true return true, false, nil diff --git a/miner/miner.go b/miner/miner.go index 27d3c040d..ed407a0c7 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -36,7 +36,7 @@ type waitFunc func(ctx context.Context, baseTime uint64) (func(bool, error), abi func randTimeOffset(width time.Duration) time.Duration { buf := make([]byte, 8) - rand.Reader.Read(buf) + rand.Reader.Read(buf) //nolint:errcheck val := time.Duration(binary.BigEndian.Uint64(buf) % uint64(width)) return val - (width / 2) @@ -508,12 +508,3 @@ func (c *cachedActorLookup) StateGetActor(ctx context.Context, a address.Address } type ActorLookup func(context.Context, address.Address, types.TipSetKey) (*types.Actor, error) - -func countFrom(msgs []*types.SignedMessage, from address.Address) (out int) { - for _, msg := range msgs { - if msg.Message.From == from { - out++ - } - } - return out -} diff --git a/node/builder.go b/node/builder.go index 2b132a7de..86d2aff7a 100644 --- a/node/builder.go +++ b/node/builder.go @@ -67,6 +67,7 @@ import ( "github.com/filecoin-project/lotus/storage/sectorblocks" ) +//nolint:deadcode,varcheck var log = logging.Logger("builder") // special is a type used to give keys to modules which diff --git a/node/impl/client/client.go b/node/impl/client/client.go index 3adc559a5..3cba94ddb 100644 --- a/node/impl/client/client.go +++ b/node/impl/client/client.go @@ -109,7 +109,7 @@ func (a *API) ClientStartDeal(ctx context.Context, params *api.StartDealParams) continue } if c.Equals(params.Data.Root) { - storeID = &importID + storeID = &importID //nolint break } } @@ -614,7 +614,7 @@ func (a *API) ClientCalcCommP(ctx context.Context, inpath string) (*api.CommPRet if err != nil { return nil, err } - defer rdr.Close() + defer rdr.Close() //nolint:errcheck stat, err := rdr.Stat() if err != nil { @@ -700,7 +700,7 @@ func (a *API) clientImport(ctx context.Context, ref api.FileRef, store *multisto if err != nil { return cid.Undef, err } - defer f.Close() + defer f.Close() //nolint:errcheck stat, err := f.Stat() if err != nil { diff --git a/node/impl/full/mpool.go b/node/impl/full/mpool.go index bde7d4f81..bd10b2ca8 100644 --- a/node/impl/full/mpool.go +++ b/node/impl/full/mpool.go @@ -2,14 +2,15 @@ package full import ( "context" - "github.com/filecoin-project/specs-actors/actors/abi" - "github.com/filecoin-project/specs-actors/actors/abi/big" + "github.com/filecoin-project/go-address" "github.com/ipfs/go-cid" "go.uber.org/fx" "golang.org/x/xerrors" - "github.com/filecoin-project/go-address" + "github.com/filecoin-project/specs-actors/actors/abi" + "github.com/filecoin-project/specs-actors/actors/abi/big" + "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/messagepool" "github.com/filecoin-project/lotus/chain/store" diff --git a/node/impl/full/multisig.go b/node/impl/full/multisig.go index 88ff4cdc9..f1e3c61fd 100644 --- a/node/impl/full/multisig.go +++ b/node/impl/full/multisig.go @@ -28,7 +28,7 @@ type MsigAPI struct { MpoolAPI MpoolAPI } -// TODO: remove gp (gasPrice) from arguemnts +// TODO: remove gp (gasPrice) from arguments func (a *MsigAPI) MsigCreate(ctx context.Context, req uint64, addrs []address.Address, duration abi.ChainEpoch, val types.BigInt, src address.Address, gp types.BigInt) (cid.Cid, error) { lenAddrs := uint64(len(addrs)) diff --git a/node/impl/full/state.go b/node/impl/full/state.go index f5421e2ba..36721a93d 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -443,9 +443,8 @@ func (a *StateAPI) StateSearchMsg(ctx context.Context, msg cid.Cid) (*api.MsgLoo TipSet: ts.Key(), Height: ts.Height(), }, nil - } else { - return nil, nil } + return nil, nil } func (a *StateAPI) StateGetReceipt(ctx context.Context, msg cid.Cid, tsk types.TipSetKey) (*types.MessageReceipt, error) { @@ -557,7 +556,7 @@ func (a *StateAPI) StateMarketDeals(ctx context.Context, tsk types.TipSetKey) (m } else if !found { s.SectorStartEpoch = -1 } - out[strconv.FormatInt(int64(i), 10)] = api.MarketDeal{ + out[strconv.FormatInt(i, 10)] = api.MarketDeal{ Proposal: d, State: s, } @@ -785,10 +784,6 @@ func (a *StateAPI) StateSectorPartition(ctx context.Context, maddr address.Addre return nil, err } - if found == nil { - - } - return found, nil } @@ -1147,12 +1142,12 @@ func (a *StateAPI) StateDealProviderCollateralBounds(ctx context.Context, size a }) if err != nil { - return api.DealCollateralBounds{}, xerrors.Errorf("getting power and reward actor states: %w") + return api.DealCollateralBounds{}, xerrors.Errorf("getting power and reward actor states: %w", err) } circ, err := a.StateCirculatingSupply(ctx, ts.Key()) if err != nil { - return api.DealCollateralBounds{}, xerrors.Errorf("getting total circulating supply: %w") + return api.DealCollateralBounds{}, xerrors.Errorf("getting total circulating supply: %w", err) } min, max := market.DealProviderCollateralBounds(size, verified, powerState.ThisEpochQualityAdjPower, rewardState.ThisEpochBaselinePower, circ.FilCirculating) @@ -1175,6 +1170,9 @@ func (a *StateAPI) StateCirculatingSupply(ctx context.Context, tsk types.TipSetK cst := cbor.NewCborStore(a.Chain.Blockstore()) sTree, err := state.LoadStateTree(cst, st) + if err != nil { + return api.CirculatingSupply{}, err + } return a.StateManager.GetCirculatingSupplyDetailed(ctx, ts.Height(), sTree) } diff --git a/node/impl/full/sync.go b/node/impl/full/sync.go index 758ecb34d..9066df56f 100644 --- a/node/impl/full/sync.go +++ b/node/impl/full/sync.go @@ -90,8 +90,7 @@ func (a *SyncAPI) SyncSubmitBlock(ctx context.Context, blk *types.BlockMsg) erro return xerrors.Errorf("serializing block for pubsub publishing failed: %w", err) } - // TODO: anything else to do here? - return a.PubSub.Publish(build.BlocksTopic(a.NetName), b) + return a.PubSub.Publish(build.BlocksTopic(a.NetName), b) //nolint:staticcheck } func (a *SyncAPI) SyncIncomingBlocks(ctx context.Context) (<-chan *types.BlockHeader, error) { diff --git a/node/impl/full/wallet.go b/node/impl/full/wallet.go index b1d963f1f..440f9642f 100644 --- a/node/impl/full/wallet.go +++ b/node/impl/full/wallet.go @@ -2,19 +2,18 @@ package full import ( "context" - "github.com/filecoin-project/specs-actors/actors/abi/big" - - "github.com/filecoin-project/lotus/lib/sigs" "github.com/filecoin-project/go-address" + "go.uber.org/fx" + "golang.org/x/xerrors" + + "github.com/filecoin-project/specs-actors/actors/abi/big" "github.com/filecoin-project/specs-actors/actors/crypto" "github.com/filecoin-project/lotus/chain/stmgr" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/wallet" - - "go.uber.org/fx" - "golang.org/x/xerrors" + "github.com/filecoin-project/lotus/lib/sigs" ) type WalletAPI struct { @@ -45,9 +44,8 @@ func (a *WalletAPI) WalletBalance(ctx context.Context, addr address.Address) (ty if xerrors.Is(err, types.ErrActorNotFound) { return big.Zero(), nil - } else { - return bal, err } + return bal, err } func (a *WalletAPI) WalletSign(ctx context.Context, k address.Address, msg []byte) (*crypto.Signature, error) { diff --git a/node/modules/client.go b/node/modules/client.go index 80675a3d2..284e254d6 100644 --- a/node/modules/client.go +++ b/node/modules/client.go @@ -123,8 +123,7 @@ func StorageClient(lc fx.Lifecycle, h host.Host, ibs dtypes.ClientBlockstore, md return c.Start(ctx) }, OnStop: func(context.Context) error { - c.Stop() - return nil + return c.Stop() }, }) return c, nil diff --git a/node/modules/core.go b/node/modules/core.go index 6d2ca64d0..0305c737e 100644 --- a/node/modules/core.go +++ b/node/modules/core.go @@ -36,8 +36,8 @@ func RecordValidator(ps peerstore.Peerstore) record.Validator { } } -const JWTSecretName = "auth-jwt-private" //nolint:gosec -const KTJwtHmacSecret = "jwt-hmac-secret" +const JWTSecretName = "auth-jwt-private" //nolint:gosec +const KTJwtHmacSecret = "jwt-hmac-secret" //nolint:gosec type JwtPayload struct { Allow []auth.Permission diff --git a/node/modules/graphsync.go b/node/modules/graphsync.go index 601ad8840..9bdc9bcca 100644 --- a/node/modules/graphsync.go +++ b/node/modules/graphsync.go @@ -8,7 +8,7 @@ import ( gsnet "github.com/ipfs/go-graphsync/network" "github.com/ipfs/go-graphsync/storeutil" "github.com/libp2p/go-libp2p-core/host" - peer "github.com/libp2p/go-libp2p-peer" + "github.com/libp2p/go-libp2p-core/peer" "go.uber.org/fx" ) diff --git a/node/modules/services.go b/node/modules/services.go index 013a6c0af..fc7486abe 100644 --- a/node/modules/services.go +++ b/node/modules/services.go @@ -76,7 +76,7 @@ func RunBlockSync(h host.Host, svc *blocksync.BlockSyncService) { func HandleIncomingBlocks(mctx helpers.MetricsCtx, lc fx.Lifecycle, ps *pubsub.PubSub, s *chain.Syncer, bserv dtypes.ChainBlockService, chain *store.ChainStore, stmgr *stmgr.StateManager, h host.Host, nn dtypes.NetworkName) { ctx := helpers.LifecycleCtx(mctx, lc) - blocksub, err := ps.Subscribe(build.BlocksTopic(nn)) + blocksub, err := ps.Subscribe(build.BlocksTopic(nn)) //nolint if err != nil { panic(err) } @@ -98,7 +98,7 @@ func HandleIncomingBlocks(mctx helpers.MetricsCtx, lc fx.Lifecycle, ps *pubsub.P func HandleIncomingMessages(mctx helpers.MetricsCtx, lc fx.Lifecycle, ps *pubsub.PubSub, mpool *messagepool.MessagePool, h host.Host, nn dtypes.NetworkName) { ctx := helpers.LifecycleCtx(mctx, lc) - msgsub, err := ps.Subscribe(build.MessagesTopic(nn)) + msgsub, err := ps.Subscribe(build.MessagesTopic(nn)) //nolint:staticcheck if err != nil { panic(err) } diff --git a/storage/adapter_storage_miner.go b/storage/adapter_storage_miner.go index 1890a369f..0963b07e6 100644 --- a/storage/adapter_storage_miner.go +++ b/storage/adapter_storage_miner.go @@ -3,7 +3,6 @@ package storage import ( "bytes" "context" - "github.com/filecoin-project/lotus/api" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" @@ -18,6 +17,7 @@ import ( "github.com/filecoin-project/specs-actors/actors/crypto" "github.com/filecoin-project/specs-actors/actors/util/adt" + "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api/apibstore" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" diff --git a/storage/addresses.go b/storage/addresses.go index e041024c6..a1c05660f 100644 --- a/storage/addresses.go +++ b/storage/addresses.go @@ -2,6 +2,7 @@ package storage import ( "context" + "golang.org/x/xerrors" "github.com/filecoin-project/go-address" diff --git a/storage/wdpost_run.go b/storage/wdpost_run.go index 7367ceafa..821c23cd7 100644 --- a/storage/wdpost_run.go +++ b/storage/wdpost_run.go @@ -4,13 +4,13 @@ import ( "bytes" "context" "errors" - "github.com/filecoin-project/specs-actors/actors/abi/big" "time" "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-address" "github.com/filecoin-project/specs-actors/actors/abi" + "github.com/filecoin-project/specs-actors/actors/abi/big" "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/crypto" diff --git a/tools/stats/head_buffer.go b/tools/stats/head_buffer.go index 1c3bf9777..0a7c63e6e 100644 --- a/tools/stats/head_buffer.go +++ b/tools/stats/head_buffer.go @@ -11,7 +11,7 @@ type headBuffer struct { size int } -func NewHeadBuffer(size int) *headBuffer { +func newHeadBuffer(size int) *headBuffer { buffer := list.New() buffer.Init() @@ -21,7 +21,7 @@ func NewHeadBuffer(size int) *headBuffer { } } -func (h *headBuffer) Push(hc *api.HeadChange) (rethc *api.HeadChange) { +func (h *headBuffer) push(hc *api.HeadChange) (rethc *api.HeadChange) { if h.buffer.Len() == h.size { var ok bool @@ -39,7 +39,7 @@ func (h *headBuffer) Push(hc *api.HeadChange) (rethc *api.HeadChange) { return } -func (h *headBuffer) Pop() { +func (h *headBuffer) pop() { el := h.buffer.Back() if el != nil { h.buffer.Remove(el) diff --git a/tools/stats/head_buffer_test.go b/tools/stats/head_buffer_test.go index 098c90a96..4059f730e 100644 --- a/tools/stats/head_buffer_test.go +++ b/tools/stats/head_buffer_test.go @@ -10,34 +10,34 @@ import ( func TestHeadBuffer(t *testing.T) { t.Run("Straight push through", func(t *testing.T) { - hb := NewHeadBuffer(5) - require.Nil(t, hb.Push(&api.HeadChange{Type: "1"})) - require.Nil(t, hb.Push(&api.HeadChange{Type: "2"})) - require.Nil(t, hb.Push(&api.HeadChange{Type: "3"})) - require.Nil(t, hb.Push(&api.HeadChange{Type: "4"})) - require.Nil(t, hb.Push(&api.HeadChange{Type: "5"})) + hb := newHeadBuffer(5) + require.Nil(t, hb.push(&api.HeadChange{Type: "1"})) + require.Nil(t, hb.push(&api.HeadChange{Type: "2"})) + require.Nil(t, hb.push(&api.HeadChange{Type: "3"})) + require.Nil(t, hb.push(&api.HeadChange{Type: "4"})) + require.Nil(t, hb.push(&api.HeadChange{Type: "5"})) - hc := hb.Push(&api.HeadChange{Type: "6"}) + hc := hb.push(&api.HeadChange{Type: "6"}) require.Equal(t, hc.Type, "1") }) t.Run("Reverts", func(t *testing.T) { - hb := NewHeadBuffer(5) - require.Nil(t, hb.Push(&api.HeadChange{Type: "1"})) - require.Nil(t, hb.Push(&api.HeadChange{Type: "2"})) - require.Nil(t, hb.Push(&api.HeadChange{Type: "3"})) - hb.Pop() - require.Nil(t, hb.Push(&api.HeadChange{Type: "3a"})) - hb.Pop() - require.Nil(t, hb.Push(&api.HeadChange{Type: "3b"})) - require.Nil(t, hb.Push(&api.HeadChange{Type: "4"})) - require.Nil(t, hb.Push(&api.HeadChange{Type: "5"})) + hb := newHeadBuffer(5) + require.Nil(t, hb.push(&api.HeadChange{Type: "1"})) + require.Nil(t, hb.push(&api.HeadChange{Type: "2"})) + require.Nil(t, hb.push(&api.HeadChange{Type: "3"})) + hb.pop() + require.Nil(t, hb.push(&api.HeadChange{Type: "3a"})) + hb.pop() + require.Nil(t, hb.push(&api.HeadChange{Type: "3b"})) + require.Nil(t, hb.push(&api.HeadChange{Type: "4"})) + require.Nil(t, hb.push(&api.HeadChange{Type: "5"})) - hc := hb.Push(&api.HeadChange{Type: "6"}) + hc := hb.push(&api.HeadChange{Type: "6"}) require.Equal(t, hc.Type, "1") - hc = hb.Push(&api.HeadChange{Type: "7"}) + hc = hb.push(&api.HeadChange{Type: "7"}) require.Equal(t, hc.Type, "2") - hc = hb.Push(&api.HeadChange{Type: "8"}) + hc = hb.push(&api.HeadChange{Type: "8"}) require.Equal(t, hc.Type, "3b") }) } diff --git a/tools/stats/metrics.go b/tools/stats/metrics.go index ab7b876bc..138e2831f 100644 --- a/tools/stats/metrics.go +++ b/tools/stats/metrics.go @@ -251,16 +251,13 @@ func RecordTipsetStatePoints(ctx context.Context, api api.FullNode, pl *PointLis return err } - err = mp.ForEach(nil, func(key string) error { + var claim power.Claim + err = mp.ForEach(&claim, func(key string) error { addr, err := address.NewFromBytes([]byte(key)) if err != nil { return err } - var claim power.Claim - keyerAddr := adt.AddrKey(addr) - mp.Get(keyerAddr, &claim) - if claim.QualityAdjPower.Int64() == 0 { return nil } @@ -311,7 +308,7 @@ func RecordTipsetMessagesPoints(ctx context.Context, api api.FullNode, pl *Point for i, msg := range msgs { // FIXME: use float so this doesn't overflow - // FIXME: this doesn't work as time points get overriden + // FIXME: this doesn't work as time points get overridden p := NewPoint("chain.message_gaspremium", msg.Message.GasPremium.Int64()) pl.AddPoint(p) p = NewPoint("chain.message_gasfeecap", msg.Message.GasFeeCap.Int64()) diff --git a/tools/stats/rpc.go b/tools/stats/rpc.go index 6b6cef283..965005f0d 100644 --- a/tools/stats/rpc.go +++ b/tools/stats/rpc.go @@ -124,7 +124,7 @@ sync_complete: func GetTips(ctx context.Context, api api.FullNode, lastHeight abi.ChainEpoch, headlag int) (<-chan *types.TipSet, error) { chmain := make(chan *types.TipSet) - hb := NewHeadBuffer(headlag) + hb := newHeadBuffer(headlag) notif, err := api.ChainNotify(ctx) if err != nil { @@ -134,7 +134,8 @@ func GetTips(ctx context.Context, api api.FullNode, lastHeight abi.ChainEpoch, h go func() { defer close(chmain) - ping := time.Tick(30 * time.Second) + ticker := time.NewTicker(30 * time.Second) + defer ticker.Stop() for { select { @@ -154,14 +155,14 @@ func GetTips(ctx context.Context, api api.FullNode, lastHeight abi.ChainEpoch, h chmain <- tipset } case store.HCApply: - if out := hb.Push(change); out != nil { + if out := hb.push(change); out != nil { chmain <- out.Val } case store.HCRevert: - hb.Pop() + hb.pop() } } - case <-ping: + case <-ticker.C: log.Info("Running health check") cctx, cancel := context.WithTimeout(ctx, 5*time.Second)