From 16096e2c71aaa60497f0780c9fbeba4135d55ffe Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Thu, 5 Mar 2020 22:46:07 -0800 Subject: [PATCH] some go vet fixes --- chain/types/bigint.go | 16 ++++++++-------- chain/validation/applier.go | 4 ++-- chain/vm/vm.go | 3 +-- cmd/lotus-shed/peerkey.go | 4 ---- lib/jsonrpc/rpc_test.go | 3 ++- lotuspond/main.go | 1 - node/impl/full/sync.go | 3 ++- tools/stats/rpc.go | 2 ++ 8 files changed, 17 insertions(+), 19 deletions(-) diff --git a/chain/types/bigint.go b/chain/types/bigint.go index d8f5e0c7b..0b8faac52 100644 --- a/chain/types/bigint.go +++ b/chain/types/bigint.go @@ -18,7 +18,7 @@ var EmptyInt = BigInt{} type BigInt = big2.Int func NewInt(i uint64) BigInt { - return BigInt{big.NewInt(0).SetUint64(i)} + return BigInt{Int: big.NewInt(0).SetUint64(i)} } func FromFil(i uint64) BigInt { @@ -27,7 +27,7 @@ func FromFil(i uint64) BigInt { func BigFromBytes(b []byte) BigInt { i := big.NewInt(0).SetBytes(b) - return BigInt{i} + return BigInt{Int: i} } func BigFromString(s string) (BigInt, error) { @@ -36,27 +36,27 @@ func BigFromString(s string) (BigInt, error) { return BigInt{}, fmt.Errorf("failed to parse string as a big int") } - return BigInt{v}, nil + return BigInt{Int: v}, nil } func BigMul(a, b BigInt) BigInt { - return BigInt{big.NewInt(0).Mul(a.Int, b.Int)} + return BigInt{Int: big.NewInt(0).Mul(a.Int, b.Int)} } func BigDiv(a, b BigInt) BigInt { - return BigInt{big.NewInt(0).Div(a.Int, b.Int)} + return BigInt{Int: big.NewInt(0).Div(a.Int, b.Int)} } func BigMod(a, b BigInt) BigInt { - return BigInt{big.NewInt(0).Mod(a.Int, b.Int)} + return BigInt{Int: big.NewInt(0).Mod(a.Int, b.Int)} } func BigAdd(a, b BigInt) BigInt { - return BigInt{big.NewInt(0).Add(a.Int, b.Int)} + return BigInt{Int: big.NewInt(0).Add(a.Int, b.Int)} } func BigSub(a, b BigInt) BigInt { - return BigInt{big.NewInt(0).Sub(a.Int, b.Int)} + return BigInt{Int: big.NewInt(0).Sub(a.Int, b.Int)} } func BigCmp(a, b BigInt) int { diff --git a/chain/validation/applier.go b/chain/validation/applier.go index 1702472bb..31fae2dbf 100644 --- a/chain/validation/applier.go +++ b/chain/validation/applier.go @@ -124,8 +124,8 @@ func toLotusMsg(msg *vtypes.Message) *types.Message { Nonce: uint64(msg.CallSeqNum), Method: msg.Method, - Value: types.BigInt{msg.Value.Int}, - GasPrice: types.BigInt{msg.GasPrice.Int}, + Value: types.BigInt{Int: msg.Value.Int}, + GasPrice: types.BigInt{Int: msg.GasPrice.Int}, GasLimit: types.NewInt(uint64(msg.GasLimit)), Params: msg.Params, diff --git a/chain/vm/vm.go b/chain/vm/vm.go index d35856495..ccb4719b4 100644 --- a/chain/vm/vm.go +++ b/chain/vm/vm.go @@ -494,7 +494,6 @@ func (vm *VM) ApplyMessage(ctx context.Context, msg *types.Message) (*ApplyRet, return nil, xerrors.Errorf("failed to look up from actor: %w", err) } - gascost := types.BigMul(msg.GasLimit, msg.GasPrice) totalCost := types.BigAdd(gascost, msg.Value) if fromActor.Balance.LessThan(totalCost) { @@ -787,5 +786,5 @@ func MiningReward(remainingReward types.BigInt) types.BigInt { res := ci.Mul(ci, build.InitialReward) res = res.Div(res, miningRewardTotal.Int) res = res.Div(res, blocksPerEpoch.Int) - return types.BigInt{res} + return types.BigInt{Int: res} } diff --git a/cmd/lotus-shed/peerkey.go b/cmd/lotus-shed/peerkey.go index 328ad455d..65220209d 100644 --- a/cmd/lotus-shed/peerkey.go +++ b/cmd/lotus-shed/peerkey.go @@ -35,14 +35,10 @@ func (ks *keystore) Get(name string) (types.KeyInfo, error) { func (ks *keystore) Delete(name string) error { panic("Implement me") - - return nil } func (ks *keystore) List() ([]string, error) { panic("Implement me") - - return []string{}, nil } var peerkeyCmd = &cli.Command{ diff --git a/lib/jsonrpc/rpc_test.go b/lib/jsonrpc/rpc_test.go index 45601f6e0..be560d958 100644 --- a/lib/jsonrpc/rpc_test.go +++ b/lib/jsonrpc/rpc_test.go @@ -409,7 +409,8 @@ func testControlChanDeadlock(t *testing.T) { serverHandler.wait <- struct{}{} } - ctx, _ := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() sub, err := client.Sub(ctx, 1, -1) require.NoError(t, err) diff --git a/lotuspond/main.go b/lotuspond/main.go index 17ad7c970..1ae49dad6 100644 --- a/lotuspond/main.go +++ b/lotuspond/main.go @@ -116,7 +116,6 @@ func logHandler(api *api) func(http.ResponseWriter, *http.Request) { id, err := strconv.ParseInt(path.Base(req.URL.Path), 10, 32) if err != nil { panic(err) - return } api.runningLk.Lock() diff --git a/node/impl/full/sync.go b/node/impl/full/sync.go index b1bcd3a55..436e14356 100644 --- a/node/impl/full/sync.go +++ b/node/impl/full/sync.go @@ -27,7 +27,8 @@ func (a *SyncAPI) SyncState(ctx context.Context) (*api.SyncState, error) { out := &api.SyncState{} - for _, ss := range states { + for i := range states { + ss := &states[i] out.ActiveSyncs = append(out.ActiveSyncs, api.ActiveSync{ Base: ss.Base, Target: ss.Target, diff --git a/tools/stats/rpc.go b/tools/stats/rpc.go index b1f51381b..03c75ced4 100644 --- a/tools/stats/rpc.go +++ b/tools/stats/rpc.go @@ -159,8 +159,10 @@ func GetTips(ctx context.Context, api api.FullNode, lastHeight abi.ChainEpoch) ( log.Info("Running health check") cctx, cancel := context.WithTimeout(ctx, 5*time.Second) + if _, err := api.ID(cctx); err != nil { log.Error("Health check failed") + cancel() return }