From bc7e458f6d69e71398713baed7952cf6a38c9b23 Mon Sep 17 00:00:00 2001
From: Benjamin Wenger <ben@elixxir.ioo>
Date: Thu, 14 Oct 2021 13:23:57 -0700
Subject: [PATCH] fixed some message pick up edge cases and a buffer bug

---
 network/rounds/retrieve.go        | 6 ++++--
 storage/rounds/uncheckedRounds.go | 4 ++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/network/rounds/retrieve.go b/network/rounds/retrieve.go
index 23249c505..646b9be11 100644
--- a/network/rounds/retrieve.go
+++ b/network/rounds/retrieve.go
@@ -156,8 +156,10 @@ func (m *Manager) getMessagesFromGateway(roundID id.Round,
 
 		// If the gateway doesnt have the round, return an error
 		msgResp, err := comms.RequestMessages(host, msgReq)
+
 		if err!=nil{
-			return nil, err
+			//you need to default to a retryable errors because otherwise we cannot enumerate all errors
+			return nil,  errors.WithMessage(err, gateway.RetryableError)
 		}
 
 		if !msgResp.GetHasRound() {
@@ -165,7 +167,7 @@ func (m *Manager) getMessagesFromGateway(roundID id.Round,
 			return message.Bundle{}, errors.WithMessage(errRtn, gateway.RetryableError)
 		}
 
-		return msgResp, err
+		return msgResp, nil
 	}, stop)
 	jww.INFO.Printf("Received message for round %d, processing...", roundID)
 	// Fail the round if an error occurs so it can be tried again later
diff --git a/storage/rounds/uncheckedRounds.go b/storage/rounds/uncheckedRounds.go
index d8082628e..aa5e57497 100644
--- a/storage/rounds/uncheckedRounds.go
+++ b/storage/rounds/uncheckedRounds.go
@@ -326,7 +326,7 @@ func (s *UncheckedRoundStore) marshal() ([]byte, error) {
 
 	// Write number of rounds the buffer
 	b := make([]byte, 8)
-	binary.PutVarint(b, int64(len(s.list)))
+	binary.BigEndian.PutUint32(b, uint32(len(s.list)))
 	buf.Write(b)
 
 	for rid, rnd := range s.list {
@@ -348,7 +348,7 @@ func (s *UncheckedRoundStore) unmarshal(data []byte) error {
 	buff := bytes.NewBuffer(data)
 
 	// Get number of rounds in list
-	length, _ := binary.Varint(buff.Next(8))
+	length := binary.BigEndian.Uint32(buff.Next(8))
 
 	for i := 0; i < int(length); i++ {
 		rnd := UncheckedRound{}
-- 
GitLab