Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 0 additions & 4 deletions agreement/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@ package agreement

import (
"github.com/algorand/go-algorand/protocol"
"github.com/algorand/msgp/msgp"
)

// A message represents an internal message which is passed between components
// of the agreement service.
type message struct {
_struct struct{} `codec:","`

// this field is for backwards compatibility with crash state serialized using go-codec prior to explicit unexport.
// should be removed after the next consensus update.
MessageHandle msgp.Raw `codec:"MessageHandle,omitempty"`
// explicitly unexport this field since we can't define serializers for interface{} type
// the only implementation of this is gossip.messageMetadata which doesn't have exported fields to serialize.
messageHandle MessageHandle
Expand Down
52 changes: 0 additions & 52 deletions agreement/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@
package agreement

import (
"encoding/base64"
"testing"

"github.com/stretchr/testify/require"

"github.com/algorand/go-algorand/crypto"
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/data/committee"
"github.com/algorand/go-algorand/network"
"github.com/algorand/go-algorand/protocol"
"github.com/algorand/go-algorand/test/partitiontest"
)

var poolAddr = basics.Address{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
Expand Down Expand Up @@ -83,52 +80,3 @@ func BenchmarkVoteDecoding(b *testing.B) {
decodeVote(msgBytes)
}
}

// TestMessageBackwardCompatibility ensures MessageHandle field can be
// properly decoded from message.
// This test is only needed for agreement state serialization switch from reflection to msgp.
func TestMessageBackwardCompatibility(t *testing.T) {
partitiontest.PartitionTest(t)

type messageMetadata struct {
raw network.IncomingMessage
}

encoded, err := base64.StdEncoding.DecodeString("iaZCdW5kbGWAr0NvbXBvdW5kTWVzc2FnZYKoUHJvcG9zYWyApFZvdGWArU1lc3NhZ2VIYW5kbGWAqFByb3Bvc2FsgKNUYWeiUFC1VW5hdXRoZW50aWNhdGVkQnVuZGxlgLdVbmF1dGhlbnRpY2F0ZWRQcm9wb3NhbICzVW5hdXRoZW50aWNhdGVkVm90ZYCkVm90ZYA=")
require.NoError(t, err)

// run on master f57a276 to get the encoded data for above
// msg := message{
// MessageHandle: &messageMetadata{raw: network.IncomingMessage{Tag: protocol.Tag("mytag"), Data: []byte("some data")}},
// Tag: protocol.ProposalPayloadTag,
// }

// result := protocol.EncodeReflect(&msg)
// fmt.Println(base64.StdEncoding.EncodeToString(result))

// messages for all rounds after this change should not have MessageHandle set so clearing it out and re-encoding/decoding it should yield this
targetMessage := message{
Tag: protocol.ProposalPayloadTag,
}

require.Containsf(t, string(encoded), "MessageHandle", "encoded message does not contain MessageHandle field")
var m1, m2, m3, m4 message
// Both msgp and reflection should decode the message containing old MessageHandle successfully
err = protocol.Decode(encoded, &m1)
require.NoError(t, err)
err = protocol.DecodeReflect(encoded, &m2)
require.NoError(t, err)
// after setting MessageHandle to nil both should re-encode and decode to same values
m1.MessageHandle = nil
m2.MessageHandle = nil
e1 := protocol.Encode(&m1)
e2 := protocol.EncodeReflect(&m2)
require.Equal(t, e1, e2)
require.NotContainsf(t, string(e1), "MessageHandle", "encoded message still contains MessageHandle field")
err = protocol.DecodeReflect(e1, &m3)
require.NoError(t, err)
err = protocol.Decode(e2, &m4)
require.NoError(t, err)
require.Equal(t, m3, m4)
require.Equal(t, m3, targetMessage)
}
99 changes: 34 additions & 65 deletions agreement/msgp_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 0 additions & 69 deletions agreement/proposalTable_test.go

This file was deleted.

Loading