Skip to content

Commit

Permalink
Fix bug with wrong serializer.SeriLengthPrefixType
Browse files Browse the repository at this point in the history
  • Loading branch information
jonastheis committed Nov 6, 2023
1 parent 9cfc673 commit 82f433e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions pkg/network/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ func (p *Peer) SetConnStatus(cs ConnectionStatus) {
func (p *Peer) Bytes() ([]byte, error) {
byteBuffer := stream.NewByteBuffer()

if err := stream.WriteObjectWithSize(byteBuffer, p.ID, serializer.UInt16ByteSize, func(id peer.ID) ([]byte, error) {
if err := stream.WriteObjectWithSize(byteBuffer, p.ID, serializer.SeriLengthPrefixTypeAsUint16, func(id peer.ID) ([]byte, error) {
return []byte(id), nil
}); err != nil {
return nil, ierrors.Wrap(err, "failed to write peer ID")
}

if err := stream.WriteCollection(byteBuffer, serializer.OneByte, func() (elementsCount int, err error) {
if err := stream.WriteCollection(byteBuffer, serializer.SeriLengthPrefixTypeAsByte, func() (elementsCount int, err error) {
for _, addr := range p.PeerAddresses {
if err = stream.WriteObjectWithSize(byteBuffer, addr, serializer.UInt16ByteSize, func(m multiaddr.Multiaddr) ([]byte, error) {
if err = stream.WriteObjectWithSize(byteBuffer, addr, serializer.SeriLengthPrefixTypeAsUint16, func(m multiaddr.Multiaddr) ([]byte, error) {
return m.Bytes(), nil
}); err != nil {
return 0, ierrors.Wrap(err, "failed to write peer address")
Expand Down Expand Up @@ -120,7 +120,7 @@ func peerFromBytes(bytes []byte) (*Peer, error) {
var err error
byteReader := stream.NewByteReader(bytes)

if p.ID, err = stream.ReadObjectWithSize(byteReader, serializer.UInt16ByteSize, func(bytes []byte) (peer.ID, int, error) {
if p.ID, err = stream.ReadObjectWithSize(byteReader, serializer.SeriLengthPrefixTypeAsUint16, func(bytes []byte) (peer.ID, int, error) {
id, err := peer.IDFromBytes(bytes)
if err != nil {
return "", 0, ierrors.Wrap(err, "failed to parse peerID")
Expand All @@ -133,8 +133,8 @@ func peerFromBytes(bytes []byte) (*Peer, error) {

p.SetConnStatus(ConnStatusDisconnected)

if err = stream.ReadCollection(byteReader, serializer.OneByte, func(i int) error {
addr, err := stream.ReadObjectWithSize(byteReader, serializer.UInt16ByteSize, func(bytes []byte) (multiaddr.Multiaddr, int, error) {
if err = stream.ReadCollection(byteReader, serializer.SeriLengthPrefixTypeAsByte, func(i int) error {
addr, err := stream.ReadObjectWithSize(byteReader, serializer.SeriLengthPrefixTypeAsUint16, func(bytes []byte) (multiaddr.Multiaddr, int, error) {
m, err := multiaddr.NewMultiaddrBytes(bytes)
if err != nil {
return nil, 0, ierrors.Wrap(err, "failed to parse peer address")
Expand Down
4 changes: 2 additions & 2 deletions pkg/network/protocols/core/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ func (p *Protocol) SendSlotCommitment(cm *model.Commitment, to ...peer.ID) {
func (p *Protocol) SendAttestations(cm *model.Commitment, attestations []*iotago.Attestation, merkleProof *merklehasher.Proof[iotago.Identifier], to ...peer.ID) {
byteBuffer := stream.NewByteBuffer()

if err := stream.WriteCollection(byteBuffer, serializer.UInt32ByteSize, func() (elementsCount int, err error) {
if err := stream.WriteCollection(byteBuffer, serializer.SeriLengthPrefixTypeAsUint32, func() (elementsCount int, err error) {
for _, att := range attestations {
if err = stream.WriteObjectWithSize(byteBuffer, att, serializer.UInt16ByteSize, (*iotago.Attestation).Bytes); err != nil {
if err = stream.WriteObjectWithSize(byteBuffer, att, serializer.SeriLengthPrefixTypeAsUint16, (*iotago.Attestation).Bytes); err != nil {
return 0, ierrors.Wrapf(err, "failed to write attestation %v", att)
}
}
Expand Down
2 changes: 1 addition & 1 deletion tools/docker-network/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ docker run --rm \
-e GOCACHE="/go-cache" \
-e GOMODCACHE="/go-mod-cache" \
-w "/workspace/tools/genesis-snapshot" \
golang:1.21 go run -tags=rocksdb . --config docker --seed 7R1itJx5hVuo9w9hjg5cwKFmek4HMSoBDgJZN8hKGxih
golang:1.21-bookworm go run -tags=rocksdb . --config docker --seed 7R1itJx5hVuo9w9hjg5cwKFmek4HMSoBDgJZN8hKGxih

# Move and set permissions for the .snapshot file
mv -f ../genesis-snapshot/*.snapshot .
Expand Down

0 comments on commit 82f433e

Please sign in to comment.