netmap

package
v0.19.3 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2024 License: GPL-3.0 Imports: 9 Imported by: 2

Documentation

Overview

Netmap contract is a contract deployed in FrostFS sidechain.

Netmap contract stores and manages FrostFS network map, Storage node candidates and epoch number counter.

Contract notifications

AddPeer notification. This notification is produced when a Storage node sends a bootstrap request by invoking AddPeer method.

AddPeer
  - name: nodeInfo
    type: ByteArray

UpdateState notification. This notification is produced when a Storage node wants to change its state (go offline) by invoking UpdateState method. Supported states: (2) -- offline.

UpdateState
  - name: state
    type: Integer
  - name: publicKey
    type: PublicKey

NewEpoch notification. This notification is produced when a new epoch is applied in the network by invoking NewEpoch method.

NewEpoch
  - name: epoch
    type: Integer

Contract storage scheme

|   Key                       | Value      |           Description             |
|-----------------------------|------------|-----------------------------------|
| `snapshotCount`             | int        | snapshot count                    |
| `snapshotEpoch`             | int        | snapshot epoch                    |
| `snapshotBlock`             | int        | snapshot block                    |
| `snapshot_` + snapshotNum   | ByteArray  | serialized '[]Node' array         |
| `snapshotCurrent`           | int        | current snapshot                  |
| `balanceScriptHash`         | Hash160    | balance contract hash             |
| `containerScriptHash`       | Hash160    | container contract hash           |

Index

Constants

View Source
const (

	// DefaultSnapshotCount contains the number of previous snapshots stored by this contract.
	// Must be less than 255.
	DefaultSnapshotCount = 10
)

Variables

This section is empty.

Functions

func AddPeer

func AddPeer(nodeInfo []byte)

AddPeer accepts information about the network map candidate in the FrostFS binary protocol format and does nothing. Keep method because storage node creates a notary transaction with this method, which produces a notary notification (implicit here).

func AddPeerIR

func AddPeerIR(nodeInfo []byte)

AddPeerIR accepts Alphabet calls in the notary-enabled contract setting and behaves similar to AddPeer in the notary-disabled one.

AddPeerIR MUST NOT be called in notary-disabled contract setting. AddPeerIR MUST be called by the Alphabet member only.

func Config

func Config(key []byte) any

Config returns configuration value of FrostFS configuration. If key does not exists, returns nil.

func Epoch

func Epoch() int

Epoch method returns the current epoch number.

func LastEpochBlock

func LastEpochBlock() int

LastEpochBlock method returns the block number when the current epoch was applied.

func ListConfig

func ListConfig() []record

ListConfig returns an array of structures that contain key and value of all FrostFS configuration records. Key and value are both byte arrays.

func NewEpoch

func NewEpoch(epochNum int)

NewEpoch method changes the epoch number up to the provided epochNum argument. It can be invoked only by Alphabet nodes. If provided epoch number is less than the current epoch number or equals it, the method throws panic.

When epoch number is updated, the contract sets storage node candidates as the current network map. The contract also invokes NewEpoch method on Balance and Container contracts.

It produces NewEpoch notification.

func SetConfig

func SetConfig(id, key, val []byte)

SetConfig key-value pair as a FrostFS runtime configuration value. It can be invoked only by Alphabet nodes.

func Update

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

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

func UpdateSnapshotCount

func UpdateSnapshotCount(count int)

UpdateSnapshotCount updates the number of the stored snapshots. If a new number is less than the old one, old snapshots are removed. Otherwise, history is extended with empty snapshots, so `Snapshot` method can return invalid results for `diff = new-old` epochs until `diff` epochs have passed.

Count MUST NOT be negative.

func UpdateState

func UpdateState(state NodeState, publicKey interop.PublicKey)

UpdateState accepts new state to be assigned to network map candidate identified by the given public key, identifies the signer. Applicable only for notary-enabled environment.

Signers:

(a) candidate himself only, if provided public key corresponds to the signer
(b) Alphabet member only
(ab) both candidate and Alphabet member
(c) others

UpdateState case-by-case behavior:

(a) panics
(b) panics
(ab) updates candidate's state in the contract storage (*), and throws
UpdateStateSuccess with the provided key and new state
(c) panics

(*) Candidate is removed from the candidate set if state is NodeStateOffline. Any other state is written into candidate's descriptor in the contract storage. If requested candidate is missing, panic occurs. Throws UpdateStateSuccess notification on success.

State MUST be from the NodeState enum. Public key MUST be interop.PublicKeyCompressedLen bytes.

func UpdateStateIR

func UpdateStateIR(state NodeState, publicKey interop.PublicKey)

UpdateStateIR accepts Alphabet calls in the notary-enabled contract setting and behaves similar to UpdateState, but does not require candidate's signature presence.

UpdateStateIR MUST NOT be called in notary-disabled contract setting. UpdateStateIR MUST be called by the Alphabet member only.

func Version

func Version() int

Version returns the version of the contract.

Types

type Node

type Node struct {
	// Information about the node encoded according to the FrostFS binary
	// protocol.
	BLOB []byte

	// Current node state.
	State NodeState
}

Node groups data related to FrostFS storage nodes registered in the FrostFS network. The information is stored in the current contract.

func Netmap

func Netmap() []Node

Netmap returns set of information about the storage nodes representing a network map in the current epoch.

Current state of each node is represented in the State field. It MAY differ with the state encoded into BLOB field, in this case binary encoded state MUST NOT be processed.

func NetmapCandidates

func NetmapCandidates() []Node

NetmapCandidates returns set of information about the storage nodes representing candidates for the network map in the coming epoch.

Current state of each node is represented in the State field. It MAY differ with the state encoded into BLOB field, in this case binary encoded state MUST NOT be processed.

func Snapshot

func Snapshot(diff int) []Node

Snapshot returns set of information about the storage nodes representing a network map in (current-diff)-th epoch.

Diff MUST NOT be negative. Diff MUST be less than maximum number of network map snapshots stored in the contract. The limit is a contract setting, DefaultSnapshotCount by default. See UpdateSnapshotCount for details.

Current state of each node is represented in the State field. It MAY differ with the state encoded into BLOB field, in this case binary encoded state MUST NOT be processed.

func SnapshotByEpoch

func SnapshotByEpoch(epoch int) []Node

SnapshotByEpoch returns set of information about the storage nodes representing a network map in the given epoch.

Behaves like Snapshot: it is called after difference with the current epoch is calculated.

type NodeState

type NodeState int

NodeState is an enumeration for node states.

const (

	// NodeStateOnline stands for nodes that are in full network and
	// operational availability.
	NodeStateOnline NodeState

	// NodeStateOffline stands for nodes that are in network unavailability.
	NodeStateOffline

	// NodeStateMaintenance stands for nodes under maintenance with partial
	// network availability.
	NodeStateMaintenance
)

Various Node states

Jump to

Keyboard shortcuts

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