several fixes and improvements while debugging interop

This commit is contained in:
Jeromy 2020-03-31 18:34:23 -07:00
parent ea135991e3
commit 417d434973
9 changed files with 57 additions and 24 deletions

View File

@ -462,7 +462,7 @@ func (mp *MessagePool) PushWithNonce(addr address.Address, cb func(uint64) (*typ
nonce, err := mp.getNonceLocked(addr, mp.curTs) nonce, err := mp.getNonceLocked(addr, mp.curTs)
if err != nil { if err != nil {
return nil, err return nil, xerrors.Errorf("get nonce locked failed: %w", err)
} }
msg, err := cb(nonce) msg, err := cb(nonce)
@ -476,7 +476,7 @@ func (mp *MessagePool) PushWithNonce(addr address.Address, cb func(uint64) (*typ
} }
if err := mp.addLocked(msg); err != nil { if err := mp.addLocked(msg); err != nil {
return nil, err return nil, xerrors.Errorf("add locked failed: %w", err)
} }
if err := mp.addLocal(msg, msgb); err != nil { if err := mp.addLocal(msg, msgb); err != nil {
log.Errorf("addLocal failed: %+v", err) log.Errorf("addLocal failed: %+v", err)

View File

@ -2,9 +2,10 @@ package sub
import ( import (
"context" "context"
"golang.org/x/xerrors"
"time" "time"
"golang.org/x/xerrors"
lru "github.com/hashicorp/golang-lru" lru "github.com/hashicorp/golang-lru"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2" logging "github.com/ipfs/go-log/v2"

View File

@ -511,10 +511,11 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) err
return xerrors.Errorf("block had nil signature") return xerrors.Errorf("block had nil signature")
} }
if h.Timestamp > uint64(time.Now().Unix()+build.AllowableClockDrift) { now := uint64(time.Now().Unix())
return xerrors.Errorf("block was from the future: %w", ErrTemporal) if h.Timestamp > now+build.AllowableClockDrift {
return xerrors.Errorf("block was from the future (now=%d, blk=%d): %w", now, h.Timestamp, ErrTemporal)
} }
if h.Timestamp > uint64(time.Now().Unix()) { if h.Timestamp > now {
log.Warn("Got block from the future, but within threshold", h.Timestamp, time.Now().Unix()) log.Warn("Got block from the future, but within threshold", h.Timestamp, time.Now().Unix())
} }

View File

@ -10,7 +10,6 @@ import (
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2" logging "github.com/ipfs/go-log/v2"
"github.com/minio/blake2b-simd"
cbg "github.com/whyrusleeping/cbor-gen" cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors" "golang.org/x/xerrors"
) )
@ -90,7 +89,7 @@ func tipsetSortFunc(blks []*BlockHeader) func(i, j int) bool {
if ti.Equals(tj) { if ti.Equals(tj) {
log.Warnf("blocks have same ticket (%s %s)", blks[i].Miner, blks[j].Miner) log.Warnf("blocks have same ticket (%s %s)", blks[i].Miner, blks[j].Miner)
return blks[i].Cid().KeyString() < blks[j].Cid().KeyString() return bytes.Compare(blks[i].Cid().Bytes(), blks[j].Cid().Bytes()) < 0
} }
return ti.Less(tj) return ti.Less(tj)
@ -171,9 +170,7 @@ func (ts *TipSet) Equals(ots *TipSet) bool {
} }
func (t *Ticket) Less(o *Ticket) bool { func (t *Ticket) Less(o *Ticket) bool {
tDigest := blake2b.Sum256(t.VRFProof) return bytes.Compare(t.VRFProof, o.VRFProof) < 0
oDigest := blake2b.Sum256(o.VRFProof)
return bytes.Compare(tDigest[:], oDigest[:]) < 0
} }
func (ts *TipSet) MinTicket() *Ticket { func (ts *TipSet) MinTicket() *Ticket {

View File

@ -16,6 +16,7 @@ import (
cborutil "github.com/filecoin-project/go-cbor-util" cborutil "github.com/filecoin-project/go-cbor-util"
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/builtin/account"
"github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/builtin/power"
"github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/filecoin-project/specs-actors/actors/util/adt"
cid "github.com/ipfs/go-cid" cid "github.com/ipfs/go-cid"
@ -469,6 +470,8 @@ var chainGetCmd = &cli.Command{
return handleHamtAddress(ctx, api, obj.Cid) return handleHamtAddress(ctx, api, obj.Cid)
case "cronevent": case "cronevent":
cbu = new(power.CronEvent) cbu = new(power.CronEvent)
case "account-state":
cbu = new(account.State)
default: default:
return fmt.Errorf("unknown type: %q", t) return fmt.Errorf("unknown type: %q", t)
} }

View File

@ -17,6 +17,11 @@ var sendCmd = &cli.Command{
Name: "source", Name: "source",
Usage: "optionally specify the account to send funds from", Usage: "optionally specify the account to send funds from",
}, },
&cli.StringFlag{
Name: "gas-price",
Usage: "specify gas price to use in AttoFIL",
Value: "0",
},
}, },
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
api, closer, err := GetFullNodeAPI(cctx) api, closer, err := GetFullNodeAPI(cctx)
@ -58,12 +63,17 @@ var sendCmd = &cli.Command{
fromAddr = addr fromAddr = addr
} }
gp, err := types.BigFromString(cctx.String("gas-price"))
if err != nil {
return err
}
msg := &types.Message{ msg := &types.Message{
From: fromAddr, From: fromAddr,
To: toAddr, To: toAddr,
Value: types.BigInt(val), Value: types.BigInt(val),
GasLimit: 10000, GasLimit: 10000,
GasPrice: types.NewInt(0), GasPrice: gp,
} }
_, err = api.MpoolPushMessage(ctx, msg) _, err = api.MpoolPushMessage(ctx, msg)

