From 44abaa8ef39756f19cdf3a42a74db28cdd61eda8 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 7 Oct 2020 15:58:33 +0300 Subject: [PATCH] smartcontract: implement `GetDefaultHonestNodeCount` We may use this in other parts of code. --- 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 0de8ade41..e413c7c07 100644 --- a/pkg/smartcontract/contract.go +++ b/pkg/smartcontract/contract.go @@ -41,7 +41,7 @@ func CreateMultiSigRedeemScript(m int, publicKeys keys.PublicKeys) ([]byte, erro // using publicKeys length with the default BFT assumptions of (n - (n-1)/3) for m. func CreateDefaultMultiSigRedeemScript(publicKeys keys.PublicKeys) ([]byte, error) { n := len(publicKeys) - m := n - (n-1)/3 + m := GetDefaultHonestNodeCount(n) return CreateMultiSigRedeemScript(m, publicKeys) } @@ -52,3 +52,9 @@ func CreateMajorityMultiSigRedeemScript(publicKeys keys.PublicKeys) ([]byte, err m := n - (n-1)/2 return CreateMultiSigRedeemScript(m, publicKeys) } + +// GetDefaultHonestNodeCount returns minimum number of honest nodes +// required for network of size n. +func GetDefaultHonestNodeCount(n int) int { + return n - (n-1)/3 +}