[#58] netmap: Use alphabet list from chain

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-03-24 11:16:17 +03:00 committed by Alex Vanin
parent 24fe1573c1
commit 7cb7b0905b
2 changed files with 6 additions and 76 deletions

View file

@ -1,5 +1,5 @@
name: "NeoFS Netmap" name: "NeoFS Netmap"
safemethods: ["innerRingList", "multiaddress", "committee", "epoch", "netmap", "snapshot", "snapshotByEpoch", "config", "listConfig", "version"] safemethods: ["epoch", "netmap", "snapshot", "snapshotByEpoch", "config", "listConfig", "version"]
events: events:
- name: AddPeer - name: AddPeer
parameters: parameters:

View file

@ -33,7 +33,6 @@ const (
version = 1 version = 1
netmapKey = "netmap" netmapKey = "netmap"
innerRingKey = "innerring"
configuredKey = "initconfig" configuredKey = "initconfig"
snapshot0Key = "snapshotCurrent" snapshot0Key = "snapshotCurrent"
@ -57,7 +56,7 @@ var (
// Init function sets up initial list of inner ring public keys and should // Init function sets up initial list of inner ring public keys and should
// be invoked once at neofs infrastructure setup. // be invoked once at neofs infrastructure setup.
func Init(owner, addrBalance, addrContainer interop.Hash160, keys []interop.PublicKey) { func Init(owner, addrBalance, addrContainer interop.Hash160) {
ctx := storage.GetContext() ctx := storage.GetContext()
if !common.HasUpdateAccess(ctx) { if !common.HasUpdateAccess(ctx) {
@ -68,17 +67,8 @@ func Init(owner, addrBalance, addrContainer interop.Hash160, keys []interop.Publ
panic("init: incorrect length of contract script hash") panic("init: incorrect length of contract script hash")
} }
var irList []common.IRNode
for i := 0; i < len(keys); i++ {
key := keys[i]
irList = append(irList, common.IRNode{PublicKey: key})
}
storage.Put(ctx, common.OwnerKey, owner) storage.Put(ctx, common.OwnerKey, owner)
common.SetSerialized(ctx, innerRingKey, irList)
// epoch number is a little endian int, it doesn't need to be serialized // epoch number is a little endian int, it doesn't need to be serialized
storage.Put(ctx, snapshotEpoch, 0) storage.Put(ctx, snapshotEpoch, 0)
@ -107,46 +97,10 @@ func Migrate(script []byte, manifest []byte) bool {
return true return true
} }
func InnerRingList() []common.IRNode {
ctx := storage.GetReadOnlyContext()
return getIRNodes(ctx)
}
func Multiaddress() []byte {
ctx := storage.GetReadOnlyContext()
return multiaddress(getIRNodes(ctx), false)
}
func Committee() []byte {
ctx := storage.GetReadOnlyContext()
return multiaddress(getIRNodes(ctx), true)
}
func UpdateInnerRing(keys []interop.PublicKey) bool {
ctx := storage.GetContext()
multiaddr := Multiaddress()
if !runtime.CheckWitness(multiaddr) {
panic("updateInnerRing: this method must be invoked by inner ring nodes")
}
var irList []common.IRNode
for i := 0; i < len(keys); i++ {
key := keys[i]
irList = append(irList, common.IRNode{PublicKey: key})
}
runtime.Log("updateInnerRing: inner ring list updated")
common.SetSerialized(ctx, innerRingKey, irList)
return true
}
func AddPeer(nodeInfo []byte) bool { func AddPeer(nodeInfo []byte) bool {
ctx := storage.GetContext() ctx := storage.GetContext()
multiaddr := Multiaddress() multiaddr := common.AlphabetAddress()
if !runtime.CheckWitness(multiaddr) { if !runtime.CheckWitness(multiaddr) {
publicKey := nodeInfo[2:35] // offset:2, len:33 publicKey := nodeInfo[2:35] // offset:2, len:33
if !runtime.CheckWitness(publicKey) { if !runtime.CheckWitness(publicKey) {
@ -179,7 +133,7 @@ func UpdateState(state int, publicKey interop.PublicKey) bool {
ctx := storage.GetContext() ctx := storage.GetContext()
multiaddr := Multiaddress() multiaddr := common.AlphabetAddress()
if !runtime.CheckWitness(multiaddr) { if !runtime.CheckWitness(multiaddr) {
if !runtime.CheckWitness(publicKey) { if !runtime.CheckWitness(publicKey) {
panic("updateState: witness check failed") panic("updateState: witness check failed")
@ -205,7 +159,7 @@ func UpdateState(state int, publicKey interop.PublicKey) bool {
func NewEpoch(epochNum int) bool { func NewEpoch(epochNum int) bool {
ctx := storage.GetContext() ctx := storage.GetContext()
multiaddr := Multiaddress() multiaddr := common.AlphabetAddress()
if !runtime.CheckWitness(multiaddr) { if !runtime.CheckWitness(multiaddr) {
panic("newEpoch: this method must be invoked by inner ring nodes") panic("newEpoch: this method must be invoked by inner ring nodes")
} }
@ -276,7 +230,7 @@ func Config(key []byte) interface{} {
} }
func SetConfig(id, key, val []byte) bool { func SetConfig(id, key, val []byte) bool {
multiaddr := Multiaddress() multiaddr := common.AlphabetAddress()
if !runtime.CheckWitness(multiaddr) { if !runtime.CheckWitness(multiaddr) {
panic("setConfig: invoked by non inner ring node") panic("setConfig: invoked by non inner ring node")
} }
@ -398,15 +352,6 @@ func filterNetmap(ctx storage.Context, st nodeState) []storageNode {
return result return result
} }
func getIRNodes(ctx storage.Context) []common.IRNode {
data := storage.Get(ctx, innerRingKey)
if data != nil {
return std.Deserialize(data.([]byte)).([]common.IRNode)
}
return []common.IRNode{}
}
func getNetmapNodes(ctx storage.Context) []netmapNode { func getNetmapNodes(ctx storage.Context) []netmapNode {
data := storage.Get(ctx, netmapKey) data := storage.Get(ctx, netmapKey)
if data != nil { if data != nil {
@ -439,21 +384,6 @@ func setConfig(ctx storage.Context, key, val interface{}) {
storage.Put(ctx, storageKey, val) storage.Put(ctx, storageKey, val)
} }
func multiaddress(n []common.IRNode, committee bool) []byte {
threshold := len(n)/3*2 + 1
if committee {
threshold = len(n)/2 + 1
}
keys := []interop.PublicKey{}
for _, node := range n {
key := node.PublicKey
keys = append(keys, key)
}
return contract.CreateMultisigAccount(threshold, keys)
}
func cleanup(ctx storage.Context, epoch int) { func cleanup(ctx storage.Context, epoch int) {
balanceContractAddr := storage.Get(ctx, balanceContractKey).(interop.Hash160) balanceContractAddr := storage.Get(ctx, balanceContractKey).(interop.Hash160)
contract.Call(balanceContractAddr, cleanupEpochMethod, contract.All, epoch) contract.Call(balanceContractAddr, cleanupEpochMethod, contract.All, epoch)