Merge pull request #2610 from rlan35/slash_fixes

Return if potential double sign
pull/2612/head
Rongjian Lan 5 years ago committed by GitHub
commit 433df933a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      consensus/double_sign.go
  2. 8
      consensus/leader.go

@ -13,7 +13,8 @@ import (
)
// Check for double sign and if any, send it out to beacon chain for slashing.
func (consensus *Consensus) checkDoubleSign(recvMsg *FBFTMessage) {
// Returns true when it is a double-sign or there is error, otherwise, false.
func (consensus *Consensus) checkDoubleSign(recvMsg *FBFTMessage) bool {
if consensus.couldThisBeADoubleSigner(recvMsg) {
if alreadyCastBallot := consensus.Decider.ReadBallot(
quorum.Commit, recvMsg.SenderPubkey,
@ -36,7 +37,7 @@ func (consensus *Consensus) checkDoubleSign(recvMsg *FBFTMessage) {
if err := doubleSign.Deserialize(recvMsg.Payload); err != nil {
consensus.getLogger().Err(err).Str("msg", recvMsg.String()).
Msg("could not deserialize potential double signer")
return
return true
}
curHeader := consensus.ChainReader.CurrentHeader()
@ -46,7 +47,7 @@ func (consensus *Consensus) checkDoubleSign(recvMsg *FBFTMessage) {
Uint32("shard", consensus.ShardID).
Uint64("epoch", curHeader.Epoch().Uint64()).
Msg("could not read shard state")
return
return true
}
offender := *shard.FromLibBLSPublicKeyUnsafe(recvMsg.SenderPubkey)
subComm, err := committee.FindCommitteeByID(
@ -56,7 +57,7 @@ func (consensus *Consensus) checkDoubleSign(recvMsg *FBFTMessage) {
consensus.getLogger().Err(err).
Str("msg", recvMsg.String()).
Msg("could not find subcommittee for bls key")
return
return true
}
addr, err := subComm.AddressForBLSKey(offender)
@ -64,7 +65,7 @@ func (consensus *Consensus) checkDoubleSign(recvMsg *FBFTMessage) {
if err != nil {
consensus.getLogger().Err(err).Str("msg", recvMsg.String()).
Msg("could not find address for bls key")
return
return true
}
now := big.NewInt(time.Now().UnixNano())
@ -93,13 +94,14 @@ func (consensus *Consensus) checkDoubleSign(recvMsg *FBFTMessage) {
}
consensus.SlashChan <- proof
}(consensus.SelfAddresses[consensus.LeaderPubKey.SerializeToHexStr()])
return
return true
}
}
}
}
return
return true
}
return false
}
func (consensus *Consensus) couldThisBeADoubleSigner(

@ -203,6 +203,11 @@ func (consensus *Consensus) onCommit(msg *msg_pb.Message) {
consensus.mutex.Lock()
defer consensus.mutex.Unlock()
// Check for potential double signing
if consensus.checkDoubleSign(recvMsg) {
return
}
validatorPubKey, commitSig, commitBitmap :=
recvMsg.SenderPubkey, recvMsg.Payload, consensus.commitBitmap
logger := consensus.getLogger().With().
@ -231,9 +236,6 @@ func (consensus *Consensus) onCommit(msg *msg_pb.Message) {
return
}
// Check for potential double signing
consensus.checkDoubleSign(recvMsg)
logger = logger.With().
Int64("numReceivedSoFar", consensus.Decider.SignersCount(quorum.Commit)).
Logger()

Loading…
Cancel
Save