Skip to content

Commit effb23d

Browse files
straheLexLuthr
andauthored
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 <[email protected]> --------- Co-authored-by: LexLuthr <[email protected]>
1 parent 84f46db commit effb23d

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

cmd/boost/direct_deal.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import (
77
"strconv"
88
"strings"
99

10+
"github.com/ipfs/go-datastore"
11+
ds_sync "github.com/ipfs/go-datastore/sync"
12+
1013
bcli "github.com/filecoin-project/boost/cli"
1114
clinode "github.com/filecoin-project/boost/cli/node"
1215
"github.com/filecoin-project/boost/cmd"
@@ -266,8 +269,9 @@ var directDealAllocate = &cli.Command{
266269

267270
var mcids []cid.Cid
268271

272+
ds := ds_sync.MutexWrap(datastore.NewMapDatastore())
269273
for _, msg := range msgs {
270-
mcid, sent, err := lib.SignAndPushToMpool(cctx, ctx, gapi, n, msg)
274+
mcid, sent, err := lib.SignAndPushToMpool(cctx, ctx, gapi, n, ds, msg)
271275
if err != nil {
272276
return err
273277
}
@@ -639,9 +643,9 @@ If the client id different then claim can be extended up to maximum 5 years from
639643
}
640644

641645
var mcids []cid.Cid
642-
646+
ds := ds_sync.MutexWrap(datastore.NewMapDatastore())
643647
for _, msg := range msgs {
644-
mcid, sent, err := lib.SignAndPushToMpool(cctx, ctx, gapi, n, msg)
648+
mcid, sent, err := lib.SignAndPushToMpool(cctx, ctx, gapi, n, ds, msg)
645649
if err != nil {
646650
return err
647651
}

cmd/boost/util/util.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ func CreateAllocationMsg(ctx context.Context, api api.Gateway, infos []PieceInfo
7878
arequest := &verifreg9.AllocationRequests{
7979
Allocations: batch,
8080
}
81+
bDataCap := big.NewInt(0)
82+
for _, bd := range batch {
83+
bDataCap.Add(big.NewInt(int64(bd.Size)).Int, bDataCap.Int)
84+
}
8185

8286
receiverParams, err := actors.SerializeParams(arequest)
8387
if err != nil {
@@ -86,7 +90,7 @@ func CreateAllocationMsg(ctx context.Context, api api.Gateway, infos []PieceInfo
8690

8791
transferParams, err := actors.SerializeParams(&datacap.TransferParams{
8892
To: builtin.VerifiedRegistryActorAddr,
89-
Amount: big.Mul(rDataCap, builtin.TokenPrecision),
93+
Amount: big.Mul(bDataCap, builtin.TokenPrecision),
9094
OperatorData: receiverParams,
9195
})
9296

cmd/boostx/utils_cmd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ var marketAddCmd = &cli.Command{
9191
Params: params,
9292
}
9393

94-
cid, sent, err := lib.SignAndPushToMpool(cctx, ctx, api, n, msg)
94+
cid, sent, err := lib.SignAndPushToMpool(cctx, ctx, api, n, nil, msg)
9595
if err != nil {
9696
return err
9797
}
@@ -166,7 +166,7 @@ var marketWithdrawCmd = &cli.Command{
166166
Params: params,
167167
}
168168

169-
cid, sent, err := lib.SignAndPushToMpool(cctx, ctx, api, n, msg)
169+
cid, sent, err := lib.SignAndPushToMpool(cctx, ctx, api, n, nil, msg)
170170
if err != nil {
171171
return err
172172
}

cmd/lib/common.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,10 @@ func getLegacyDealsFSM(ctx context.Context, ds *backupds.Datastore) (fsm.Group,
134134
return deals, err
135135
}
136136

137-
func SignAndPushToMpool(cctx *cli.Context, ctx context.Context, api api.Gateway, n *clinode.Node, msg *types.Message) (cid cid.Cid, sent bool, err error) {
138-
ds := ds_sync.MutexWrap(datastore.NewMapDatastore())
137+
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) {
138+
if ds == nil {
139+
ds = ds_sync.MutexWrap(datastore.NewMapDatastore())
140+
}
139141
vmessagesigner := messagesigner.NewMessageSigner(n.Wallet, &modules.MpoolNonceAPI{ChainModule: api, StateModule: api}, ds)
140142

141143
head, err := api.ChainHead(ctx)
@@ -173,6 +175,7 @@ func SignAndPushToMpool(cctx *cli.Context, ctx context.Context, api api.Gateway,
173175
fmt.Println("gas limit: ", smsg.Message.GasLimit)
174176
fmt.Println("gas premium: ", types.FIL(smsg.Message.GasPremium))
175177
fmt.Println("basefee: ", types.FIL(basefee))
178+
fmt.Println("nonce: ", smsg.Message.Nonce)
176179
fmt.Println()
177180
if !cctx.Bool("assume-yes") {
178181
validate := func(input string) error {
@@ -215,7 +218,7 @@ func SignAndPushToMpool(cctx *cli.Context, ctx context.Context, api api.Gateway,
215218
err = fmt.Errorf("mpool push: failed to push message: %w", err)
216219
return
217220
}
218-
221+
fmt.Println("sent message: ", cid)
219222
sent = true
220223
return
221224
}

0 commit comments

Comments
 (0)