Skip to content

Conversation

@DarkLord017
Copy link

Related Issues

Fixes #13246

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 Oct 18, 2025
@DarkLord017
Copy link
Author

@wjmelements is there any way to test this , like instead of running it e2e

cli/state.go Outdated
sort.Slice(sortedMsgs, func(i, j int) bool {
return sortedMsgs[i].Nonce < sortedMsgs[j].Nonce
})
for _, sm := range sortedMsgs {
Copy link
Member

Choose a reason for hiding this comment

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

You now have duplicate code here, you could be doing all of this once, probably appending to a slice defined before the loop (with a named struct type would be good), then doing a second loop to print what's been selected; or perhaps just making a printMsg function you can reuse that handles the "cids" thing and the JSONification. But I think that the loop is simple and cheap enough that you could just do it twice and reduce the duplication down to essentially nothing here

Copy link
Author

Choose a reason for hiding this comment

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

Now check @rvagg

@BigLep BigLep moved this from 📌 Triage to 🔎 Awaiting Review in FilOz Oct 21, 2025
@BigLep BigLep marked this pull request as ready for review October 21, 2025 05:00
@Copilot Copilot AI review requested due to automatic review settings October 21, 2025 05:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a new --order-by-nonce flag to the state list-msgs CLI command, enabling users to retrieve messages ordered sequentially by nonce when filtering by a 'from' address. This addresses issue #13246 by providing a way to view messages in the order they were intended to be executed.

Key changes:

  • Added --order-by-nonce boolean flag with appropriate usage documentation
  • Implemented message buffering and sorting logic that orders messages by nonce when the flag is enabled
  • The ordering only applies when a 'from' address filter is specified

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

cli/state.go Outdated
Comment on lines 928 to 930
sort.Slice(orderedMessages, func(i, j int) bool {
return orderedMessages[i].Nonce < orderedMessages[j].Nonce
})
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

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

The sorting logic is executed after every tipset iteration, leading to O(n log n) sorting operations per tipset. Consider moving the sort operation outside the main loop (after line 935) to sort all collected messages only once, improving performance when processing multiple tipsets.

Copilot uses AI. Check for mistakes.
cli/state.go Outdated
}
fmt.Println(string(b))

if cctx.Bool("order-by-nonce") && !froma.Empty() {
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

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

The condition cctx.Bool("order-by-nonce") && !froma.Empty() is evaluated for every message. Consider checking this once before the loop and storing the result in a boolean variable to avoid repeated context lookups.

Copilot uses AI. Check for mistakes.
cli/state.go Outdated
Comment on lines 927 to 935
if cctx.Bool("order-by-nonce") && !froma.Empty() {
sort.Slice(orderedMessages, func(i, j int) bool {
return orderedMessages[i].Nonce < orderedMessages[j].Nonce
})
for _, om := range orderedMessages {
fmt.Println(string(om.Msg))
}
orderedMessages = orderedMessages[:0]
}
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

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

Messages are sorted and printed after each tipset, which could result in interleaved output from different tipsets and doesn't provide true global ordering by nonce. If the intent is to order all messages across all tipsets, the sorting and printing should occur after the entire loop completes.

Copilot uses AI. Check for mistakes.
@DarkLord017 DarkLord017 requested a review from Copilot October 21, 2025 08:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +881 to +884
var orderedMessages []struct {
Nonce uint64
Msg []byte
}
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

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

[nitpick] The inline anonymous struct makes the code harder to maintain. Consider defining a named type like type OrderedMessage struct { Nonce uint64; Msg []byte } at the package level or before the command definition.

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

should i do this @rvagg @wjmelements

Co-authored-by: Copilot <[email protected]>
@DarkLord017 DarkLord017 requested a review from rvagg October 24, 2025 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🔎 Awaiting Review

Development

Successfully merging this pull request may close these issues.

list-messages order should be sequential

2 participants