Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion cli/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,10 @@
Name: "cids",
Usage: "print message CIDs instead of messages",
},
&cli.BoolFlag{
Name: "order-by-nonce",
Usage: "order messages by nonce (only applies when filtering by 'from' address)",
},
},
Action: func(cctx *cli.Context) error {
api, closer, err := GetFullNodeAPI(cctx)
Expand Down Expand Up @@ -872,6 +876,11 @@

windowSize := abi.ChainEpoch(100)

var orderedMessages []struct {
Nonce uint64
Msg []byte
}
Comment on lines +881 to +884
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


cur := ts
for cur.Height() > toh {
if ctx.Err() != nil {
Expand All @@ -898,11 +907,31 @@
if err != nil {
return err
}

b, err := json.MarshalIndent(m, "", " ")
if err != nil {
return err
}
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.
orderedMessages = append(orderedMessages, struct {
Nonce uint64
Msg []byte
}{Nonce: m.Nonce, Msg: b})
continue
} else {

Check failure on line 922 in cli/state.go

View workflow job for this annotation

GitHub Actions / Check (lint-all)

superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (revive)
fmt.Println(string(b))
}
}

if cctx.Bool("order-by-nonce") && !froma.Empty() {
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.
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.

if end <= 0 {
Expand Down
Loading