From effb23d7930499b84c478718ed7ecb90eaee5aba Mon Sep 17 00:00:00 2001 From: Lee Date: Tue, 27 Aug 2024 18:51:22 +0800 Subject: [PATCH] fix: boost allocate commands (#1957) * fix: incorrect datacap calculation * debug: print nonce && msg cid * fix: Share datastore across all sign msg * fix lint * Update cmd/lib/common.go Co-authored-by: LexLuthr <88259624+LexLuthr@users.noreply.github.com> --------- Co-authored-by: LexLuthr <88259624+LexLuthr@users.noreply.github.com> --- cmd/boost/direct_deal.go | 10 +++++++--- cmd/boost/util/util.go | 6 +++++- cmd/boostx/utils_cmd.go | 4 ++-- cmd/lib/common.go | 9 ++++++--- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/cmd/boost/direct_deal.go b/cmd/boost/direct_deal.go index 61f0e161d..d5e8b84e6 100644 --- a/cmd/boost/direct_deal.go +++ b/cmd/boost/direct_deal.go @@ -7,6 +7,9 @@ import ( "strconv" "strings" + "github.com/ipfs/go-datastore" + ds_sync "github.com/ipfs/go-datastore/sync" + bcli "github.com/filecoin-project/boost/cli" clinode "github.com/filecoin-project/boost/cli/node" "github.com/filecoin-project/boost/cmd" @@ -266,8 +269,9 @@ var directDealAllocate = &cli.Command{ var mcids []cid.Cid + ds := ds_sync.MutexWrap(datastore.NewMapDatastore()) for _, msg := range msgs { - mcid, sent, err := lib.SignAndPushToMpool(cctx, ctx, gapi, n, msg) + mcid, sent, err := lib.SignAndPushToMpool(cctx, ctx, gapi, n, ds, msg) if err != nil { return err } @@ -639,9 +643,9 @@ If the client id different then claim can be extended up to maximum 5 years from } var mcids []cid.Cid - + ds := ds_sync.MutexWrap(datastore.NewMapDatastore()) for _, msg := range msgs { - mcid, sent, err := lib.SignAndPushToMpool(cctx, ctx, gapi, n, msg) + mcid, sent, err := lib.SignAndPushToMpool(cctx, ctx, gapi, n, ds, msg) if err != nil { return err } diff --git a/cmd/boost/util/util.go b/cmd/boost/util/util.go index 565c6fc5a..c3d494110 100644 --- a/cmd/boost/util/util.go +++ b/cmd/boost/util/util.go @@ -78,6 +78,10 @@ func CreateAllocationMsg(ctx context.Context, api api.Gateway, infos []PieceInfo arequest := &verifreg9.AllocationRequests{ Allocations: batch, } + bDataCap := big.NewInt(0) + for _, bd := range batch { + bDataCap.Add(big.NewInt(int64(bd.Size)).Int, bDataCap.Int) + } receiverParams, err := actors.SerializeParams(arequest) if err != nil { @@ -86,7 +90,7 @@ func CreateAllocationMsg(ctx context.Context, api api.Gateway, infos []PieceInfo transferParams, err := actors.SerializeParams(&datacap.TransferParams{ To: builtin.VerifiedRegistryActorAddr, - Amount: big.Mul(rDataCap, builtin.TokenPrecision), + Amount: big.Mul(bDataCap, builtin.TokenPrecision), OperatorData: receiverParams, }) diff --git a/cmd/boostx/utils_cmd.go b/cmd/boostx/utils_cmd.go index 54b9378c6..7060231f5 100644 --- a/cmd/boostx/utils_cmd.go +++ b/cmd/boostx/utils_cmd.go @@ -91,7 +91,7 @@ var marketAddCmd = &cli.Command{ Params: params, } - cid, sent, err := lib.SignAndPushToMpool(cctx, ctx, api, n, msg) + cid, sent, err := lib.SignAndPushToMpool(cctx, ctx, api, n, nil, msg) if err != nil { return err } @@ -166,7 +166,7 @@ var marketWithdrawCmd = &cli.Command{ Params: params, } - cid, sent, err := lib.SignAndPushToMpool(cctx, ctx, api, n, msg) + cid, sent, err := lib.SignAndPushToMpool(cctx, ctx, api, n, nil, msg) if err != nil { return err } diff --git a/cmd/lib/common.go b/cmd/lib/common.go index 6836fbb95..0ce027976 100644 --- a/cmd/lib/common.go +++ b/cmd/lib/common.go @@ -134,8 +134,10 @@ func getLegacyDealsFSM(ctx context.Context, ds *backupds.Datastore) (fsm.Group, return deals, err } -func SignAndPushToMpool(cctx *cli.Context, ctx context.Context, api api.Gateway, n *clinode.Node, msg *types.Message) (cid cid.Cid, sent bool, err error) { - ds := ds_sync.MutexWrap(datastore.NewMapDatastore()) +func SignAndPushToMpool(cctx *cli.Context, ctx context.Context, api api.Gateway, n *clinode.Node, ds *ds_sync.MutexDatastore, msg *types.Message) (cid cid.Cid, sent bool, err error) { + if ds == nil { + ds = ds_sync.MutexWrap(datastore.NewMapDatastore()) + } vmessagesigner := messagesigner.NewMessageSigner(n.Wallet, &modules.MpoolNonceAPI{ChainModule: api, StateModule: api}, ds) head, err := api.ChainHead(ctx) @@ -173,6 +175,7 @@ func SignAndPushToMpool(cctx *cli.Context, ctx context.Context, api api.Gateway, fmt.Println("gas limit: ", smsg.Message.GasLimit) fmt.Println("gas premium: ", types.FIL(smsg.Message.GasPremium)) fmt.Println("basefee: ", types.FIL(basefee)) + fmt.Println("nonce: ", smsg.Message.Nonce) fmt.Println() if !cctx.Bool("assume-yes") { validate := func(input string) error { @@ -215,7 +218,7 @@ func SignAndPushToMpool(cctx *cli.Context, ctx context.Context, api api.Gateway, err = fmt.Errorf("mpool push: failed to push message: %w", err) return } - + fmt.Println("sent message: ", cid) sent = true return }