forked from TrueCloudLab/frostfs-contract
[#74] alphabet: Support notary disabled work flow
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
76aca4c6f5
commit
5e22426768
1 changed files with 56 additions and 5 deletions
|
@ -3,6 +3,7 @@ package alphabetcontract
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop"
|
"github.com/nspcc-dev/neo-go/pkg/interop"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/crypto"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/native/gas"
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/gas"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/native/management"
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/management"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/native/neo"
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/neo"
|
||||||
|
@ -112,6 +113,7 @@ func checkPermission(ir []common.IRNode) bool {
|
||||||
|
|
||||||
func Emit() bool {
|
func Emit() bool {
|
||||||
ctx := storage.GetReadOnlyContext()
|
ctx := storage.GetReadOnlyContext()
|
||||||
|
notaryDisabled := storage.Get(ctx, notaryDisabledKey).(bool)
|
||||||
|
|
||||||
alphabet := common.AlphabetNodes()
|
alphabet := common.AlphabetNodes()
|
||||||
if !checkPermission(alphabet) {
|
if !checkPermission(alphabet) {
|
||||||
|
@ -134,7 +136,15 @@ func Emit() bool {
|
||||||
gas.Transfer(contractHash, proxyAddr, proxyGas, nil)
|
gas.Transfer(contractHash, proxyAddr, proxyGas, nil)
|
||||||
runtime.Log("utility token has been emitted to proxy contract")
|
runtime.Log("utility token has been emitted to proxy contract")
|
||||||
|
|
||||||
innerRing := common.InnerRingNodes()
|
var innerRing []common.IRNode
|
||||||
|
|
||||||
|
if notaryDisabled {
|
||||||
|
netmapContract := storage.Get(ctx, netmapKey).(interop.Hash160)
|
||||||
|
innerRing = common.InnerRingNodesFromNetmap(netmapContract)
|
||||||
|
} else {
|
||||||
|
innerRing = common.InnerRingNodes()
|
||||||
|
}
|
||||||
|
|
||||||
gasPerNode := gasBalance / 2 * 7 / 8 / len(innerRing)
|
gasPerNode := gasBalance / 2 * 7 / 8 / len(innerRing)
|
||||||
|
|
||||||
if gasPerNode != 0 {
|
if gasPerNode != 0 {
|
||||||
|
@ -150,14 +160,28 @@ func Emit() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Vote(epoch int, candidates []interop.PublicKey) {
|
func Vote(epoch int, candidates []interop.PublicKey) {
|
||||||
ctx := storage.GetReadOnlyContext()
|
ctx := storage.GetContext()
|
||||||
|
notaryDisabled := storage.Get(ctx, notaryDisabledKey).(bool)
|
||||||
index := index(ctx)
|
index := index(ctx)
|
||||||
name := name(ctx)
|
name := name(ctx)
|
||||||
|
|
||||||
|
var ( // for invocation collection without notary
|
||||||
|
alphabet []common.IRNode
|
||||||
|
nodeKey []byte
|
||||||
|
)
|
||||||
|
|
||||||
|
if notaryDisabled {
|
||||||
|
alphabet = common.AlphabetNodes()
|
||||||
|
nodeKey = common.InnerRingInvoker(alphabet)
|
||||||
|
if len(nodeKey) == 0 {
|
||||||
|
panic("invalid invoker")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
multiaddr := common.AlphabetAddress()
|
multiaddr := common.AlphabetAddress()
|
||||||
if !runtime.CheckWitness(multiaddr) {
|
if !runtime.CheckWitness(multiaddr) {
|
||||||
panic("invalid invoker")
|
panic("invalid invoker")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
curEpoch := currentEpoch(ctx)
|
curEpoch := currentEpoch(ctx)
|
||||||
if epoch != curEpoch {
|
if epoch != curEpoch {
|
||||||
|
@ -167,6 +191,18 @@ func Vote(epoch int, candidates []interop.PublicKey) {
|
||||||
candidate := candidates[index%len(candidates)]
|
candidate := candidates[index%len(candidates)]
|
||||||
address := runtime.GetExecutingScriptHash()
|
address := runtime.GetExecutingScriptHash()
|
||||||
|
|
||||||
|
if notaryDisabled {
|
||||||
|
threshold := len(alphabet)*2/3 + 1
|
||||||
|
id := voteID(epoch, candidates)
|
||||||
|
|
||||||
|
n := common.Vote(ctx, id, nodeKey)
|
||||||
|
if n < threshold {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
common.RemoveVotes(ctx, id)
|
||||||
|
}
|
||||||
|
|
||||||
ok := neo.Vote(address, candidate)
|
ok := neo.Vote(address, candidate)
|
||||||
if ok {
|
if ok {
|
||||||
runtime.Log(name + ": successfully voted for validator")
|
runtime.Log(name + ": successfully voted for validator")
|
||||||
|
@ -177,6 +213,21 @@ func Vote(epoch int, candidates []interop.PublicKey) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func voteID(epoch interface{}, args []interop.PublicKey) []byte {
|
||||||
|
var (
|
||||||
|
result []byte
|
||||||
|
epochBytes = epoch.([]byte)
|
||||||
|
)
|
||||||
|
|
||||||
|
result = append(result, epochBytes...)
|
||||||
|
|
||||||
|
for i := range args {
|
||||||
|
result = append(result, args[i]...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return crypto.Sha256(result)
|
||||||
|
}
|
||||||
|
|
||||||
func Name() string {
|
func Name() string {
|
||||||
ctx := storage.GetReadOnlyContext()
|
ctx := storage.GetReadOnlyContext()
|
||||||
return name(ctx)
|
return name(ctx)
|
||||||
|
|
Loading…
Reference in a new issue