[#74] reputation: Support notary disabled work flow

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-04-29 16:20:22 +03:00 committed by Alex Vanin
parent 2672e663a0
commit 2cc9c4fc66

View file

@ -50,9 +50,24 @@ func Migrate(script []byte, manifest []byte) bool {
func Put(epoch int, peerID []byte, value []byte) { func Put(epoch int, peerID []byte, value []byte) {
ctx := storage.GetContext() ctx := storage.GetContext()
notaryDisabled := storage.Get(ctx, notaryDisabledKey).(bool)
var ( // for invocation collection without notary
alphabet []common.IRNode
nodeKey []byte
alphabetCall bool
)
if notaryDisabled {
alphabet = common.AlphabetNodes()
nodeKey = common.InnerRingInvoker(alphabet)
alphabetCall = len(nodeKey) != 0
} else {
multiaddr := common.AlphabetAddress() multiaddr := common.AlphabetAddress()
if !runtime.CheckWitness(multiaddr) { alphabetCall = runtime.CheckWitness(multiaddr)
}
if !alphabetCall {
runtime.Notify("reputationPut", epoch, peerID, value) runtime.Notify("reputationPut", epoch, peerID, value)
return return
} }
@ -63,6 +78,18 @@ func Put(epoch int, peerID []byte, value []byte) {
reputationValues = append(reputationValues, value) reputationValues = append(reputationValues, value)
rawValues := std.Serialize(reputationValues) rawValues := std.Serialize(reputationValues)
if notaryDisabled {
threshold := len(alphabet)*2/3 + 1
n := common.Vote(ctx, id, nodeKey)
if n < threshold {
return
}
common.RemoveVotes(ctx, id)
}
storage.Put(ctx, id, rawValues) storage.Put(ctx, id, rawValues)
} }
@ -93,6 +120,7 @@ func ListByEpoch(epoch int) [][]byte {
ignore := [][]byte{ ignore := [][]byte{
[]byte(common.OwnerKey), []byte(common.OwnerKey),
[]byte(notaryDisabledKey),
} }
loop: loop: