[quorum] Add interface method to check if I am in committee, implemen… (#1892)

* [quorum] Add interface method to check if I am in committee, implement in both concrete types

* [quorum] Only handle message when I am in committee

* [quorum][consensus] Let non-member still get onCommitted messages
pull/1900/head
Edgar Aroutiounian 5 years ago committed by GitHub
parent 60d0ef6e04
commit ae5d010f9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      cmd/harmony/main.go
  2. 3
      consensus/consensus_service.go
  3. 8
      consensus/consensus_v2.go
  4. 12
      consensus/quorum/one-node-one-vote.go
  5. 8
      consensus/quorum/one-node-staked-vote.go
  6. 12
      consensus/quorum/quorum.go

@ -293,6 +293,11 @@ func setupConsensusAndNode(nodeConfig *nodeconfig.ConfigType) *node.Node {
currentConsensus.Decider.SetShardIDProvider(func() (uint32, error) {
return currentConsensus.ShardID, nil
})
currentConsensus.Decider.SetMyPublicKeyProvider(func() (*bls.PublicKey, error) {
return currentConsensus.PubKey, nil
})
currentConsensus.SelfAddress = common.ParseAddr(initialAccount.Address)
if err != nil {

@ -480,6 +480,9 @@ func (consensus *Consensus) UpdateConsensusInformation() Mode {
consensus.Decider.SetShardIDProvider(func() (uint32, error) {
return consensus.ShardID, nil
})
consensus.Decider.SetMyPublicKeyProvider(func() (*bls.PublicKey, error) {
return consensus.PubKey, nil
})
utils.Logger().Info().
Uint64("block-number", curHeader.Number().Uint64()).

@ -66,6 +66,14 @@ func (consensus *Consensus) handleMessageUpdate(payload []byte) {
}
}
notMemberButStillCatchup := !consensus.Decider.AmIMemberOfCommitee() &&
msg.Type == msg_pb.MessageType_COMMITTED
if notMemberButStillCatchup {
consensus.onCommitted(msg)
return
}
switch msg.Type {
case msg_pb.MessageType_ANNOUNCE:
consensus.onAnnounce(msg)

@ -99,3 +99,15 @@ func (v *uniformVoteWeight) JSON() string {
b1, _ := json.Marshal(t{v.Policy().String(), s, len(members), members})
return string(b1)
}
func (v *uniformVoteWeight) AmIMemberOfCommitee() bool {
identity, _ := v.MyPublicKey()()
everyone := v.DumpParticipants()
myVoterID := identity.SerializeToHexStr()
for i := range everyone {
if everyone[i] == myVoterID {
return true
}
}
return false
}

@ -239,3 +239,11 @@ func (v *stakedVoteWeight) JSON() string {
})
return string(b1)
}
func (v *stakedVoteWeight) AmIMemberOfCommitee() bool {
identity, _ := v.MyPublicKey()()
w := shard.BlsPublicKey{}
w.FromLibBLSPublicKey(identity)
_, ok := v.roster.Voters[w]
return ok
}

@ -89,11 +89,13 @@ type SignatureReader interface {
// DependencyInjectionWriter ..
type DependencyInjectionWriter interface {
SetShardIDProvider(func() (uint32, error))
SetMyPublicKeyProvider(func() (*bls.PublicKey, error))
}
// DependencyInjectionReader ..
type DependencyInjectionReader interface {
ShardIDProvider() func() (uint32, error)
MyPublicKey() func() (*bls.PublicKey, error)
}
//WithJSONDump representation dump
@ -112,6 +114,7 @@ type Decider interface {
Policy() Policy
IsQuorumAchieved(Phase) bool
QuorumThreshold() numeric.Dec
AmIMemberOfCommitee() bool
IsRewardThresholdAchieved() bool
}
@ -130,6 +133,7 @@ type cIdentities struct {
type depInject struct {
shardIDProvider func() (uint32, error)
publicKeyProvider func() (*bls.PublicKey, error)
}
func (s *cIdentities) IndexOf(pubKey *bls.PublicKey) int {
@ -286,6 +290,14 @@ func (d *depInject) ShardIDProvider() func() (uint32, error) {
return d.shardIDProvider
}
func (d *depInject) SetMyPublicKeyProvider(p func() (*bls.PublicKey, error)) {
d.publicKeyProvider = p
}
func (d *depInject) MyPublicKey() func() (*bls.PublicKey, error) {
return d.publicKeyProvider
}
// NewDecider ..
func NewDecider(p Policy) Decider {
signatureStore := newMapBackedSignatureReader()

Loading…
Cancel
Save