[#74] netmap: Store inner ring node list when notary disabled

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-04-27 13:56:02 +03:00 committed by Alex Vanin
parent 622a83e014
commit 76aca4c6f5
2 changed files with 46 additions and 2 deletions

View file

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

View file

@ -35,6 +35,7 @@ const (
netmapKey = "netmap" netmapKey = "netmap"
configuredKey = "initconfig" configuredKey = "initconfig"
notaryDisabledKey = "notary" notaryDisabledKey = "notary"
innerRingKey = "innerring"
snapshot0Key = "snapshotCurrent" snapshot0Key = "snapshotCurrent"
snapshot1Key = "snapshotPrevious" snapshot1Key = "snapshotPrevious"
@ -58,7 +59,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(notaryDisabled bool, owner, addrBalance, addrContainer interop.Hash160) { func Init(notaryDisabled bool, owner, addrBalance, addrContainer interop.Hash160, keys []interop.PublicKey) {
ctx := storage.GetContext() ctx := storage.GetContext()
if !common.HasUpdateAccess(ctx) { if !common.HasUpdateAccess(ctx) {
@ -85,6 +86,14 @@ func Init(notaryDisabled bool, owner, addrBalance, addrContainer interop.Hash160
// initialize the way to collect signatures // initialize the way to collect signatures
storage.Put(ctx, notaryDisabledKey, notaryDisabled) storage.Put(ctx, notaryDisabledKey, notaryDisabled)
if notaryDisabled { if notaryDisabled {
var irList []common.IRNode
for i := 0; i < len(keys); i++ {
key := keys[i]
irList = append(irList, common.IRNode{PublicKey: key})
}
common.SetSerialized(ctx, innerRingKey, irList)
common.InitVote(ctx) common.InitVote(ctx)
} }
@ -105,6 +114,32 @@ func Migrate(script []byte, manifest []byte) bool {
return true return true
} }
func InnerRingList() []common.IRNode {
ctx := storage.GetReadOnlyContext()
return getIRNodes(ctx)
}
func UpdateInnerRing(keys []interop.PublicKey) bool {
ctx := storage.GetContext()
multiaddr := common.AlphabetAddress()
if !runtime.CheckWitness(multiaddr) {
panic("updateInnerRing: this method must be invoked by alpahbet 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()
@ -399,3 +434,12 @@ func cleanup(ctx storage.Context, epoch int) {
containerContractAddr := storage.Get(ctx, containerContractKey).(interop.Hash160) containerContractAddr := storage.Get(ctx, containerContractKey).(interop.Hash160)
contract.Call(containerContractAddr, cleanupEpochMethod, contract.All, epoch) contract.Call(containerContractAddr, cleanupEpochMethod, contract.All, epoch)
} }
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{}
}