Skip to content

Commit

Permalink
[FAB-9598] Store config block number
Browse files Browse the repository at this point in the history
This ensures that the membership reference is only
recreated when the config block changes

Change-Id: Iae78c50c8e12955e68d004c358b7d79d0e676561
Signed-off-by: Divyank Katira <Divyank.Katira@securekey.com>
  • Loading branch information
d1vyank committed Apr 19, 2018
1 parent 95c8574 commit 50f07dd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
21 changes: 11 additions & 10 deletions pkg/common/errors/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,17 @@ const (

// GroupName maps the groups in this packages to human-readable strings
var GroupName = map[int32]string{
0: "Unknown",
1: "gRPC Transport Status",
2: "HTTP Transport Status",
3: "Endorser Server Status",
4: "Event Server Status",
5: "Orderer Server Status",
6: "Fabric CA Server Status",
7: "Endorser Client Status",
8: "Orderer Client Status",
9: "Client Status",
0: "Unknown",
1: "gRPC Transport Status",
2: "HTTP Transport Status",
3: "Endorser Server Status",
4: "Event Server Status",
5: "Orderer Server Status",
6: "Fabric CA Server Status",
7: "Endorser Client Status",
8: "Orderer Client Status",
9: "Client Status",
10: "Chaincode status",
}

func (g Group) String() string {
Expand Down
9 changes: 7 additions & 2 deletions pkg/fab/channel/membership/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/util/concurrent/lazyref"
mb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/msp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

type badKey struct {
Expand All @@ -30,9 +31,11 @@ func (b *badKey) String() string {
func TestMembershipCache(t *testing.T) {
testChannelID := "test"
goodMSPID := "GoodMSP"
testBlockNum := uint64(5)

cfg := mocks.NewMockChannelCfg(testChannelID)
cfg.MockMSPs = []*mb.MSPConfig{buildMSPConfig(goodMSPID, []byte(validRootCA))}
cfg.MockBlockNumber = testBlockNum

ctx := mocks.NewMockProviderContext()

Expand All @@ -50,8 +53,8 @@ func TestMembershipCache(t *testing.T) {
assert.Nil(t, err)
assert.NotNil(t, r)

mem, ok := r.(fab.ChannelMembership)
assert.True(t, ok)
mem, ok := r.(*Ref)
require.True(t, ok)

sID := &mb.SerializedIdentity{Mspid: goodMSPID, IdBytes: []byte(certPem)}
goodEndorser, err := proto.Marshal(sID)
Expand All @@ -62,6 +65,8 @@ func TestMembershipCache(t *testing.T) {

err = mem.Verify(goodEndorser, []byte("test"), []byte("test1"))
assert.Nil(t, err)

assert.Equal(t, testBlockNum, mem.configBlockNumber)
}

func TestMembershipCacheBad(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/fab/channel/membership/reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ func (ref *Ref) initializer() lazyref.Initializer {

// Membership is refreshed only if we have a newer config block
if ref.mem == nil || cfg.BlockNumber() > ref.configBlockNumber {
logger.Debugf("Creating membership...")
logger.Debugf("Creating membership for channel [%s]...", cfg.ID())
ref.mem, err = New(ref.context, cfg)
if err != nil {
return nil, err
}
ref.configBlockNumber = cfg.BlockNumber()
}

return ref.mem, nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/fab/endpointconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ const (
defaultResMgmtTimeout = time.Minute * 3
defaultConnIdleInterval = time.Second * 30
defaultEventServiceIdleInterval = time.Minute * 2
defaultChannelConfigRefreshInterval = time.Minute * 30
defaultChannelMemshpRefreshInterval = time.Second * 30
defaultChannelConfigRefreshInterval = time.Minute * 90
defaultChannelMemshpRefreshInterval = time.Second * 60

defaultCacheSweepInterval = time.Second * 15
)
Expand Down

0 comments on commit 50f07dd

Please sign in to comment.