smartcontract: add GetMajorityNodeCount()

This commit is contained in:
Evgeniy Stratonikov 2021-02-02 12:34:15 +03:00
parent 717be43a5d
commit 7a176727ca

View file

@ -49,7 +49,7 @@ func CreateDefaultMultiSigRedeemScript(publicKeys keys.PublicKeys) ([]byte, erro
// using publicKeys length with m set to majority.
func CreateMajorityMultiSigRedeemScript(publicKeys keys.PublicKeys) ([]byte, error) {
n := len(publicKeys)
m := n - (n-1)/2
m := GetMajorityHonestNodeCount(n)
return CreateMultiSigRedeemScript(m, publicKeys)
}
@ -58,3 +58,9 @@ func CreateMajorityMultiSigRedeemScript(publicKeys keys.PublicKeys) ([]byte, err
func GetDefaultHonestNodeCount(n int) int {
return n - (n-1)/3
}
// GetMajorityHonestNodeCount returns minimum number of honest nodes
// required for majority-style agreement.
func GetMajorityHonestNodeCount(n int) int {
return n - (n-1)/2
}