container

package
v0.19.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2023 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package container contains implementation of Container contract deployed in NeoFS sidechain.

Container contract stores and manages containers, extended ACLs and container size estimations. Contract does not perform sanity or signature checks of containers or extended ACLs, it is done by Alphabet nodes of the Inner Ring. Alphabet nodes approve it by invoking the same Put or SetEACL methods with the same arguments.

Contract notifications

containerPut notification. This notification is produced when a user wants to create a new container. Alphabet nodes of the Inner Ring catch the notification and validate container data, signature and token if present.

containerPut:
  - name: container
    type: ByteArray
  - name: signature
    type: Signature
  - name: publicKey
    type: PublicKey
  - name: token
    type: ByteArray

containerDelete notification. This notification is produced when a container owner wants to delete a container. Alphabet nodes of the Inner Ring catch the notification and validate container ownership, signature and token if present.

containerDelete:
  - name: containerID
    type: ByteArray
  - name: signature
    type: Signature
  - name: token
    type: ByteArray

setEACL notification. This notification is produced when a container owner wants to update an extended ACL of a container. Alphabet nodes of the Inner Ring catch the notification and validate container ownership, signature and token if present.

setEACL:
  - name: eACL
    type: ByteArray
  - name: signature
    type: Signature
  - name: publicKey
    type: PublicKey
  - name: token
    type: ByteArray

StartEstimation notification. This notification is produced when Storage nodes should exchange estimation values of container sizes among other Storage nodes.

StartEstimation:
  - name: epoch
    type: Integer

StopEstimation notification. This notification is produced when Storage nodes should calculate average container size based on received estimations and store it in Container contract.

StopEstimation:
  - name: epoch
    type: Integer

Index

Constants

View Source
const (

	// RegistrationFeeKey is a key in netmap config which contains fee for container registration.
	RegistrationFeeKey = "ContainerFee"
	// AliasFeeKey is a key in netmap config which contains fee for nice-name registration.
	AliasFeeKey = "ContainerAliasFee"

	// CleanupDelta contains the number of the last epochs for which container estimations are present.
	CleanupDelta = 3
	// TotalCleanupDelta contains the number of the epochs after which estimation
	// will be removed by epoch tick cleanup if any of the nodes hasn't updated
	// container size and/or container has been removed. It must be greater than CleanupDelta.
	TotalCleanupDelta = CleanupDelta + 1

	// NotFoundError is returned if container is missing.
	NotFoundError = "container does not exist"
)

Variables

This section is empty.

Functions

func Alias added in v0.18.0

func Alias(cid []byte) string

Alias method returns a string with an alias of the container if it's set (Null otherwise).

If the container doesn't exist, it panics with NotFoundError.

func ContainersOf added in v0.17.0

func ContainersOf(owner []byte) iterator.Iterator

ContainersOf iterates over all container IDs owned by the specified owner. If owner is nil, it iterates over all containers.

func Count added in v0.15.2

func Count() int

Count method returns the number of registered containers.

func Delete

func Delete(containerID []byte, signature interop.Signature, token []byte)

Delete method removes a container from the contract storage if it has been invoked by Alphabet nodes of the Inner Ring. Otherwise, it produces containerDelete notification.

Signature is a RFC6979 signature of the container ID. Token is optional and should be a stable marshaled SessionToken structure from API.

If the container doesn't exist, it panics with NotFoundError.

func IterateAllContainerSizes added in v0.17.0

func IterateAllContainerSizes(epoch int) iterator.Iterator

IterateAllContainerSizes method returns iterator over all container size estimations that have been registered for the specified epoch. Items returned from this iterator are key-value pairs with keys having container ID as a prefix and values being Estimation structures.

func IterateContainerSizes added in v0.17.0

func IterateContainerSizes(epoch int, cid interop.Hash256) iterator.Iterator

IterateContainerSizes method returns iterator over specific container size estimations that have been registered for the specified epoch. The iterator items are Estimation structures.

func List

func List(owner []byte) [][]byte

List method returns a list of all container IDs owned by the specified owner.

func ListContainerSizes deprecated added in v0.4.0

func ListContainerSizes(epoch int) [][]byte

ListContainerSizes method returns the IDs of container size estimations that have been registered for the specified epoch.

Deprecated: please use IterateAllContainerSizes API, this one is not convenient to use and limited in the number of items it can return. It will be removed in future versions.

func NewEpoch added in v0.5.0

func NewEpoch(epochNum int)

