Repository navigation
fix(server): carry referrer pull responses as protojson bytes - #2463
muscariello merged 3 commits into
Conversation
Signed-off-by: jay23606 <[email protected]>
muscariello
left a comment
There was a problem hiding this comment.
Thanks. The fix is correct and minimal, and the regression test fails on base with the error from #2461. I also ran a referrer through the whole path (serve, msgpack, referrerFromResponse) with nested, unicode and large-number data. It comes back proto.Equal to the original, with identical canonical Marshal() bytes. Two small things:
- The test doesn't cover the decode side (inline). It passes for any bytes in
Data, so it would not notice a brokenreferrerFromResponse. server/go.mod:github.com/ugorji/go/codecis// indirect, but the test now imports it directly.go mod tidyinserver/moves it to the direct block. Please run it so the next person doesn't get the churn.
Optional: one line in the description on old and new peers. A new server talking to a v1.8.0 client gives a nil referrer, which verifyReferrer rejects. A v1.8.0 server talking to a new client fails in protojson.Unmarshal on empty Data. Both fail the way they do today, so nothing regresses.
The two-node test #2461 suggests isn't here. I'm fine with that as a follow-up, since the codec round trip is what regressed.
|
|
||
| var got PullReferrerResponse | ||
| require.NoError(t, codec.NewDecoder(&wire, h).Decode(&got)) | ||
| require.Equal(t, out, got) |
There was a problem hiding this comment.
This only shows the Data bytes survive msgpack, so it passes for any bytes. Decode with referrerFromResponse(&got) and compare with proto.Equal against the original referrer. I ran that and it passes, so it costs one extra line and covers the client side too.
There was a problem hiding this comment.
The test now decodes the received response with referrerFromResponse and checks it with proto.Equal against the served referrer, so the client-side decode is covered as well as the msgpack round trip.
muscariello
left a comment
There was a problem hiding this comment.
The same change as the inline comment on line 63, written as three suggestions to apply together. server/go.mod isn't in the diff, so it can't be suggested: go mod tidy in server/ does it.
| "github.com/agntcy/dir/server/types" | ||
| "github.com/stretchr/testify/require" | ||
| "github.com/ugorji/go/codec" | ||
| "google.golang.org/protobuf/types/known/structpb" |
There was a problem hiding this comment.
Import proto for the comparison in the last suggestion. The three suggestions go together.
| "google.golang.org/protobuf/types/known/structpb" | |
| "google.golang.org/protobuf/proto" | |
| "google.golang.org/protobuf/types/known/structpb" |
| api := &RPCAPI{service: &Service{ | ||
| store: &peerStore{present: true}, | ||
| refStore: referrerStore{referrer: &corev1.RecordReferrer{ | ||
| Type: corev1.SignatureReferrerType, | ||
| ReferrerRef: &corev1.ReferrerRef{Cid: referrerCID}, | ||
| Data: data, | ||
| }}, | ||
| gate: peerGate{servable: true}, | ||
| }} |
There was a problem hiding this comment.
Keep the served referrer in want, so the decoded one can be compared with it.
| api := &RPCAPI{service: &Service{ | |
| store: &peerStore{present: true}, | |
| refStore: referrerStore{referrer: &corev1.RecordReferrer{ | |
| Type: corev1.SignatureReferrerType, | |
| ReferrerRef: &corev1.ReferrerRef{Cid: referrerCID}, | |
| Data: data, | |
| }}, | |
| gate: peerGate{servable: true}, | |
| }} | |
| want := &corev1.RecordReferrer{ | |
| Type: corev1.SignatureReferrerType, | |
| ReferrerRef: &corev1.ReferrerRef{Cid: referrerCID}, | |
| Data: data, | |
| } | |
| api := &RPCAPI{service: &Service{ | |
| store: &peerStore{present: true}, | |
| refStore: referrerStore{referrer: want}, | |
| gate: peerGate{servable: true}, | |
| }} |
There was a problem hiding this comment.
The served referrer is now held in a want variable that is passed to the referrer store, so the decoded result can be compared against it.
|
|
||
| var got PullReferrerResponse | ||
| require.NoError(t, codec.NewDecoder(&wire, h).Decode(&got)) | ||
| require.Equal(t, out, got) |
There was a problem hiding this comment.
Decode what the receiving node would get and compare it with what the serving node held. With the three suggestions applied, gofmt and go vet are clean and the test passes.
| require.Equal(t, out, got) | |
| require.Equal(t, out, got) | |
| // The receiving node decodes what the serving node held. | |
| referrer, err := referrerFromResponse(&got) | |
| require.NoError(t, err) | |
| require.True(t, proto.Equal(want, referrer)) |
There was a problem hiding this comment.
After the msgpack round trip the test now decodes the response through referrerFromResponse and asserts proto.Equal with the served referrer.
Signed-off-by: jay23606 <[email protected]>
|
Thanks, the test changes look good. One thing is still open from my first review: Minor: the description says the test fails on base with Otherwise this looks good to me. |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Bug
Autosync pulls a record from a trusted peer and then pulls its referrers (signatures, public keys, scan reports). Every referrer pull failed to decode on the receiving node.
PullReferrerResponsecarried a*corev1.RecordReferrer, whoseDatais astructpb.Struct. The msgpack codec used by go-libp2p-gorpc cannot decode thestructpb.Valueoneof, so the response was rejected whatever the referrer contained. The record was ingested unsigned and the failure was only logged at Warn.Change
PullReferrerResponsenow carries the referrer as protojson bytes, the same wayPullResponsecarries the record. The serving side marshals withprotojson.Marshal, and the client decodes withprotojson.Unmarshal.structpbno longer crosses the msgpack wire.Testing
go test -C server ./routing/rpc/ -run TestPullReferrer_ResponseSurvivesMsgpack -count=1 -vpasses on the fix. On the base commit it fails withmsgpack decode error ... structpb.isValue_Kind.go test -C server ./routing/... -count=1:server/routing/rpcandserver/routing/autosyncpass.server/routingfails inTestPublishList_ValidMultiSkillQueryon Windows, where temp-directory cleanup cannot remove a Badger vlog file still in use. That test does not touch the referrer path.Regression test: fails on base twice (/msgpack decode error.*structpb.isValue_Kind/), passes on fix twice (
go test -C server ./routing/rpc/ -run TestPullReferrer_ResponseSurvivesMsgpack -count=1 -v)Fixes #2461