Skip to content

Conversation

beck-8
Copy link
Contributor

@beck-8 beck-8 commented Jun 30, 2025

Related Issues

https://filecoinproject.slack.com/archives/C03CKDLEWG1/p1751257247291959?thread_ts=1745286086.505189&cid=C03CKDLEWG1

Proposed Changes

Additional Info

Checklist

Before you mark the PR ready for review, please make sure that:

@github-project-automation github-project-automation bot moved this to 📌 Triage in FilOz Jun 30, 2025
@BigLep
Copy link
Member

BigLep commented Jul 1, 2025

@beck-8 : looks like there's a small lint error to fix.

@BigLep BigLep requested a review from rvagg July 1, 2025 06:19
@BigLep BigLep moved this from 📌 Triage to 🔎 Awaiting Review in FilOz Jul 1, 2025
rvagg
rvagg previously requested changes Jul 1, 2025
Copy link
Member

@rvagg rvagg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's too much duplicated code in here from cli/spcli/actor.go, we need to reduce the overlap because they're doing almost identical things so we can share the code even if we have it in two difference places.

I'm assuming that the intention here is that you'd like to have it available as a lotus-shed and not need to have the full lotus-miner setup available and you shouldn't be tied to a specific miner address? That's fine, but we need to dedupe.

@github-project-automation github-project-automation bot moved this from 🔎 Awaiting Review to ⌨️ In Progress in FilOz Jul 1, 2025
@beck-8
Copy link
Contributor Author

beck-8 commented Jul 1, 2025

I originally wanted to change it on the original foundation (lotus-miner). I don't think anyone will need to check the details of the message. Now everyone who uses this tool urgently wants to take out the locked amount.

However, considering that someone may really ask to check the payment, I changed the logic to lotus-shed. This is my idea. Do you have any suggestions?

@beck-8
Copy link
Contributor Author

beck-8 commented Jul 1, 2025

Or should I ask if we really need this part of logic? Or put this small part elsewhere in the future?

lotus/cli/spcli/actor.go

Lines 141 to 171 in cfb4c8e

// wait for it to get mined into a block
wait, err := api.StateWaitMsg(ctx, res, uint64(cctx.Int("confidence")), lapi.LookbackNoLimit, true)
if err != nil {
return xerrors.Errorf("Timeout waiting for deal settlement message %s", res)
}
if wait.Receipt.ExitCode.IsError() {
return xerrors.Errorf("Failed to execute withdrawal message %s: %w", wait.Message, wait.Receipt.ExitCode.Error())
}
var settlementReturn markettypes14.SettleDealPaymentsReturn
if err = settlementReturn.UnmarshalCBOR(bytes.NewReader(wait.Receipt.Return)); err != nil {
return err
}
fmt.Printf("Settled %d out of %d deals\n", settlementReturn.Results.SuccessCount, len(dealIDs))
var (
totalPayment = big.Zero()
totalCompletedDeals = 0
)
for _, s := range settlementReturn.Settlements {
totalPayment = big.Add(totalPayment, s.Payment)
if s.Completed {
totalCompletedDeals++
}
}
fmt.Printf("Total payment: %s\n", types.FIL(totalPayment))
fmt.Printf("Total number of deals finished their lifetime: %d\n", totalCompletedDeals)

@rvagg
Copy link
Member

rvagg commented Jul 2, 2025

Actually @beck-8, hold off from putting in all that work. I think maybe you should just explain, both briefly in the CHANGELOG and a little more verbose in the Description of the new command what it does and why it's useful instead of the lotus-miner variant. I think maybe you've got a very narrow use-case here.

The alternative is to just go ahead and adapt your use-case to the lotus-miner one, make one command but make it do what you want to do on top of its existing flexibility -- or make a judgement about whether its existing flexibility is even very useful. I see complaints about it, if you just want to fix it then we can get additional SP feedback before doing so but we shouldn't feel like these things are not open to changing.

@beck-8
Copy link
Contributor Author

beck-8 commented Jul 2, 2025

In fact, no matter which one, SP will still complain, because StateMarketDeals is as high as 29G, and the premise of executing settlement is to wait for a few minutes to pull this data.

@beck-8
Copy link
Contributor Author

beck-8 commented Jul 2, 2025

I will give more explanations later. I know that the use case is relatively narrow, but I have no other good way to help SP. Some experienced people will use lotus-miner sectors status to extract deal, but it only applies to certain environments of some people.

As we discussed at that time, I put forward my ideas and cases. But you don't have to merge this PR. You can close it and restructure it, but you should know my idea.

@beck-8 beck-8 marked this pull request as draft July 10, 2025 02:07
@beck-8
Copy link
Contributor Author

