Skip to content

Commit

Permalink
Merge pull request #667 from ava-labs/empty-app-response-handling
Browse files Browse the repository at this point in the history
Empty app response handling
  • Loading branch information
iansuvak authored Feb 7, 2025
2 parents f136e3b + df1e07b commit 616890e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
6 changes: 5 additions & 1 deletion signature-aggregator/aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ func (s *SignatureAggregator) isValidSignatureResponse(
return blsSignatureBuf{}, false
}

signature, err := s.unmarshalResponse(appResponse.AppBytes)
signature, err := s.unmarshalResponse(appResponse.GetAppBytes())
if err != nil {
s.logger.Error(
"Error unmarshaling signature response",
Expand Down Expand Up @@ -644,6 +644,10 @@ func (s *SignatureAggregator) marshalRequest(
}

func (s *SignatureAggregator) unmarshalResponse(responseBytes []byte) (blsSignatureBuf, error) {
// empty responses are valid and indicate the node has not seen the message
if len(responseBytes) == 0 {
return blsSignatureBuf{}, nil
}
var sigResponse sdk.SignatureResponse
err := proto.Unmarshal(responseBytes, &sigResponse)
if err != nil {
Expand Down
50 changes: 50 additions & 0 deletions signature-aggregator/aggregator/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"os"
"testing"

"crypto/rand"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/message"
"github.com/ava-labs/avalanchego/proto/pb/sdk"
Expand Down Expand Up @@ -346,6 +348,54 @@ func TestCreateSignedMessageSucceeds(t *testing.T) {
require.NoError(t, verifyErr)
}

func TestUnmarshalResponse(t *testing.T) {
aggregator, _ := instantiateAggregator(t)

emptySignatureResponse, err := proto.Marshal(&sdk.SignatureResponse{Signature: []byte{}})
require.NoError(t, err)

randSignature := make([]byte, 96)
_, err = rand.Read(randSignature)
require.NoError(t, err)

randSignatureResponse, err := proto.Marshal(&sdk.SignatureResponse{Signature: randSignature})
require.NoError(t, err)

testCases := []struct {
name string
appResponseBytes []byte
expectedSignature blsSignatureBuf
}{
{
name: "empty slice",
appResponseBytes: []byte{},
expectedSignature: blsSignatureBuf{},
},
{
name: "nil slice",
appResponseBytes: nil,
expectedSignature: blsSignatureBuf{},
},
{
name: "empty signature",
appResponseBytes: emptySignatureResponse,
expectedSignature: blsSignatureBuf{},
},
{
name: "random signature",
appResponseBytes: randSignatureResponse,
expectedSignature: blsSignatureBuf(randSignature),
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
signature, err := aggregator.unmarshalResponse(tc.appResponseBytes)
require.NoError(t, err)
require.Equal(t, tc.expectedSignature, signature)
})
}
}

type pChainStateStub struct {
subnetIDByChainID map[ids.ID]ids.ID
connectedCanonicalValidators *peers.ConnectedCanonicalValidators
Expand Down

0 comments on commit 616890e

Please sign in to comment.