View File

@ -7,12 +7,13 @@ import (
"encoding/binary" "encoding/binary"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/filecoin-project/lotus/node/modules"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strconv" "strconv"
"github.com/filecoin-project/lotus/node/modules"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore"
"github.com/libp2p/go-libp2p-core/crypto" "github.com/libp2p/go-libp2p-core/crypto"
@ -42,7 +43,7 @@ import (
"github.com/filecoin-project/lotus/node/repo" "github.com/filecoin-project/lotus/node/repo"
"github.com/filecoin-project/lotus/storage" "github.com/filecoin-project/lotus/storage"
"github.com/filecoin-project/lotus/storage/sealing" "github.com/filecoin-project/lotus/storage/sealing"
"github.com/filecoin-project/sector-storage" sectorstorage "github.com/filecoin-project/sector-storage"
"github.com/filecoin-project/sector-storage/ffiwrapper" "github.com/filecoin-project/sector-storage/ffiwrapper"
"github.com/filecoin-project/sector-storage/stores" "github.com/filecoin-project/sector-storage/stores"
) )
@ -99,12 +100,22 @@ var initCmd = &cli.Command{
Name: "no-local-storage", Name: "no-local-storage",
Usage: "don't use storageminer repo for sector storage", Usage: "don't use storageminer repo for sector storage",
}, },
&cli.StringFlag{
Name: "gas-price",
Usage: "set gas price for initialization messages in AttoFIL",
Value: "0",
},
}, },
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
log.Info("Initializing lotus storage miner") log.Info("Initializing lotus storage miner")
ssize := abi.SectorSize(cctx.Uint64("sector-size")) ssize := abi.SectorSize(cctx.Uint64("sector-size"))
gasPrice, err := types.BigFromString(cctx.String("gas-price"))
if err != nil {
return xerrors.Errorf("failed to parse gas-price flag: %s", err)
}
symlink := cctx.Bool("symlink-imported-sectors") symlink := cctx.Bool("symlink-imported-sectors")
if symlink { if symlink {
log.Info("will attempt to symlink to imported sectors") log.Info("will attempt to symlink to imported sectors")
@ -218,7 +229,7 @@ var initCmd = &cli.Command{
} }
} }
if err := storageMinerInit(ctx, cctx, api, r, ssize); err != nil { if err := storageMinerInit(ctx, cctx, api, r, ssize, gasPrice); err != nil {
log.Errorf("Failed to initialize lotus-storage-miner: %+v", err) log.Errorf("Failed to initialize lotus-storage-miner: %+v", err)
path, err := homedir.Expand(repoPath) path, err := homedir.Expand(repoPath)
if err != nil { if err != nil {
@ -358,7 +369,7 @@ func findMarketDealID(ctx context.Context, api lapi.FullNode, deal market.DealPr
return 0, xerrors.New("deal not found") return 0, xerrors.New("deal not found")
} }
func storageMinerInit(ctx context.Context, cctx *cli.Context, api lapi.FullNode, r repo.Repo, ssize abi.SectorSize) error { func storageMinerInit(ctx context.Context, cctx *cli.Context, api lapi.FullNode, r repo.Repo, ssize abi.SectorSize, gasPrice types.BigInt) error {
lr, err := r.Lock(repo.StorageMiner) lr, err := r.Lock(repo.StorageMiner)
if err != nil { if err != nil {
return err return err
@ -424,7 +435,7 @@ func storageMinerInit(ctx context.Context, cctx *cli.Context, api lapi.FullNode,
return xerrors.Errorf("failed to start up genesis miner: %w", err) return xerrors.Errorf("failed to start up genesis miner: %w", err)
} }
cerr := configureStorageMiner(ctx, api, a, peerid) cerr := configureStorageMiner(ctx, api, a, peerid, gasPrice)
if err := m.Unregister(ctx, a); err != nil { if err := m.Unregister(ctx, a); err != nil {
log.Error("failed to shut down storage miner: ", err) log.Error("failed to shut down storage miner: ", err)
@ -464,13 +475,13 @@ func storageMinerInit(ctx context.Context, cctx *cli.Context, api lapi.FullNode,
} }
} }
if err := configureStorageMiner(ctx, api, a, peerid); err != nil { if err := configureStorageMiner(ctx, api, a, peerid, gasPrice); err != nil {
return xerrors.Errorf("failed to configure storage miner: %w", err) return xerrors.Errorf("failed to configure storage miner: %w", err)
} }
addr = a addr = a
} else { } else {
a, err := createStorageMiner(ctx, api, peerid, cctx) a, err := createStorageMiner(ctx, api, peerid, gasPrice, cctx)
if err != nil { if err != nil {
return xerrors.Errorf("creating miner failed: %w", err) return xerrors.Errorf("creating miner failed: %w", err)
} }
@ -512,7 +523,7 @@ func makeHostKey(lr repo.LockedRepo) (crypto.PrivKey, error) {
return pk, nil return pk, nil
} }
func configureStorageMiner(ctx context.Context, api lapi.FullNode, addr address.Address, peerid peer.ID) error { func configureStorageMiner(ctx context.Context, api lapi.FullNode, addr address.Address, peerid peer.ID, gasPrice types.BigInt) error {
waddr, err := api.StateMinerWorker(ctx, addr, types.EmptyTSK) waddr, err := api.StateMinerWorker(ctx, addr, types.EmptyTSK)
if err != nil { if err != nil {
return xerrors.Errorf("getWorkerAddr returned bad address: %w", err) return xerrors.Errorf("getWorkerAddr returned bad address: %w", err)
@ -529,7 +540,7 @@ func configureStorageMiner(ctx context.Context, api lapi.FullNode, addr address.
Method: builtin.MethodsMiner.ChangePeerID, Method: builtin.MethodsMiner.ChangePeerID,
Params: enc, Params: enc,
Value: types.NewInt(0), Value: types.NewInt(0),
GasPrice: types.NewInt(0), GasPrice: gasPrice,
GasLimit: 100000000, GasLimit: 100000000,
} }
@ -551,7 +562,7 @@ func configureStorageMiner(ctx context.Context, api lapi.FullNode, addr address.
return nil return nil
} }
func createStorageMiner(ctx context.Context, api lapi.FullNode, peerid peer.ID, cctx *cli.Context) (address.Address, error) { func createStorageMiner(ctx context.Context, api lapi.FullNode, peerid peer.ID, gasPrice types.BigInt, cctx *cli.Context) (address.Address, error) {
log.Info("Creating StorageMarket.CreateStorageMiner message") log.Info("Creating StorageMarket.CreateStorageMiner message")
var err error var err error
@ -602,7 +613,7 @@ func createStorageMiner(ctx context.Context, api lapi.FullNode, peerid peer.ID,
Params: params, Params: params,
GasLimit: 10000000, GasLimit: 10000000,
GasPrice: types.NewInt(0), GasPrice: gasPrice,
} }
signed, err := api.MpoolPushMessage(ctx, createStorageMinerMsg) signed, err := api.MpoolPushMessage(ctx, createStorageMinerMsg)

View File

@ -59,7 +59,7 @@ import (
"github.com/filecoin-project/lotus/storage" "github.com/filecoin-project/lotus/storage"
"github.com/filecoin-project/lotus/storage/sealing" "github.com/filecoin-project/lotus/storage/sealing"
"github.com/filecoin-project/lotus/storage/sectorblocks" "github.com/filecoin-project/lotus/storage/sectorblocks"
"github.com/filecoin-project/sector-storage" sectorstorage "github.com/filecoin-project/sector-storage"
"github.com/filecoin-project/sector-storage/ffiwrapper" "github.com/filecoin-project/sector-storage/ffiwrapper"
"github.com/filecoin-project/sector-storage/stores" "github.com/filecoin-project/sector-storage/stores"
) )

View File

@ -92,6 +92,16 @@ func (hs *Service) HandleStream(s inet.Stream) {
} }
}() }()
protos, err := hs.h.Peerstore().GetProtocols(s.Conn().RemotePeer())
if err != nil {
log.Warnf("got error from peerstore.GetProtocols: %s", err)
}
if len(protos) == 0 {
log.Warn("other peer hasnt completed libp2p identify, waiting a bit")
// TODO: this better
time.Sleep(time.Millisecond * 300)
}
ts, err := hs.syncer.FetchTipSet(context.Background(), s.Conn().RemotePeer(), types.NewTipSetKey(hmsg.HeaviestTipSet...)) ts, err := hs.syncer.FetchTipSet(context.Background(), s.Conn().RemotePeer(), types.NewTipSetKey(hmsg.HeaviestTipSet...))
if err != nil { if err != nil {
log.Errorf("failed to fetch tipset from peer during hello: %+v", err) log.Errorf("failed to fetch tipset from peer during hello: %+v", err)