From 7a176727caec5a9f872e6146713a595257eedd85 Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Tue, 2 Feb 2021 12:34:15 +0300 Subject: [PATCH] smartcontract: add `GetMajorityNodeCount()` --- pkg/smartcontract/contract.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/smartcontract/contract.go b/pkg/smartcontract/contract.go index e413c7c07..7168e83e4 100644 --- a/pkg/smartcontract/contract.go +++ b/pkg/smartcontract/contract.go @@ -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 +}