Merge pull request #743 from filecoin-project/feat/static-check-2
more of that sweet staticcheck goodness
This commit is contained in:
commit
3673a9110f
@ -67,7 +67,7 @@ func TestDealFlow(t *testing.T, b APIBuilder) {
|
||||
time.Sleep(time.Second)
|
||||
fmt.Println("mining a block now")
|
||||
if err := sn[0].MineOne(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/filecoin-project/lotus/lib/addrutil"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
rice "github.com/GeertJohan/go.rice"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
@ -16,6 +17,10 @@ func BuiltinBootstrap() ([]peer.AddrInfo, error) {
|
||||
|
||||
b := rice.MustFindBox("bootstrap")
|
||||
err := b.Walk("", func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to walk box: %w", err)
|
||||
}
|
||||
|
||||
if !strings.HasSuffix(path, ".pi") {
|
||||
return nil
|
||||
}
|
||||
|
@ -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:
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
@ -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 {
|
||||
|
@ -199,6 +199,9 @@ func (c *Client) Start(ctx context.Context, p ClientDealProposal) (cid.Cid, erro
|
||||
}
|
||||
|
||||
commP, pieceSize, err := c.commP(ctx, p.Data)
|
||||
if err != nil {
|
||||
return cid.Undef, xerrors.Errorf("computing commP failed: %w", err)
|
||||
}
|
||||
|
||||
dealProposal := &actors.StorageDealProposal{
|
||||
PieceRef: commP,
|
||||
|
@ -80,7 +80,7 @@ type minerDealUpdate struct {
|
||||
|
||||
var (
|
||||
// ErrDataTransferFailed means a data transfer for a deal failed
|
||||
ErrDataTransferFailed = errors.New("Deal data transfer failed")
|
||||
ErrDataTransferFailed = errors.New("deal data transfer failed")
|
||||
)
|
||||
|
||||
func NewProvider(ds dtypes.MetadataDS, sminer *storage.Miner, secb *sectorblocks.SectorBlocks, dag dtypes.StagingDAG, dataTransfer dtypes.ProviderDataTransfer, fullNode api.FullNode) (*Provider, error) {
|
||||
|
@ -168,6 +168,9 @@ func (p *Provider) accept(ctx context.Context, deal MinerDeal) (func(*MinerDeal)
|
||||
deal.Ref,
|
||||
allSelector,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to open pull data channel: %w", err)
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -69,6 +69,9 @@ func newClientDeal(minerID peer.ID, state api.DealState) (deals.ClientDeal, erro
|
||||
return deals.ClientDeal{}, err
|
||||
}
|
||||
minerAddr, err := address.NewIDAddress(uint64(rand.Int()))
|
||||
if err != nil {
|
||||
return deals.ClientDeal{}, err
|
||||
}
|
||||
|
||||
return deals.ClientDeal{
|
||||
Proposal: newProposal,
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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)
|
||||
|
@ -273,7 +273,7 @@ func (cs *ChainStore) reorgWorker(ctx context.Context) chan<- reorg {
|
||||
}
|
||||
|
||||
func (cs *ChainStore) takeHeaviestTipSet(ctx context.Context, ts *types.TipSet) error {
|
||||
ctx, span := trace.StartSpan(ctx, "takeHeaviestTipSet")
|
||||
_, span := trace.StartSpan(ctx, "takeHeaviestTipSet")
|
||||
defer span.End()
|
||||
|
||||
if cs.heaviest != nil { // buf
|
||||
|
@ -112,7 +112,7 @@ func (blk *BlockHeader) SigningBytes() ([]byte, error) {
|
||||
}
|
||||
|
||||
func (blk *BlockHeader) CheckBlockSignature(ctx context.Context, worker address.Address) error {
|
||||
ctx, span := trace.StartSpan(ctx, "checkBlockSignature")
|
||||
_, span := trace.StartSpan(ctx, "checkBlockSignature")
|
||||
defer span.End()
|
||||
|
||||
sigb, err := blk.SigningBytes()
|
||||
|
@ -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
|
||||
|
15
cli/state.go
15
cli/state.go
@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/address"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/ipfs/go-cid"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
@ -22,6 +23,7 @@ var stateCmd = &cli.Command{
|
||||
stateListMinersCmd,
|
||||
stateGetActorCmd,
|
||||
stateLookupIDCmd,
|
||||
stateReplaySetCmd,
|
||||
},
|
||||
}
|
||||
|
||||
@ -176,7 +178,18 @@ var stateReplaySetCmd = &cli.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
api.StateReplay(ctx, ts, mcid)
|
||||
res, err := api.StateReplay(ctx, ts, mcid)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("replay call failed: %w", err)
|
||||
}
|
||||
|
||||
fmt.Println("Replay receipt:")
|
||||
fmt.Printf("Exit code: %d\n", res.Receipt.ExitCode)
|
||||
fmt.Printf("Return: %x\n", res.Receipt.Return)
|
||||
fmt.Printf("Gas Used: %s\n", res.Receipt.GasUsed)
|
||||
if res.Receipt.ExitCode != 0 {
|
||||
fmt.Printf("Error message: %q\n", res.Error)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
|
@ -72,5 +72,4 @@ func main() {
|
||||
log.Warnf("%+v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -81,7 +81,8 @@ func toReadableFile(r io.Reader, n int64) (*os.File, func() error, error) {
|
||||
go func() {
|
||||
defer wait.Unlock()
|
||||
|
||||
copied, werr := io.CopyN(w, r, n)
|
||||
var copied int64
|
||||
copied, werr = io.CopyN(w, r, n)
|
||||
if werr != nil {
|
||||
log.Warnf("toReadableFile: copy error: %+v", werr)
|
||||
}
|
||||
|
@ -6,15 +6,12 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/opentracing/opentracing-go/log"
|
||||
)
|
||||
|
||||
type outmux struct {
|
||||
lk sync.Mutex
|
||||
|
||||
errpw *io.PipeWriter
|
||||
outpw *io.PipeWriter
|
||||
|
||||
@ -127,5 +124,4 @@ func (m *outmux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
m.new <- c
|
||||
return
|
||||
}
|
||||
|
@ -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{})
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
"github.com/libp2p/go-libp2p-core/host"
|
||||
inet "github.com/libp2p/go-libp2p-core/network"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
protocol "github.com/libp2p/go-libp2p-protocol"
|
||||
protocol "github.com/libp2p/go-libp2p-core/protocol"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain"
|
||||
"github.com/filecoin-project/lotus/chain/store"
|
||||
|
@ -11,8 +11,8 @@ import (
|
||||
"github.com/ipfs/go-datastore"
|
||||
blockstore "github.com/ipfs/go-ipfs-blockstore"
|
||||
"github.com/libp2p/go-libp2p-core/host"
|
||||
peer "github.com/libp2p/go-libp2p-core/peer"
|
||||
"github.com/libp2p/go-libp2p-core/routing"
|
||||
peer "github.com/libp2p/go-libp2p-peer"
|
||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||
"go.uber.org/fx"
|
||||
"golang.org/x/xerrors"
|
||||
|
@ -49,7 +49,9 @@ func ClientBlockstore(fstore dtypes.ClientFilestore) dtypes.ClientBlockstore {
|
||||
// request validator with the data transfer module as the validator for
|
||||
// StorageDataTransferVoucher types
|
||||
func RegisterClientValidator(crv *deals.ClientRequestValidator, dtm dtypes.ClientDataTransfer) {
|
||||
dtm.RegisterVoucherType(reflect.TypeOf(deals.StorageDataTransferVoucher{}), crv)
|
||||
if err := dtm.RegisterVoucherType(reflect.TypeOf(deals.StorageDataTransferVoucher{}), crv); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// NewClientDAGServiceDataTransfer returns a data transfer manager that just
|
||||
|
@ -139,7 +139,9 @@ func HandleDeals(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, h *de
|
||||
// request validator with the data transfer module as the validator for
|
||||
// StorageDataTransferVoucher types
|
||||
func RegisterProviderValidator(mrv *deals.ProviderRequestValidator, dtm dtypes.ProviderDataTransfer) {
|
||||
dtm.RegisterVoucherType(reflect.TypeOf(deals.StorageDataTransferVoucher{}), mrv)
|
||||
if err := dtm.RegisterVoucherType(reflect.TypeOf(deals.StorageDataTransferVoucher{}), mrv); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// NewProviderDAGServiceDataTransfer returns a data transfer manager that just
|
||||
|
@ -29,7 +29,6 @@ const (
|
||||
fsAPIToken = "token"
|
||||
fsConfig = "config.toml"
|
||||
fsDatastore = "datastore"
|
||||
fsLibp2pKey = "libp2p.priv"
|
||||
fsLock = "repo.lock"
|
||||
fsKeystore = "keystore"
|
||||
)
|
||||
|
@ -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{}
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user