beck-8 commented Jul 10, 2025

  1. Quickly obtain the relationship between sectors and deals
  2. Reasonably handle batches and send messages.

I suggest exporting this method or transferring it to a reasonable place, and then GetMinerAllDeals -> GetMarketDealIDs
https://github.com/sumitvekariya/lotus/blob/7f2a7b7179dd75b5e379ac78e2af1f9caca04d58/cli/state.go#L1752

@BigLep
Copy link
Member

BigLep commented Jul 10, 2025

My 2025-07-10 understanding of where this PR is at:

  • Related conversation: https://filecoinproject.slack.com/archives/C03CKDLEWG1/p1745286086505189
  • @beck-8's core goal is to make this API faster. It's currently too slow because it has to load and transfer all the deals.
  • Maintainers want to avoid a duplicated lotus-shed settle-deal when there’s a lotus-miner settle-deal
  • @beck-8 and @tediou5 will work to land this so it has a faster API and that it's leveraged in lotus-miner settle-deal
  • For now while it's still being worked on, it's in draft.

@beck-8
Copy link
Contributor Author

beck-8 commented Jul 29, 2025

I know this may not meet some norms. I just want to express the effect I want.

I may merge the command into lotus-miner later (still some logic will be removed)

@beck-8 beck-8 force-pushed the op/settle-deal branch 3 times, most recently from 7aaa5b4 to 1880e60 Compare July 29, 2025 11:42
@beck-8 beck-8 changed the title feat: add settle-deal to lotus-shed feat(spcli): correctly handle the batch logic of lotus-miner actor settle-deal Jul 29, 2025
@beck-8 beck-8 marked this pull request as ready for review July 29, 2025 11:44
@beck-8
Copy link
Contributor Author

beck-8 commented Jul 29, 2025

Test completed, currently meets my expectations.

./lotus-miner --actor f01703655 actor settle-deal --really-do-it --max-deals 50 --from f3tdlvj4lzhdnes5qzg2w6cghsotka7kjeaiho3qpffctyqlncgls5oxlnclgk4mevivj3acvx46sumyg5ng5a
There are a total of 3335 deals, and about 66 messages will be sent out quickly.
Requested deal settlement in message: bafy2bzacea2j2oscgzjkcrc4pcyh4whja346tf2fkqmp7eqcajvpvegciauqg
Requested deal settlement in message: bafy2bzaceausxqeos6e5qglqqwdfn7yq3pu74opupun4muy6msovmjutdcyw2
Requested deal settlement in message: bafy2bzacecro7en6ij2zik6uvmih6kkukdfbi2p6rkz3stt3yok5xcmuhuyz4
Requested deal settlement in message: bafy2bzaceddzbutjwhg53n3ard7ktomuts4fwr5jevv5slhnasxnev3grikwy
Requested deal settlement in message: bafy2bzaced7by4ol2lnwqs3aabgkcuitad22xpxd46xttxn6dyqnjrdjly4ck
Requested deal settlement in message: bafy2bzaceb7p4gug4vcw23g4i7iogykr3qe4biibjfu37zur7in25teiymppa
Requested deal settlement in message: bafy2bzacebpec5kfuk2ofnq66qlbl4jd6pmtbfip4xuzk5g64ekxg3ivkcjgk
Requested deal settlement in message: bafy2bzacede35a4owjk7eark63vvucibklz2yfurs6p4aeclkqquujfl4cy3a
Requested deal settlement in message: bafy2bzacebafpufpphriwrh7zrxzqcliwcsefbdw5bfzbhhfivvw5kubafnfo
Requested deal settlement in message: bafy2bzaced7ttpkttehptrylyrwgemj7qeuam2iucfs5l2tldgzkordzu7tye
Requested deal settlement in message: bafy2bzacea5puvzm6ncj6gvzq4nblpsgtbbp2nwdbm5ug66j4sxjxktbqhlq4
Requested deal settlement in message: bafy2bzacedxpsykecnfhibggweaa5tphb2pn7oxcv3dg63jzbipvk42bmw5x6
Requested deal settlement in message: bafy2bzaceat3z7hrkocyverij2sre2trp3l7ti7cueaps4mnr5py5hmu666yg
ERROR: mpool push: failed to push message: failed to check balance: not enough funds including pending messages (required: 0.422663959546500762 FIL, balance: 0.3917174615362471 FIL): validation failure

			&cli.IntFlag{
				Name:  "max-deals",
				Usage: "the maximum number of deals contained in each message",
				Value: 50,
			},

--max-deals 500 --max-deals 100 out of gas, so set 50

@rjan90 rjan90 requested a review from tediou5 July 29, 2025 11:46
@beck-8
Copy link
Contributor Author

beck-8 commented Jul 29, 2025

I don't know how to deal with the conflict in UNRELEASED.md. If I'm wrong, please help me correct it directly.

@rjan90
Copy link
Contributor

rjan90 commented Jul 29, 2025

@beck-8 I resolved the conflict in the CHANGELOG.md for you

Copy link
Contributor

@tediou5 tediou5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your pr.

From my perspective, this PR contains two parts:

  1. An optimization for the GetDeals method.
  2. Batch submission for settle-deal.

Regarding the first part, I'm in full agreement. This will greatly improve the quality of life for SPs.

However, for the second part, I have some concerns:

  1. I might be lacking some background knowledge on this, but is it necessary to batch settle-deal transactions? This shouldn't be a particularly heavy transaction.
  2. The logic after the transaction is modified here to exit immediately without waiting. While I can understand this behavior, it's a breaking change.

I think, would it be better to preserve the original behavior of waiting for the packaging to complete, but provide a flag to skip it directly?

Additionally, I suggest splitting this PR into two parts. This PR should only contain the GetDeals optimization, which we can merge directly. For the batching part, please submit it as a new, separate PR where we can have a more detailed discussion and work on the implementation.

Copy link
Contributor

@tediou5 tediou5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, this is very close to completion. The rest of it looks good to me. I think we can get this merged once the batch push message is optimized.

@tediou5
Copy link
Contributor

tediou5 commented Jul 30, 2025

I've submitted the change to switch to using MpoolBatchPushMessage, also combine logs to prevent interleaving caused by concurrency.

@beck-8
Copy link
Contributor Author

beck-8 commented Jul 30, 2025

It looks fine, very good, take off 🛫

@rjan90 rjan90 dismissed rvagg’s stale review July 30, 2025 13:42

Dismissing the request for change, since that request was for the lotus-shed cmd variant, but this has now changed fix/correctly handle the batch logic of lotus-miner actor settle-deal

Copy link
Contributor

@tediou5 tediou5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks!

@github-project-automation github-project-automation bot moved this from ⌨️ In Progress to ✔️ Approved by reviewer in FilOz Jul 31, 2025
@tediou5
Copy link
Contributor

tediou5 commented Jul 31, 2025

lets go 🛫!

@tediou5 tediou5 merged commit 0edb14c into filecoin-project:master Jul 31, 2025
95 checks passed
@github-project-automation github-project-automation bot moved this from ✔️ Approved by reviewer to 🎉 Done in FilOz Jul 31, 2025
rjan90 added a commit that referenced this pull request Jul 31, 2025
…ettle-deal` (#13189)

* feat(spcli): correctly handle the batch logic of `lotus-miner actor settle-deal`

* retain StateWaitMsg logic

* use v0api.WrapperV1Full

* opt(spcli): push settle-deals Chucks with MpoolBatchPushMessage

* chore(spcli): combine logs to prevent interleaving caused by concurrency

* fix typo

* chore: remove unnecessary var

---------

Co-authored-by: Phi-rjan <orjan.roren@gmail.com>
Co-authored-by: qians <qiangezaici@outlook.com>
rjan90 added a commit that referenced this pull request Jul 31, 2025
* feat(spcli): correctly handle the batch logic of `lotus-miner actor settle-deal` (#13189)

* feat(spcli): correctly handle the batch logic of `lotus-miner actor settle-deal`

* retain StateWaitMsg logic

* use v0api.WrapperV1Full

* opt(spcli): push settle-deals Chucks with MpoolBatchPushMessage

* chore(spcli): combine logs to prevent interleaving caused by concurrency

* fix typo

* chore: remove unnecessary var

---------

Co-authored-by: Phi-rjan <orjan.roren@gmail.com>
Co-authored-by: qians <qiangezaici@outlook.com>

* Empty commit to trigger CI

---------

Co-authored-by: beck <34204218+beck-8@users.noreply.github.com>
Co-authored-by: qians <qiangezaici@outlook.com>
@rjan90 rjan90 mentioned this pull request Jul 31, 2025
43 tasks
@beck-8
Copy link
Contributor Author

beck-8 commented Aug 1, 2025

I want to add a flag to indicate whether the deal is expired. By default, only expired deals will be processed.

@tediou5
Copy link
Contributor

tediou5 commented Aug 4, 2025

I want to add a flag to indicate whether the deal is expired. By default, only expired deals will be processed.

Makes sense to me, let's open a new PR to add this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🎉 Done
Development

Successfully merging this pull request may close these issues.

5 participants