Skip to content

Commit 20de11a

Browse files
committed
[FAB-6741] Deprecate stateInfo.Metadata
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>
1 parent 09e1f8d commit 20de11a

20 files changed

+344
-475
lines changed

gossip/common/metastate.go

-64
This file was deleted.

gossip/common/metastate_test.go

-65
This file was deleted.

gossip/gossip/anchor_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ func TestAnchorPeer(t *testing.T) {
263263
p := newGossipInstanceWithExternalEndpoint(portPrefix, 0, cs, endpoint)
264264
defer p.Stop()
265265
p.JoinChan(jcm, channel)
266-
p.UpdateChannelMetadata(createMetadata(1), channel)
266+
p.UpdateLedgerHeight(1, channel)
267267

268268
time.Sleep(time.Second * 5)
269269

gossip/gossip/channel/channel.go

+80-9
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,13 @@ type GossipChannel interface {
5555
// IsMemberInChan checks whether the given member is eligible to be in the channel
5656
IsMemberInChan(member discovery.NetworkMember) bool
5757

58-
// UpdateStateInfo updates this channel's StateInfo message
59-
// that is periodically published
60-
UpdateStateInfo(msg *proto.SignedGossipMessage)
58+
// UpdateLedgerHeight updates the ledger height the peer
59+
// publishes to other peers in the channel
60+
UpdateLedgerHeight(height uint64)
61+
62+
// UpdateChaincodes updates the chaincodes the peer publishes
63+
// to other peers in the channel
64+
UpdateChaincodes(chaincode []*proto.Chaincode)
6165

6266
// IsOrgInChannel returns whether the given organization is in the channel
6367
IsOrgInChannel(membersOrg api.OrgIdentityType) bool
@@ -86,6 +90,8 @@ type GossipChannel interface {
8690
// Adapter enables the gossipChannel
8791
// to communicate with gossipServiceImpl.
8892
type Adapter interface {
93+
Sign(msg *proto.GossipMessage) (*proto.SignedGossipMessage, error)
94+
8995
// GetConf returns the configuration that this GossipChannel will posses
9096
GetConf() Config
9197

@@ -140,6 +146,7 @@ type gossipChannel struct {
140146
stateInfoRequestScheduler *time.Ticker
141147
memFilter *membershipFilter
142148
ledgerHeight uint64
149+
incTime uint64
143150
leftChannel int32
144151
}
145152

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

282290
// LeaveChannel makes the peer leave the channel
283291
func (gc *gossipChannel) LeaveChannel() {
292+
gc.Lock()
293+
defer gc.Unlock()
294+
284295
atomic.StoreInt32(&gc.leftChannel, 1)
296+
297+
var chaincodes []*proto.Chaincode
298+
var height uint64
299+
if prevMsg := gc.stateInfoMsg; prevMsg != nil {
300+
chaincodes = prevMsg.GetStateInfo().Properties.Chaincodes
301+
height = prevMsg.GetStateInfo().Properties.LedgerHeight
302+
}
303+
gc.updateProperties(height, chaincodes, true)
285304
}
286305

287306
func (gc *gossipChannel) hasLeftChannel() bool {
@@ -307,7 +326,6 @@ func (gc *gossipChannel) GetPeers() []discovery.NetworkMember {
307326
if props != nil && props.LeftChannel {
308327
continue
309328
}
310-
member.Metadata = stateInf.GetStateInfo().Metadata
311329
member.Properties = stateInf.GetStateInfo().Properties
312330
members = append(members, member)
313331
}
@@ -772,22 +790,75 @@ func (gc *gossipChannel) createStateInfoRequest() (*proto.SignedGossipMessage, e
772790
}).NoopSign()
773791
}
774792

775-
// UpdateStateInfo updates this channel's StateInfo message
776-
// that is periodically published
777-
func (gc *gossipChannel) UpdateStateInfo(msg *proto.SignedGossipMessage) {
778-
if !msg.IsStateInfoMsg() {
779-
return
793+
// UpdateLedgerHeight updates the ledger height the peer
794+
// publishes to other peers in the channel
795+
func (gc *gossipChannel) UpdateLedgerHeight(height uint64) {
796+
gc.Lock()
797+
defer gc.Unlock()
798+
799+
var chaincodes []*proto.Chaincode
800+
var leftChannel bool
801+
if prevMsg := gc.stateInfoMsg; prevMsg != nil {
802+
leftChannel = prevMsg.GetStateInfo().Properties.LeftChannel
803+
chaincodes = prevMsg.GetStateInfo().Properties.Chaincodes
780804
}
805+
gc.updateProperties(height, chaincodes, leftChannel)
806+
}
781807

808+
// UpdateChaincodes updates the chaincodes the peer publishes
809+
// to other peers in the channel
810+
func (gc *gossipChannel) UpdateChaincodes(chaincodes []*proto.Chaincode) {
782811
gc.Lock()
783812
defer gc.Unlock()
784813

814+
var ledgerHeight uint64 = 1
815+
var leftChannel bool
816+
if prevMsg := gc.stateInfoMsg; prevMsg != nil {
817+
ledgerHeight = prevMsg.GetStateInfo().Properties.LedgerHeight
818+
leftChannel = prevMsg.GetStateInfo().Properties.LeftChannel
819+
}
820+
gc.updateProperties(ledgerHeight, chaincodes, leftChannel)
821+
}
822+
823+
// UpdateStateInfo updates this channel's StateInfo message
824+
// that is periodically published
825+
func (gc *gossipChannel) updateStateInfo(msg *proto.SignedGossipMessage) {
785826
gc.stateInfoMsgStore.Add(msg)
786827
gc.ledgerHeight = msg.GetStateInfo().Properties.LedgerHeight
787828
gc.stateInfoMsg = msg
788829
atomic.StoreInt32(&gc.shouldGossipStateInfo, int32(1))
789830
}
790831

832+
func (gc *gossipChannel) updateProperties(ledgerHeight uint64, chaincodes []*proto.Chaincode, leftChannel bool) {
833+
stateInfMsg := &proto.StateInfo{
834+
Channel_MAC: GenerateMAC(gc.pkiID, gc.chainID),
835+
PkiId: gc.pkiID,
836+
Timestamp: &proto.PeerTime{
837+
IncNum: gc.incTime,
838+
SeqNum: uint64(time.Now().UnixNano()),
839+
},
840+
Properties: &proto.Properties{
841+
LeftChannel: leftChannel,
842+
LedgerHeight: ledgerHeight,
843+
Chaincodes: chaincodes,
844+
},
845+
}
846+
m := &proto.GossipMessage{
847+
Nonce: 0,
848+
Tag: proto.GossipMessage_CHAN_OR_ORG,
849+
Content: &proto.GossipMessage_StateInfo{
850+
StateInfo: stateInfMsg,
851+
},
852+
}
853+
854+
msg, err := gc.Sign(m)
855+
if err != nil {
856+
gc.logger.Error("Failed signing message:", err)
857+
return
858+
}
859+
gc.updateStateInfo(msg)
860+
}
861+
791862
func newStateInfoCache(sweepInterval time.Duration, hasExpired func(interface{}) bool, verifyFunc membershipPredicate) *stateInfoCache {
792863
membershipStore := util.NewMembershipStore()
793864
pol := proto.NewGossipMessageComparator(0)

0 commit comments

Comments
 (0)