Skip to content

Commit

Permalink
Log proposal response differences (#3420)
Browse files Browse the repository at this point in the history
In the gateway, if proposal responses from different endorsing peers don’t match, then it’s very difficult for the end user to diagnose why.  This commit adds extra logging to help identify the cause of the mismatch.

If the log level is set to ‘debug’ for the ‘gateway’, then the proposal response payloads are unmarshalled and analysed to log specific differences between individual key/values in the read/write sets, SBE policy write differences, event differences and chaincode response differences.  For private collections, only the hashes are logged if they are different.

Signed-off-by: andrew-coleman <andrew_coleman@uk.ibm.com>
(cherry picked from commit 863cdd7)

# Conflicts:
#	internal/pkg/gateway/api_test.go
  • Loading branch information
andrew-coleman authored and mergify[bot] committed May 20, 2022
1 parent 4c6ef91 commit 63ce182
Show file tree
Hide file tree
Showing 4 changed files with 1,003 additions and 0 deletions.
37 changes: 37 additions & 0 deletions internal/pkg/gateway/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"context"
"fmt"
"io"
"strings"
"testing"
"time"

Expand All @@ -23,7 +24,13 @@ import (
ab "github.com/hyperledger/fabric-protos-go/orderer"
"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/common/crypto/tlsgen"
<<<<<<< HEAD
commonledger "github.com/hyperledger/fabric/common/ledger"
=======
"github.com/hyperledger/fabric/common/flogging"
"github.com/hyperledger/fabric/common/flogging/mock"
"github.com/hyperledger/fabric/common/ledger"
>>>>>>> 863cdd788 (Log proposal response differences (#3420))
"github.com/hyperledger/fabric/gossip/api"
"github.com/hyperledger/fabric/gossip/common"
gdiscovery "github.com/hyperledger/fabric/gossip/discovery"
Expand All @@ -36,6 +43,7 @@ import (
"github.com/pkg/errors"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -167,6 +175,8 @@ type preparedTest struct {
ledgerProvider *mocks.LedgerProvider
ledger *mocks.Ledger
blockIterator *mocks.ResultsIterator
logLevel string
logFields []string
}

type contextKey string
Expand Down Expand Up @@ -770,6 +780,26 @@ func TestEndorse(t *testing.T) {
Message: "ProposalResponsePayloads do not match",
},
},
postSetup: func(t *testing.T, def *preparedTest) {
def.logLevel = flogging.LoggerLevel("gateway")
flogging.ActivateSpec("debug")
logObserver := &mock.Observer{}
logObserver.WriteEntryStub = func(entry zapcore.Entry, fields []zapcore.Field) {
if strings.HasPrefix(entry.Message, "Proposal response mismatch") {
for _, field := range fields {
def.logFields = append(def.logFields, field.String)
}
}
}
flogging.SetObserver(logObserver)
},
postTest: func(t *testing.T, def *preparedTest) {
require.Equal(t, "chaincode response mismatch", def.logFields[0])
require.Equal(t, "status: 200, message: , payload: different_response", def.logFields[1])
require.Equal(t, "status: 200, message: , payload: mock_response", def.logFields[2])
flogging.ActivateSpec(def.logLevel)
flogging.SetObserver(nil)
},
},
{
name: "discovery fails",
Expand Down Expand Up @@ -963,6 +993,9 @@ func TestEndorse(t *testing.T) {

if checkError(t, &tt, err) {
require.Nil(t, response, "response on error")
if tt.postTest != nil {
tt.postTest(t, test)
}
return
}

Expand All @@ -979,6 +1012,10 @@ func TestEndorse(t *testing.T) {

// check the correct endorsers (mocks) were called with the right parameters
checkEndorsers(t, tt.expectedEndorsers, test)

if tt.postTest != nil {
tt.postTest(t, test)
}
})
}
}
Expand Down
Loading

0 comments on commit 63ce182

Please sign in to comment.