forked from TrueCloudLab/frostfs-contract
[#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>
This commit is contained in:
parent
c7a02f0259
commit
4961e9b436
6 changed files with 35 additions and 19 deletions
|
@ -24,6 +24,7 @@ type (
|
||||||
// epoch and container ID since we iterate over these values. But we can shrink
|
// epoch and container ID since we iterate over these values. But we can shrink
|
||||||
// public key by using first bytes of the hashed value.
|
// public key by using first bytes of the hashed value.
|
||||||
|
|
||||||
|
// V2 format
|
||||||
const maxKeySize = 24 // 24 + 32 (container ID length) + 8 (epoch length) = 64
|
const maxKeySize = 24 // 24 + 32 (container ID length) + 8 (epoch length) = 64
|
||||||
|
|
||||||
func (a auditHeader) ID() []byte {
|
func (a auditHeader) ID() []byte {
|
||||||
|
@ -211,6 +212,7 @@ func readNext(input []byte) ([]byte, int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func newAuditHeader(input []byte) auditHeader {
|
func newAuditHeader(input []byte) auditHeader {
|
||||||
|
// V2 format
|
||||||
offset := int(input[1])
|
offset := int(input[1])
|
||||||
offset = 2 + offset + 1 // version prefix + version len + epoch prefix
|
offset = 2 + offset + 1 // version prefix + version len + epoch prefix
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func WalletToScriptHash(wallet []byte) []byte {
|
func WalletToScriptHash(wallet []byte) []byte {
|
||||||
|
// V2 format
|
||||||
return wallet[1 : len(wallet)-4]
|
return wallet[1 : len(wallet)-4]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,7 @@ const (
|
||||||
// AliasFeeKey is a key in netmap config which contains fee for nice-name registration.
|
// AliasFeeKey is a key in netmap config which contains fee for nice-name registration.
|
||||||
AliasFeeKey = "ContainerAliasFee"
|
AliasFeeKey = "ContainerAliasFee"
|
||||||
|
|
||||||
|
// V2 format
|
||||||
containerIDSize = 32 // SHA256 size
|
containerIDSize = 32 // SHA256 size
|
||||||
|
|
||||||
estimateKeyPrefix = "cnr"
|
estimateKeyPrefix = "cnr"
|
||||||
|
@ -414,6 +415,7 @@ func SetEACL(eACL []byte, signature interop.Signature, publicKey interop.PublicK
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
notaryDisabled := storage.Get(ctx, notaryDisabledKey).(bool)
|
notaryDisabled := storage.Get(ctx, notaryDisabledKey).(bool)
|
||||||
|
|
||||||
|
// V2 format
|
||||||
// get container ID
|
// get container ID
|
||||||
offset := int(eACL[1])
|
offset := int(eACL[1])
|
||||||
offset = 2 + offset + 4
|
offset = 2 + offset + 4
|
||||||
|
@ -520,6 +522,7 @@ func PutContainerSize(epoch int, cid []byte, usedSize int, pubKey interop.Public
|
||||||
func GetContainerSize(id []byte) containerSizes {
|
func GetContainerSize(id []byte) containerSizes {
|
||||||
ctx := storage.GetReadOnlyContext()
|
ctx := storage.GetReadOnlyContext()
|
||||||
|
|
||||||
|
// V2 format
|
||||||
// this `id` expected to be from `ListContainerSizes`
|
// this `id` expected to be from `ListContainerSizes`
|
||||||
// therefore it is not contains postfix, we ignore it in the cut.
|
// therefore it is not contains postfix, we ignore it in the cut.
|
||||||
ln := len(id)
|
ln := len(id)
|
||||||
|
@ -693,6 +696,7 @@ func getAllContainers(ctx storage.Context) [][]byte {
|
||||||
it := storage.Find(ctx, []byte{}, storage.KeysOnly)
|
it := storage.Find(ctx, []byte{}, storage.KeysOnly)
|
||||||
for iterator.Next(it) {
|
for iterator.Next(it) {
|
||||||
key := iterator.Value(it).([]byte) // it MUST BE `storage.KeysOnly`
|
key := iterator.Value(it).([]byte) // it MUST BE `storage.KeysOnly`
|
||||||
|
// V2 format
|
||||||
if len(key) == containerIDSize {
|
if len(key) == containerIDSize {
|
||||||
list = append(list, key)
|
list = append(list, key)
|
||||||
}
|
}
|
||||||
|
@ -730,6 +734,7 @@ func getOwnerByID(ctx storage.Context, cid []byte) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ownerFromBinaryContainer(container []byte) []byte {
|
func ownerFromBinaryContainer(container []byte) []byte {
|
||||||
|
// V2 format
|
||||||
offset := int(container[1])
|
offset := int(container[1])
|
||||||
offset = 2 + offset + 4 // version prefix + version size + owner prefix
|
offset = 2 + offset + 4 // version prefix + version size + owner prefix
|
||||||
return container[offset : offset+25] // offset + size of owner
|
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)
|
snapshot := contract.Call(netmapContractAddr, "snapshot", contract.ReadOnly, 1).([]storageNode)
|
||||||
|
|
||||||
for i := range snapshot {
|
for i := range snapshot {
|
||||||
|
// V2 format
|
||||||
nodeInfo := snapshot[i].info
|
nodeInfo := snapshot[i].info
|
||||||
nodeKey := nodeInfo[2:35] // offset:2, len:33
|
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)
|
it := storage.Find(ctx, []byte(estimateKeyPrefix), storage.KeysOnly)
|
||||||
for iterator.Next(it) {
|
for iterator.Next(it) {
|
||||||
k := iterator.Value(it).([]byte)
|
k := iterator.Value(it).([]byte)
|
||||||
|
// V2 format
|
||||||
nbytes := k[len(estimateKeyPrefix) : len(k)-containerIDSize-estimatePostfixSize]
|
nbytes := k[len(estimateKeyPrefix) : len(k)-containerIDSize-estimatePostfixSize]
|
||||||
|
|
||||||
var n interface{} = nbytes
|
var n interface{} = nbytes
|
||||||
|
|
|
@ -32,6 +32,7 @@ func _deploy(data interface{}, isUpdate bool) {
|
||||||
it := storage.Find(ctx, []byte{}, storage.None)
|
it := storage.Find(ctx, []byte{}, storage.None)
|
||||||
for iterator.Next(it) {
|
for iterator.Next(it) {
|
||||||
kv := iterator.Value(it).([][]byte)
|
kv := iterator.Value(it).([][]byte)
|
||||||
|
// V2 format
|
||||||
if len(kv[0]) == 25 {
|
if len(kv[0]) == 25 {
|
||||||
info := std.Deserialize(kv[1]).(UserInfo)
|
info := std.Deserialize(kv[1]).(UserInfo)
|
||||||
key := append([]byte{ownerKeysPrefix}, kv[0]...)
|
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.
|
// This method panics if OwnerID is not 25 byte or public key is not 33 byte long.
|
||||||
// If key is already bound, ignores it.
|
// If key is already bound, ignores it.
|
||||||
func AddKey(owner []byte, keys []interop.PublicKey) {
|
func AddKey(owner []byte, keys []interop.PublicKey) {
|
||||||
|
// V2 format
|
||||||
if len(owner) != 25 {
|
if len(owner) != 25 {
|
||||||
panic("addKey: incorrect owner")
|
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.
|
// This method panics if OwnerID is not 25 byte or public key is not 33 byte long.
|
||||||
// If key is already unbound, ignores it.
|
// If key is already unbound, ignores it.
|
||||||
func RemoveKey(owner []byte, keys []interop.PublicKey) {
|
func RemoveKey(owner []byte, keys []interop.PublicKey) {
|
||||||
|
// V2 format
|
||||||
if len(owner) != 25 {
|
if len(owner) != 25 {
|
||||||
panic("removeKey: incorrect owner")
|
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.
|
// This method panics if owner is not 25 byte long.
|
||||||
func Key(owner []byte) [][]byte {
|
func Key(owner []byte) [][]byte {
|
||||||
|
// V2 format
|
||||||
if len(owner) != 25 {
|
if len(owner) != 25 {
|
||||||
panic("key: incorrect owner")
|
panic("key: incorrect owner")
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// V2 format
|
||||||
_ nodeState = iota
|
_ nodeState = iota
|
||||||
onlineState
|
onlineState
|
||||||
offlineState
|
offlineState
|
||||||
|
@ -215,6 +216,7 @@ func AddPeer(nodeInfo []byte) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !alphabetCall {
|
if !alphabetCall {
|
||||||
|
// V2 format
|
||||||
publicKey := nodeInfo[2:35] // offset:2, len:33
|
publicKey := nodeInfo[2:35] // offset:2, len:33
|
||||||
if !runtime.CheckWitness(publicKey) {
|
if !runtime.CheckWitness(publicKey) {
|
||||||
panic("addPeer: witness check failed")
|
panic("addPeer: witness check failed")
|
||||||
|
|
|
@ -84,7 +84,7 @@ func Update(script []byte, manifest []byte, data interface{}) {
|
||||||
|
|
||||||
// Put creates new subnet with the specified owner and info.
|
// Put creates new subnet with the specified owner and info.
|
||||||
func Put(id []byte, ownerKey interop.PublicKey, info []byte) {
|
func Put(id []byte, ownerKey interop.PublicKey, info []byte) {
|
||||||
// V2 format check
|
// V2 format
|
||||||
if len(id) != subnetIDSize {
|
if len(id) != subnetIDSize {
|
||||||
panic("put: " + ErrInvalidSubnetID)
|
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.
|
// Get returns info about subnet with the specified id.
|
||||||
func Get(id []byte) []byte {
|
func Get(id []byte) []byte {
|
||||||
// V2 format check
|
// V2 format
|
||||||
if len(id) != subnetIDSize {
|
if len(id) != subnetIDSize {
|
||||||
panic("get: " + ErrInvalidSubnetID)
|
panic("get: " + ErrInvalidSubnetID)
|
||||||
}
|
}
|
||||||
|
@ -152,7 +152,7 @@ func Get(id []byte) []byte {
|
||||||
|
|
||||||
// Delete deletes subnet with the specified id.
|
// Delete deletes subnet with the specified id.
|
||||||
func Delete(id []byte) {
|
func Delete(id []byte) {
|
||||||
// V2 format check
|
// V2 format
|
||||||
if len(id) != subnetIDSize {
|
if len(id) != subnetIDSize {
|
||||||
panic("delete: " + ErrInvalidSubnetID)
|
panic("delete: " + ErrInvalidSubnetID)
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ func Delete(id []byte) {
|
||||||
|
|
||||||
// AddNodeAdmin adds new node administrator to the specified subnetwork.
|
// AddNodeAdmin adds new node administrator to the specified subnetwork.
|
||||||
func AddNodeAdmin(subnetID []byte, adminKey interop.PublicKey) {
|
func AddNodeAdmin(subnetID []byte, adminKey interop.PublicKey) {
|
||||||
// V2 format check
|
// V2 format
|
||||||
if len(subnetID) != subnetIDSize {
|
if len(subnetID) != subnetIDSize {
|
||||||
panic("addNodeAdmin: " + ErrInvalidSubnetID)
|
panic("addNodeAdmin: " + ErrInvalidSubnetID)
|
||||||
}
|
}
|
||||||
|
@ -226,7 +226,7 @@ func AddNodeAdmin(subnetID []byte, adminKey interop.PublicKey) {
|
||||||
// RemoveNodeAdmin removes node administrator from the specified subnetwork.
|
// RemoveNodeAdmin removes node administrator from the specified subnetwork.
|
||||||
// Must be called by subnet owner only.
|
// Must be called by subnet owner only.
|
||||||
func RemoveNodeAdmin(subnetID []byte, adminKey interop.PublicKey) {
|
func RemoveNodeAdmin(subnetID []byte, adminKey interop.PublicKey) {
|
||||||
// V2 format check
|
// V2 format
|
||||||
if len(subnetID) != subnetIDSize {
|
if len(subnetID) != subnetIDSize {
|
||||||
panic("removeNodeAdmin: " + ErrInvalidSubnetID)
|
panic("removeNodeAdmin: " + ErrInvalidSubnetID)
|
||||||
}
|
}
|
||||||
|
@ -262,7 +262,7 @@ func RemoveNodeAdmin(subnetID []byte, adminKey interop.PublicKey) {
|
||||||
// Must be called by subnet's owner or node administrator
|
// Must be called by subnet's owner or node administrator
|
||||||
// only.
|
// only.
|
||||||
func AddNode(subnetID []byte, node interop.PublicKey) {
|
func AddNode(subnetID []byte, node interop.PublicKey) {
|
||||||
// V2 format check
|
// V2 format
|
||||||
if len(subnetID) != subnetIDSize {
|
if len(subnetID) != subnetIDSize {
|
||||||
panic("addNode: " + ErrInvalidSubnetID)
|
panic("addNode: " + ErrInvalidSubnetID)
|
||||||
}
|
}
|
||||||
|
@ -301,7 +301,7 @@ func AddNode(subnetID []byte, node interop.PublicKey) {
|
||||||
// Must be called by subnet's owner or node administrator
|
// Must be called by subnet's owner or node administrator
|
||||||
// only.
|
// only.
|
||||||
func RemoveNode(subnetID []byte, node interop.PublicKey) {
|
func RemoveNode(subnetID []byte, node interop.PublicKey) {
|
||||||
// V2 format check
|
// V2 format
|
||||||
if len(subnetID) != subnetIDSize {
|
if len(subnetID) != subnetIDSize {
|
||||||
panic("removeNode: " + ErrInvalidSubnetID)
|
panic("removeNode: " + ErrInvalidSubnetID)
|
||||||
}
|
}
|
||||||
|
@ -341,7 +341,7 @@ func RemoveNode(subnetID []byte, node interop.PublicKey) {
|
||||||
// NodeAllowed checks if node is included in the
|
// NodeAllowed checks if node is included in the
|
||||||
// specified subnet or not.
|
// specified subnet or not.
|
||||||
func NodeAllowed(subnetID []byte, node interop.PublicKey) bool {
|
func NodeAllowed(subnetID []byte, node interop.PublicKey) bool {
|
||||||
// V2 format check
|
// V2 format
|
||||||
if len(subnetID) != subnetIDSize {
|
if len(subnetID) != subnetIDSize {
|
||||||
panic("nodeAllowed: " + ErrInvalidSubnetID)
|
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.
|
// AddClientAdmin adds new client administrator of the specified group in the specified subnetwork.
|
||||||
// Must be called by owner only.
|
// Must be called by owner only.
|
||||||
func AddClientAdmin(subnetID []byte, groupID []byte, adminPublicKey interop.PublicKey) {
|
func AddClientAdmin(subnetID []byte, groupID []byte, adminPublicKey interop.PublicKey) {
|
||||||
// V2 format check
|
// V2 format
|
||||||
if len(subnetID) != subnetIDSize {
|
if len(subnetID) != subnetIDSize {
|
||||||
panic("addClientAdmin: " + ErrInvalidSubnetID)
|
panic("addClientAdmin: " + ErrInvalidSubnetID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// V2 format check
|
// V2 format
|
||||||
if len(groupID) != groupIDSize {
|
if len(groupID) != groupIDSize {
|
||||||
panic("addClientAdmin: " + ErrInvalidGroupID)
|
panic("addClientAdmin: " + ErrInvalidGroupID)
|
||||||
}
|
}
|
||||||
|
@ -409,12 +409,12 @@ func AddClientAdmin(subnetID []byte, groupID []byte, adminPublicKey interop.Publ
|
||||||
// specified group in the specified subnetwork.
|
// specified group in the specified subnetwork.
|
||||||
// Must be called by owner only.
|
// Must be called by owner only.
|
||||||
func RemoveClientAdmin(subnetID []byte, groupID []byte, adminPublicKey interop.PublicKey) {
|
func RemoveClientAdmin(subnetID []byte, groupID []byte, adminPublicKey interop.PublicKey) {
|
||||||
// V2 format check
|
// V2 format
|
||||||
if len(subnetID) != subnetIDSize {
|
if len(subnetID) != subnetIDSize {
|
||||||
panic("removeClientAdmin: " + ErrInvalidSubnetID)
|
panic("removeClientAdmin: " + ErrInvalidSubnetID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// V2 format check
|
// V2 format
|
||||||
if len(groupID) != groupIDSize {
|
if len(groupID) != groupIDSize {
|
||||||
panic("removeClientAdmin: " + ErrInvalidGroupID)
|
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.
|
// AddUser adds user to the specified subnetwork and group.
|
||||||
// Must be called by the owner or the group's admin only.
|
// Must be called by the owner or the group's admin only.
|
||||||
func AddUser(subnetID []byte, groupID []byte, userID []byte) {
|
func AddUser(subnetID []byte, groupID []byte, userID []byte) {
|
||||||
// V2 format check
|
// V2 format
|
||||||
if len(subnetID) != subnetIDSize {
|
if len(subnetID) != subnetIDSize {
|
||||||
panic("addUser: " + ErrInvalidSubnetID)
|
panic("addUser: " + ErrInvalidSubnetID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// V2 format check
|
// V2 format
|
||||||
if len(userID) != userIDSize {
|
if len(userID) != userIDSize {
|
||||||
panic("addUser: " + ErrInvalidUser)
|
panic("addUser: " + ErrInvalidUser)
|
||||||
}
|
}
|
||||||
|
|
||||||
// V2 format check
|
// V2 format
|
||||||
if len(groupID) != groupIDSize {
|
if len(groupID) != groupIDSize {
|
||||||
panic("addUser: " + ErrInvalidGroupID)
|
panic("addUser: " + ErrInvalidGroupID)
|
||||||
}
|
}
|
||||||
|
@ -495,17 +495,17 @@ func AddUser(subnetID []byte, groupID []byte, userID []byte) {
|
||||||
// RemoveUser removes user from the specified subnetwork and group.
|
// RemoveUser removes user from the specified subnetwork and group.
|
||||||
// Must be called by the owner or the group's admin only.
|
// Must be called by the owner or the group's admin only.
|
||||||
func RemoveUser(subnetID []byte, groupID []byte, userID []byte) {
|
func RemoveUser(subnetID []byte, groupID []byte, userID []byte) {
|
||||||
// V2 format check
|
// V2 format
|
||||||
if len(subnetID) != subnetIDSize {
|
if len(subnetID) != subnetIDSize {
|
||||||
panic("removeUser: " + ErrInvalidSubnetID)
|
panic("removeUser: " + ErrInvalidSubnetID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// V2 format check
|
// V2 format
|
||||||
if len(groupID) != groupIDSize {
|
if len(groupID) != groupIDSize {
|
||||||
panic("removeUser: " + ErrInvalidGroupID)
|
panic("removeUser: " + ErrInvalidGroupID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// V2 format check
|
// V2 format
|
||||||
if len(userID) != userIDSize {
|
if len(userID) != userIDSize {
|
||||||
panic("addUser: " + ErrInvalidUser)
|
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
|
// UserAllowed returns bool that indicates if node is included in the
|
||||||
// specified subnet or not.
|
// specified subnet or not.
|
||||||
func UserAllowed(subnetID []byte, user []byte) bool {
|
func UserAllowed(subnetID []byte, user []byte) bool {
|
||||||
// V2 format check
|
// V2 format
|
||||||
if len(subnetID) != subnetIDSize {
|
if len(subnetID) != subnetIDSize {
|
||||||
panic("userAllowed: " + ErrInvalidSubnetID)
|
panic("userAllowed: " + ErrInvalidSubnetID)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue