From 69ebd2bb850be754a4fc856e9f55186baaf8925b Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Mon, 20 Jul 2020 10:15:01 +0200 Subject: [PATCH 01/25] move mutex before select --- miner/miner.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/miner/miner.go b/miner/miner.go index ba2a69d6e..d418c03f0 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -91,12 +91,13 @@ func (m *Miner) Start(ctx context.Context) error { func (m *Miner) Stop(ctx context.Context) error { m.lk.Lock() - defer m.lk.Unlock() m.stopping = make(chan struct{}) stopping := m.stopping close(m.stop) + m.lk.Unlock() + select { case <-stopping: return nil From d16529dacb464843991ad26137a4993992538ed4 Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Mon, 20 Jul 2020 10:49:13 +0200 Subject: [PATCH 02/25] shutdown for peermgr --- lib/peermgr/peermgr.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/peermgr/peermgr.go b/lib/peermgr/peermgr.go index d275be3d5..8d6cf8cc3 100644 --- a/lib/peermgr/peermgr.go +++ b/lib/peermgr/peermgr.go @@ -51,9 +51,11 @@ type PeerMgr struct { dht *dht.IpfsDHT notifee *net.NotifyBundle + + done chan struct{} } -func NewPeerMgr(h host.Host, dht *dht.IpfsDHT, bootstrap dtypes.BootstrapPeers) *PeerMgr { +func NewPeerMgr(lc fx.Lifecycle, h host.Host, dht *dht.IpfsDHT, bootstrap dtypes.BootstrapPeers) *PeerMgr { pm := &PeerMgr{ h: h, dht: dht, @@ -64,8 +66,16 @@ func NewPeerMgr(h host.Host, dht *dht.IpfsDHT, bootstrap dtypes.BootstrapPeers) maxFilPeers: MaxFilPeers, minFilPeers: MinFilPeers, + + done: make(chan struct{}), } + lc.Append(fx.Hook{ + OnStop: func(ctx context.Context) error { + return pm.Stop(ctx) + }, + }) + pm.notifee = &net.NotifyBundle{ DisconnectedF: func(_ net.Network, c net.Conn) { pm.Disconnect(c.RemotePeer()) @@ -107,6 +117,12 @@ func (pmgr *PeerMgr) Disconnect(p peer.ID) { } } +func (pmgr *PeerMgr) Stop(ctx context.Context) error { + log.Warn("closing peermgr done") + close(pmgr.done) + return nil +} + func (pmgr *PeerMgr) Run(ctx context.Context) { tick := build.Clock.Ticker(time.Second * 5) for { @@ -119,6 +135,9 @@ func (pmgr *PeerMgr) Run(ctx context.Context) { log.Debug("peer count about threshold: %d > %d", pcount, pmgr.maxFilPeers) } stats.Record(ctx, metrics.PeerCount.M(int64(pmgr.getPeerCount()))) + case <-pmgr.done: + log.Warn("exiting peermgr run") + return } } } From bb33994219784205fb6abfc585d417c8175d9591 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Mon, 20 Jul 2020 17:59:05 +0200 Subject: [PATCH 03/25] Make reward actor state in genesis more realistic Signed-off-by: Jakub Sztandera --- chain/gen/gen_test.go | 4 ++-- chain/gen/genesis/genesis.go | 5 ++++- chain/gen/genesis/miners.go | 5 +++++ chain/gen/genesis/t02_reward.go | 7 +++---- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/chain/gen/gen_test.go b/chain/gen/gen_test.go index 7a4d73031..52766af7a 100644 --- a/chain/gen/gen_test.go +++ b/chain/gen/gen_test.go @@ -39,8 +39,8 @@ func testGeneration(t testing.TB, n int, msgs int, sectors int) { } func TestChainGeneration(t *testing.T) { - testGeneration(t, 10, 20, 1) - testGeneration(t, 10, 20, 25) + t.Run("10-20-1", func(t *testing.T) { testGeneration(t, 10, 20, 1) }) + t.Run("10-20-25", func(t *testing.T) { testGeneration(t, 10, 20, 25) }) } func BenchmarkChainGeneration(b *testing.B) { diff --git a/chain/gen/genesis/genesis.go b/chain/gen/genesis/genesis.go index 84ff25a6a..cd3881a27 100644 --- a/chain/gen/genesis/genesis.go +++ b/chain/gen/genesis/genesis.go @@ -6,6 +6,7 @@ import ( "github.com/filecoin-project/go-amt-ipld/v2" "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/account" "github.com/filecoin-project/specs-actors/actors/builtin/multisig" @@ -62,6 +63,7 @@ The process: - market.AddFunds with correct value - market.PublishDeals for related sectors - Set network power in the power actor to what we'll have after genesis creation + - Recreate reward actor state with the right power - For each precommitted sector - Get deal weight - Calculate QA Power @@ -139,7 +141,8 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge } // Setup reward - rewact, err := SetupRewardActor(bs) + // RewardActor's state is overrwritten by SetupStorageMiners + rewact, err := SetupRewardActor(bs, big.Zero()) if err != nil { return nil, xerrors.Errorf("setup init actor: %w", err) } diff --git a/chain/gen/genesis/miners.go b/chain/gen/genesis/miners.go index 1897118ef..be2dbbefe 100644 --- a/chain/gen/genesis/miners.go +++ b/chain/gen/genesis/miners.go @@ -198,6 +198,11 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid if err != nil { return cid.Undef, xerrors.Errorf("mutating state: %w", err) } + + err = vm.MutateState(ctx, builtin.RewardActorAddr, func(sct cbor.IpldStore, st *reward.State) error { + st = reward.ConstructState(qaPow) + return nil + }) } for i, m := range miners { diff --git a/chain/gen/genesis/t02_reward.go b/chain/gen/genesis/t02_reward.go index b573726cc..0866f9fa3 100644 --- a/chain/gen/genesis/t02_reward.go +++ b/chain/gen/genesis/t02_reward.go @@ -2,6 +2,7 @@ package genesis import ( "context" + "github.com/filecoin-project/specs-actors/actors/abi/big" "github.com/filecoin-project/lotus/build" @@ -12,12 +13,10 @@ import ( cbor "github.com/ipfs/go-ipld-cbor" ) -func SetupRewardActor(bs bstore.Blockstore) (*types.Actor, error) { +func SetupRewardActor(bs bstore.Blockstore, qaPower big.Int) (*types.Actor, error) { cst := cbor.NewCborStore(bs) - z := big.Zero() - st := reward.ConstructState(z) - st.ThisEpochReward = types.FromFil(100) + st := reward.ConstructState(qaPower) hcid, err := cst.Put(context.TODO(), st) if err != nil { From 217890c822160ccdd90d98ec35d3c4788fe0d3b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 20 Jul 2020 19:02:52 +0200 Subject: [PATCH 04/25] client: Pretty print fil amounts in list-deals --- cli/client.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/client.go b/cli/client.go index 7846dd243..3a1518b4f 100644 --- a/cli/client.go +++ b/cli/client.go @@ -768,7 +768,8 @@ var clientListDeals = &cli.Command{ slashed = fmt.Sprintf("Y (epoch %d)", d.OnChainDealState.SlashEpoch) } - fmt.Fprintf(w, "%s\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%s\n", d.LocalDeal.ProposalCid, d.LocalDeal.DealID, d.LocalDeal.Provider, storagemarket.DealStates[d.LocalDeal.State], onChain, slashed, d.LocalDeal.PieceCID, types.SizeStr(types.NewInt(d.LocalDeal.Size)), d.LocalDeal.PricePerEpoch, d.LocalDeal.Duration, d.LocalDeal.Message) + price := types.FIL(types.BigMul(d.LocalDeal.PricePerEpoch, types.NewInt(d.LocalDeal.Duration))) + fmt.Fprintf(w, "%s\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%s\n", d.LocalDeal.ProposalCid, d.LocalDeal.DealID, d.LocalDeal.Provider, storagemarket.DealStates[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() }, From 901f9c3760ffdf0442446673de07544ce3ee2090 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 20 Jul 2020 19:21:10 +0200 Subject: [PATCH 05/25] wdpost: Actually set post.Proofs --- storage/wdpost_run.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/storage/wdpost_run.go b/storage/wdpost_run.go index c7d99b2fc..f04d07bf2 100644 --- a/storage/wdpost_run.go +++ b/storage/wdpost_run.go @@ -418,6 +418,8 @@ func (s *WindowPoStScheduler) runPost(ctx context.Context, di miner.DeadlineInfo return nil, xerrors.Errorf("received proofs back from generate window post") } + params.Proofs = postOut + for _, sector := range postSkipped { params.Partitions[sidToPart[sector.Number]].Skipped.Set(uint64(sector.Number)) } From 310fa67f9d979ee5d356adfb9f855b38e04dced0 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Mon, 20 Jul 2020 19:48:30 +0200 Subject: [PATCH 06/25] Add gas estimation Signed-off-by: Jakub Sztandera --- api/api_full.go | 14 ++++++- api/apistruct/struct.go | 26 ++++++++---- build/version.go | 2 +- chain/messagepool/messagepool.go | 1 + chain/stmgr/call.go | 69 ++++++++++++++++++++++++++++++++ cli/send.go | 1 - node/impl/full.go | 11 +++++ node/impl/full/gas.go | 55 +++++++++++++++++++++++++ node/impl/full/mpool.go | 20 ++++++--- scripts/dev/sminer-init | 2 +- 10 files changed, 183 insertions(+), 18 deletions(-) create mode 100644 node/impl/full/gas.go diff --git a/api/api_full.go b/api/api_full.go index 895c1e65b..4200755af 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -101,6 +101,16 @@ type FullNode interface { // ChainExport returns a stream of bytes with CAR dump of chain data. ChainExport(context.Context, types.TipSetKey) (<-chan []byte, error) + // GasEstimateGasLimit estimates gas used by the message and returns it. + // It fails if message fails to execute. + GasEstimateGasLimit(context.Context, *types.Message, types.TipSetKey) (int64, error) + + // GasEstimateGasPrice estimates what gas price should be used for a + // message to have high likelihood of inclusion in `nblocksincl` epochs. + + GasEstimateGasPrice(_ context.Context, nblocksincl uint64, + sender address.Address, gaslimit int64, tsk types.TipSetKey) (types.BigInt, error) + // MethodGroup: Sync // The Sync method group contains methods for interacting with and // observing the lotus sync service. @@ -143,8 +153,8 @@ type FullNode interface { MpoolGetNonce(context.Context, address.Address) (uint64, error) MpoolSub(context.Context) (<-chan MpoolUpdate, error) - // MpoolEstimateGasPrice estimates what gas price should be used for a - // message to have high likelihood of inclusion in `nblocksincl` epochs. + // MpoolEstimateGasPrice is depracated + // Deprecated: use GasEstimateGasPrice instead MpoolEstimateGasPrice(ctx context.Context, nblocksincl uint64, sender address.Address, gaslimit int64, tsk types.TipSetKey) (types.BigInt, error) // MethodGroup: Miner diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index d5efd5266..665024858 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -82,18 +82,20 @@ type FullNodeStruct struct { ChainGetPath func(context.Context, types.TipSetKey, types.TipSetKey) ([]*api.HeadChange, error) `perm:"read"` ChainExport func(context.Context, types.TipSetKey) (<-chan []byte, error) `perm:"read"` + GasEstimateGasPrice func(context.Context, uint64, address.Address, int64, types.TipSetKey) (types.BigInt, error) `perm:"read"` + GasEstimateGasLimit func(context.Context, *types.Message, types.TipSetKey) (int64, error) `perm:"read"` + SyncState func(context.Context) (*api.SyncState, error) `perm:"read"` SyncSubmitBlock func(ctx context.Context, blk *types.BlockMsg) error `perm:"write"` SyncIncomingBlocks func(ctx context.Context) (<-chan *types.BlockHeader, error) `perm:"read"` SyncMarkBad func(ctx context.Context, bcid cid.Cid) error `perm:"admin"` SyncCheckBad func(ctx context.Context, bcid cid.Cid) (string, error) `perm:"read"` - MpoolPending func(context.Context, types.TipSetKey) ([]*types.SignedMessage, error) `perm:"read"` - MpoolPush func(context.Context, *types.SignedMessage) (cid.Cid, error) `perm:"write"` - MpoolPushMessage func(context.Context, *types.Message) (*types.SignedMessage, error) `perm:"sign"` - MpoolGetNonce func(context.Context, address.Address) (uint64, error) `perm:"read"` - MpoolSub func(context.Context) (<-chan api.MpoolUpdate, error) `perm:"read"` - MpoolEstimateGasPrice func(context.Context, uint64, address.Address, int64, types.TipSetKey) (types.BigInt, error) `perm:"read"` + MpoolPending func(context.Context, types.TipSetKey) ([]*types.SignedMessage, error) `perm:"read"` + MpoolPush func(context.Context, *types.SignedMessage) (cid.Cid, error) `perm:"write"` + MpoolPushMessage func(context.Context, *types.Message) (*types.SignedMessage, error) `perm:"sign"` + MpoolGetNonce func(context.Context, address.Address) (uint64, error) `perm:"read"` + MpoolSub func(context.Context) (<-chan api.MpoolUpdate, error) `perm:"read"` MinerGetBaseInfo func(context.Context, address.Address, abi.ChainEpoch, types.TipSetKey) (*api.MiningBaseInfo, error) `perm:"read"` MinerCreateBlock func(context.Context, *api.BlockTemplate) (*types.BlockMsg, error) `perm:"write"` @@ -400,6 +402,16 @@ func (c *FullNodeStruct) ClientGenCar(ctx context.Context, ref api.FileRef, outp return c.Internal.ClientGenCar(ctx, ref, outpath) } +func (c *FullNodeStruct) GasEstimateGasPrice(ctx context.Context, nblocksincl uint64, + sender address.Address, gaslimit int64, tsk types.TipSetKey) (types.BigInt, error) { + return c.Internal.GasEstimateGasPrice(ctx, nblocksincl, sender, gaslimit, tsk) +} + +func (c *FullNodeStruct) GasEstimateGasLimit(ctx context.Context, msg *types.Message, + tsk types.TipSetKey) (int64, error) { + return c.Internal.GasEstimateGasLimit(ctx, msg, tsk) +} + func (c *FullNodeStruct) MpoolPending(ctx context.Context, tsk types.TipSetKey) ([]*types.SignedMessage, error) { return c.Internal.MpoolPending(ctx, tsk) } @@ -417,7 +429,7 @@ func (c *FullNodeStruct) MpoolSub(ctx context.Context) (<-chan api.MpoolUpdate, } func (c *FullNodeStruct) MpoolEstimateGasPrice(ctx context.Context, nblocksincl uint64, sender address.Address, limit int64, tsk types.TipSetKey) (types.BigInt, error) { - return c.Internal.MpoolEstimateGasPrice(ctx, nblocksincl, sender, limit, tsk) + return c.Internal.GasEstimateGasPrice(ctx, nblocksincl, sender, limit, tsk) } func (c *FullNodeStruct) MinerGetBaseInfo(ctx context.Context, maddr address.Address, epoch abi.ChainEpoch, tsk types.TipSetKey) (*api.MiningBaseInfo, error) { diff --git a/build/version.go b/build/version.go index 508dfad71..35d5637e4 100644 --- a/build/version.go +++ b/build/version.go @@ -53,7 +53,7 @@ func (ve Version) EqMajorMinor(v2 Version) bool { } // APIVersion is a semver version of the rpc api exposed -var APIVersion Version = newVer(0, 8, 0) +var APIVersion Version = newVer(0, 8, 1) //nolint:varcheck,deadcode const ( diff --git a/chain/messagepool/messagepool.go b/chain/messagepool/messagepool.go index 7b2f19bbd..633b3b351 100644 --- a/chain/messagepool/messagepool.go +++ b/chain/messagepool/messagepool.go @@ -875,6 +875,7 @@ func (mp *MessagePool) loadLocal() error { const MinGasPrice = 0 +//TODO: remove replaced by Gas module func (mp *MessagePool) EstimateGasPrice(ctx context.Context, nblocksincl uint64, sender address.Address, gaslimit int64, tsk types.TipSetKey) (types.BigInt, error) { // TODO: something smarter obviously switch nblocksincl { diff --git a/chain/stmgr/call.go b/chain/stmgr/call.go index 4f55ca5e5..f48e0d707 100644 --- a/chain/stmgr/call.go +++ b/chain/stmgr/call.go @@ -4,7 +4,9 @@ import ( "context" "fmt" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/specs-actors/actors/abi" + "github.com/filecoin-project/specs-actors/actors/crypto" "github.com/ipfs/go-cid" "go.opencensus.io/trace" "golang.org/x/xerrors" @@ -84,6 +86,73 @@ func (sm *StateManager) Call(ctx context.Context, msg *types.Message, ts *types. return sm.CallRaw(ctx, msg, state, r, ts.Height()) } +func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, ts *types.TipSet) (*api.InvocResult, error) { + ctx, span := trace.StartSpan(ctx, "statemanager.CallWithGas") + defer span.End() + + if ts == nil { + ts = sm.cs.GetHeaviestTipSet() + } + + state := ts.ParentState() + + r := store.NewChainRand(sm.cs, ts.Cids(), ts.Height()) + + if span.IsRecordingEvents() { + span.AddAttributes( + trace.Int64Attribute("gas_limit", msg.GasLimit), + trace.Int64Attribute("gas_price", int64(msg.GasPrice.Uint64())), + trace.StringAttribute("value", msg.Value.String()), + ) + } + + fromKey, err := sm.ResolveToKeyAddress(ctx, msg.From, ts) + var msgApply types.ChainMsg + switch fromKey.Protocol() { + case address.BLS: + msgApply = msg + case address.SECP256K1: + msgApply = &types.SignedMessage{ + Message: *msg, + Signature: crypto.Signature{ + Type: crypto.SigTypeSecp256k1, + Data: make([]byte, 65), + }, + } + + } + + vmi, err := vm.NewVM(state, ts.Height(), r, sm.cs.Blockstore(), sm.cs.VMSys()) + if err != nil { + return nil, xerrors.Errorf("failed to set up vm: %w", err) + } + + fromActor, err := vmi.StateTree().GetActor(msg.From) + if err != nil { + return nil, xerrors.Errorf("call raw get actor: %s", err) + } + + msg.Nonce = fromActor.Nonce + + ret, err := vmi.ApplyMessage(ctx, msgApply) + if err != nil { + return nil, xerrors.Errorf("apply message failed: %w", err) + } + + var errs string + if ret.ActorErr != nil { + errs = ret.ActorErr.Error() + } + + return &api.InvocResult{ + Msg: msg, + MsgRct: &ret.MessageReceipt, + ExecutionTrace: ret.ExecutionTrace, + Error: errs, + Duration: ret.Duration, + }, nil +} + var errHaltExecution = fmt.Errorf("halt") func (sm *StateManager) Replay(ctx context.Context, ts *types.TipSet, mcid cid.Cid) (*types.Message, *vm.ApplyRet, error) { diff --git a/cli/send.go b/cli/send.go index 379f2dd93..ce7879a97 100644 --- a/cli/send.go +++ b/cli/send.go @@ -77,7 +77,6 @@ var sendCmd = &cli.Command{ From: fromAddr, To: toAddr, Value: types.BigInt(val), - GasLimit: 100_000_000, GasPrice: gp, } diff --git a/node/impl/full.go b/node/impl/full.go index 0091737c4..46a706f2b 100644 --- a/node/impl/full.go +++ b/node/impl/full.go @@ -1,9 +1,13 @@ package impl import ( + "context" + logging "github.com/ipfs/go-log/v2" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/lotus/api" + "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/node/impl/client" "github.com/filecoin-project/lotus/node/impl/common" "github.com/filecoin-project/lotus/node/impl/full" @@ -18,6 +22,7 @@ type FullNodeAPI struct { full.ChainAPI client.API full.MpoolAPI + full.GasAPI market.MarketAPI paych.PaychAPI full.StateAPI @@ -26,4 +31,10 @@ type FullNodeAPI struct { full.SyncAPI } +// MpoolEstimateGasPrice estimates gas price +// Deprecated: used GasEstimateGasPrice instead +func (fa *FullNodeAPI) MpoolEstimateGasPrice(ctx context.Context, nblocksincl uint64, sender address.Address, limit int64, tsk types.TipSetKey) (types.BigInt, error) { + return fa.GasEstimateGasPrice(ctx, nblocksincl, sender, limit, tsk) +} + var _ api.FullNode = &FullNodeAPI{} diff --git a/node/impl/full/gas.go b/node/impl/full/gas.go new file mode 100644 index 000000000..73367ea4b --- /dev/null +++ b/node/impl/full/gas.go @@ -0,0 +1,55 @@ +package full + +import ( + "context" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/lotus/build" + "github.com/filecoin-project/lotus/chain/stmgr" + "github.com/filecoin-project/lotus/chain/store" + "github.com/filecoin-project/lotus/chain/types" + "github.com/filecoin-project/specs-actors/actors/runtime/exitcode" + "go.uber.org/fx" + "golang.org/x/xerrors" +) + +type GasAPI struct { + fx.In + Stmgr *stmgr.StateManager + Cs *store.ChainStore +} + +const MinGasPrice = 1 + +func (a *GasAPI) GasEstimateGasPrice(ctx context.Context, nblocksincl uint64, + sender address.Address, gaslimit int64, tsk types.TipSetKey) (types.BigInt, error) { + + // TODO: something smarter obviously + switch nblocksincl { + case 0: + return types.NewInt(MinGasPrice + 2), nil + case 1: + return types.NewInt(MinGasPrice + 1), nil + default: + return types.NewInt(MinGasPrice), nil + } +} + +func (a *GasAPI) GasEstimateGasLimit(ctx context.Context, msgIn *types.Message, + tsk types.TipSetKey) (int64, error) { + + msg := &(*msgIn) + msg.GasLimit = build.BlockGasLimit + + ts, err := a.Cs.GetTipSetFromKey(tsk) + if err != nil { + return -1, xerrors.Errorf("could not get tipset: %w", err) + } + + res, err := a.Stmgr.CallWithGas(ctx, msg, ts) + if res.MsgRct.ExitCode != exitcode.Ok { + return -1, xerrors.Errorf("could not apply message: exit %s, reason: %s", res.MsgRct.ExitCode, res.Error) + } + + return res.MsgRct.GasUsed, nil +} diff --git a/node/impl/full/mpool.go b/node/impl/full/mpool.go index d5b77b0bb..50eb0ce00 100644 --- a/node/impl/full/mpool.go +++ b/node/impl/full/mpool.go @@ -18,6 +18,7 @@ type MpoolAPI struct { fx.In WalletAPI + GasAPI Chain *store.ChainStore @@ -86,15 +87,26 @@ func (a *MpoolAPI) MpoolPush(ctx context.Context, smsg *types.SignedMessage) (ci return a.Mpool.Push(smsg) } +// GasMargin sets by how much should gas limit be increased over test execution +var GasMargin = 1.2 + func (a *MpoolAPI) MpoolPushMessage(ctx context.Context, msg *types.Message) (*types.SignedMessage, error) { if msg.Nonce != 0 { return nil, xerrors.Errorf("MpoolPushMessage expects message nonce to be 0, was %d", msg.Nonce) } if msg.GasLimit == 0 { - msg.GasLimit = 100_000_000 // TODO: gas limit estimation + gasLimit, err := a.GasEstimateGasLimit(ctx, msg, types.TipSetKey{}) + if err != nil { + return nil, xerrors.Errorf("estimating gas limit: %w", err) + } + msg.GasLimit = int64(float64(gasLimit) * GasMargin) } if types.BigCmp(msg.GasPrice, types.NewInt(0)) == 0 { - msg.GasPrice = types.NewInt(1) // TODO: gas price estimation + gasPrice, err := a.GasEstimateGasPrice(ctx, 2, msg.From, msg.GasLimit, types.TipSetKey{}) + if err != nil { + return nil, xerrors.Errorf("estimating gas price: %w", err) + } + msg.GasPrice = gasPrice } return a.Mpool.PushWithNonce(ctx, msg.From, func(from address.Address, nonce uint64) (*types.SignedMessage, error) { @@ -124,7 +136,3 @@ func (a *MpoolAPI) MpoolGetNonce(ctx context.Context, addr address.Address) (uin func (a *MpoolAPI) MpoolSub(ctx context.Context) (<-chan api.MpoolUpdate, error) { return a.Mpool.Updates(ctx) } - -func (a *MpoolAPI) MpoolEstimateGasPrice(ctx context.Context, nblocksincl uint64, sender address.Address, gaslimit int64, tsk types.TipSetKey) (types.BigInt, error) { - return a.Mpool.EstimateGasPrice(ctx, nblocksincl, sender, gaslimit, tsk) -} diff --git a/scripts/dev/sminer-init b/scripts/dev/sminer-init index 767921511..2f4a3f7af 100755 --- a/scripts/dev/sminer-init +++ b/scripts/dev/sminer-init @@ -7,4 +7,4 @@ export TRUST_PARAMS=1 tag=${TAG:-debug} go run -tags=$tag ./cmd/lotus wallet import ~/.genesis-sectors/pre-seal-t01000.key -go run -tags=$tag ./cmd/lotus-miner init --actor=t01000 --genesis-miner --pre-sealed-sectors=~/.genesis-sectors --pre-sealed-metadata=~/.genesis-sectors/pre-seal-t01000.json +go run -tags=$tag ./cmd/lotus-storage-miner init --actor=t01000 --genesis-miner --pre-sealed-sectors=~/.genesis-sectors --pre-sealed-metadata=~/.genesis-sectors/pre-seal-t01000.json From 7da629d03bad9d6d5d0af3443929c43f74889345 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Mon, 20 Jul 2020 19:57:06 +0200 Subject: [PATCH 07/25] Update gas prices Signed-off-by: Jakub Sztandera --- chain/market/fundmgr.go | 12 +++++------- chain/stmgr/forks_test.go | 4 ++-- chain/stmgr/utils.go | 2 +- chain/types/message.go | 2 ++ cli/chain.go | 2 +- cmd/chain-noise/main.go | 2 +- cmd/lotus-fountain/main.go | 6 +++--- cmd/lotus-shed/nonce-fix.go | 2 +- cmd/lotus-shed/verifreg.go | 4 ++-- cmd/lotus-storage-miner/init.go | 4 ++-- markets/storageadapter/client.go | 2 +- markets/storageadapter/provider.go | 4 ++-- node/impl/full/multisig.go | 6 +++--- node/impl/full/state.go | 2 +- node/impl/paych/paych.go | 4 ++-- node/node_test.go | 2 +- paychmgr/simple.go | 4 ++-- storage/adapter_storage_miner.go | 2 +- storage/wdpost_run.go | 4 ++-- 19 files changed, 35 insertions(+), 35 deletions(-) diff --git a/chain/market/fundmgr.go b/chain/market/fundmgr.go index 1bafda3c9..83ea6dca5 100644 --- a/chain/market/fundmgr.go +++ b/chain/market/fundmgr.go @@ -66,13 +66,11 @@ func (fm *FundMgr) EnsureAvailable(ctx context.Context, addr, wallet address.Add } smsg, err := fm.mpool.MpoolPushMessage(ctx, &types.Message{ - To: builtin.StorageMarketActorAddr, - From: wallet, - Value: toAdd, - GasPrice: types.NewInt(0), - GasLimit: 100_000_000, - Method: builtin.MethodsMarket.AddBalance, - Params: params, + To: builtin.StorageMarketActorAddr, + From: wallet, + Value: toAdd, + Method: builtin.MethodsMarket.AddBalance, + Params: params, }) if err != nil { return cid.Undef, err diff --git a/chain/stmgr/forks_test.go b/chain/stmgr/forks_test.go index c84b0b7b9..5a6c8a34e 100644 --- a/chain/stmgr/forks_test.go +++ b/chain/stmgr/forks_test.go @@ -179,7 +179,7 @@ func TestForkHeightTriggers(t *testing.T) { To: builtin.InitActorAddr, Method: builtin.MethodsInit.Exec, Params: enc, - GasLimit: 100_000_000, + GasLimit: types.TestGasLimit, GasPrice: types.NewInt(0), } sig, err := cg.Wallet().Sign(ctx, cg.Banker(), m.Cid().Bytes()) @@ -206,7 +206,7 @@ func TestForkHeightTriggers(t *testing.T) { Method: 2, Params: nil, Nonce: nonce, - GasLimit: 100_000_000, + GasLimit: types.TestGasLimit, GasPrice: types.NewInt(0), } nonce++ diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index 7464bbd03..79585ba68 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -586,7 +586,7 @@ func (sm *StateManager) CirculatingSupply(ctx context.Context, ts *types.TipSet) unsafeVM := &vm.UnsafeVM{VM: vmi} rt := unsafeVM.MakeRuntime(ctx, &types.Message{ - GasLimit: 1_000_000_000, + GasLimit: 100e6, From: builtin.SystemActorAddr, }, builtin.SystemActorAddr, 0, 0, 0) diff --git a/chain/types/message.go b/chain/types/message.go index b0d7f885f..d402490f2 100644 --- a/chain/types/message.go +++ b/chain/types/message.go @@ -158,3 +158,5 @@ func (m *Message) ValidForBlockInclusion(minGas int64) error { return nil } + +const TestGasLimit = 100e6 diff --git a/cli/chain.go b/cli/chain.go index 69f3d7413..8ae2c3c5e 100644 --- a/cli/chain.go +++ b/cli/chain.go @@ -935,7 +935,7 @@ var slashConsensusFault = &cli.Command{ From: def, Value: types.NewInt(0), GasPrice: types.NewInt(1), - GasLimit: 100_000_000, + GasLimit: 0, Method: builtin.MethodsMiner.ReportConsensusFault, Params: enc, } diff --git a/cmd/chain-noise/main.go b/cmd/chain-noise/main.go index 5a04fbf21..d429a8d59 100644 --- a/cmd/chain-noise/main.go +++ b/cmd/chain-noise/main.go @@ -77,7 +77,7 @@ func sendSmallFundsTxs(ctx context.Context, api api.FullNode, from address.Addre From: from, To: sendSet[rand.Intn(20)], Value: types.NewInt(1), - GasLimit: 100_000_000, + GasLimit: 0, GasPrice: types.NewInt(0), } diff --git a/cmd/lotus-fountain/main.go b/cmd/lotus-fountain/main.go index b9c0fe26a..62fd25509 100644 --- a/cmd/lotus-fountain/main.go +++ b/cmd/lotus-fountain/main.go @@ -281,7 +281,7 @@ func (h *handler) send(w http.ResponseWriter, r *http.Request) { To: to, GasPrice: types.NewInt(0), - GasLimit: 100_000_000, + GasLimit: 0, }) if err != nil { w.WriteHeader(400) @@ -355,7 +355,7 @@ func (h *handler) mkminer(w http.ResponseWriter, r *http.Request) { To: owner, GasPrice: types.NewInt(0), - GasLimit: 100_000_000, + GasLimit: 0, }) if err != nil { w.WriteHeader(400) @@ -391,7 +391,7 @@ func (h *handler) mkminer(w http.ResponseWriter, r *http.Request) { Method: builtin.MethodsPower.CreateMiner, Params: params, - GasLimit: 100_000_000, + GasLimit: 0, GasPrice: types.NewInt(0), } diff --git a/cmd/lotus-shed/nonce-fix.go b/cmd/lotus-shed/nonce-fix.go index c85e91797..1cd713852 100644 --- a/cmd/lotus-shed/nonce-fix.go +++ b/cmd/lotus-shed/nonce-fix.go @@ -89,7 +89,7 @@ var noncefix = &cli.Command{ From: addr, To: addr, Value: types.NewInt(1), - GasLimit: 100_000_000, + GasLimit: 0, GasPrice: types.NewInt(1), Nonce: i, } diff --git a/cmd/lotus-shed/verifreg.go b/cmd/lotus-shed/verifreg.go index 3641ac2df..90d12bee4 100644 --- a/cmd/lotus-shed/verifreg.go +++ b/cmd/lotus-shed/verifreg.go @@ -76,7 +76,7 @@ var verifRegAddVerifierCmd = &cli.Command{ From: fromk, Method: builtin.MethodsVerifiedRegistry.AddVerifier, GasPrice: types.NewInt(1), - GasLimit: 100_000_000, + GasLimit: 0, Params: params, } @@ -152,7 +152,7 @@ var verifRegVerifyClientCmd = &cli.Command{ From: fromk, Method: builtin.MethodsVerifiedRegistry.AddVerifiedClient, GasPrice: types.NewInt(1), - GasLimit: 100_000_000, + GasLimit: 0, Params: params, } diff --git a/cmd/lotus-storage-miner/init.go b/cmd/lotus-storage-miner/init.go index 8468c7f96..01a14093e 100644 --- a/cmd/lotus-storage-miner/init.go +++ b/cmd/lotus-storage-miner/init.go @@ -557,7 +557,7 @@ func configureStorageMiner(ctx context.Context, api lapi.FullNode, addr address. Params: enc, Value: types.NewInt(0), GasPrice: gasPrice, - GasLimit: 100_000_000, + GasLimit: 0, } smsg, err := api.MpoolPushMessage(ctx, msg) @@ -636,7 +636,7 @@ func createStorageMiner(ctx context.Context, api lapi.FullNode, peerid peer.ID, Method: builtin.MethodsPower.CreateMiner, Params: params, - GasLimit: 100_000_000, + GasLimit: 0, GasPrice: gasPrice, } diff --git a/markets/storageadapter/client.go b/markets/storageadapter/client.go index 2bb762e28..38c8d5a4e 100644 --- a/markets/storageadapter/client.go +++ b/markets/storageadapter/client.go @@ -138,7 +138,7 @@ func (c *ClientNodeAdapter) AddFunds(ctx context.Context, addr address.Address, From: addr, Value: amount, GasPrice: types.NewInt(0), - GasLimit: 200_000_000, + GasLimit: 0, Method: builtin.MethodsMarket.AddBalance, }) if err != nil { diff --git a/markets/storageadapter/provider.go b/markets/storageadapter/provider.go index 9e1a101cc..968ced4cf 100644 --- a/markets/storageadapter/provider.go +++ b/markets/storageadapter/provider.go @@ -78,7 +78,7 @@ func (n *ProviderNodeAdapter) PublishDeals(ctx context.Context, deal storagemark From: mi.Worker, Value: types.NewInt(0), GasPrice: types.NewInt(0), - GasLimit: 600_000_000, + GasLimit: 0, Method: builtin.MethodsMarket.PublishStorageDeals, Params: params, }) @@ -175,7 +175,7 @@ func (n *ProviderNodeAdapter) AddFunds(ctx context.Context, addr address.Address From: addr, Value: amount, GasPrice: types.NewInt(0), - GasLimit: 200_000_000, + GasLimit: 0, Method: builtin.MethodsMarket.AddBalance, }) if err != nil { diff --git a/node/impl/full/multisig.go b/node/impl/full/multisig.go index 779c140cf..2ae28f6a0 100644 --- a/node/impl/full/multisig.go +++ b/node/impl/full/multisig.go @@ -77,7 +77,7 @@ func (a *MsigAPI) MsigCreate(ctx context.Context, req uint64, addrs []address.Ad Method: builtin.MethodsInit.Exec, Params: enc, GasPrice: gp, - GasLimit: 100_000_000, + GasLimit: 0, Value: val, } @@ -124,7 +124,7 @@ func (a *MsigAPI) MsigPropose(ctx context.Context, msig address.Address, to addr Value: types.NewInt(0), Method: builtin.MethodsMultisig.Propose, Params: enc, - GasLimit: 100_000_000, + GasLimit: 0, GasPrice: types.NewInt(1), } @@ -240,7 +240,7 @@ func (a *MsigAPI) msigApproveOrCancel(ctx context.Context, operation api.MsigPro Value: types.NewInt(0), Method: msigResponseMethod, Params: enc, - GasLimit: 100_000_000, + GasLimit: 0, GasPrice: types.NewInt(1), } diff --git a/node/impl/full/state.go b/node/impl/full/state.go index d505538a7..94e28eae9 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -974,7 +974,7 @@ func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr From: maddr, To: builtin.StorageMarketActorAddr, Method: builtin.MethodsMarket.VerifyDealsForActivation, - GasLimit: 100_000_000, + GasLimit: 0, GasPrice: types.NewInt(0), Params: params, }, ts) diff --git a/node/impl/paych/paych.go b/node/impl/paych/paych.go index 20778b9f2..f7a51fc25 100644 --- a/node/impl/paych/paych.go +++ b/node/impl/paych/paych.go @@ -127,7 +127,7 @@ func (a *PaychAPI) PaychClose(ctx context.Context, addr address.Address) (cid.Ci Method: builtin.MethodsPaych.Settle, Nonce: nonce, - GasLimit: 100_000_000, + GasLimit: 0, GasPrice: types.NewInt(0), } @@ -242,7 +242,7 @@ func (a *PaychAPI) PaychVoucherSubmit(ctx context.Context, ch address.Address, s Nonce: nonce, Method: builtin.MethodsPaych.UpdateChannelState, Params: enc, - GasLimit: 100_000_000, + GasLimit: 0, GasPrice: types.NewInt(0), } diff --git a/node/node_test.go b/node/node_test.go index e03d9ed4f..714449dac 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -107,7 +107,7 @@ func testStorageNode(ctx context.Context, t *testing.T, waddr address.Address, a Params: enc, Value: types.NewInt(0), GasPrice: types.NewInt(0), - GasLimit: 100_000_000, + GasLimit: 0, } _, err = tnd.MpoolPushMessage(ctx, msg) diff --git a/paychmgr/simple.go b/paychmgr/simple.go index ddc49f864..0d0075d62 100644 --- a/paychmgr/simple.go +++ b/paychmgr/simple.go @@ -37,7 +37,7 @@ func (pm *Manager) createPaych(ctx context.Context, from, to address.Address, am Value: amt, Method: builtin.MethodsInit.Exec, Params: enc, - GasLimit: 100_000_000, + GasLimit: 0, GasPrice: types.NewInt(0), } @@ -92,7 +92,7 @@ func (pm *Manager) addFunds(ctx context.Context, ch address.Address, from addres From: from, Value: amt, Method: 0, - GasLimit: 100_000_000, + GasLimit: 0, GasPrice: types.NewInt(0), } diff --git a/storage/adapter_storage_miner.go b/storage/adapter_storage_miner.go index aa8a93274..7a41563a1 100644 --- a/storage/adapter_storage_miner.go +++ b/storage/adapter_storage_miner.go @@ -117,7 +117,7 @@ func (s SealingAPIAdapter) StateComputeDataCommitment(ctx context.Context, maddr From: maddr, Value: types.NewInt(0), GasPrice: types.NewInt(0), - GasLimit: 100_000_000, + GasLimit: 0, Method: builtin.MethodsMarket.ComputeDataCommitment, Params: ccparams, } diff --git a/storage/wdpost_run.go b/storage/wdpost_run.go index c7d99b2fc..063a5c5a3 100644 --- a/storage/wdpost_run.go +++ b/storage/wdpost_run.go @@ -176,7 +176,7 @@ func (s *WindowPoStScheduler) checkNextRecoveries(ctx context.Context, dlIdx uin Method: builtin.MethodsMiner.DeclareFaultsRecovered, Params: enc, Value: types.NewInt(0), - GasLimit: 100_000_000, // i dont know help + GasLimit: 0, GasPrice: types.NewInt(2), } @@ -260,7 +260,7 @@ func (s *WindowPoStScheduler) checkNextFaults(ctx context.Context, dlIdx uint64, Method: builtin.MethodsMiner.DeclareFaults, Params: enc, Value: types.NewInt(0), // TODO: Is there a fee? - GasLimit: 100_000_000, // i dont know help + GasLimit: 0, GasPrice: types.NewInt(2), } From e6b3ba0178fbbbe8a7f02dea6c4180c356482863 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Mon, 20 Jul 2020 20:33:15 +0200 Subject: [PATCH 08/25] Slow down pledgeSectors test Signed-off-by: Jakub Sztandera --- .circleci/config.yml | 1 + api/test/ccupgrade.go | 2 +- api/test/window_post.go | 19 +++++++++++++++---- cmd/lotus-storage-miner/rewards.go | 21 +++++---------------- node/impl/full/gas.go | 6 +++++- 5 files changed, 27 insertions(+), 22 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d88bbc9be..229bf3182 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -156,6 +156,7 @@ jobs: - download-params - go/install-gotestsum: gobin: $HOME/.local/bin + version: 0.5.2 - run: name: go test environment: diff --git a/api/test/ccupgrade.go b/api/test/ccupgrade.go index f8e8b1162..9380ac7be 100644 --- a/api/test/ccupgrade.go +++ b/api/test/ccupgrade.go @@ -54,7 +54,7 @@ func TestCCUpgrade(t *testing.T, b APIBuilder, blocktime time.Duration) { CC := abi.SectorNumber(GenesisPreseals + 1) Upgraded := CC + 1 - pledgeSectors(t, ctx, miner, 1) + pledgeSectors(t, ctx, miner, 1, nil) sl, err := miner.SectorsList(ctx) if err != nil { diff --git a/api/test/window_post.go b/api/test/window_post.go index 874bcadcf..03cc9535d 100644 --- a/api/test/window_post.go +++ b/api/test/window_post.go @@ -3,6 +3,7 @@ package test import ( "context" "fmt" + "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" @@ -41,26 +42,36 @@ func TestPledgeSector(t *testing.T, b APIBuilder, blocktime time.Duration, nSect mine := true done := make(chan struct{}) + blockNotif := make(chan struct{}, 1) go func() { defer close(done) for mine { build.Clock.Sleep(blocktime) - if err := sn[0].MineOne(ctx, func(bool, error) {}); err != nil { + if err := sn[0].MineOne(ctx, func(bool, error) { + select { + case blockNotif <- struct{}{}: + default: + } + + }); err != nil { t.Error(err) } } }() - pledgeSectors(t, ctx, miner, nSectors) + pledgeSectors(t, ctx, miner, nSectors, blockNotif) mine = false <-done } -func pledgeSectors(t *testing.T, ctx context.Context, miner TestStorageNode, n int) { +func pledgeSectors(t *testing.T, ctx context.Context, miner TestStorageNode, n int, blockNotif <-chan struct{}) { for i := 0; i < n; i++ { err := miner.PledgeSector(ctx) require.NoError(t, err) + if i%3 == 0 && blockNotif != nil { + <-blockNotif + } } for { @@ -131,7 +142,7 @@ func TestWindowPost(t *testing.T, b APIBuilder, blocktime time.Duration, nSector } }() - pledgeSectors(t, ctx, miner, nSectors) + pledgeSectors(t, ctx, miner, nSectors, nil) maddr, err := miner.ActorAddress(ctx) require.NoError(t, err) diff --git a/cmd/lotus-storage-miner/rewards.go b/cmd/lotus-storage-miner/rewards.go index 4152880ae..38a797dcc 100644 --- a/cmd/lotus-storage-miner/rewards.go +++ b/cmd/lotus-storage-miner/rewards.go @@ -22,13 +22,6 @@ var rewardsCmd = &cli.Command{ var rewardsRedeemCmd = &cli.Command{ Name: "redeem", Usage: "Redeem block rewards", - Flags: []cli.Flag{ - &cli.Int64Flag{ - Name: "gas-limit", - Usage: "set gas limit", - Value: 100000, - }, - }, Action: func(cctx *cli.Context) error { nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { @@ -66,16 +59,12 @@ var rewardsRedeemCmd = &cli.Command{ return err } - gasLimit := cctx.Int64("gas-limit") - smsg, err := api.MpoolPushMessage(ctx, &types.Message{ - To: maddr, - From: mi.Owner, - Value: types.NewInt(0), - GasPrice: types.NewInt(1), - GasLimit: gasLimit, - Method: builtin.MethodsMiner.WithdrawBalance, - Params: params, + To: maddr, + From: mi.Owner, + Value: types.NewInt(0), + Method: builtin.MethodsMiner.WithdrawBalance, + Params: params, }) if err != nil { return err diff --git a/node/impl/full/gas.go b/node/impl/full/gas.go index 73367ea4b..d6e2caf2d 100644 --- a/node/impl/full/gas.go +++ b/node/impl/full/gas.go @@ -40,6 +40,7 @@ func (a *GasAPI) GasEstimateGasLimit(ctx context.Context, msgIn *types.Message, msg := &(*msgIn) msg.GasLimit = build.BlockGasLimit + msg.GasPrice = types.NewInt(1) ts, err := a.Cs.GetTipSetFromKey(tsk) if err != nil { @@ -47,8 +48,11 @@ func (a *GasAPI) GasEstimateGasLimit(ctx context.Context, msgIn *types.Message, } res, err := a.Stmgr.CallWithGas(ctx, msg, ts) + if err != nil { + return -1, xerrors.Errorf("CallWithGas failed: %w", err) + } if res.MsgRct.ExitCode != exitcode.Ok { - return -1, xerrors.Errorf("could not apply message: exit %s, reason: %s", res.MsgRct.ExitCode, res.Error) + return -1, xerrors.Errorf("message execution failed: exit %s, reason: %s", res.MsgRct.ExitCode, res.Error) } return res.MsgRct.GasUsed, nil From a5334eb2b3c7137aae4bd5efee43bdcafa471633 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Mon, 20 Jul 2020 21:41:05 +0200 Subject: [PATCH 09/25] Fix lint warnings Signed-off-by: Jakub Sztandera --- chain/messagepool/messagepool.go | 15 --------------- chain/stmgr/call.go | 5 +++++ node/impl/full/gas.go | 4 ++-- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/chain/messagepool/messagepool.go b/chain/messagepool/messagepool.go index 633b3b351..c12359482 100644 --- a/chain/messagepool/messagepool.go +++ b/chain/messagepool/messagepool.go @@ -872,18 +872,3 @@ func (mp *MessagePool) loadLocal() error { return nil } - -const MinGasPrice = 0 - -//TODO: remove replaced by Gas module -func (mp *MessagePool) EstimateGasPrice(ctx context.Context, nblocksincl uint64, sender address.Address, gaslimit int64, tsk types.TipSetKey) (types.BigInt, error) { - // TODO: something smarter obviously - switch nblocksincl { - case 0: - return types.NewInt(MinGasPrice + 2), nil - case 1: - return types.NewInt(MinGasPrice + 1), nil - default: - return types.NewInt(MinGasPrice), nil - } -} diff --git a/chain/stmgr/call.go b/chain/stmgr/call.go index f48e0d707..893db33a8 100644 --- a/chain/stmgr/call.go +++ b/chain/stmgr/call.go @@ -107,7 +107,12 @@ func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, ts } fromKey, err := sm.ResolveToKeyAddress(ctx, msg.From, ts) + if err != nil { + return nil, xerrors.Errorf("could not resolve key: %w", err) + } + var msgApply types.ChainMsg + switch fromKey.Protocol() { case address.BLS: msgApply = msg diff --git a/node/impl/full/gas.go b/node/impl/full/gas.go index d6e2caf2d..1d09e5844 100644 --- a/node/impl/full/gas.go +++ b/node/impl/full/gas.go @@ -38,7 +38,7 @@ func (a *GasAPI) GasEstimateGasPrice(ctx context.Context, nblocksincl uint64, func (a *GasAPI) GasEstimateGasLimit(ctx context.Context, msgIn *types.Message, tsk types.TipSetKey) (int64, error) { - msg := &(*msgIn) + msg := *msgIn msg.GasLimit = build.BlockGasLimit msg.GasPrice = types.NewInt(1) @@ -47,7 +47,7 @@ func (a *GasAPI) GasEstimateGasLimit(ctx context.Context, msgIn *types.Message, return -1, xerrors.Errorf("could not get tipset: %w", err) } - res, err := a.Stmgr.CallWithGas(ctx, msg, ts) + res, err := a.Stmgr.CallWithGas(ctx, &msg, ts) if err != nil { return -1, xerrors.Errorf("CallWithGas failed: %w", err) } From 71ce8845d5a9675173a4c33ea54f72a709b4afe1 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Mon, 20 Jul 2020 21:50:03 +0200 Subject: [PATCH 10/25] Fix nil big int Signed-off-by: Jakub Sztandera --- node/impl/full/mpool.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/node/impl/full/mpool.go b/node/impl/full/mpool.go index 50eb0ce00..8bc90666a 100644 --- a/node/impl/full/mpool.go +++ b/node/impl/full/mpool.go @@ -101,7 +101,8 @@ func (a *MpoolAPI) MpoolPushMessage(ctx context.Context, msg *types.Message) (*t } msg.GasLimit = int64(float64(gasLimit) * GasMargin) } - if types.BigCmp(msg.GasPrice, types.NewInt(0)) == 0 { + + if msg.GasPrice == types.EmptyInt || types.BigCmp(msg.GasPrice, types.NewInt(0)) == 0 { gasPrice, err := a.GasEstimateGasPrice(ctx, 2, msg.From, msg.GasLimit, types.TipSetKey{}) if err != nil { return nil, xerrors.Errorf("estimating gas price: %w", err) From cf917fc4266b44452b212793930deb1a399cd8ab Mon Sep 17 00:00:00 2001 From: Mike Greenberg Date: Mon, 20 Jul 2020 17:31:27 -0400 Subject: [PATCH 11/25] fix(chainwatch): Restore base block reward metric capture --- cmd/lotus-chainwatch/processor/reward.go | 7 ++----- cmd/lotus-chainwatch/syncer/sync.go | 13 ++++++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd/lotus-chainwatch/processor/reward.go b/cmd/lotus-chainwatch/processor/reward.go index a767b7e78..fb628bd6f 100644 --- a/cmd/lotus-chainwatch/processor/reward.go +++ b/cmd/lotus-chainwatch/processor/reward.go @@ -118,11 +118,8 @@ func (p *Processor) processRewardActors(ctx context.Context, rewardTips ActorTip return nil, xerrors.Errorf("unmarshal state (@ %s): %w", rw.common.stateroot.String(), err) } - // TODO: Resolve Actor API shift - //rw.baseBlockReward = rewardActorState.LastPerEpochReward - //rw.baselinePower = rewardActorState.BaselinePower - rw.baseBlockReward = big.Zero() - rw.baselinePower = big.Zero() + rw.baseBlockReward = rewardActorState.ThisEpochReward + rw.baselinePower = rewardActorState.ThisEpochBaselinePower out = append(out, rw) } } diff --git a/cmd/lotus-chainwatch/syncer/sync.go b/cmd/lotus-chainwatch/syncer/sync.go index 6a9bdc350..db82631e9 100644 --- a/cmd/lotus-chainwatch/syncer/sync.go +++ b/cmd/lotus-chainwatch/syncer/sync.go @@ -110,7 +110,8 @@ create table if not exists blocks miner text not null, timestamp bigint not null, ticket bytea not null, - eprof bytea, + election_proof bytea, + win_count bigint, forksig bigint not null ); @@ -401,15 +402,16 @@ create temp table b (like blocks excluding constraints) on commit drop; } } - stmt2, err := tx.Prepare(`copy b (cid, parentWeight, parentStateRoot, height, miner, "timestamp", ticket, eprof, forksig) from stdin`) + stmt2, err := tx.Prepare(`copy b (cid, parentWeight, parentStateRoot, height, miner, "timestamp", ticket, election_proof, win_count, forksig) from stdin`) if err != nil { return err } for _, bh := range bhs { - var eprof interface{} + var eproof, winCount interface{} if bh.ElectionProof != nil { - eprof = bh.ElectionProof.VRFProof + eproof = bh.ElectionProof.VRFProof + winCount = bh.ElectionProof.WinCount } if bh.Ticket == nil { @@ -428,7 +430,8 @@ create temp table b (like blocks excluding constraints) on commit drop; bh.Miner.String(), bh.Timestamp, bh.Ticket.VRFProof, - eprof, + eproof, + winCount, bh.ForkSignaling); err != nil { log.Error(err) } From b1eb2cf3a783140e93e9233c52230146010d80cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 20 Jul 2020 20:23:45 +0200 Subject: [PATCH 12/25] Update storage-fsm --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index b425c9d5d..2a7e52880 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,7 @@ require ( github.com/filecoin-project/sector-storage v0.0.0-20200717213554-a109ef9cbeab github.com/filecoin-project/specs-actors v0.8.1-0.20200720115956-cd051eabf328 github.com/filecoin-project/specs-storage v0.1.1-0.20200622113353-88a9704877ea - github.com/filecoin-project/storage-fsm v0.0.0-20200717125541-d575c3a5f7f2 + github.com/filecoin-project/storage-fsm v0.0.0-20200720190000-2cfe2fe3c334 github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1 github.com/go-kit/kit v0.10.0 github.com/go-ole/go-ole v1.2.4 // indirect diff --git a/go.sum b/go.sum index 3007c62e1..4acc25972 100644 --- a/go.sum +++ b/go.sum @@ -277,8 +277,8 @@ github.com/filecoin-project/specs-storage v0.1.0 h1:PkDgTOT5W5Ao7752onjDl4QSv+sg github.com/filecoin-project/specs-storage v0.1.0/go.mod h1:Pr5ntAaxsh+sLG/LYiL4tKzvA83Vk5vLODYhfNwOg7k= github.com/filecoin-project/specs-storage v0.1.1-0.20200622113353-88a9704877ea h1:iixjULRQFPn7Q9KlIqfwLJnlAXO10bbkI+xy5GKGdLY= github.com/filecoin-project/specs-storage v0.1.1-0.20200622113353-88a9704877ea/go.mod h1:Pr5ntAaxsh+sLG/LYiL4tKzvA83Vk5vLODYhfNwOg7k= -github.com/filecoin-project/storage-fsm v0.0.0-20200717125541-d575c3a5f7f2 h1:A9zUXOMuVnSTp9a0i0KtHkB05hA8mRWVLls6Op9Czuo= -github.com/filecoin-project/storage-fsm v0.0.0-20200717125541-d575c3a5f7f2/go.mod h1:1CGbd11KkHuyWPT+xwwCol1zl/jnlpiKD2L4fzKxaiI= +github.com/filecoin-project/storage-fsm v0.0.0-20200720190000-2cfe2fe3c334 h1:gRp8IlJ3XDYuOUFvncmlCI6HtuK61W2wE1aEqgj4opA= +github.com/filecoin-project/storage-fsm v0.0.0-20200720190000-2cfe2fe3c334/go.mod h1:1CGbd11KkHuyWPT+xwwCol1zl/jnlpiKD2L4fzKxaiI= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/flynn/noise v0.0.0-20180327030543-2492fe189ae6 h1:u/UEqS66A5ckRmS4yNpjmVH56sVtS/RfclBAYocb4as= github.com/flynn/noise v0.0.0-20180327030543-2492fe189ae6/go.mod h1:1i71OnUq3iUe1ma7Lr6yG6/rjvM3emb6yoL7xLFzcVQ= From d07c379c6914efd489e35218a65da942c9387006 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 21 Jul 2020 01:07:08 +0200 Subject: [PATCH 13/25] Update to newer gotestsum Signed-off-by: Jakub Sztandera --- .circleci/config.yml | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d88bbc9be..7e34184c3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,7 +5,7 @@ orbs: executors: golang: docker: - - image: circleci/golang:1.14.2 + - image: circleci/golang:1.14.6 resource_class: 2xlarge ubuntu: docker: @@ -134,7 +134,7 @@ jobs: description: Test suite name to report to CircleCI. gotestsum-format: type: string - default: short + default: pkgname-and-test-fails description: gotestsum format. https://github.com/gotestyourself/gotestsum#format coverage: type: string @@ -156,21 +156,27 @@ jobs: - download-params - go/install-gotestsum: gobin: $HOME/.local/bin + version: 0.5.2 - run: name: go test environment: - GOTESTSUM_JUNITFILE: /tmp/test-reports/<< parameters.test-suite-name >>/junit.xml - GOTESTSUM_FORMAT: << parameters.gotestsum-format >> LOTUS_TEST_WINDOW_POST: << parameters.winpost-test >> command: | mkdir -p /tmp/test-reports/<< parameters.test-suite-name >> - gotestsum -- \ + mkdir -p /tmp/test-artifacts + gotestsum \ + --format << parameters.gotestsum-format >> \ + --junitfile /tmp/test-reports/<< parameters.test-suite-name >>/junit.xml \ + --jsonfile /tmp/test-artifacts/<< parameters.test-suite-name >>.json \ + -- \ << parameters.coverage >> \ << parameters.go-test-flags >> \ << parameters.packages >> no_output_timeout: 30m - store_test_results: path: /tmp/test-reports + - store_artifacts: + path: /tmp/test-artifacts/<< parameters.test-suite-name >>.json - when: condition: << parameters.codecov-upload >> steps: @@ -319,11 +325,14 @@ workflows: - gofmt - test: codecov-upload: true + test-suite-name: full - test-window-post: go-test-flags: "-run=TestWindowedPost" winpost-test: "1" + test-suite-name: window-post - test-short: go-test-flags: "--timeout 10m --short" + test-suite-name: short filters: tags: only: From 42a7cb1248f13198cb8e008caa49badba2817a5d Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Mon, 20 Jul 2020 17:17:53 -0700 Subject: [PATCH 14/25] fix a few multisig cli issues --- chain/store/store.go | 5 +++-- cli/multisig.go | 13 +++++++++---- node/impl/full/multisig.go | 5 +++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/chain/store/store.go b/chain/store/store.go index aaf6cf44d..e0cd0e91a 100644 --- a/chain/store/store.go +++ b/chain/store/store.go @@ -5,11 +5,12 @@ import ( "context" "encoding/binary" "encoding/json" - "github.com/filecoin-project/lotus/lib/adtutil" "io" "os" "sync" + "github.com/filecoin-project/lotus/lib/adtutil" + "github.com/filecoin-project/specs-actors/actors/crypto" "github.com/minio/blake2b-simd" @@ -659,7 +660,7 @@ func (cs *ChainStore) GetCMessage(c cid.Cid) (types.ChainMsg, error) { return m, nil } if err != bstore.ErrNotFound { - log.Warn("GetCMessage: unexpected error getting unsigned message: %s", err) + log.Warnf("GetCMessage: unexpected error getting unsigned message: %s", err) } return cs.GetSignedMessage(c) diff --git a/cli/multisig.go b/cli/multisig.go index 5412f4819..ef38c8168 100644 --- a/cli/multisig.go +++ b/cli/multisig.go @@ -364,12 +364,17 @@ var msigProposeCmd = &cli.Command{ return fmt.Errorf("proposal returned exit %d", wait.Receipt.ExitCode) } - _, v, err := cbg.CborReadHeader(bytes.NewReader(wait.Receipt.Return)) - if err != nil { - return err + var retval samsig.ProposeReturn + if err := retval.UnmarshalCBOR(bytes.NewReader(wait.Receipt.Return)); err != nil { + return fmt.Errorf("failed to unmarshal propose return value: %w", err) } - fmt.Printf("Transaction ID: %d\n", v) + fmt.Printf("Transaction ID: %d\n", retval.TxnID) + if retval.Applied { + fmt.Printf("Transaction was executed during propose\n") + fmt.Printf("Exit Code: %d\n", retval.Code) + fmt.Printf("Return Value: %x\n", retval.Ret) + } return nil }, diff --git a/node/impl/full/multisig.go b/node/impl/full/multisig.go index 2ae28f6a0..6e0025a83 100644 --- a/node/impl/full/multisig.go +++ b/node/impl/full/multisig.go @@ -2,6 +2,7 @@ package full import ( "context" + "github.com/filecoin-project/specs-actors/actors/abi/big" "github.com/filecoin-project/go-address" @@ -115,7 +116,7 @@ func (a *MsigAPI) MsigPropose(ctx context.Context, msig address.Address, to addr Params: params, }) if actErr != nil { - return cid.Undef, actErr + return cid.Undef, xerrors.Errorf("failed to serialize parameters: %w", actErr) } msg := &types.Message{ @@ -130,7 +131,7 @@ func (a *MsigAPI) MsigPropose(ctx context.Context, msig address.Address, to addr smsg, err := a.MpoolAPI.MpoolPushMessage(ctx, msg) if err != nil { - return cid.Undef, nil + return cid.Undef, xerrors.Errorf("failed to push message: %w", err) } return smsg.Cid(), nil From 3e00885ba6c36640070c3a99dbd9c535e92ae244 Mon Sep 17 00:00:00 2001 From: Jim Pick Date: Mon, 20 Jul 2020 18:30:21 -0700 Subject: [PATCH 15/25] Spelling fix --- cli/mpool.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/mpool.go b/cli/mpool.go index fec7b2e0d..5281c8eb1 100644 --- a/cli/mpool.go +++ b/cli/mpool.go @@ -80,7 +80,7 @@ var mpoolPending = &cli.Command{ var mpoolSub = &cli.Command{ Name: "sub", - Usage: "Subscibe to mpool changes", + Usage: "Subscribe to mpool changes", Action: func(cctx *cli.Context) error { api, closer, err := GetFullNodeAPI(cctx) if err != nil { From 6673a80db5801d72ffa8c40704b0996ce6c50f9f Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 21 Jul 2020 03:41:18 +0200 Subject: [PATCH 16/25] Fix nonce setting in gas estimation Signed-off-by: Jakub Sztandera --- chain/stmgr/call.go | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/chain/stmgr/call.go b/chain/stmgr/call.go index 893db33a8..29c97c3d8 100644 --- a/chain/stmgr/call.go +++ b/chain/stmgr/call.go @@ -106,6 +106,17 @@ func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, ts ) } + vmi, err := vm.NewVM(state, ts.Height(), r, sm.cs.Blockstore(), sm.cs.VMSys()) + if err != nil { + return nil, xerrors.Errorf("failed to set up vm: %w", err) + } + fromActor, err := vmi.StateTree().GetActor(msg.From) + if err != nil { + return nil, xerrors.Errorf("call raw get actor: %s", err) + } + + msg.Nonce = fromActor.Nonce + fromKey, err := sm.ResolveToKeyAddress(ctx, msg.From, ts) if err != nil { return nil, xerrors.Errorf("could not resolve key: %w", err) @@ -127,18 +138,6 @@ func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, ts } - vmi, err := vm.NewVM(state, ts.Height(), r, sm.cs.Blockstore(), sm.cs.VMSys()) - if err != nil { - return nil, xerrors.Errorf("failed to set up vm: %w", err) - } - - fromActor, err := vmi.StateTree().GetActor(msg.From) - if err != nil { - return nil, xerrors.Errorf("call raw get actor: %s", err) - } - - msg.Nonce = fromActor.Nonce - ret, err := vmi.ApplyMessage(ctx, msgApply) if err != nil { return nil, xerrors.Errorf("apply message failed: %w", err) From a59ee872ffaf880bb3372c7f15fadb1aa98c842d Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 21 Jul 2020 16:11:01 +0800 Subject: [PATCH 17/25] only show updated env --- cli/auth.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/cli/auth.go b/cli/auth.go index 21bdb54b7..40947d797 100644 --- a/cli/auth.go +++ b/cli/auth.go @@ -2,8 +2,6 @@ package cli import ( "fmt" - "os" - "github.com/urfave/cli/v2" "golang.org/x/xerrors" @@ -126,14 +124,9 @@ var authApiInfoToken = &cli.Command{ return xerrors.Errorf("could not get API info: %w", err) } - envVar := envForRepo(t) - if _, ok := os.LookupEnv(envForRepo(t)); !ok { - envVar = envForRepoDeprecation(t) - } - // TODO: Log in audit log when it is implemented - fmt.Printf("%s=%s:%s\n", envVar, string(token), ainfo.Addr) + fmt.Printf("%s=%s:%s\n", envForRepo(t), string(token), ainfo.Addr) return nil }, } From 08006bce3dd52b9f5a65f038e3b08f18f0eba707 Mon Sep 17 00:00:00 2001 From: frrist Date: Tue, 21 Jul 2020 08:49:27 -0700 Subject: [PATCH 18/25] fix: use bigint for gas_used in message receipt - prevents overflows --- cmd/lotus-chainwatch/processor/messages.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/lotus-chainwatch/processor/messages.go b/cmd/lotus-chainwatch/processor/messages.go index 16d77546f..65ad153d8 100644 --- a/cmd/lotus-chainwatch/processor/messages.go +++ b/cmd/lotus-chainwatch/processor/messages.go @@ -74,7 +74,7 @@ create table if not exists receipts state text not null, idx int not null, exit int not null, - gas_used int not null, + gas_used bigint not null, return bytea, constraint receipts_pk primary key (msg, state) From 9154939d8fb4a74ceacffd341f47df95f2e53a75 Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Tue, 21 Jul 2020 18:47:38 +0200 Subject: [PATCH 19/25] expose ComputeStateHTMLTempl --- cli/state.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/state.go b/cli/state.go index 1f605f0bf..6af988531 100644 --- a/cli/state.go +++ b/cli/state.go @@ -874,7 +874,7 @@ var stateComputeStateCmd = &cli.Command{ return c.Code, nil } - return computeStateHTMLTempl(ts, stout, getCode) + return ComputeStateHTMLTempl(ts, stout, getCode) } fmt.Println("computed state cid: ", stout.Root) @@ -1081,7 +1081,7 @@ type compStateHTMLIn struct { Comp *api.ComputeStateOutput } -func computeStateHTMLTempl(ts *types.TipSet, o *api.ComputeStateOutput, getCode func(addr address.Address) (cid.Cid, error)) error { +func ComputeStateHTMLTempl(ts *types.TipSet, o *api.ComputeStateOutput, getCode func(addr address.Address) (cid.Cid, error)) error { t, err := template.New("compute_state").Funcs(map[string]interface{}{ "GetCode": getCode, "GetMethod": getMethod, From fcd6a18090921402203ed4e50942e48298dc5a53 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 21 Jul 2020 19:00:29 +0200 Subject: [PATCH 20/25] Add election count to influx Signed-off-by: Jakub Sztandera --- tools/stats/metrics.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/stats/metrics.go b/tools/stats/metrics.go index a6a3db3ad..52ef0c660 100644 --- a/tools/stats/metrics.go +++ b/tools/stats/metrics.go @@ -134,7 +134,7 @@ func RecordTipsetPoints(ctx context.Context, api api.FullNode, pl *PointList, ti if err != nil { return err } - p := NewPoint("chain.election", 1) + p := NewPoint("chain.election", blockheader.ElectionProof.WinCount) p.AddTag("miner", blockheader.Miner.String()) pl.AddPoint(p) From 54f1f6b8c9ef80862795d89b8f4443687b754e83 Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Tue, 21 Jul 2020 19:23:25 +0200 Subject: [PATCH 21/25] use io.Writer --- cli/state.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cli/state.go b/cli/state.go index 6af988531..8c5d712d0 100644 --- a/cli/state.go +++ b/cli/state.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "html/template" + "io" "os" "reflect" "sort" @@ -874,7 +875,7 @@ var stateComputeStateCmd = &cli.Command{ return c.Code, nil } - return ComputeStateHTMLTempl(ts, stout, getCode) + return ComputeStateHTMLTempl(os.Stdout, ts, stout, getCode) } fmt.Println("computed state cid: ", stout.Root) @@ -1081,7 +1082,7 @@ type compStateHTMLIn struct { Comp *api.ComputeStateOutput } -func ComputeStateHTMLTempl(ts *types.TipSet, o *api.ComputeStateOutput, getCode func(addr address.Address) (cid.Cid, error)) error { +func ComputeStateHTMLTempl(w io.Writer, ts *types.TipSet, o *api.ComputeStateOutput, getCode func(addr address.Address) (cid.Cid, error)) error { t, err := template.New("compute_state").Funcs(map[string]interface{}{ "GetCode": getCode, "GetMethod": getMethod, @@ -1114,7 +1115,7 @@ func ComputeStateHTMLTempl(ts *types.TipSet, o *api.ComputeStateOutput, getCode return err } - return t.ExecuteTemplate(os.Stdout, "compute_state", &compStateHTMLIn{ + return t.ExecuteTemplate(w, "compute_state", &compStateHTMLIn{ TipSet: ts, Comp: o, }) From cd00b0090be0b41dd8edd8b59993b7157d4e418e Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Tue, 21 Jul 2020 11:42:38 -0700 Subject: [PATCH 22/25] mitigate epoch boundary attacks by randomizing cutoff --- miner/miner.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/miner/miner.go b/miner/miner.go index d418c03f0..cc5c85b5a 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -3,6 +3,8 @@ package miner import ( "bytes" "context" + "crypto/rand" + "encoding/binary" "fmt" big2 "math/big" "sort" @@ -33,6 +35,14 @@ var log = logging.Logger("miner") // returns a callback reporting whether we mined a blocks in this round type waitFunc func(ctx context.Context, baseTime uint64) (func(bool, error), error) +func randTimeOffset(width time.Duration) time.Duration { + buf := make([]byte, 8) + rand.Reader.Read(buf) + val := time.Duration(binary.BigEndian.Uint64(buf) % uint64(width)) + + return val - (width / 2) +} + func NewMiner(api api.FullNode, epp gen.WinningPoStProver, addr address.Address) *Miner { arc, err := lru.NewARC(10000) if err != nil { @@ -46,7 +56,11 @@ func NewMiner(api api.FullNode, epp gen.WinningPoStProver, addr address.Address) waitFunc: func(ctx context.Context, baseTime uint64) (func(bool, error), error) { // Wait around for half the block time in case other parents come in deadline := baseTime + build.PropagationDelaySecs - build.Clock.Sleep(build.Clock.Until(time.Unix(int64(deadline), 0))) + baseT := time.Unix(int64(deadline), 0) + + baseT = baseT.Add(randTimeOffset(time.Second)) + + build.Clock.Sleep(build.Clock.Until(baseT)) return func(bool, error) {}, nil }, From fda0651bb56f3f0ed558ec3f029e3281fb1a715c Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Tue, 21 Jul 2020 16:43:57 -0700 Subject: [PATCH 23/25] a few improvements and fixes for the retrieval CLI --- api/api_full.go | 1 + cli/client.go | 61 +++++++++++++++++++++++++++++++++++++- node/impl/client/client.go | 1 + 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/api/api_full.go b/api/api_full.go index 4200755af..081fce0d3 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -421,6 +421,7 @@ type DealInfo struct { Message string // more information about deal state, particularly errors Provider address.Address + DataRef *storagemarket.DataRef PieceCID cid.Cid Size uint64 diff --git a/cli/client.go b/cli/client.go index 3a1518b4f..2125f524a 100644 --- a/cli/client.go +++ b/cli/client.go @@ -1,6 +1,7 @@ package cli import ( + "encoding/json" "fmt" "os" "path/filepath" @@ -65,6 +66,7 @@ var clientCmd = &cli.Command{ clientQueryAskCmd, clientListDeals, clientCarGenCmd, + clientGetDealCmd, }, } @@ -483,7 +485,7 @@ var clientFindCmd = &cli.Command{ fmt.Printf("ERR %s@%s: %s\n", offer.Miner, offer.MinerPeerID, offer.Err) continue } - fmt.Printf("RETRIEVAL %s@%s-%sfil-%s\n", offer.Miner, offer.MinerPeerID, types.FIL(offer.MinPrice), types.SizeStr(types.NewInt(offer.Size))) + fmt.Printf("RETRIEVAL %s@%s-%s-%s\n", offer.Miner, offer.MinerPeerID, types.FIL(offer.MinPrice), types.SizeStr(types.NewInt(offer.Size))) } return nil @@ -572,6 +574,16 @@ var clientRetrieveCmd = &cli.Command{ if minerStrAddr == "" { // Local discovery offers, err := fapi.ClientFindData(ctx, file, pieceCid) + var cleaned []api.QueryOffer + // filter out offers that errored + for _, o := range offers { + if o.Err != "" { + cleaned = append(cleaned, o) + } + } + + offers = cleaned + // sort by price low to high sort.Slice(offers, func(i, j int) bool { return offers[i].MinPrice.LessThan(offers[j].MinPrice) @@ -779,3 +791,50 @@ type deal struct { LocalDeal lapi.DealInfo OnChainDealState market.DealState } + +var clientGetDealCmd = &cli.Command{ + Name: "get-deal", + Usage: "Print detailed deal information", + Action: func(cctx *cli.Context) error { + if !cctx.Args().Present() { + return cli.ShowCommandHelp(cctx, cctx.Command.Name) + } + + api, closer, err := GetFullNodeAPI(cctx) + if err != nil { + return err + } + defer closer() + ctx := ReqContext(cctx) + + propcid, err := cid.Decode(cctx.Args().First()) + if err != nil { + return err + } + + di, err := api.ClientGetDealInfo(ctx, propcid) + if err != nil { + return err + } + + out := map[string]interface{}{ + "DealInfo: ": di, + } + + if di.DealID != 0 { + onChain, err := api.StateMarketStorageDeal(ctx, di.DealID, types.EmptyTSK) + if err != nil { + return err + } + + out["OnChain"] = onChain + } + + b, err := json.MarshalIndent(out, "", " ") + if err != nil { + return err + } + fmt.Println(b) + return nil + }, +} diff --git a/node/impl/client/client.go b/node/impl/client/client.go index 16024a0da..e3eefd3f9 100644 --- a/node/impl/client/client.go +++ b/node/impl/client/client.go @@ -162,6 +162,7 @@ func (a *API) ClientListDeals(ctx context.Context) ([]api.DealInfo, error) { for k, v := range deals { out[k] = api.DealInfo{ ProposalCid: v.ProposalCid, + DataRef: v.DataRef, State: v.State, Message: v.Message, Provider: v.Proposal.Provider, From a7bbf56cae6d7cae99b7c2b07a95925528e43529 Mon Sep 17 00:00:00 2001 From: Whyrusleeping Date: Tue, 21 Jul 2020 16:52:48 -0700 Subject: [PATCH 24/25] Update cli/client.go --- cli/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/client.go b/cli/client.go index 2125f524a..5cc16480c 100644 --- a/cli/client.go +++ b/cli/client.go @@ -577,7 +577,7 @@ var clientRetrieveCmd = &cli.Command{ var cleaned []api.QueryOffer // filter out offers that errored for _, o := range offers { - if o.Err != "" { + if o.Err == "" { cleaned = append(cleaned, o) } } From 6f04b1dbd8dc2c026505908e6e7bd63aafb713cd Mon Sep 17 00:00:00 2001 From: lanzafame Date: Wed, 22 Jul 2020 10:40:41 +1000 Subject: [PATCH 25/25] change debug to debugf --- lib/peermgr/peermgr.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/peermgr/peermgr.go b/lib/peermgr/peermgr.go index 8d6cf8cc3..80b05e8ce 100644 --- a/lib/peermgr/peermgr.go +++ b/lib/peermgr/peermgr.go @@ -132,7 +132,7 @@ func (pmgr *PeerMgr) Run(ctx context.Context) { if pcount < pmgr.minFilPeers { pmgr.expandPeers() } else if pcount > pmgr.maxFilPeers { - log.Debug("peer count about threshold: %d > %d", pcount, pmgr.maxFilPeers) + log.Debugf("peer count about threshold: %d > %d", pcount, pmgr.maxFilPeers) } stats.Record(ctx, metrics.PeerCount.M(int64(pmgr.getPeerCount()))) case <-pmgr.done: