Skip to content

Commit

Permalink
[FAB-6741] Deprecate stateInfo.Metadata
Browse files Browse the repository at this point in the history
The stateInfo.Metadata field was used in v1.0 for storing the peer's
ledger height.

In v1.1 we added a properties proto structure field that would replace
the metadata for ledger height.
In v1.2 (next release) we deprecate the metadata and as a result, peers
in v1.0 won't be able to gossip in channel context with peers
from v1.2

Change-Id: Ieefa98563500760eb23bf579f93ed786b935acf4
Signed-off-by: yacovm <yacovm@il.ibm.com>
  • Loading branch information
yacovm committed Mar 5, 2018
1 parent 09e1f8d commit 20de11a
Show file tree
Hide file tree
Showing 20 changed files with 344 additions and 475 deletions.
64 changes: 0 additions & 64 deletions gossip/common/metastate.go

This file was deleted.

65 changes: 0 additions & 65 deletions gossip/common/metastate_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion gossip/gossip/anchor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func TestAnchorPeer(t *testing.T) {
p := newGossipInstanceWithExternalEndpoint(portPrefix, 0, cs, endpoint)
defer p.Stop()
p.JoinChan(jcm, channel)
p.UpdateChannelMetadata(createMetadata(1), channel)
p.UpdateLedgerHeight(1, channel)

time.Sleep(time.Second * 5)

Expand Down
89 changes: 80 additions & 9 deletions gossip/gossip/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ type GossipChannel interface {
// IsMemberInChan checks whether the given member is eligible to be in the channel
IsMemberInChan(member discovery.NetworkMember) bool

// UpdateStateInfo updates this channel's StateInfo message
// that is periodically published
UpdateStateInfo(msg *proto.SignedGossipMessage)
// UpdateLedgerHeight updates the ledger height the peer
// publishes to other peers in the channel
UpdateLedgerHeight(height uint64)

// UpdateChaincodes updates the chaincodes the peer publishes
// to other peers in the channel
UpdateChaincodes(chaincode []*proto.Chaincode)

// IsOrgInChannel returns whether the given organization is in the channel
IsOrgInChannel(membersOrg api.OrgIdentityType) bool
Expand Down Expand Up @@ -86,6 +90,8 @@ type GossipChannel interface {
// Adapter enables the gossipChannel
// to communicate with gossipServiceImpl.
type Adapter interface {
Sign(msg *proto.GossipMessage) (*proto.SignedGossipMessage, error)

// GetConf returns the configuration that this GossipChannel will posses
GetConf() Config

Expand Down Expand Up @@ -140,6 +146,7 @@ type gossipChannel struct {
stateInfoRequestScheduler *time.Ticker
memFilter *membershipFilter
ledgerHeight uint64
incTime uint64
leftChannel int32
}

Expand All @@ -166,6 +173,7 @@ func (mf *membershipFilter) GetMembership() []discovery.NetworkMember {
func NewGossipChannel(pkiID common.PKIidType, org api.OrgIdentityType, mcs api.MessageCryptoService,
chainID common.ChainID, adapter Adapter, joinMsg api.JoinChannelMessage) GossipChannel {
gc := &gossipChannel{
incTime: uint64(time.Now().UnixNano()),
selfOrg: org,
pkiID: pkiID,
mcs: mcs,
Expand Down Expand Up @@ -281,7 +289,18 @@ func (gc *gossipChannel) periodicalInvocation(fn func(), c <-chan time.Time) {

// LeaveChannel makes the peer leave the channel
func (gc *gossipChannel) LeaveChannel() {
gc.Lock()
defer gc.Unlock()

atomic.StoreInt32(&gc.leftChannel, 1)

var chaincodes []*proto.Chaincode
var height uint64
if prevMsg := gc.stateInfoMsg; prevMsg != nil {
chaincodes = prevMsg.GetStateInfo().Properties.Chaincodes
height = prevMsg.GetStateInfo().Properties.LedgerHeight
}
gc.updateProperties(height, chaincodes, true)
}

func (gc *gossipChannel) hasLeftChannel() bool {
Expand All @@ -307,7 +326,6 @@ func (gc *gossipChannel) GetPeers() []discovery.NetworkMember {
if props != nil && props.LeftChannel {
continue
}
member.Metadata = stateInf.GetStateInfo().Metadata
member.Properties = stateInf.GetStateInfo().Properties
members = append(members, member)
}
Expand Down Expand Up @@ -772,22 +790,75 @@ func (gc *gossipChannel) createStateInfoRequest() (*proto.SignedGossipMessage, e
}).NoopSign()
}

// UpdateStateInfo updates this channel's StateInfo message
// that is periodically published
func (gc *gossipChannel) UpdateStateInfo(msg *proto.SignedGossipMessage) {
if !msg.IsStateInfoMsg() {
return
// UpdateLedgerHeight updates the ledger height the peer
// publishes to other peers in the channel
func (gc *gossipChannel) UpdateLedgerHeight(height uint64) {
gc.Lock()
defer gc.Unlock()

var chaincodes []*proto.Chaincode
var leftChannel bool
if prevMsg := gc.stateInfoMsg; prevMsg != nil {
leftChannel = prevMsg.GetStateInfo().Properties.LeftChannel
chaincodes = prevMsg.GetStateInfo().Properties.Chaincodes
}
gc.updateProperties(height, chaincodes, leftChannel)
}

// UpdateChaincodes updates the chaincodes the peer publishes
// to other peers in the channel
func (gc *gossipChannel) UpdateChaincodes(chaincodes []*proto.Chaincode) {
gc.Lock()
defer gc.Unlock()

var ledgerHeight uint64 = 1
var leftChannel bool
if prevMsg := gc.stateInfoMsg; prevMsg != nil {
ledgerHeight = prevMsg.GetStateInfo().Properties.LedgerHeight
leftChannel = prevMsg.GetStateInfo().Properties.LeftChannel
}
gc.updateProperties(ledgerHeight, chaincodes, leftChannel)
}

// UpdateStateInfo updates this channel's StateInfo message
// that is periodically published
func (gc *gossipChannel) updateStateInfo(msg *proto.SignedGossipMessage) {
gc.stateInfoMsgStore.Add(msg)
gc.ledgerHeight = msg.GetStateInfo().Properties.LedgerHeight
gc.stateInfoMsg = msg
atomic.StoreInt32(&gc.shouldGossipStateInfo, int32(1))
}

func (gc *gossipChannel) updateProperties(ledgerHeight uint64, chaincodes []*proto.Chaincode, leftChannel bool) {
stateInfMsg := &proto.StateInfo{
Channel_MAC: GenerateMAC(gc.pkiID, gc.chainID),
PkiId: gc.pkiID,
Timestamp: &proto.PeerTime{
IncNum: gc.incTime,
SeqNum: uint64(time.Now().UnixNano()),
},
Properties: &proto.Properties{
LeftChannel: leftChannel,
LedgerHeight: ledgerHeight,
Chaincodes: chaincodes,
},
}
m := &proto.GossipMessage{
Nonce: 0,
Tag: proto.GossipMessage_CHAN_OR_ORG,
Content: &proto.GossipMessage_StateInfo{
StateInfo: stateInfMsg,
},
}

msg, err := gc.Sign(m)
if err != nil {
gc.logger.Error("Failed signing message:", err)
return
}
gc.updateStateInfo(msg)
}

func newStateInfoCache(sweepInterval time.Duration, hasExpired func(interface{}) bool, verifyFunc membershipPredicate) *stateInfoCache {
membershipStore := util.NewMembershipStore()
pol := proto.NewGossipMessageComparator(0)
Expand Down
Loading

0 comments on commit 20de11a

Please sign in to comment.