From 417d434973ebf5872eef829b5f727d59f49ae8d4 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Tue, 31 Mar 2020 18:34:23 -0700 Subject: [PATCH 1/2] several fixes and improvements while debugging interop --- chain/messagepool/messagepool.go | 4 ++-- chain/sub/incoming.go | 3 ++- chain/sync.go | 7 ++++--- chain/types/tipset.go | 7 ++----- cli/chain.go | 3 +++ cli/send.go | 12 +++++++++++- cmd/lotus-storage-miner/init.go | 33 +++++++++++++++++++++----------- node/builder.go | 2 +- node/hello/hello.go | 10 ++++++++++ 9 files changed, 57 insertions(+), 24 deletions(-) diff --git a/chain/messagepool/messagepool.go b/chain/messagepool/messagepool.go index c8bbb1b7f..8f6ce719f 100644 --- a/chain/messagepool/messagepool.go +++ b/chain/messagepool/messagepool.go @@ -462,7 +462,7 @@ func (mp *MessagePool) PushWithNonce(addr address.Address, cb func(uint64) (*typ nonce, err := mp.getNonceLocked(addr, mp.curTs) if err != nil { - return nil, err + return nil, xerrors.Errorf("get nonce locked failed: %w", err) } 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 { - return nil, err + return nil, xerrors.Errorf("add locked failed: %w", err) } if err := mp.addLocal(msg, msgb); err != nil { log.Errorf("addLocal failed: %+v", err) diff --git a/chain/sub/incoming.go b/chain/sub/incoming.go index be1643425..1f994d317 100644 --- a/chain/sub/incoming.go +++ b/chain/sub/incoming.go @@ -2,9 +2,10 @@ package sub import ( "context" - "golang.org/x/xerrors" "time" + "golang.org/x/xerrors" + lru "github.com/hashicorp/golang-lru" "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log/v2" diff --git a/chain/sync.go b/chain/sync.go index 9d10f13a4..a29d09594 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -511,10 +511,11 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) err return xerrors.Errorf("block had nil signature") } - if h.Timestamp > uint64(time.Now().Unix()+build.AllowableClockDrift) { - return xerrors.Errorf("block was from the future: %w", ErrTemporal) + now := uint64(time.Now().Unix()) + 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()) } diff --git a/chain/types/tipset.go b/chain/types/tipset.go index 86e82032c..6df8eae30 100644 --- a/chain/types/tipset.go +++ b/chain/types/tipset.go @@ -10,7 +10,6 @@ import ( "github.com/filecoin-project/specs-actors/actors/abi" "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log/v2" - "github.com/minio/blake2b-simd" cbg "github.com/whyrusleeping/cbor-gen" "golang.org/x/xerrors" ) @@ -90,7 +89,7 @@ func tipsetSortFunc(blks []*BlockHeader) func(i, j int) bool { if ti.Equals(tj) { 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) @@ -171,9 +170,7 @@ func (ts *TipSet) Equals(ots *TipSet) bool { } func (t *Ticket) Less(o *Ticket) bool { - tDigest := blake2b.Sum256(t.VRFProof) - oDigest := blake2b.Sum256(o.VRFProof) - return bytes.Compare(tDigest[:], oDigest[:]) < 0 + return bytes.Compare(t.VRFProof, o.VRFProof) < 0 } func (ts *TipSet) MinTicket() *Ticket { diff --git a/cli/chain.go b/cli/chain.go index 84fe75c0e..8d19e2637 100644 --- a/cli/chain.go +++ b/cli/chain.go @@ -16,6 +16,7 @@ import ( cborutil "github.com/filecoin-project/go-cbor-util" "github.com/filecoin-project/specs-actors/actors/abi" "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/util/adt" cid "github.com/ipfs/go-cid" @@ -469,6 +470,8 @@ var chainGetCmd = &cli.Command{ return handleHamtAddress(ctx, api, obj.Cid) case "cronevent": cbu = new(power.CronEvent) + case "account-state": + cbu = new(account.State) default: return fmt.Errorf("unknown type: %q", t) } diff --git a/cli/send.go b/cli/send.go index eb61b4167..91fe78715 100644 --- a/cli/send.go +++ b/cli/send.go @@ -17,6 +17,11 @@ var sendCmd = &cli.Command{ Name: "source", 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 { api, closer, err := GetFullNodeAPI(cctx) @@ -58,12 +63,17 @@ var sendCmd = &cli.Command{ fromAddr = addr } + gp, err := types.BigFromString(cctx.String("gas-price")) + if err != nil { + return err + } + msg := &types.Message{ From: fromAddr, To: toAddr, Value: types.BigInt(val), GasLimit: 10000, - GasPrice: types.NewInt(0), + GasPrice: gp, } _, err = api.MpoolPushMessage(ctx, msg) diff --git a/cmd/lotus-storage-miner/init.go b/cmd/lotus-storage-miner/init.go index a6e6c0fa1..018050653 100644 --- a/cmd/lotus-storage-miner/init.go +++ b/cmd/lotus-storage-miner/init.go @@ -7,12 +7,13 @@ import ( "encoding/binary" "encoding/json" "fmt" - "github.com/filecoin-project/lotus/node/modules" "io/ioutil" "os" "path/filepath" "strconv" + "github.com/filecoin-project/lotus/node/modules" + "github.com/google/uuid" "github.com/ipfs/go-datastore" "github.com/libp2p/go-libp2p-core/crypto" @@ -42,7 +43,7 @@ import ( "github.com/filecoin-project/lotus/node/repo" "github.com/filecoin-project/lotus/storage" "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/stores" ) @@ -99,12 +100,22 @@ var initCmd = &cli.Command{ Name: "no-local-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 { log.Info("Initializing lotus storage miner") 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") if symlink { 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) path, err := homedir.Expand(repoPath) 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") } -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) if err != nil { 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) } - cerr := configureStorageMiner(ctx, api, a, peerid) + cerr := configureStorageMiner(ctx, api, a, peerid, gasPrice) if err := m.Unregister(ctx, a); err != nil { 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) } addr = a } else { - a, err := createStorageMiner(ctx, api, peerid, cctx) + a, err := createStorageMiner(ctx, api, peerid, gasPrice, cctx) if err != nil { return xerrors.Errorf("creating miner failed: %w", err) } @@ -512,7 +523,7 @@ func makeHostKey(lr repo.LockedRepo) (crypto.PrivKey, error) { 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) if err != nil { 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, Params: enc, Value: types.NewInt(0), - GasPrice: types.NewInt(0), + GasPrice: gasPrice, GasLimit: 100000000, } @@ -551,7 +562,7 @@ func configureStorageMiner(ctx context.Context, api lapi.FullNode, addr address. 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") var err error @@ -602,7 +613,7 @@ func createStorageMiner(ctx context.Context, api lapi.FullNode, peerid peer.ID, Params: params, GasLimit: 10000000, - GasPrice: types.NewInt(0), + GasPrice: gasPrice, } signed, err := api.MpoolPushMessage(ctx, createStorageMinerMsg) diff --git a/node/builder.go b/node/builder.go index 5cb722b45..3d22b0bd0 100644 --- a/node/builder.go +++ b/node/builder.go @@ -59,7 +59,7 @@ import ( "github.com/filecoin-project/lotus/storage" "github.com/filecoin-project/lotus/storage/sealing" "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/stores" ) diff --git a/node/hello/hello.go b/node/hello/hello.go index 45143fe47..7ef13300b 100644 --- a/node/hello/hello.go +++ b/node/hello/hello.go @@ -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...)) if err != nil { log.Errorf("failed to fetch tipset from peer during hello: %+v", err) From cdd97ce959a884ff4409490d6853d72c9a6645c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 1 Apr 2020 17:17:05 +0200 Subject: [PATCH 2/2] Revert ticket compare function to comparing vrf hashes --- chain/types/tipset.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/chain/types/tipset.go b/chain/types/tipset.go index 6df8eae30..c1934d1d8 100644 --- a/chain/types/tipset.go +++ b/chain/types/tipset.go @@ -10,6 +10,7 @@ import ( "github.com/filecoin-project/specs-actors/actors/abi" "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log/v2" + "github.com/minio/blake2b-simd" cbg "github.com/whyrusleeping/cbor-gen" "golang.org/x/xerrors" ) @@ -170,7 +171,9 @@ func (ts *TipSet) Equals(ots *TipSet) bool { } func (t *Ticket) Less(o *Ticket) bool { - return bytes.Compare(t.VRFProof, o.VRFProof) < 0 + tDigest := blake2b.Sum256(t.VRFProof) + oDigest := blake2b.Sum256(o.VRFProof) + return bytes.Compare(tDigest[:], oDigest[:]) < 0 } func (ts *TipSet) MinTicket() *Ticket {