Skip to content

Commit

Permalink
[FAB-3333] Fix the inc_number in gossip msg
Browse files Browse the repository at this point in the history
* Fix the field from inc_number to inc_num, which is aligned to the other
field like seq_num in the same messsage structure.
* Update the generated proto files.
* Update the extensions.go to use the new field.

Change-Id: Ic449e59c893f31ae3f193b2d6f302b2f96a36825
Signed-off-by: Baohua Yang <baohyang@cn.ibm.com>
  • Loading branch information
yeasy authored and yacovm committed May 3, 2017
1 parent 2a3ad9d commit f41f4ff
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 124 deletions.
18 changes: 9 additions & 9 deletions gossip/discovery/discovery_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ func (d *gossipDiscoveryImpl) resurrectMember(am *proto.SignedGossipMessage, t p
d.aliveLastTS[string(pkiID)] = &timestamp{
lastSeen: time.Now(),
seqNum: t.SeqNum,
incTime: tsToTime(t.IncNumber),
incTime: tsToTime(t.IncNum),
}

var internalEndpoint string
Expand Down Expand Up @@ -722,8 +722,8 @@ func (d *gossipDiscoveryImpl) createAliveMessage(includeInternalEndpoint bool) *
PkiId: pkiID,
},
Timestamp: &proto.PeerTime{
IncNumber: uint64(d.incTime),
SeqNum: seqNum,
IncNum: uint64(d.incTime),
SeqNum: seqNum,
},
},
},
Expand Down Expand Up @@ -782,7 +782,7 @@ func (d *gossipDiscoveryImpl) learnExistingMembers(aliveArr []*proto.SignedGossi
d.logger.Debug("Updating aliveness data:", am)
// update existing aliveness data
alive := d.aliveLastTS[string(am.Membership.PkiId)]
alive.incTime = tsToTime(am.Timestamp.IncNumber)
alive.incTime = tsToTime(am.Timestamp.IncNum)
alive.lastSeen = time.Now()
alive.seqNum = am.Timestamp.SeqNum

Expand Down Expand Up @@ -811,7 +811,7 @@ func (d *gossipDiscoveryImpl) learnNewMembers(aliveMembers []*proto.SignedGossip
continue
}
d.aliveLastTS[string(am.GetAliveMsg().Membership.PkiId)] = &timestamp{
incTime: tsToTime(am.GetAliveMsg().Timestamp.IncNumber),
incTime: tsToTime(am.GetAliveMsg().Timestamp.IncNum),
lastSeen: time.Now(),
seqNum: am.GetAliveMsg().Timestamp.SeqNum,
}
Expand All @@ -825,7 +825,7 @@ func (d *gossipDiscoveryImpl) learnNewMembers(aliveMembers []*proto.SignedGossip
continue
}
d.deadLastTS[string(dm.GetAliveMsg().Membership.PkiId)] = &timestamp{
incTime: tsToTime(dm.GetAliveMsg().Timestamp.IncNumber),
incTime: tsToTime(dm.GetAliveMsg().Timestamp.IncNum),
lastSeen: time.Now(),
seqNum: dm.GetAliveMsg().Timestamp.SeqNum,
}
Expand Down Expand Up @@ -927,12 +927,12 @@ func equalPKIid(a, b common.PKIidType) bool {
}

func same(a *timestamp, b *proto.PeerTime) bool {
return uint64(a.incTime.UnixNano()) == b.IncNumber && a.seqNum == b.SeqNum
return uint64(a.incTime.UnixNano()) == b.IncNum && a.seqNum == b.SeqNum
}

func before(a *timestamp, b *proto.PeerTime) bool {
return (uint64(a.incTime.UnixNano()) == b.IncNumber && a.seqNum < b.SeqNum) ||
uint64(a.incTime.UnixNano()) < b.IncNumber
return (uint64(a.incTime.UnixNano()) == b.IncNum && a.seqNum < b.SeqNum) ||
uint64(a.incTime.UnixNano()) < b.IncNum
}

func getAliveTimeInterval() time.Duration {
Expand Down
4 changes: 2 additions & 2 deletions gossip/election/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ func (ai *adapterImpl) CreateMessage(isDeclaration bool) Msg {
PkiId: ai.selfPKIid,
IsDeclaration: isDeclaration,
Timestamp: &proto.PeerTime{
IncNumber: ai.incTime,
SeqNum: seqNum,
IncNum: ai.incTime,
SeqNum: seqNum,
},
}

Expand Down
2 changes: 1 addition & 1 deletion gossip/gossip/channel/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1406,7 +1406,7 @@ func createStateInfoMsg(ledgerHeight int, pkiID common.PKIidType, channel common
Content: &proto.GossipMessage_StateInfo{
StateInfo: &proto.StateInfo{
Channel_MAC: GenerateMAC(pkiID, channel),
Timestamp: &proto.PeerTime{IncNumber: uint64(time.Now().UnixNano()), SeqNum: 1},
Timestamp: &proto.PeerTime{IncNum: uint64(time.Now().UnixNano()), SeqNum: 1},
Metadata: []byte(fmt.Sprintf("%d", ledgerHeight)),
PkiId: []byte(pkiID),
},
Expand Down
4 changes: 2 additions & 2 deletions gossip/gossip/gossip_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1023,8 +1023,8 @@ func (g *gossipServiceImpl) createStateInfoMsg(metadata []byte, chainID common.C
Metadata: metadata,
PkiId: g.comm.GetPKIid(),
Timestamp: &proto.PeerTime{
IncNumber: uint64(g.incTime.UnixNano()),
SeqNum: uint64(time.Now().UnixNano()),
IncNum: uint64(g.incTime.UnixNano()),
SeqNum: uint64(time.Now().UnixNano()),
},
}
m := &proto.GossipMessage{
Expand Down
4 changes: 2 additions & 2 deletions gossip/gossip/gossip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1066,8 +1066,8 @@ func createLeadershipMsg(isDeclaration bool, channel common.ChainID, incTime uin
IsDeclaration: isDeclaration,
PkiId: pkiid,
Timestamp: &proto.PeerTime{
IncNumber: incTime,
SeqNum: seqNum,
IncNum: incTime,
SeqNum: seqNum,
},
}

Expand Down
4 changes: 2 additions & 2 deletions protos/gossip/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ func leaderInvalidationPolicy(thisMsg *LeadershipMessage, thatMsg *LeadershipMes
}

func compareTimestamps(thisTS *PeerTime, thatTS *PeerTime) common.InvalidationResult {
if thisTS.IncNumber == thatTS.IncNumber {
if thisTS.IncNum == thatTS.IncNum {
if thisTS.SeqNum > thatTS.SeqNum {
return common.MessageInvalidates
}

return common.MessageInvalidated
}
if thisTS.IncNumber < thatTS.IncNumber {
if thisTS.IncNum < thatTS.IncNum {
return common.MessageInvalidated
}
return common.MessageInvalidates
Expand Down
34 changes: 17 additions & 17 deletions protos/gossip/extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ func TestAliveMessageNoActionTaken(t *testing.T) {
PkiId: []byte{17},
},
Timestamp: &PeerTime{
IncNumber: 1,
SeqNum: 1,
IncNum: 1,
SeqNum: 1,
},
Identity: []byte("peerID1"),
},
Expand All @@ -165,8 +165,8 @@ func TestAliveMessageNoActionTaken(t *testing.T) {
PkiId: []byte{15},
},
Timestamp: &PeerTime{
IncNumber: 2,
SeqNum: 2,
IncNum: 2,
SeqNum: 2,
},
Identity: []byte("peerID1"),
},
Expand Down Expand Up @@ -226,8 +226,8 @@ func TestAliveMessageInvalidation(t *testing.T) {
PkiId: []byte{17},
},
Timestamp: &PeerTime{
IncNumber: 1,
SeqNum: 1,
IncNum: 1,
SeqNum: 1,
},
Identity: []byte("peerID1"),
},
Expand All @@ -241,8 +241,8 @@ func TestAliveMessageInvalidation(t *testing.T) {
PkiId: []byte{17},
},
Timestamp: &PeerTime{
IncNumber: 2,
SeqNum: 2,
IncNum: 2,
SeqNum: 2,
},
Identity: []byte("peerID1"),
},
Expand All @@ -256,8 +256,8 @@ func TestAliveMessageInvalidation(t *testing.T) {
PkiId: []byte{17},
},
Timestamp: &PeerTime{
IncNumber: 1,
SeqNum: 2,
IncNum: 1,
SeqNum: 2,
},
Identity: []byte("peerID1"),
},
Expand Down Expand Up @@ -365,8 +365,8 @@ func TestCheckGossipMessageTypes(t *testing.T) {
Endpoint: "localhost",
},
Timestamp: &PeerTime{
SeqNum: 1,
IncNumber: 1,
SeqNum: 1,
IncNum: 1,
},
},
})
Expand Down Expand Up @@ -827,20 +827,20 @@ func leadershipMessage(incNum uint64, seqNum uint64, pkid []byte) *GossipMessage
PkiId: pkid,
IsDeclaration: false,
Timestamp: &PeerTime{
IncNumber: incNum,
SeqNum: seqNum,
IncNum: incNum,
SeqNum: seqNum,
},
},
}
}

func stateInfoMessage(incNumber uint64, seqNum uint64, pkid []byte, mac []byte) *GossipMessage_StateInfo {
func stateInfoMessage(incNum uint64, seqNum uint64, pkid []byte, mac []byte) *GossipMessage_StateInfo {
return &GossipMessage_StateInfo{
StateInfo: &StateInfo{
Metadata: []byte{},
Timestamp: &PeerTime{
IncNumber: incNumber,
SeqNum: seqNum,
IncNum: incNum,
SeqNum: seqNum,
},
PkiId: pkid,
Channel_MAC: mac,
Expand Down
Loading

0 comments on commit f41f4ff

Please sign in to comment.