NewEpoch method removes all container size estimations from epoch older than epochNum + 3. It can be invoked only by NewEpoch method of the Netmap contract.

func OnNEP11Payment added in v0.12.0

func OnNEP11Payment(a interop.Hash160, b int, c []byte, d any)

OnNEP11Payment is needed for registration with contract as the owner to work.

func Owner

func Owner(containerID []byte) []byte

Owner method returns a 25 byte Owner ID of the container.

If the container doesn't exist, it panics with NotFoundError.

func Put

func Put(container []byte, signature interop.Signature, publicKey interop.PublicKey, token []byte)

Put method creates a new container if it has been invoked by Alphabet nodes of the Inner Ring. Otherwise, it produces containerPut notification.

Container should be a stable marshaled Container structure from API. Signature is a RFC6979 signature of the Container. PublicKey contains the public key of the signer. Token is optional and should be a stable marshaled SessionToken structure from API.

func PutContainerSize added in v0.4.0

func PutContainerSize(epoch int, cid []byte, usedSize int, pubKey interop.PublicKey)

PutContainerSize method saves container size estimation in contract memory. It can be invoked only by Storage nodes from the network map. This method checks witness based on the provided public key of the Storage node.

If the container doesn't exist, it panics with NotFoundError.

func PutNamed added in v0.12.0

func PutNamed(container []byte, signature interop.Signature,
	publicKey interop.PublicKey, token []byte,
	name, zone string)

PutNamed is similar to put but also sets a TXT record in nns contract. Note that zone must exist.

func SetEACL

func SetEACL(eACL []byte, signature interop.Signature, publicKey interop.PublicKey, token []byte)

SetEACL method sets a new extended ACL table related to the contract if it was invoked by Alphabet nodes of the Inner Ring. Otherwise, it produces setEACL notification.

EACL should be a stable marshaled EACLTable structure from API. Protocol version and container reference must be set in 'version' and 'container_id' fields respectively. Signature is a RFC6979 signature of the Container. PublicKey contains the public key of the signer. Token is optional and should be a stable marshaled SessionToken structure from API.

If the container doesn't exist, it panics with NotFoundError.

func StartContainerEstimation added in v0.4.0

func StartContainerEstimation(epoch int)

StartContainerEstimation method produces StartEstimation notification. It can be invoked only by Alphabet nodes of the Inner Ring.

func StopContainerEstimation added in v0.4.0

func StopContainerEstimation(epoch int)

StopContainerEstimation method produces StopEstimation notification. It can be invoked only by Alphabet nodes of the Inner Ring.

func Update added in v0.11.0

func Update(script []byte, manifest []byte, data any)

Update method updates contract source code and manifest. It can be invoked by committee only.

func Version

func Version() int

Version returns the version of the contract.

Types

type Container added in v0.9.0

type Container struct {
	Value []byte
	Sig   interop.Signature
	Pub   interop.PublicKey
	Token []byte
}

func Get

func Get(containerID []byte) Container

Get method returns a structure that contains a stable marshaled Container structure, the signature, the public key of the container creator and a stable marshaled SessionToken structure if it was provided.

If the container doesn't exist, it panics with NotFoundError.

type ContainerSizes added in v0.18.0

type ContainerSizes struct {
	CID         []byte
	Estimations []Estimation
}

func GetContainerSize deprecated added in v0.4.0

func GetContainerSize(id []byte) ContainerSizes

GetContainerSize method returns the container ID and a slice of container estimations. Container estimation includes the public key of the Storage Node that registered estimation and value of estimation.

Use the ID obtained from ListContainerSizes method. Estimations are removed from contract storage every epoch, see NewEpoch method; therefore, this method can return different results during different epochs.

Deprecated: please use IterateContainerSizes API, this one is not convenient to use and limited in the number of items it can return. It will be removed in future versions.

type Estimation added in v0.17.0

type Estimation struct {
	From interop.PublicKey
	Size int
}

Estimation contains the public key of the estimator (storage node) and the size this estimator has for the container.

type ExtendedACL added in v0.9.0

type ExtendedACL struct {
	Value []byte
	Sig   interop.Signature
	Pub   interop.PublicKey
	Token []byte
}

func EACL

func EACL(containerID []byte) ExtendedACL

EACL method returns a structure that contains a stable marshaled EACLTable structure, the signature, the public key of the extended ACL setter and a stable marshaled SessionToken structure if it was provided.

If the container doesn't exist, it panics with NotFoundError.

type StorageNode added in v0.18.0

type StorageNode struct {
	Info []byte
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL