Skip to content

Commit

Permalink
fix: boost allocate commands (#1957)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

---------

Co-authored-by: LexLuthr <[email protected]>
  • Loading branch information
strahe and LexLuthr authored Aug 27, 2024
1 parent 84f46db commit effb23d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
10 changes: 7 additions & 3 deletions cmd/boost/direct_deal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 5 additions & 1 deletion cmd/boost/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
})

Expand Down
4 changes: 2 additions & 2 deletions cmd/boostx/utils_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
9 changes: 6 additions & 3 deletions cmd/lib/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

0 comments on commit effb23d

Please sign in to comment.