[#186] *: Add `// V2 format` comment

Add `// V2 format` comment to V2 specific code
in contracts. In `subnet` contract change comment
to sync with other.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
enable-notary-in-public-chains
Pavel Karpy 2021-11-29 20:58:27 +03:00 committed by Alex Vanin
parent c7a02f0259
commit 4961e9b436
6 changed files with 35 additions and 19 deletions

View File

@ -24,6 +24,7 @@ type (
// epoch and container ID since we iterate over these values. But we can shrink
// public key by using first bytes of the hashed value.
// V2 format
const maxKeySize = 24 // 24 + 32 (container ID length) + 8 (epoch length) = 64
func (a auditHeader) ID() []byte {
@ -211,6 +212,7 @@ func readNext(input []byte) ([]byte, int) {
}
func newAuditHeader(input []byte) auditHeader {
// V2 format
offset := int(input[1])
offset = 2 + offset + 1 // version prefix + version len + epoch prefix

View File

@ -9,6 +9,7 @@ var (
)
func WalletToScriptHash(wallet []byte) []byte {
// V2 format
return wallet[1 : len(wallet)-4]
}

View File

@ -56,6 +56,7 @@ const (
// AliasFeeKey is a key in netmap config which contains fee for nice-name registration.
AliasFeeKey = "ContainerAliasFee"
// V2 format
containerIDSize = 32 // SHA256 size
estimateKeyPrefix = "cnr"
@ -414,6 +415,7 @@ func SetEACL(eACL []byte, signature interop.Signature, publicKey interop.PublicK
ctx := storage.GetContext()
notaryDisabled := storage.Get(ctx, notaryDisabledKey).(bool)
// V2 format
// get container ID
offset := int(eACL[1])
offset = 2 + offset + 4
@ -520,6 +522,7 @@ func PutContainerSize(epoch int, cid []byte, usedSize int, pubKey interop.Public
func GetContainerSize(id []byte) containerSizes {
ctx := storage.GetReadOnlyContext()
// V2 format
// this `id` expected to be from `ListContainerSizes`
// therefore it is not contains postfix, we ignore it in the cut.
ln := len(id)
@ -693,6 +696,7 @@ func getAllContainers(ctx storage.Context) [][]byte {
it := storage.Find(ctx, []byte{}, storage.KeysOnly)
for iterator.Next(it) {
key := iterator.Value(it).([]byte) // it MUST BE `storage.KeysOnly`
// V2 format
if len(key) == containerIDSize {
list = append(list, key)
}
@ -730,6 +734,7 @@ func getOwnerByID(ctx storage.Context, cid []byte) []byte {
}
func ownerFromBinaryContainer(container []byte) []byte {
// V2 format
offset := int(container[1])
offset = 2 + offset + 4 // version prefix + version size + owner prefix
return container[offset : offset+25] // offset + size of owner
@ -770,6 +775,7 @@ func isStorageNode(ctx storage.Context, key interop.PublicKey) bool {
snapshot := contract.Call(netmapContractAddr, "snapshot", contract.ReadOnly, 1).([]storageNode)
for i := range snapshot {
// V2 format
nodeInfo := snapshot[i].info
nodeKey := nodeInfo[2:35] // offset:2, len:33
@ -787,6 +793,7 @@ func keysToDelete(ctx storage.Context, epoch int) [][]byte {
it := storage.Find(ctx, []byte(estimateKeyPrefix), storage.KeysOnly)
for iterator.Next(it) {
k := iterator.Value(it).([]byte)
// V2 format
nbytes := k[len(estimateKeyPrefix) : len(k)-containerIDSize-estimatePostfixSize]
var n interface{} = nbytes

View File

@ -32,6 +32,7 @@ func _deploy(data interface{}, isUpdate bool) {
it := storage.Find(ctx, []byte{}, storage.None)
for iterator.Next(it) {
kv := iterator.Value(it).([][]byte)
// V2 format
if len(kv[0]) == 25 {
info := std.Deserialize(kv[1]).(UserInfo)
key := append([]byte{ownerKeysPrefix}, kv[0]...)
@ -84,6 +85,7 @@ func Update(script []byte, manifest []byte, data interface{}) {
// This method panics if OwnerID is not 25 byte or public key is not 33 byte long.
// If key is already bound, ignores it.
func AddKey(owner []byte, keys []interop.PublicKey) {
// V2 format
if len(owner) != 25 {
panic("addKey: incorrect owner")
}
@ -149,6 +151,7 @@ func AddKey(owner []byte, keys []interop.PublicKey) {
// This method panics if OwnerID is not 25 byte or public key is not 33 byte long.
// If key is already unbound, ignores it.
func RemoveKey(owner []byte, keys []interop.PublicKey) {
// V2 format
if len(owner) != 25 {
panic("removeKey: incorrect owner")
}
@ -203,6 +206,7 @@ func RemoveKey(owner []byte, keys []interop.PublicKey) {
//
// This method panics if owner is not 25 byte long.
func Key(owner []byte) [][]byte {
// V2 format
if len(owner) != 25 {
panic("key: incorrect owner")
}

View File

@ -47,6 +47,7 @@ const (
)
const (
// V2 format
_ nodeState = iota
onlineState
offlineState
@ -215,6 +216,7 @@ func AddPeer(nodeInfo []byte) {
}
if !alphabetCall {
// V2 format
publicKey := nodeInfo[2:35] // offset:2, len:33
if !runtime.CheckWitness(publicKey) {
panic("addPeer: witness check failed")

View File

@ -84,7 +84,7 @@ func Update(script []byte, manifest []byte, data interface{}) {
// Put creates new subnet with the specified owner and info.
func Put(id []byte, ownerKey interop.PublicKey, info []byte) {
// V2 format check
// V2 format
if len(id) != subnetIDSize {
panic("put: " + ErrInvalidSubnetID)
}
@ -136,7 +136,7 @@ func Put(id []byte, ownerKey interop.PublicKey, info []byte) {
// Get returns info about subnet with the specified id.
func Get(id []byte) []byte {
// V2 format check
// V2 format
if len(id) != subnetIDSize {
panic("get: " + ErrInvalidSubnetID)
}
@ -152,7 +152,7 @@ func Get(id []byte) []byte {
// Delete deletes subnet with the specified id.
func Delete(id []byte) {
// V2 format check
// V2 format
if len(id) != subnetIDSize {
panic("delete: " + ErrInvalidSubnetID)
}
@ -191,7 +191,7 @@ func Delete(id []byte) {
// AddNodeAdmin adds new node administrator to the specified subnetwork.
func AddNodeAdmin(subnetID []byte, adminKey interop.PublicKey) {
// V2 format check
// V2 format
if len(subnetID) != subnetIDSize {
panic("addNodeAdmin: " + ErrInvalidSubnetID)
}
@ -226,7 +226,7 @@ func AddNodeAdmin(subnetID []byte, adminKey interop.PublicKey) {
// RemoveNodeAdmin removes node administrator from the specified subnetwork.
// Must be called by subnet owner only.
func RemoveNodeAdmin(subnetID []byte, adminKey interop.PublicKey) {
// V2 format check
// V2 format
if len(subnetID) != subnetIDSize {
panic("removeNodeAdmin: " + ErrInvalidSubnetID)
}
@ -262,7 +262,7 @@ func RemoveNodeAdmin(subnetID []byte, adminKey interop.PublicKey) {
// Must be called by subnet's owner or node administrator
// only.
func AddNode(subnetID []byte, node interop.PublicKey) {
// V2 format check
// V2 format
if len(subnetID) != subnetIDSize {
panic("addNode: " + ErrInvalidSubnetID)
}
@ -301,7 +301,7 @@ func AddNode(subnetID []byte, node interop.PublicKey) {
// Must be called by subnet's owner or node administrator
// only.
func RemoveNode(subnetID []byte, node interop.PublicKey) {
// V2 format check
// V2 format
if len(subnetID) != subnetIDSize {
panic("removeNode: " + ErrInvalidSubnetID)
}
@ -341,7 +341,7 @@ func RemoveNode(subnetID []byte, node interop.PublicKey) {
// NodeAllowed checks if node is included in the
// specified subnet or not.
func NodeAllowed(subnetID []byte, node interop.PublicKey) bool {
// V2 format check
// V2 format
if len(subnetID) != subnetIDSize {
panic("nodeAllowed: " + ErrInvalidSubnetID)
}
@ -367,12 +367,12 @@ func NodeAllowed(subnetID []byte, node interop.PublicKey) bool {
// AddClientAdmin adds new client administrator of the specified group in the specified subnetwork.
// Must be called by owner only.
func AddClientAdmin(subnetID []byte, groupID []byte, adminPublicKey interop.PublicKey) {
// V2 format check
// V2 format
if len(subnetID) != subnetIDSize {
panic("addClientAdmin: " + ErrInvalidSubnetID)
}
// V2 format check
// V2 format
if len(groupID) != groupIDSize {
panic("addClientAdmin: " + ErrInvalidGroupID)
}
@ -409,12 +409,12 @@ func AddClientAdmin(subnetID []byte, groupID []byte, adminPublicKey interop.Publ
// specified group in the specified subnetwork.
// Must be called by owner only.
func RemoveClientAdmin(subnetID []byte, groupID []byte, adminPublicKey interop.PublicKey) {
// V2 format check
// V2 format
if len(subnetID) != subnetIDSize {
panic("removeClientAdmin: " + ErrInvalidSubnetID)
}
// V2 format check
// V2 format
if len(groupID) != groupIDSize {
panic("removeClientAdmin: " + ErrInvalidGroupID)
}
@ -450,17 +450,17 @@ func RemoveClientAdmin(subnetID []byte, groupID []byte, adminPublicKey interop.P
// AddUser adds user to the specified subnetwork and group.
// Must be called by the owner or the group's admin only.
func AddUser(subnetID []byte, groupID []byte, userID []byte) {
// V2 format check
// V2 format
if len(subnetID) != subnetIDSize {
panic("addUser: " + ErrInvalidSubnetID)
}
// V2 format check
// V2 format
if len(userID) != userIDSize {
panic("addUser: " + ErrInvalidUser)
}
// V2 format check
// V2 format
if len(groupID) != groupIDSize {
panic("addUser: " + ErrInvalidGroupID)
}
@ -495,17 +495,17 @@ func AddUser(subnetID []byte, groupID []byte, userID []byte) {
// RemoveUser removes user from the specified subnetwork and group.
// Must be called by the owner or the group's admin only.
func RemoveUser(subnetID []byte, groupID []byte, userID []byte) {
// V2 format check
// V2 format
if len(subnetID) != subnetIDSize {
panic("removeUser: " + ErrInvalidSubnetID)
}
// V2 format check
// V2 format
if len(groupID) != groupIDSize {
panic("removeUser: " + ErrInvalidGroupID)
}
// V2 format check
// V2 format
if len(userID) != userIDSize {
panic("addUser: " + ErrInvalidUser)
}
@ -540,7 +540,7 @@ func RemoveUser(subnetID []byte, groupID []byte, userID []byte) {
// UserAllowed returns bool that indicates if node is included in the
// specified subnet or not.
func UserAllowed(subnetID []byte, user []byte) bool {
// V2 format check
// V2 format
if len(subnetID) != subnetIDSize {
panic("userAllowed: " + ErrInvalidSubnetID)
}