Skip to content

Commit

Permalink
Perform switchToNotary actions only for versions earlier than v0.17.0
Browse files Browse the repository at this point in the history
Signed-off-by: Leonard Lyubich <ctulhurider@gmail.com>
  • Loading branch information
cthulhu-rider committed Feb 13, 2023
1 parent 77026aa commit f47058c
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 56 deletions.
12 changes: 10 additions & 2 deletions alphabet/alphabet_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,17 @@ func _deploy(data interface{}, isUpdate bool) {
ctx := storage.GetContext()
if isUpdate {
args := data.([]interface{})
common.CheckVersion(args[len(args)-1].(int))
version := args[len(args)-1].(int)

switchToNotary(ctx, args)
common.CheckVersion(version)

// switch to notary mode if version of the current contract deployment is
// earlier than v0.17.0 (initial version when non-notary mode was taken out of
// use)
// TODO: avoid number magic, add function for version comparison to common package
if version < 17_000 {
switchToNotary(ctx, args)
}

return
}
Expand Down
16 changes: 12 additions & 4 deletions audit/audit_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,17 @@ func _deploy(data interface{}, isUpdate bool) {
ctx := storage.GetContext()
if isUpdate {
args := data.([]interface{})
common.CheckVersion(args[len(args)-1].(int))
version := args[len(args)-1].(int)

switchToNotary(ctx, args)
common.CheckVersion(version)

// switch to notary mode if version of the current contract deployment is
// earlier than v0.17.0 (initial version when non-notary mode was taken out of
// use)
// TODO: avoid number magic, add function for version comparison to common package
if version < 17_000 {
switchToNotary(ctx)
}

return
}
Expand All @@ -62,10 +70,10 @@ func _deploy(data interface{}, isUpdate bool) {

// re-initializes contract from non-notary to notary mode. Does nothing if
// action has already been done. The function is called on contract update with
// storage.Context and parameters from _deploy.
// storage.Context from _deploy.
//
// switchToNotary removes values stored by 'netmapScriptHash' and 'notary' keys.
func switchToNotary(ctx storage.Context, args []interface{}) {
func switchToNotary(ctx storage.Context) {
const notaryDisabledKey = "notary" // non-notary legacy

notaryVal := storage.Get(ctx, notaryDisabledKey)
Expand Down
16 changes: 12 additions & 4 deletions balance/balance_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,17 @@ func _deploy(data interface{}, isUpdate bool) {
ctx := storage.GetContext()
if isUpdate {
args := data.([]interface{})
common.CheckVersion(args[len(args)-1].(int))
version := args[len(args)-1].(int)

switchToNotary(ctx, args)
common.CheckVersion(version)

// switch to notary mode if version of the current contract deployment is
// earlier than v0.17.0 (initial version when non-notary mode was taken out of
// use)
// TODO: avoid number magic, add function for version comparison to common package
if version < 17_000 {
switchToNotary(ctx)
}

return
}
Expand All @@ -80,14 +88,14 @@ func _deploy(data interface{}, isUpdate bool) {

// re-initializes contract from non-notary to notary mode. Does nothing if
// action has already been done. The function is called on contract update with
// storage.Context and parameters from _deploy.
// storage.Context from _deploy.
//
// If contract stores non-empty value by 'ballots' key, switchToNotary panics.
// Otherwise, existing value is removed.
//
// switchToNotary removes values stored by 'netmapScriptHash',
// 'containerScriptHash' and 'notary' keys.
func switchToNotary(ctx storage.Context, args []interface{}) {
func switchToNotary(ctx storage.Context) {
const notaryDisabledKey = "notary" // non-notary legacy

notaryVal := storage.Get(ctx, notaryDisabledKey)
Expand Down
15 changes: 11 additions & 4 deletions container/container_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ func _deploy(data interface{}, isUpdate bool) {
ctx := storage.GetContext()
if isUpdate {
args := data.([]interface{})
common.CheckVersion(args[len(args)-1].(int))
version := args[len(args)-1].(int)
common.CheckVersion(version)

it := storage.Find(ctx, []byte{}, storage.None)
for iterator.Next(it) {
Expand All @@ -123,7 +124,13 @@ func _deploy(data interface{}, isUpdate bool) {
}
}

switchToNotary(ctx, args)
// switch to notary mode if version of the current contract deployment is
// earlier than v0.17.0 (initial version when non-notary mode was taken out of
// use)
// TODO: avoid number magic, add function for version comparison to common package
if version < 17_000 {
switchToNotary(ctx)
}

return
}
Expand Down Expand Up @@ -161,13 +168,13 @@ func _deploy(data interface{}, isUpdate bool) {

// re-initializes contract from non-notary to notary mode. Does nothing if
// action has already been done. The function is called on contract update with
// storage.Context and parameters from _deploy.
// storage.Context from _deploy.
//
// If contract stores non-empty value by 'ballots' key, switchToNotary panics.
// Otherwise, existing value is removed.
//
// switchToNotary removes value stored by 'notary' key.
func switchToNotary(ctx storage.Context, args []interface{}) {
func switchToNotary(ctx storage.Context) {
const notaryDisabledKey = "notary" // non-notary legacy

notaryVal := storage.Get(ctx, notaryDisabledKey)
Expand Down
16 changes: 12 additions & 4 deletions neofsid/neofsid_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,17 @@ func _deploy(data interface{}, isUpdate bool) {

if isUpdate {
args := data.([]interface{})
common.CheckVersion(args[len(args)-1].(int))
version := args[len(args)-1].(int)

switchToNotary(ctx, args)
common.CheckVersion(version)

// switch to notary mode if version of the current contract deployment is
// earlier than v0.17.0 (initial version when non-notary mode was taken out of
// use)
// TODO: avoid number magic, add function for version comparison to common package
if version < 17_000 {
switchToNotary(ctx)
}

return
}
Expand All @@ -60,14 +68,14 @@ func _deploy(data interface{}, isUpdate bool) {

// re-initializes contract from non-notary to notary mode. Does nothing if
// action has already been done. The function is called on contract update with
// storage.Context and parameters from _deploy.
// storage.Context from _deploy.
//
// If contract stores non-empty value by 'ballots' key, switchToNotary panics.
// Otherwise, existing value is removed.
//
// switchToNotary removes values stored by 'containerScriptHash' and 'notary'
// keys.
func switchToNotary(ctx storage.Context, args []interface{}) {
func switchToNotary(ctx storage.Context) {
const notaryDisabledKey = "notary" // non-notary legacy

notaryVal := storage.Get(ctx, notaryDisabledKey)
Expand Down
66 changes: 36 additions & 30 deletions netmap/netmap_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,39 +121,45 @@ func _deploy(data interface{}, isUpdate bool) {
if isUpdate {
common.CheckVersion(args.version)

if args.version >= 16*1_000 { // 0.16.0+ already have appropriate format
return
}
if args.version < 16*1_000 {
count := getSnapshotCount(ctx)
prefix := []byte(snapshotKeyPrefix)
for i := 0; i < count; i++ {
key := append(prefix, byte(i))
data := storage.Get(ctx, key)
if data != nil {
nodes := std.Deserialize(data.([]byte)).([]oldNode)
var newnodes []Node
for j := range nodes {
// Old structure contains only the first field,
// second is implicitly assumed to be Online.
newnodes = append(newnodes, Node{
BLOB: nodes[j].BLOB,
State: NodeStateOnline,
})
}
common.SetSerialized(ctx, key, newnodes)
}
}

count := getSnapshotCount(ctx)
prefix := []byte(snapshotKeyPrefix)
for i := 0; i < count; i++ {
key := append(prefix, byte(i))
data := storage.Get(ctx, key)
if data != nil {
nodes := std.Deserialize(data.([]byte)).([]oldNode)
var newnodes []Node
for j := range nodes {
// Old structure contains only the first field,
// second is implicitly assumed to be Online.
newnodes = append(newnodes, Node{
BLOB: nodes[j].BLOB,
State: NodeStateOnline,
})
it := storage.Find(ctx, candidatePrefix, storage.None)
for iterator.Next(it) {
cand := iterator.Value(it).(kv)
oldcan := std.Deserialize(cand.v).(oldCandidate)
newcan := Node{
BLOB: oldcan.f1.BLOB,
State: oldcan.f2,
}
common.SetSerialized(ctx, key, newnodes)
common.SetSerialized(ctx, cand.k, newcan)
}
}

it := storage.Find(ctx, candidatePrefix, storage.None)
for iterator.Next(it) {
cand := iterator.Value(it).(kv)
oldcan := std.Deserialize(cand.v).(oldCandidate)
newcan := Node{
BLOB: oldcan.f1.BLOB,
State: oldcan.f2,
}
common.SetSerialized(ctx, cand.k, newcan)
// switch to notary mode if version of the current contract deployment is
// earlier than v0.17.0 (initial version when non-notary mode was taken out of
// use)
// TODO: avoid number magic, add function for version comparison to common package
if args.version < 17_000 {
switchToNotary(ctx)
}

return
Expand Down Expand Up @@ -182,13 +188,13 @@ func _deploy(data interface{}, isUpdate bool) {

// re-initializes contract from non-notary to notary mode. Does nothing if
// action has already been done. The function is called on contract update with
// storage.Context and parameters from _deploy.
// storage.Context from _deploy.
//
// If contract stores non-empty value by 'ballots' key, switchToNotary panics.
// Otherwise, existing value is removed.
//
// switchToNotary removes values stored by 'innerring' and 'notary' keys.
func switchToNotary(ctx storage.Context, args []interface{}) {
func switchToNotary(ctx storage.Context) {
const notaryDisabledKey = "notary" // non-notary legacy

notaryVal := storage.Get(ctx, notaryDisabledKey)
Expand Down
16 changes: 12 additions & 4 deletions reputation/reputation_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,17 @@ func _deploy(data interface{}, isUpdate bool) {

if isUpdate {
args := data.([]interface{})
common.CheckVersion(args[len(args)-1].(int))
version := args[len(args)-1].(int)

switchToNotary(ctx, args)
common.CheckVersion(version)

// switch to notary mode if version of the current contract deployment is
// earlier than v0.17.0 (initial version when non-notary mode was taken out of
// use)
// TODO: avoid number magic, add function for version comparison to common package
if version < 17_000 {
switchToNotary(ctx)
}

return
}
Expand All @@ -42,13 +50,13 @@ func _deploy(data interface{}, isUpdate bool) {

// re-initializes contract from non-notary to notary mode. Does nothing if
// action has already been done. The function is called on contract update with
// storage.Context and parameters from _deploy.
// storage.Context from _deploy.
//
// If contract stores non-empty value by 'ballots' key, switchToNotary panics.
// Otherwise, existing value is removed.
//
// switchToNotary removes value stored by 'notary' key.
func switchToNotary(ctx storage.Context, args []interface{}) {
func switchToNotary(ctx storage.Context) {
const notaryDisabledKey = "notary" // non-notary legacy

notaryVal := storage.Get(ctx, notaryDisabledKey)
Expand Down
16 changes: 12 additions & 4 deletions subnet/subnet_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,17 @@ const (
func _deploy(data interface{}, isUpdate bool) {
if isUpdate {
args := data.([]interface{})
common.CheckVersion(args[len(args)-1].(int))
version := args[len(args)-1].(int)

switchToNotary(storage.GetContext(), args)
common.CheckVersion(version)

// switch to notary mode if version of the current contract deployment is
// earlier than v0.17.0 (initial version when non-notary mode was taken out of
// use)
// TODO: avoid number magic, add function for version comparison to common package
if version < 17_000 {
switchToNotary(storage.GetContext())
}

return
}
Expand All @@ -77,13 +85,13 @@ func _deploy(data interface{}, isUpdate bool) {

// re-initializes contract from non-notary to notary mode. Does nothing if
// action has already been done. The function is called on contract update with
// storage.Context and parameters from _deploy.
// storage.Context from _deploy.
//
// If contract stores non-empty value by 'ballots' key, switchToNotary panics.
// Otherwise, existing value is removed.
//
// switchToNotary removes value stored by 'notary' key.
func switchToNotary(ctx storage.Context, args []interface{}) {
func switchToNotary(ctx storage.Context) {
const notaryDisabledKey = "notary" // non-notary legacy

notaryVal := storage.Get(ctx, notaryDisabledKey)
Expand Down

0 comments on commit f47058c

Please sign in to comment.