From 80eadb4e5e24aeb74e4a567a5011d015ecadf90d Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 24 Mar 2021 13:30:51 +0300 Subject: [PATCH] [#58] neofs: Allow alphabet nodes to remove candidates When alphabet nodes update inner ring list with new candidate, then they remove it from neofs contract. Signed-off-by: Alex Vanin --- neofs/neofs_contract.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/neofs/neofs_contract.go b/neofs/neofs_contract.go index 37a1a4d..87f3ec9 100644 --- a/neofs/neofs_contract.go +++ b/neofs/neofs_contract.go @@ -143,7 +143,21 @@ func InnerRingCandidateRemove(key interop.PublicKey) bool { ctx := storage.GetContext() if !runtime.CheckWitness(key) { - panic("irCandidateRemove: you should be the owner of the public key") + alphabet := getNodes(ctx, alphabetKey) + threshold := len(alphabet)/3*2 + 1 + + nodeKey := common.InnerRingInvoker(alphabet) + if len(nodeKey) == 0 { + panic("irCandidateRemove: invoked by non alphabet node") + } + + id := append(key, []byte("delete")...) + hashID := crypto.Sha256(id) + + n := common.Vote(ctx, hashID, nodeKey) + if n < threshold { + return true + } } nodes := []common.IRNode{} // it is explicit declaration of empty slice, not nil