[#100] netmap: Migrate netmap candidates storage

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-06-29 23:30:42 +03:00 committed by Alex Vanin
parent 0b04200815
commit c368eac796

View file

@ -33,7 +33,6 @@ type (
const ( const (
version = 1 version = 1
netmapKey = "netmap"
configuredKey = "initconfig" configuredKey = "initconfig"
notaryDisabledKey = "notary" notaryDisabledKey = "notary"
innerRingKey = "innerring" innerRingKey = "innerring"
@ -61,7 +60,10 @@ var (
// _deploy function sets up initial list of inner ring public keys. // _deploy function sets up initial list of inner ring public keys.
func _deploy(data interface{}, isUpdate bool) { func _deploy(data interface{}, isUpdate bool) {
ctx := storage.GetContext()
if isUpdate { if isUpdate {
migrateNetmapCandidates(ctx) // from v0.9.1 to v0.9.2
return return
} }
@ -72,8 +74,6 @@ func _deploy(data interface{}, isUpdate bool) {
addrContainer := args[3].(interop.Hash160) addrContainer := args[3].(interop.Hash160)
keys := args[4].([]interop.PublicKey) keys := args[4].([]interop.PublicKey)
ctx := storage.GetContext()
if !common.HasUpdateAccess(ctx) { if !common.HasUpdateAccess(ctx) {
panic("only owner can reinitialize contract") panic("only owner can reinitialize contract")
} }
@ -87,8 +87,6 @@ func _deploy(data interface{}, isUpdate bool) {
// 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)
// simplified: this used for const sysfee in AddPeer method
common.SetSerialized(ctx, netmapKey, []netmapNode{})
common.SetSerialized(ctx, snapshot0Key, []netmapNode{}) common.SetSerialized(ctx, snapshot0Key, []netmapNode{})
common.SetSerialized(ctx, snapshot1Key, []netmapNode{}) common.SetSerialized(ctx, snapshot1Key, []netmapNode{})
@ -113,6 +111,24 @@ func _deploy(data interface{}, isUpdate bool) {
runtime.Log("netmap contract initialized") runtime.Log("netmap contract initialized")
} }
func migrateNetmapCandidates(ctx storage.Context) {
const netmapKey = "netmap"
data := storage.Get(ctx, netmapKey)
if data == nil {
return
}
candidates := std.Deserialize(data.([]byte)).([]netmapNode)
for i := range candidates {
candidate := candidates[i]
addToNetmap(ctx, candidate.node)
}
storage.Delete(ctx, netmapKey)
}
func Migrate(script []byte, manifest []byte, data interface{}) bool { func Migrate(script []byte, manifest []byte, data interface{}) bool {
ctx := storage.GetReadOnlyContext() ctx := storage.GetReadOnlyContext()