-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: add ordering by nonce flag to get sequential messages #13394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
|
@@ -872,6 +876,11 @@ | |
|
|
||
| windowSize := abi.ChainEpoch(100) | ||
|
|
||
| var orderedMessages []struct { | ||
| Nonce uint64 | ||
| Msg []byte | ||
| } | ||
|
|
||
| cur := ts | ||
| for cur.Height() > toh { | ||
| if ctx.Err() != nil { | ||
|
|
@@ -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() { | ||
|
||
| orderedMessages = append(orderedMessages, struct { | ||
| Nonce uint64 | ||
| Msg []byte | ||
| }{Nonce: m.Nonce, Msg: b}) | ||
| continue | ||
| } else { | ||
| fmt.Println(string(b)) | ||
| } | ||
DarkLord017 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| 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] | ||
| } | ||
|
||
|
|
||
| if end <= 0 { | ||
|
|
||
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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