Open
Description
Checklist
- This is not a security-related bug/issue. If it is, please follow please follow the security policy.
- I have searched on the issue tracker and the lotus forum, and there is no existing related issue or discussion.
- I am running the
Latest release
, the most recent RC(release canadiate) for the upcoming release or the dev branch(master), or have an issue updating to any of these. - I did not make any code changes to lotus.
Lotus component
- lotus daemon - chain sync
- lotus fvm/fevm - Lotus FVM and FEVM interactions
- lotus miner/worker - sealing
- lotus miner - proving(WindowPoSt/WinningPoSt)
- lotus JSON-RPC API
- lotus message management (mpool)
- Other
Lotus Version
$ ./lotus --version
lotus version 1.25.2+calibnet+git.f51f83bfe
Repro Steps
N/A
Describe the Bug
Background
In Go
, []
slices have three states, which are serialized differently:
- Uninitialized (never assigned), serialized as
null
- Initialized, but empty, serialized as
[]
- Initialized, but non-empty, serialized as
[<item>]
var unrelated bool = true
var s []int
if unrelated {
s = []int{}
}
ser, _ := json.Marshal(s)
fmt.Printf("%s\n", ser) // `null` or `[]`
Motivation
Specification of JSON types in the Common Node API FIP
The current draft of the spec represents slices as null | []
.
However, the fact that unrelated
in the example above affects serialization output causes:
- Issues for nodes like
forest
that want to reproduce Lotus' RPC output.- To exactly match lotus, we'd need to track initialization stack and program logic that Lotus does, which is basically non-deterministic from the outside.
- Issues for clients when switching nodes.
Fix
Lotus should always serialize slices as JSON Arrays, and the Common Node API should specify serialization as such.
AIUI this is a longstanding quirk of go that has existing solutions:
- https://freshman.tech/snippets/go/nil-vs-empty-slices/
- proposal: encoding/json:
nilasempty
to encode nil-slices as[]
golang/go#37711 (comment) - proposal: encoding/json:
nilasempty
to encode nil-slices as[]
golang/go#37711 (comment) - https://github.com/pkierski/niltoempty
Logging Information
N/A