Skip to content

Commit

Permalink
add batching
Browse files Browse the repository at this point in the history
  • Loading branch information
LexLuthr committed Mar 21, 2024
1 parent 9325c1c commit 1bc9116
Showing 1 changed file with 45 additions and 32 deletions.
77 changes: 45 additions & 32 deletions cli/filplus.go
Original file line number Diff line number Diff line change
Expand Up @@ -1276,22 +1276,27 @@ func CreateExtendClaimMsg(ctx context.Context, api api.FullNode, pcm map[verifre

var msgs []*types.Message

if len(terms) > 0 {
const batchSize = 1000
for i := 0; i < len(terms); i += batchSize {
batchEnd := i + batchSize
if batchEnd > len(terms) {
batchEnd = len(terms)
}

batch := terms[i:batchEnd]

params, err := actors.SerializeParams(&verifregtypes13.ExtendClaimTermsParams{
Terms: terms,
Terms: batch,
})

if err != nil {
return nil, xerrors.Errorf("failed to searialise the parameters: %s", err)
}

oclaimMsg := &types.Message{
To: verifreg.Address,
From: wallet,
Method: verifreg.Methods.ExtendClaimTerms,
Params: params,
}

msgs = append(msgs, oclaimMsg)
}

Expand All @@ -1311,32 +1316,6 @@ func CreateExtendClaimMsg(ctx context.Context, api api.FullNode, pcm map[verifre
return nil, xerrors.Errorf("requested datacap %s is greater then the available datacap %s", rDataCap, aDataCap)
}

ncparams, err := actors.SerializeParams(&verifregtypes13.AllocationRequests{
Extensions: newClaims,
})

if err != nil {
return nil, xerrors.Errorf("failed to searialise the parameters: %s", err)
}

transferParams, err := actors.SerializeParams(&datacap2.TransferParams{
To: builtin.VerifiedRegistryActorAddr,
Amount: big.Mul(rDataCap, builtin.TokenPrecision),
OperatorData: ncparams,
})

if err != nil {
return nil, xerrors.Errorf("failed to serialize transfer parameters: %s", err)
}

nclaimMsg := &types.Message{
To: builtin.DatacapActorAddr,
From: wallet,
Method: datacap.Methods.TransferExported,
Params: transferParams,
Value: big.Zero(),
}

if !assumeYes {
out := fmt.Sprintf("Some of the specified allocation have a different client address and will require %d Datacap to extend. Proceed? Yes [Y/y] / No [N/n], Ctrl+C (^C) to exit", rDataCap.Int)
validate := func(input string) error {
Expand Down Expand Up @@ -1372,7 +1351,41 @@ func CreateExtendClaimMsg(ctx context.Context, api api.FullNode, pcm map[verifre
}
}

msgs = append(msgs, nclaimMsg)
// Batch in 1000 to avoid running out of gas
for i := 0; i < len(newClaims); i += batchSize {
batchEnd := i + batchSize
if batchEnd > len(newClaims) {
batchEnd = len(newClaims)
}

batch := newClaims[i:batchEnd]

ncparams, err := actors.SerializeParams(&verifregtypes13.AllocationRequests{
Extensions: batch,
})
if err != nil {
return nil, xerrors.Errorf("failed to searialise the parameters: %s", err)
}

transferParams, err := actors.SerializeParams(&datacap2.TransferParams{
To: builtin.VerifiedRegistryActorAddr,
Amount: big.Mul(rDataCap, builtin.TokenPrecision),
OperatorData: ncparams,
})

if err != nil {
return nil, xerrors.Errorf("failed to serialize transfer parameters: %s", err)
}

nclaimMsg := &types.Message{
To: builtin.DatacapActorAddr,
From: wallet,
Method: datacap.Methods.TransferExported,
Params: transferParams,
Value: big.Zero(),
}
msgs = append(msgs, nclaimMsg)
}
}

return msgs, nil
Expand Down

0 comments on commit 1bc9116

Please sign in to comment.