forked from TrueCloudLab/frostfs-contract
[#63] Fix threshold number calculation
`x*2/3` is not equal to `x/3*2` with integers. The only correct way to calculate threshold is the first one. Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
80eadb4e5e
commit
23f5f1e0e7
2 changed files with 5 additions and 5 deletions
|
@ -48,7 +48,7 @@ func AlphabetAddress() []byte {
|
||||||
// Multiaddress returns default multi signature account address for N keys.
|
// Multiaddress returns default multi signature account address for N keys.
|
||||||
// If committee set to true, then it is `M = N/2+1` committee account.
|
// If committee set to true, then it is `M = N/2+1` committee account.
|
||||||
func Multiaddress(n []interop.PublicKey, committee bool) []byte {
|
func Multiaddress(n []interop.PublicKey, committee bool) []byte {
|
||||||
threshold := len(n)/3*2 + 1
|
threshold := len(n)*2/3 + 1
|
||||||
if committee {
|
if committee {
|
||||||
threshold = len(n)/2 + 1
|
threshold = len(n)/2 + 1
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,7 +144,7 @@ func InnerRingCandidateRemove(key interop.PublicKey) bool {
|
||||||
|
|
||||||
if !runtime.CheckWitness(key) {
|
if !runtime.CheckWitness(key) {
|
||||||
alphabet := getNodes(ctx, alphabetKey)
|
alphabet := getNodes(ctx, alphabetKey)
|
||||||
threshold := len(alphabet)/3*2 + 1
|
threshold := len(alphabet)*2/3 + 1
|
||||||
|
|
||||||
nodeKey := common.InnerRingInvoker(alphabet)
|
nodeKey := common.InnerRingInvoker(alphabet)
|
||||||
if len(nodeKey) == 0 {
|
if len(nodeKey) == 0 {
|
||||||
|
@ -286,7 +286,7 @@ func Withdraw(user []byte, amount int) bool {
|
||||||
func Cheque(id []byte, user interop.Hash160, amount int, lockAcc []byte) bool {
|
func Cheque(id []byte, user interop.Hash160, amount int, lockAcc []byte) bool {
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
alphabet := getNodes(ctx, alphabetKey)
|
alphabet := getNodes(ctx, alphabetKey)
|
||||||
threshold := len(alphabet)/3*2 + 1
|
threshold := len(alphabet)*2/3 + 1
|
||||||
|
|
||||||
cashedCheques := getCashedCheques(ctx)
|
cashedCheques := getCashedCheques(ctx)
|
||||||
hashID := crypto.Sha256(id)
|
hashID := crypto.Sha256(id)
|
||||||
|
@ -369,7 +369,7 @@ func AlphabetUpdate(chequeID []byte, args []interop.PublicKey) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
alphabet := getNodes(ctx, alphabetKey)
|
alphabet := getNodes(ctx, alphabetKey)
|
||||||
threshold := len(alphabet)/3*2 + 1
|
threshold := len(alphabet)*2/3 + 1
|
||||||
|
|
||||||
key := common.InnerRingInvoker(alphabet)
|
key := common.InnerRingInvoker(alphabet)
|
||||||
if len(key) == 0 {
|
if len(key) == 0 {
|
||||||
|
@ -426,7 +426,7 @@ func SetConfig(id, key, val []byte) bool {
|
||||||
|
|
||||||
// check if it is alphabet invocation
|
// check if it is alphabet invocation
|
||||||
alphabet := getNodes(ctx, alphabetKey)
|
alphabet := getNodes(ctx, alphabetKey)
|
||||||
threshold := len(alphabet)/3*2 + 1
|
threshold := len(alphabet)*2/3 + 1
|
||||||
|
|
||||||
nodeKey := common.InnerRingInvoker(alphabet)
|
nodeKey := common.InnerRingInvoker(alphabet)
|
||||||
if len(nodeKey) == 0 {
|
if len(nodeKey) == 0 {
|
||||||
|
|
Loading…
Reference in a new issue