From 9ffcee7a4c7d6a10200050b46bef2c710d77c180 Mon Sep 17 00:00:00 2001 From: Ian Suvak Date: Fri, 11 Aug 2023 15:04:49 -0400 Subject: [PATCH] review feedback --- agreement/sort.go | 2 +- crypto/stateproof/structs_test.go | 12 ++++++------ data/basics/sort.go | 4 ---- protocol/codec.go | 4 ++-- protocol/codec_tester.go | 2 +- 5 files changed, 10 insertions(+), 14 deletions(-) diff --git a/agreement/sort.go b/agreement/sort.go index debb0fcb18..051d10b870 100644 --- a/agreement/sort.go +++ b/agreement/sort.go @@ -101,7 +101,7 @@ func (a SortProposalValue) Less(i, j int) bool { func (a SortProposalValue) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -// ProposalLess is necessary for msgp:sort directive +// ProposalValueLess is necessary for msgp:sort directive // which used to generate UnmarshalValidateMsg generators func ProposalValueLess(a, b proposalValue) bool { if a.OriginalPeriod != b.OriginalPeriod { diff --git a/crypto/stateproof/structs_test.go b/crypto/stateproof/structs_test.go index 39915213ec..8611d5edb8 100644 --- a/crypto/stateproof/structs_test.go +++ b/crypto/stateproof/structs_test.go @@ -34,10 +34,10 @@ const ( wrongMapOrder ) -// TestDecodeValidate ensures that DecodeValidate detects non-canonical encodings +// TestDecodeCanonicalMsg ensures that DecodeValidate detects non-canonical encodings // this is tested here because StateProof contains an example of a map and is itself contained within // Transaction message which is a relevant message to check canonical encoding for. -func TestDecodeValidate(t *testing.T) { +func TestDecodeCanonicalMsg(t *testing.T) { partitiontest.PartitionTest(t) t.Parallel() @@ -51,25 +51,25 @@ func TestDecodeValidate(t *testing.T) { b := protocol.Encode(&z) var zDecode, zDecodeValidate StateProof require.NoError(t, protocol.Decode(b, &zDecode)) - require.NoError(t, protocol.DecodeValidate(b, &zDecodeValidate)) + require.NoError(t, protocol.DecodeCanonicalMsg(b, &zDecodeValidate)) zDecode = StateProof{} zDecodeValidate = StateProof{} bCorrect := z.marshalWrongOrder(nil, canonical) require.NoError(t, protocol.Decode(bCorrect, &zDecode)) - require.NoError(t, protocol.DecodeValidate(bCorrect, &zDecodeValidate)) + require.NoError(t, protocol.DecodeCanonicalMsg(bCorrect, &zDecodeValidate)) zDecode = StateProof{} zDecodeValidate = StateProof{} bWrongMapOrder := z.marshalWrongOrder(nil, wrongMapOrder) require.NoError(t, protocol.Decode(bWrongMapOrder, &zDecode)) - require.ErrorContains(t, protocol.DecodeValidate(bWrongMapOrder, &zDecodeValidate), "msgp: non-canonical encoding detected") + require.ErrorContains(t, protocol.DecodeCanonicalMsg(bWrongMapOrder, &zDecodeValidate), "msgp: non-canonical encoding detected") zDecode = StateProof{} zDecodeValidate = StateProof{} bWrongStructOrder := z.marshalWrongOrder(nil, wrongStructOrder) require.NoError(t, protocol.Decode(bWrongStructOrder, &zDecode)) - require.ErrorContains(t, protocol.DecodeValidate(bWrongStructOrder, &zDecodeValidate), "msgp: non-canonical encoding detected") + require.ErrorContains(t, protocol.DecodeCanonicalMsg(bWrongStructOrder, &zDecodeValidate), "msgp: non-canonical encoding detected") } diff --git a/data/basics/sort.go b/data/basics/sort.go index 7293c4d799..cea3656795 100644 --- a/data/basics/sort.go +++ b/data/basics/sort.go @@ -31,10 +31,6 @@ func (a SortUint64) Len() int { return len(a) } func (a SortUint64) Less(i, j int) bool { return a[i] < a[j] } func (a SortUint64) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -// Uint64Less is necessary for msgp:sort directive -// which used to generate UnmarshalValidateMsg generators -func Uint64Less(a, b uint64) bool { return a < b } - // SortAssetIndex implements sorting by AssetIndex keys for // canonical encoding of maps in msgpack format. // diff --git a/protocol/codec.go b/protocol/codec.go index 389f3779d6..d9f24b6223 100644 --- a/protocol/codec.go +++ b/protocol/codec.go @@ -186,12 +186,12 @@ func DecodeMsgp(b []byte, objptr msgp.Unmarshaler) (err error) { return nil } -// DecodeValidate attempts to decode a msgpack-encoded byte buffer into +// DecodeCanonicalMsg attempts to decode a msgpack-encoded byte buffer into // an object instance pointed to by objptr, requiring that we pre- // generated the code for doing so using msgp. It also validates that // the decoded object is canonically encoded. It will return an error // if struct fields or maps are out of canonical order -func DecodeValidate(b []byte, objptr msgp.UnmarshalerValidator) (err error) { +func DecodeCanonicalMsg(b []byte, objptr msgp.UnmarshalerValidator) (err error) { defer func() { if x := recover(); x != nil { err = fmt.Errorf("DecodeMsgp: %v", x) diff --git a/protocol/codec_tester.go b/protocol/codec_tester.go index 12e5efec04..ee8c667fac 100644 --- a/protocol/codec_tester.go +++ b/protocol/codec_tester.go @@ -466,7 +466,7 @@ func EncodingTest(template msgpMarshalUnmarshal) error { if _, ok := v1.(msgp.UnmarshalerValidator); ok { vValidate := reflect.New(reflect.TypeOf(template).Elem()).Interface().(msgp.UnmarshalerValidator) - err = (DecodeValidate(ee1, vValidate)) + err = (DecodeCanonicalMsg(ee1, vValidate)) if err != nil { return err }