Documentation
¶
Index ¶
- Constants
- Variables
- func AssertEqualIR(a, b *InputRecord) error
- func BlockHash(algorithm crypto.Hash, h *Header, txs []*TransactionRecord, stateHash []byte, ...) ([]byte, error)
- func CheckNonEquivocatingCertificates(prevUC, newUC *UnicityCertificate) error
- func EnsureVersion(data Versioned, actual, expected Version) error
- func EqualIR(a, b *InputRecord) (bool, error)
- func ErrInvalidVersion(s Versioned) error
- func HashCBOR(data any, hashAlgorithm crypto.Hash) ([]byte, error)
- func NewTimestamp() uint64
- func VerifyTxInclusion(txRecordProof *TxRecordProof, tb RootTrustBase, hashAlgorithm crypto.Hash) error
- func VerifyTxProof(txRecordProof *TxRecordProof, tb RootTrustBase, hashAlgorithm crypto.Hash) error
- type AuthProofSigData
- type Block
- func (b *Block) CalculateBlockHash(algorithm crypto.Hash) (*InputRecord, error)
- func (b *Block) GetBlockFees() (uint64, error)
- func (b *Block) GetProposerID() string
- func (b *Block) GetRoundNumber() (uint64, error)
- func (b *Block) HeaderHash(algorithm crypto.Hash) ([]byte, error)
- func (b *Block) InputRecord() (*InputRecord, error)
- func (b *Block) IsValid(algorithm crypto.Hash, shardConfHash []byte) error
- func (b *Block) PartitionID() PartitionID
- func (b *Block) Size() (bs uint64, _ error)
- type CborTag
- type ClientMetadata
- type FeeCreditBill
- type FeeProofSigData
- type GenericChainItem
- type Header
- type InputRecord
- func (x *InputRecord) AddToHasher(hasher abhash.Hasher)
- func (x *InputRecord) Bytes() ([]byte, error)
- func (x *InputRecord) GetVersion() Version
- func (x *InputRecord) IsValid() error
- func (x *InputRecord) MarshalCBOR() ([]byte, error)
- func (x *InputRecord) NewRepeatIR() *InputRecord
- func (x *InputRecord) String() string
- func (x *InputRecord) UnmarshalCBOR(data []byte) error
- type NetworkID
- type NodeInfo
- type Option
- type PartitionDescriptionRecord
- func (pdr *PartitionDescriptionRecord) ComposeUnitID(shard ShardID, unitType uint32, prndSh func([]byte) error) (UnitID, error)
- func (pdr *PartitionDescriptionRecord) ExtractUnitType(id UnitID) (uint32, error)
- func (pdr *PartitionDescriptionRecord) GetNetworkID() NetworkID
- func (pdr *PartitionDescriptionRecord) GetPartitionID() PartitionID
- func (pdr *PartitionDescriptionRecord) GetVersion() Version
- func (pdr *PartitionDescriptionRecord) Hash(hashAlgorithm crypto.Hash) ([]byte, error)
- func (pdr *PartitionDescriptionRecord) IsValid() error
- func (pdr *PartitionDescriptionRecord) MarshalCBOR() ([]byte, error)
- func (pdr *PartitionDescriptionRecord) UnitIDValidator(sid ShardID) func(unitID UnitID) error
- func (pdr *PartitionDescriptionRecord) UnmarshalCBOR(data []byte) error
- func (pdr *PartitionDescriptionRecord) Verify(prev *PartitionDescriptionRecord) error
- type PartitionID
- type PartitionShardID
- type PartitionType
- type PartitionTypeID
- type PathItem
- type Payload
- type PredicateBytes
- type RawCBOR
- type RootTrustBase
- type RootTrustBaseV1
- func (r *RootTrustBaseV1) GetMaxFaultyNodes() uint64
- func (r *RootTrustBaseV1) GetNetworkID() NetworkID
- func (r *RootTrustBaseV1) GetQuorumThreshold() uint64
- func (r *RootTrustBaseV1) GetRootNodes() []*NodeInfo
- func (r *RootTrustBaseV1) GetVersion() Version
- func (r *RootTrustBaseV1) Hash(hashAlgo crypto.Hash) ([]byte, error)
- func (r *RootTrustBaseV1) MarshalCBOR() ([]byte, error)
- func (r RootTrustBaseV1) SigBytes() ([]byte, error)
- func (r *RootTrustBaseV1) Sign(nodeID string, signer abcrypto.Signer) error
- func (r *RootTrustBaseV1) UnmarshalCBOR(data []byte) error
- func (r *RootTrustBaseV1) VerifyQuorumSignatures(data []byte, signatures map[string]hex.Bytes) error
- func (r *RootTrustBaseV1) VerifySignature(data []byte, sig []byte, nodeID string) (uint64, error)
- type ServerMetadata
- type ShardID
- func (id ShardID) AddToHasher(h abhash.Hasher)
- func (id ShardID) Bytes() []byte
- func (id ShardID) Comparator() func([]byte) bool
- func (id ShardID) Equal(v ShardID) bool
- func (id ShardID) Key() string
- func (id ShardID) Length() uint
- func (id ShardID) MarshalCBOR() ([]byte, error)
- func (id ShardID) MarshalText() ([]byte, error)
- func (id ShardID) Split() (ShardID, ShardID)
- func (id ShardID) String() (s string)
- func (id *ShardID) UnmarshalCBOR(data []byte) (err error)
- func (id *ShardID) UnmarshalText(src []byte) error
- type ShardTree
- type ShardTreeCertificate
- type ShardTreeInput
- type ShardingScheme
- type SignatureMap
- type StateLock
- type StateLockProofSigData
- type StateTreeCert
- type StateTreePathItem
- type StateUnlockProofKind
- type TaggedCBOR
- type TransactionOrder
- func (t *TransactionOrder) AddStateUnlockCommitProof(unlockProof []byte)
- func (t *TransactionOrder) AddStateUnlockRollbackProof(unlockProof []byte)
- func (t *TransactionOrder) AuthProofSigBytes() ([]byte, error)
- func (t *TransactionOrder) FeeCreditRecordID() []byte
- func (t *TransactionOrder) FeeProofSigBytes() ([]byte, error)
- func (t *TransactionOrder) GetNetworkID() NetworkID
- func (t *TransactionOrder) GetPartitionID() PartitionID
- func (t *TransactionOrder) GetUnitID() UnitID
- func (t *TransactionOrder) GetVersion() Version
- func (t *TransactionOrder) HasStateLock() bool
- func (t *TransactionOrder) Hash(algorithm crypto.Hash) ([]byte, error)
- func (t *TransactionOrder) MarshalCBOR() ([]byte, error)
- func (t *TransactionOrder) MaxFee() uint64
- func (t *TransactionOrder) ReferenceNumber() []byte
- func (t *TransactionOrder) SetAttributes(attr any) error
- func (t *TransactionOrder) SetAuthProof(authProof any) error
- func (t *TransactionOrder) StateLockProofSigBytes() ([]byte, error)
- func (t *TransactionOrder) Timeout() uint64
- func (t *TransactionOrder) UnmarshalAttributes(v any) error
- func (t *TransactionOrder) UnmarshalAuthProof(v any) error
- func (t *TransactionOrder) UnmarshalCBOR(data []byte) error
- type TransactionOrderCBOR
- type TransactionRecord
- func (t *TransactionRecord) Bytes() ([]byte, error)
- func (t *TransactionRecord) GetActualFee() uint64
- func (t *TransactionRecord) GetTransactionOrderV1() (*TransactionOrder, error)
- func (t *TransactionRecord) GetVersion() Version
- func (t *TransactionRecord) Hash(algorithm crypto.Hash) ([]byte, error)
- func (t *TransactionRecord) IsSuccessful() bool
- func (t *TransactionRecord) IsValid() error
- func (t *TransactionRecord) MarshalCBOR() ([]byte, error)
- func (t *TransactionRecord) TargetUnits() []UnitID
- func (t *TransactionRecord) TxStatus() TxStatus
- func (t *TransactionRecord) UnmarshalCBOR(data []byte) error
- func (t *TransactionRecord) UnmarshalProcessingDetails(v any) error
- type TxProof
- type TxRecordProof
- type TxStatus
- type UnicityCertificate
- func (x *UnicityCertificate) GetBlockHash() []byte
- func (x *UnicityCertificate) GetETHash() []byte
- func (x *UnicityCertificate) GetFeeSum() uint64
- func (x *UnicityCertificate) GetPartitionID() PartitionID
- func (x *UnicityCertificate) GetPreviousStateHash() []byte
- func (x *UnicityCertificate) GetRootRoundNumber() uint64
- func (x *UnicityCertificate) GetRoundNumber() uint64
- func (x *UnicityCertificate) GetShardID() ShardID
- func (x *UnicityCertificate) GetStateHash() []byte
- func (x *UnicityCertificate) GetSummaryValue() []byte
- func (x *UnicityCertificate) GetVersion() Version
- func (x *UnicityCertificate) Hash(hash crypto.Hash) ([]byte, error)
- func (x *UnicityCertificate) IsDuplicate(prevUC *UnicityCertificate) bool
- func (x *UnicityCertificate) IsInitial() bool
- func (x *UnicityCertificate) IsRepeat(prevUC *UnicityCertificate) (bool, error)
- func (x *UnicityCertificate) IsSuccessor(prevUC *UnicityCertificate) bool
- func (x *UnicityCertificate) IsValid(partitionID PartitionID, shardConfHash []byte) error
- func (x *UnicityCertificate) MarshalCBOR() ([]byte, error)
- func (x *UnicityCertificate) UnmarshalCBOR(data []byte) error
- func (x *UnicityCertificate) Verify(tb RootTrustBase, algorithm crypto.Hash, partitionID PartitionID, ...) error
- type UnicityCertificateValidator
- type UnicitySeal
- func (x *UnicitySeal) AddToHasher(hasher abhash.Hasher)
- func (x *UnicitySeal) GetVersion() Version
- func (x *UnicitySeal) IsValid() error
- func (x *UnicitySeal) MarshalCBOR() ([]byte, error)
- func (x UnicitySeal) SigBytes() ([]byte, error)
- func (x *UnicitySeal) Sign(id string, signer crypto.Signer) error
- func (x *UnicitySeal) UnmarshalCBOR(b []byte) (err error)
- func (x *UnicitySeal) Verify(tb RootTrustBase) error
- type UnicityTree
- type UnicityTreeCertificate
- func (utc *UnicityTreeCertificate) AddToHasher(hasher abhash.Hasher)
- func (utc *UnicityTreeCertificate) EvalAuthPath(shardTreeRoot []byte, hashAlgorithm crypto.Hash) ([]byte, error)
- func (utc *UnicityTreeCertificate) GetVersion() Version
- func (utc *UnicityTreeCertificate) IsValid(partition PartitionID) error
- func (utc *UnicityTreeCertificate) MarshalCBOR() ([]byte, error)
- func (utc *UnicityTreeCertificate) UnmarshalCBOR(data []byte) error
- type UnicityTreeData
- type UnitData
- type UnitID
- type UnitState
- type UnitStateProof
- func (u *UnitStateProof) CalculateStateTreeOutput(algorithm crypto.Hash) ([]byte, uint64, error)
- func (u *UnitStateProof) GetVersion() Version
- func (u *UnitStateProof) IsValid() error
- func (u *UnitStateProof) MarshalCBOR() ([]byte, error)
- func (u *UnitStateProof) UnmarshalCBOR(data []byte) error
- func (u *UnitStateProof) Verify(algorithm crypto.Hash, unitState *UnitState, ucv UnicityCertificateValidator, ...) error
- type UnitStateWithProof
- type UnitTreeCert
- type Version
- type Versioned
Constants ¶
const ( PartitionIDLength = 4 NetworkIDLength = 2 )
const ( UnicitySealTag RootGenesisTag GenesisRootRecordTag ConsensusParamsTag GenesisPartitionRecordTag PartitionNodeTag UnicityCertificateTag InputRecordTag TxProofTag UnitStateProofTag PartitionDescriptionRecordTag BlockTag RootTrustBaseTag UnicityTreeCertificateTag TransactionRecordTag TransactionOrderTag RootPartitionBlockDataTag RootPartitionRoundInfoTag )
const GenesisTime uint64 = 1681971084
GenesisTime min timestamp Thursday, April 20, 2023 6:11:24 AM GMT+00:00 Epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT)
Variables ¶
var ( ErrInputRecordIsNil = errors.New("input record is nil") ErrSummaryValueIsNil = errors.New("summary value is nil") )
var ( ErrTransactionRecordIsNil = errors.New("transaction record is nil") ErrTransactionOrderIsNil = errors.New("transaction order is nil") ErrServerMetadataIsNil = errors.New("server metadata is nil") )
var ( ErrTxRecordProofIsNil = errors.New("transaction record proof is nil") ErrOutOfGas = errors.New("out of gas") )
var ( ErrUnicitySealIsNil = errors.New("unicity seal is nil") ErrSignerIsNil = errors.New("signer is nil") ErrUnicitySealHashIsNil = errors.New("hash is nil") ErrInvalidRootRound = errors.New("invalid root round number") ErrUnicitySealSignatureIsNil = errors.New("no signatures") ErrRootValidatorInfoMissing = errors.New("root node info is missing") ErrInvalidTimestamp = errors.New("invalid timestamp") )
var ( ErrUnicityTreeCertificateIsNil = errors.New("unicity tree certificate is nil") ErrUCIsNil = errors.New("new UC is nil") ErrLastUCIsNil = errors.New("last UC is nil") )
var (
Cbor = cborHandler{}
)
var (
ErrBlockIsNil = errors.New("block is nil")
)
var (
ErrSystemDescriptionIsNil = errors.New("system description record is nil")
)
var ErrUnicityCertificateIsNil = errors.New("unicity certificate is nil")
Functions ¶
func AssertEqualIR ¶
func AssertEqualIR(a, b *InputRecord) error
func BlockHash ¶
func BlockHash(algorithm crypto.Hash, h *Header, txs []*TransactionRecord, stateHash []byte, prevStateHash []byte) ([]byte, error)
BlockHash returns the hash of the block. Hash of a block is computed as hash of block header fields and tree hash of transactions.
func CheckNonEquivocatingCertificates ¶
func CheckNonEquivocatingCertificates(prevUC, newUC *UnicityCertificate) error
CheckNonEquivocatingCertificates checks if provided certificates are equivocating NB! order is important, also it is assumed that validity of both UCs is checked before The algorithm is based on Yellowpaper: "Algorithm 6 Checking two UC-s for equivocation"
func EnsureVersion ¶
func EqualIR ¶
func EqualIR(a, b *InputRecord) (bool, error)
func ErrInvalidVersion ¶
func HashCBOR ¶
HashCBOR encodes the provided "data" to CBOR and calculates hash using the provided "hashAlgorithm". The "data" parameter should be a CBOR struct with the "toarray" tag. The purpose of CBOR encoding before hashing is to avoid "field offset attacks" e.g. when two structs of the same type, but with different values, would yield the same hash if otherwise normally concatenated.
func NewTimestamp ¶
func NewTimestamp() uint64
NewTimestamp - returns timestamp in seconds from epoch
func VerifyTxInclusion ¶
func VerifyTxInclusion(txRecordProof *TxRecordProof, tb RootTrustBase, hashAlgorithm crypto.Hash) error
VerifyTxInclusion checks if the transaction is included in the block.
func VerifyTxProof ¶
func VerifyTxProof(txRecordProof *TxRecordProof, tb RootTrustBase, hashAlgorithm crypto.Hash) error
VerifyTxProof checks if the transaction is included in the block and was successfully executed.
Types ¶
type AuthProofSigData ¶
type Block ¶
type Block struct {
Header *Header
Transactions []*TransactionRecord
UnicityCertificate TaggedCBOR
// contains filtered or unexported fields
}
func (*Block) CalculateBlockHash ¶
func (b *Block) CalculateBlockHash(algorithm crypto.Hash) (*InputRecord, error)
CalculateBlockHash calculates the block hash, updates UC and returns the updated input record with the block hash.
func (*Block) GetBlockFees ¶
func (*Block) GetProposerID ¶
func (*Block) GetRoundNumber ¶
func (*Block) InputRecord ¶
func (b *Block) InputRecord() (*InputRecord, error)
func (*Block) PartitionID ¶
func (b *Block) PartitionID() PartitionID
type ClientMetadata ¶
type ClientMetadata struct {
Timeout uint64
MaxTransactionFee uint64
FeeCreditRecordID []byte
ReferenceNumber []byte
// contains filtered or unexported fields
}
func (*ClientMetadata) GetFeeCreditRecordID ¶
func (c *ClientMetadata) GetFeeCreditRecordID() []byte
func (*ClientMetadata) GetMaxFee ¶
func (c *ClientMetadata) GetMaxFee() uint64
func (*ClientMetadata) GetReferenceNumber ¶
func (c *ClientMetadata) GetReferenceNumber() []byte
func (*ClientMetadata) GetTimeout ¶
func (c *ClientMetadata) GetTimeout() uint64
type FeeCreditBill ¶
type FeeCreditBill struct {
UnitID UnitID `json:"unitId"`
OwnerPredicate PredicateBytes `json:"ownerPredicate"`
// contains filtered or unexported fields
}
type FeeProofSigData ¶
type GenericChainItem ¶
type Header ¶
type Header struct {
Version Version
PartitionID PartitionID
ShardID ShardID
ProposerID string
PreviousBlockHash hex.Bytes
// contains filtered or unexported fields
}
func (*Header) GetVersion ¶
func (*Header) MarshalCBOR ¶
func (*Header) UnmarshalCBOR ¶
type InputRecord ¶
type InputRecord struct {
Version Version `json:"version"`
RoundNumber uint64 `json:"roundNumber"` // shard's round number
Epoch uint64 `json:"epoch"` // shard’s epoch number
PreviousHash hex.Bytes `json:"previousHash"` // previously certified state hash
Hash hex.Bytes `json:"hash"` // state hash to be certified
SummaryValue hex.Bytes `json:"summaryValue"` // summary value to certified
Timestamp uint64 `json:"timestamp"` // reference time for transaction validation
BlockHash hex.Bytes `json:"blockHash"` // hash of the block
SumOfEarnedFees uint64 `json:"sumOfEarnedFees"` // sum of the actual fees over all transaction records in the block
ETHash hex.Bytes `json:"executedTransactionsHash"` // hash of executed transactions
// contains filtered or unexported fields
}
Shard input record (IR) of a shard of a partition.
func (*InputRecord) AddToHasher ¶
func (x *InputRecord) AddToHasher(hasher abhash.Hasher)
func (*InputRecord) Bytes ¶
func (x *InputRecord) Bytes() ([]byte, error)
func (*InputRecord) GetVersion ¶
func (x *InputRecord) GetVersion() Version
func (*InputRecord) IsValid ¶
func (x *InputRecord) IsValid() error
func (*InputRecord) MarshalCBOR ¶
func (x *InputRecord) MarshalCBOR() ([]byte, error)
func (*InputRecord) NewRepeatIR ¶
func (x *InputRecord) NewRepeatIR() *InputRecord
NewRepeatIR - creates new repeat IR from current IR
func (*InputRecord) String ¶
func (x *InputRecord) String() string
func (*InputRecord) UnmarshalCBOR ¶
func (x *InputRecord) UnmarshalCBOR(data []byte) error
type NodeInfo ¶
type NodeInfo struct {
NodeID string `json:"nodeId"` // node identifier
SigKey hex.Bytes `json:"sigKey"` // signing key of the node
Stake uint64 `json:"stake"` // amount of staked coins for this node
// contains filtered or unexported fields
}
type Option ¶
type Option func(c *trustBaseConf)
func WithQuorumThreshold ¶
WithQuorumThreshold overrides the default 2/3+1 quorum threshold.
type PartitionDescriptionRecord ¶
type PartitionDescriptionRecord struct {
Version Version `json:"version"`
NetworkID NetworkID `json:"networkId"`
PartitionID PartitionID `json:"partitionId"`
ShardID ShardID `json:"shardId"`
PartitionTypeID PartitionTypeID `json:"partitionTypeId"`
PartitionType *PartitionType `json:"partitionType,omitempty"` // non-nil only if PartitionTypeID == 0
TypeIDLen uint32 `json:"typeIdLength"`
UnitIDLen uint32 `json:"unitIdLength"`
SummaryTrustBase hex.Bytes `json:"summaryTrustBase"`
T2Timeout time.Duration `json:"t2timeout"`
FeeCreditBill *FeeCreditBill `json:"feeCreditBill"`
//todo: Transaction cost function
PartitionParams map[string]string `json:"partitionParams,omitempty"`
Epoch uint64 `json:"epoch"`
EpochStart uint64 `json:"epochStart"` // Root round when this epoch is activated
Validators []*NodeInfo `json:"validators"`
// contains filtered or unexported fields
}
func (*PartitionDescriptionRecord) ComposeUnitID ¶
func (*PartitionDescriptionRecord) ExtractUnitType ¶
func (pdr *PartitionDescriptionRecord) ExtractUnitType(id UnitID) (uint32, error)
func (*PartitionDescriptionRecord) GetNetworkID ¶
func (pdr *PartitionDescriptionRecord) GetNetworkID() NetworkID
func (*PartitionDescriptionRecord) GetPartitionID ¶
func (pdr *PartitionDescriptionRecord) GetPartitionID() PartitionID
func (*PartitionDescriptionRecord) GetVersion ¶
func (pdr *PartitionDescriptionRecord) GetVersion() Version
func (*PartitionDescriptionRecord) Hash ¶
func (pdr *PartitionDescriptionRecord) Hash(hashAlgorithm crypto.Hash) ([]byte, error)
func (*PartitionDescriptionRecord) IsValid ¶
func (pdr *PartitionDescriptionRecord) IsValid() error
func (*PartitionDescriptionRecord) MarshalCBOR ¶
func (pdr *PartitionDescriptionRecord) MarshalCBOR() ([]byte, error)
func (*PartitionDescriptionRecord) UnitIDValidator ¶
func (pdr *PartitionDescriptionRecord) UnitIDValidator(sid ShardID) func(unitID UnitID) error
UnitIDValidator returns function which checks that unit ID passed as argument has correct length and that the unit belongs into the given shard.
func (*PartitionDescriptionRecord) UnmarshalCBOR ¶
func (pdr *PartitionDescriptionRecord) UnmarshalCBOR(data []byte) error
func (*PartitionDescriptionRecord) Verify ¶
func (pdr *PartitionDescriptionRecord) Verify(prev *PartitionDescriptionRecord) error
Verify verifies validator info and that it extends the previous shard conf if provided.
type PartitionID ¶
type PartitionID uint32
func BytesToPartitionID ¶
func BytesToPartitionID(b []byte) (PartitionID, error)
func (PartitionID) Bytes ¶
func (sid PartitionID) Bytes() []byte
func (PartitionID) String ¶
func (sid PartitionID) String() string
type PartitionShardID ¶
type PartitionShardID struct {
PartitionID PartitionID
ShardID string // types.ShardID is not comparable, use ShardID.Key() here
}
func (*PartitionShardID) String ¶
func (i *PartitionShardID) String() string
type PartitionType ¶
type PartitionType struct {
}
func (*PartitionType) AddToHasher ¶
func (std *PartitionType) AddToHasher(h abhash.Hasher)
type PartitionTypeID ¶
type PartitionTypeID uint32
type PathItem ¶
type PathItem struct {
Key PartitionID
Hash hex.Bytes
// contains filtered or unexported fields
}
func (*PathItem) ToIMTPathItem ¶
type Payload ¶
type Payload struct {
NetworkID NetworkID
PartitionID PartitionID
UnitID UnitID
Type uint16 // transaction type, ie mint, transfer,...
Attributes RawCBOR // transaction type specific attributes
StateLock *StateLock
ClientMetadata *ClientMetadata // metadata about the transaction added by the client
// contains filtered or unexported fields
}
Payload helper struct for transaction signing. Includes all TransactionOrder fields except for the signatures themselves (StateUnlock, AuthProof and FeeProof). Payload is an embedded field of TransactionOrder so that the fields get "flattened" in CBOR encoding.
type PredicateBytes ¶
type RawCBOR ¶
type RawCBOR []byte
func (RawCBOR) MarshalCBOR ¶
MarshalCBOR returns r or CBOR nil if r is empty.
func (RawCBOR) MarshalText ¶
func (*RawCBOR) UnmarshalCBOR ¶
UnmarshalCBOR copies data into r unless it's CBOR "nil marker" - in that case r is set to empty slice.
func (*RawCBOR) UnmarshalText ¶
type RootTrustBase ¶
type RootTrustBaseV1 ¶
type RootTrustBaseV1 struct {
Version Version `json:"version"`
NetworkID NetworkID `json:"networkId"`
Epoch uint64 `json:"epoch"` // current epoch number
EpochStartRound uint64 `json:"epochStartRound"` // root chain round number when the epoch begins
RootNodes []*NodeInfo `json:"rootNodes"` // list of all root nodes for the current epoch
QuorumThreshold uint64 `json:"quorumThreshold"` // amount of coins required to reach consensus, currently each node gets equal amount of voting power i.e. +1 for each node
StateHash hex.Bytes `json:"stateHash"` // unicity tree root hash
ChangeRecordHash hex.Bytes `json:"changeRecordHash"` // epoch change request hash
PreviousEntryHash hex.Bytes `json:"previousEntryHash"` // previous trust base entry hash
Signatures map[string]hex.Bytes `json:"signatures"` // signatures of previous epoch validators, over all fields except for the signatures fields itself
// contains filtered or unexported fields
}
func NewTrustBaseGenesis ¶
func NewTrustBaseGenesis(networkID NetworkID, rootNodes []*NodeInfo, opts ...Option) (*RootTrustBaseV1, error)
NewTrustBaseGenesis creates new unsigned root trust base with default parameters.
func (*RootTrustBaseV1) GetMaxFaultyNodes ¶
func (r *RootTrustBaseV1) GetMaxFaultyNodes() uint64
GetMaxFaultyNodes returns max allowed faulty nodes, only works if one node == one vote.
func (*RootTrustBaseV1) GetNetworkID ¶
func (r *RootTrustBaseV1) GetNetworkID() NetworkID
func (*RootTrustBaseV1) GetQuorumThreshold ¶
func (r *RootTrustBaseV1) GetQuorumThreshold() uint64
GetQuorumThreshold returns the quorum threshold for the latest trust base entry.
func (*RootTrustBaseV1) GetRootNodes ¶
func (r *RootTrustBaseV1) GetRootNodes() []*NodeInfo
func (*RootTrustBaseV1) GetVersion ¶
func (r *RootTrustBaseV1) GetVersion() Version
func (*RootTrustBaseV1) Hash ¶
func (r *RootTrustBaseV1) Hash(hashAlgo crypto.Hash) ([]byte, error)
Hash hashes the entire structure including the signatures.
func (*RootTrustBaseV1) MarshalCBOR ¶
func (r *RootTrustBaseV1) MarshalCBOR() ([]byte, error)
func (RootTrustBaseV1) SigBytes ¶
func (r RootTrustBaseV1) SigBytes() ([]byte, error)
SigBytes serializes all fields expect for the signatures field.
func (*RootTrustBaseV1) Sign ¶
func (r *RootTrustBaseV1) Sign(nodeID string, signer abcrypto.Signer) error
Sign signs the trust base entry, storing the signature to Signatures map.
func (*RootTrustBaseV1) UnmarshalCBOR ¶
func (r *RootTrustBaseV1) UnmarshalCBOR(data []byte) error
func (*RootTrustBaseV1) VerifyQuorumSignatures ¶
func (r *RootTrustBaseV1) VerifyQuorumSignatures(data []byte, signatures map[string]hex.Bytes) error
VerifyQuorumSignatures verifies that the data is signed by enough root nodes so that quorum is reached, returns error if quorum is not reached.
func (*RootTrustBaseV1) VerifySignature ¶
VerifySignature verifies that the data is signed by the given root validator, returns the validator's stake if it is signed.
type ServerMetadata ¶
type ServerMetadata struct {
ActualFee uint64
TargetUnits []UnitID
SuccessIndicator TxStatus
ProcessingDetails RawCBOR
// contains filtered or unexported fields
}
func (*ServerMetadata) ErrDetail ¶
func (sm *ServerMetadata) ErrDetail() error
func (*ServerMetadata) GetActualFee ¶
func (sm *ServerMetadata) GetActualFee() uint64
func (*ServerMetadata) GetTargetUnits ¶
func (sm *ServerMetadata) GetTargetUnits() []UnitID
func (*ServerMetadata) SetError ¶
func (sm *ServerMetadata) SetError(e error)
func (*ServerMetadata) TxStatus ¶
func (sm *ServerMetadata) TxStatus() TxStatus
func (*ServerMetadata) UnmarshalDetails ¶
func (sm *ServerMetadata) UnmarshalDetails(v any) error
type ShardID ¶
type ShardID struct {
// contains filtered or unexported fields
}
func (ShardID) AddToHasher ¶
func (ShardID) Comparator ¶
Comparator returns function which checks does the byte slice argument have the prefix which matches the shard ID. NB! It is callers responsibility to not pass shorter slice than the shard id!
func (ShardID) MarshalCBOR ¶
func (ShardID) MarshalText ¶
func (ShardID) Split ¶
Split increases shard ID length by one bit and returns the two new IDs. The original shard ID is not altered.
func (*ShardID) UnmarshalCBOR ¶
func (*ShardID) UnmarshalText ¶
type ShardTree ¶
func CreateShardTree ¶
func CreateShardTree(scheme ShardingScheme, states []ShardTreeInput, algo crypto.Hash) (ShardTree, error)
"states" must contain record for each shard in the "scheme".
func (ShardTree) Certificate ¶
func (tree ShardTree) Certificate(shardID ShardID) (ShardTreeCertificate, error)
Certificate returns Shard Tree Certificate for the shard.
type ShardTreeCertificate ¶
type ShardTreeCertificate struct {
Shard ShardID
SiblingHashes [][]byte
// contains filtered or unexported fields
}
func (ShardTreeCertificate) ComputeCertificateHash ¶
func (cert ShardTreeCertificate) ComputeCertificateHash(IR *InputRecord, TRHash []byte, shardConfHash []byte, algo crypto.Hash) ([]byte, error)
ComputeCertificateHash implements the "Compute Shard Tree Certificate" algorithm. Input:
IR - input record of the shard TRHash - hash of the TechnicalRecord ShardConfHash - hash of the ShardConf
Output: Root hash
func (ShardTreeCertificate) IsValid ¶
func (cert ShardTreeCertificate) IsValid() error
type ShardTreeInput ¶
type ShardTreeInput struct {
Shard ShardID
IR *InputRecord
TRHash []byte // hash of TechnicalRecord
ShardConfHash []byte
}
ShardTreeInput is source data for leaf node in a shard tree
type ShardingScheme ¶
type ShardingScheme []ShardID
func (ShardingScheme) All ¶
func (sh ShardingScheme) All() iter.Seq[ShardID]
All returns iterator over all shard IDs in the sharding scheme.
For a single shard scheme (empty list) single empty shard ID is returned.
func (ShardingScheme) IsValid ¶
func (sh ShardingScheme) IsValid() error
type SignatureMap ¶
type StateLock ¶
type StateLockProofSigData ¶
type StateTreeCert ¶
type StateTreeCert struct {
LeftSummaryHash hex.Bytes `json:"leftSummaryHash"`
LeftSummaryValue uint64 `json:"leftSummaryValue,string"`
RightSummaryHash hex.Bytes `json:"rightSummaryHash"`
RightSummaryValue uint64 `json:"rightSummaryValue,string"`
Path []*StateTreePathItem `json:"path"`
// contains filtered or unexported fields
}
type StateTreePathItem ¶
type StateTreePathItem struct {
UnitID UnitID `json:"unitId"` // (ι′)
LogsHash hex.Bytes `json:"logsHash"` // (z)
Value uint64 `json:"value,string"` // (V)
SiblingSummaryHash hex.Bytes `json:"siblingSummaryHash"`
SiblingSummaryValue uint64 `json:"siblingSummaryValue,string"`
// contains filtered or unexported fields
}
type StateUnlockProofKind ¶
type StateUnlockProofKind byte
const ( StateUnlockRollback StateUnlockProofKind = iota StateUnlockExecute )
type TaggedCBOR ¶
type TaggedCBOR = RawCBOR
type TransactionOrder ¶
type TransactionOrder struct {
Version Version
Payload // the embedded Payload field is "flattened" in CBOR array
StateUnlock []byte // two CBOR data items: [0|1]+[<state lock/rollback predicate input>]
AuthProof RawCBOR // transaction type specific signatures/authorisation proofs
FeeProof []byte
// contains filtered or unexported fields
}
func (*TransactionOrder) AddStateUnlockCommitProof ¶
func (t *TransactionOrder) AddStateUnlockCommitProof(unlockProof []byte)
func (*TransactionOrder) AddStateUnlockRollbackProof ¶
func (t *TransactionOrder) AddStateUnlockRollbackProof(unlockProof []byte)
func (*TransactionOrder) AuthProofSigBytes ¶
func (t *TransactionOrder) AuthProofSigBytes() ([]byte, error)
func (*TransactionOrder) FeeCreditRecordID ¶
func (t *TransactionOrder) FeeCreditRecordID() []byte
func (*TransactionOrder) FeeProofSigBytes ¶
func (t *TransactionOrder) FeeProofSigBytes() ([]byte, error)
func (*TransactionOrder) GetNetworkID ¶
func (t *TransactionOrder) GetNetworkID() NetworkID
func (*TransactionOrder) GetPartitionID ¶
func (t *TransactionOrder) GetPartitionID() PartitionID
func (*TransactionOrder) GetUnitID ¶
func (t *TransactionOrder) GetUnitID() UnitID
func (*TransactionOrder) GetVersion ¶
func (t *TransactionOrder) GetVersion() Version
func (*TransactionOrder) HasStateLock ¶
func (t *TransactionOrder) HasStateLock() bool
func (*TransactionOrder) Hash ¶
func (t *TransactionOrder) Hash(algorithm crypto.Hash) ([]byte, error)
func (*TransactionOrder) MarshalCBOR ¶
func (t *TransactionOrder) MarshalCBOR() ([]byte, error)
func (*TransactionOrder) MaxFee ¶
func (t *TransactionOrder) MaxFee() uint64
func (*TransactionOrder) ReferenceNumber ¶
func (t *TransactionOrder) ReferenceNumber() []byte
func (*TransactionOrder) SetAttributes ¶
func (t *TransactionOrder) SetAttributes(attr any) error
SetAttributes serializes "attr" and assigns the result to payload's Attributes field. The "attr" is expected to be one of the transaction attribute structs but there is no validation! The TransactionOrder.UnmarshalAttributes can be used to decode the attributes.
func (*TransactionOrder) SetAuthProof ¶
func (t *TransactionOrder) SetAuthProof(authProof any) error
SetAuthProof converts provided authProof struct to CBOR and sets the AuthProof field.
func (*TransactionOrder) StateLockProofSigBytes ¶
func (t *TransactionOrder) StateLockProofSigBytes() ([]byte, error)
func (*TransactionOrder) Timeout ¶
func (t *TransactionOrder) Timeout() uint64
func (*TransactionOrder) UnmarshalAttributes ¶
func (t *TransactionOrder) UnmarshalAttributes(v any) error
func (*TransactionOrder) UnmarshalAuthProof ¶
func (t *TransactionOrder) UnmarshalAuthProof(v any) error
func (*TransactionOrder) UnmarshalCBOR ¶
func (t *TransactionOrder) UnmarshalCBOR(data []byte) error
type TransactionOrderCBOR ¶
type TransactionOrderCBOR = TaggedCBOR
type TransactionRecord ¶
type TransactionRecord struct {
Version Version
TransactionOrder TransactionOrderCBOR
ServerMetadata *ServerMetadata
// contains filtered or unexported fields
}
TransactionRecord is a transaction order with "server-side" metadata added to it. TransactionRecord is a structure that is added to the block.
func (*TransactionRecord) Bytes ¶
func (t *TransactionRecord) Bytes() ([]byte, error)
func (*TransactionRecord) GetActualFee ¶
func (t *TransactionRecord) GetActualFee() uint64
func (*TransactionRecord) GetTransactionOrderV1 ¶
func (t *TransactionRecord) GetTransactionOrderV1() (*TransactionOrder, error)
func (*TransactionRecord) GetVersion ¶
func (t *TransactionRecord) GetVersion() Version
func (*TransactionRecord) Hash ¶
func (t *TransactionRecord) Hash(algorithm crypto.Hash) ([]byte, error)
func (*TransactionRecord) IsSuccessful ¶
func (t *TransactionRecord) IsSuccessful() bool
func (*TransactionRecord) IsValid ¶
func (t *TransactionRecord) IsValid() error
func (*TransactionRecord) MarshalCBOR ¶
func (t *TransactionRecord) MarshalCBOR() ([]byte, error)
func (*TransactionRecord) TargetUnits ¶
func (t *TransactionRecord) TargetUnits() []UnitID
func (*TransactionRecord) TxStatus ¶
func (t *TransactionRecord) TxStatus() TxStatus
func (*TransactionRecord) UnmarshalCBOR ¶
func (t *TransactionRecord) UnmarshalCBOR(data []byte) error
func (*TransactionRecord) UnmarshalProcessingDetails ¶
func (t *TransactionRecord) UnmarshalProcessingDetails(v any) error
type TxProof ¶
type TxProof struct {
Version Version
BlockHeaderHash []byte
Chain []*GenericChainItem
UnicityCertificate TaggedCBOR
// contains filtered or unexported fields
}
TxProof is a transaction execution proof.
func (*TxProof) GetUC ¶
func (p *TxProof) GetUC() (*UnicityCertificate, error)
func (*TxProof) GetVersion ¶
func (*TxProof) MarshalCBOR ¶
func (*TxProof) UnmarshalCBOR ¶
type TxRecordProof ¶
type TxRecordProof struct {
TxRecord *TransactionRecord
TxProof *TxProof
// contains filtered or unexported fields
}
func NewTxRecordProof ¶
func (*TxRecordProof) ActualFee ¶
func (t *TxRecordProof) ActualFee() uint64
func (*TxRecordProof) GetTransactionOrderV1 ¶
func (t *TxRecordProof) GetTransactionOrderV1() (*TransactionOrder, error)
func (*TxRecordProof) IsValid ¶
func (t *TxRecordProof) IsValid() error
func (*TxRecordProof) TxStatus ¶
func (t *TxRecordProof) TxStatus() TxStatus
func (*TxRecordProof) Verify ¶
func (t *TxRecordProof) Verify(getTrustBase func(epoch uint64) (RootTrustBase, error)) error
type TxStatus ¶
type TxStatus uint64
const ( // TxStatusFailed is the status code of a transaction if execution failed. TxStatusFailed TxStatus = 0 // TxStatusSuccessful is the status code of a transaction if execution succeeded. TxStatusSuccessful TxStatus = 1 // TxErrOutOfGas tx execution run out of gas, try with bigger 'MaxTransactionFee' TxErrOutOfGas TxStatus = 2 )
type UnicityCertificate ¶
type UnicityCertificate struct {
Version Version `json:"version"`
InputRecord *InputRecord `json:"inputRecord"`
TRHash hex.Bytes `json:"trHash"` // hash of the TechnicalRecord
ShardConfHash hex.Bytes `json:"shardConfHash"`
ShardTreeCertificate ShardTreeCertificate `json:"shardTreeCertificate"`
UnicityTreeCertificate *UnicityTreeCertificate `json:"unicityTreeCertificate"`
UnicitySeal *UnicitySeal `json:"unicitySeal"`
// contains filtered or unexported fields
}
func (*UnicityCertificate) GetBlockHash ¶
func (x *UnicityCertificate) GetBlockHash() []byte
func (*UnicityCertificate) GetETHash ¶
func (x *UnicityCertificate) GetETHash() []byte
func (*UnicityCertificate) GetFeeSum ¶
func (x *UnicityCertificate) GetFeeSum() uint64
func (*UnicityCertificate) GetPartitionID ¶
func (x *UnicityCertificate) GetPartitionID() PartitionID
func (*UnicityCertificate) GetPreviousStateHash ¶
func (x *UnicityCertificate) GetPreviousStateHash() []byte
func (*UnicityCertificate) GetRootRoundNumber ¶
func (x *UnicityCertificate) GetRootRoundNumber() uint64
func (*UnicityCertificate) GetRoundNumber ¶
func (x *UnicityCertificate) GetRoundNumber() uint64
func (*UnicityCertificate) GetShardID ¶
func (x *UnicityCertificate) GetShardID() ShardID
func (*UnicityCertificate) GetStateHash ¶
func (x *UnicityCertificate) GetStateHash() []byte
func (*UnicityCertificate) GetSummaryValue ¶
func (x *UnicityCertificate) GetSummaryValue() []byte
func (*UnicityCertificate) GetVersion ¶
func (x *UnicityCertificate) GetVersion() Version
func (*UnicityCertificate) Hash ¶
func (x *UnicityCertificate) Hash(hash crypto.Hash) ([]byte, error)
func (*UnicityCertificate) IsDuplicate ¶
func (x *UnicityCertificate) IsDuplicate(prevUC *UnicityCertificate) bool
func (*UnicityCertificate) IsInitial ¶
func (x *UnicityCertificate) IsInitial() bool
func (*UnicityCertificate) IsRepeat ¶
func (x *UnicityCertificate) IsRepeat(prevUC *UnicityCertificate) (bool, error)
func (*UnicityCertificate) IsSuccessor ¶
func (x *UnicityCertificate) IsSuccessor(prevUC *UnicityCertificate) bool
func (*UnicityCertificate) IsValid ¶
func (x *UnicityCertificate) IsValid(partitionID PartitionID, shardConfHash []byte) error
func (*UnicityCertificate) MarshalCBOR ¶
func (x *UnicityCertificate) MarshalCBOR() ([]byte, error)
func (*UnicityCertificate) UnmarshalCBOR ¶
func (x *UnicityCertificate) UnmarshalCBOR(data []byte) error
func (*UnicityCertificate) Verify ¶
func (x *UnicityCertificate) Verify(tb RootTrustBase, algorithm crypto.Hash, partitionID PartitionID, shardConfHash []byte) error
type UnicityCertificateValidator ¶
type UnicityCertificateValidator interface {
Validate(uc *UnicityCertificate, shardConfHash []byte) error
}
type UnicitySeal ¶
type UnicitySeal struct {
Version Version `json:"version"`
NetworkID NetworkID `json:"network"`
RootChainRoundNumber uint64 `json:"rootChainRoundNumber"`
Epoch uint64 `json:"epoch"` // Root Chain Epoch number
Timestamp uint64 `json:"timestamp"` // Round creation time (wall clock value specified and verified by the Root Chain)
PreviousHash hex.Bytes `json:"previousHash"` // Root hash of previous round’s Unicity Tree
Hash hex.Bytes `json:"hash"` // Root hash of the Unicity Tree
Signatures SignatureMap `json:"signatures"`
// contains filtered or unexported fields
}
func (*UnicitySeal) AddToHasher ¶
func (x *UnicitySeal) AddToHasher(hasher abhash.Hasher)
AddToHasher - add all UC data including signature bytes for hash calculation
func (*UnicitySeal) GetVersion ¶
func (x *UnicitySeal) GetVersion() Version
func (*UnicitySeal) IsValid ¶
func (x *UnicitySeal) IsValid() error
func (*UnicitySeal) MarshalCBOR ¶
func (x *UnicitySeal) MarshalCBOR() ([]byte, error)
func (UnicitySeal) SigBytes ¶
func (x UnicitySeal) SigBytes() ([]byte, error)
SigBytes - serialize everything except signatures (used for sign and verify)
func (*UnicitySeal) UnmarshalCBOR ¶
func (x *UnicitySeal) UnmarshalCBOR(b []byte) (err error)
func (*UnicitySeal) Verify ¶
func (x *UnicitySeal) Verify(tb RootTrustBase) error
type UnicityTree ¶
type UnicityTree struct {
// contains filtered or unexported fields
}
func NewUnicityTree ¶
func NewUnicityTree(hashAlgorithm crypto.Hash, data []*UnicityTreeData) (*UnicityTree, error)
NewUnicityTree creates a new unicity tree with given partitions.
NB! Sorts the "data" slice without making copy of it!
func (*UnicityTree) Certificate ¶
func (u *UnicityTree) Certificate(partitionID PartitionID) (*UnicityTreeCertificate, error)
Certificate returns an unicity tree certificate for given partition identifier.
func (*UnicityTree) RootHash ¶
func (u *UnicityTree) RootHash() []byte
type UnicityTreeCertificate ¶
type UnicityTreeCertificate struct {
Version Version `json:"version"`
Partition PartitionID `json:"partitionId"`
HashSteps []*PathItem `json:"hashSteps"`
// contains filtered or unexported fields
}
func (*UnicityTreeCertificate) AddToHasher ¶
func (utc *UnicityTreeCertificate) AddToHasher(hasher abhash.Hasher)
func (*UnicityTreeCertificate) EvalAuthPath ¶
func (utc *UnicityTreeCertificate) EvalAuthPath(shardTreeRoot []byte, hashAlgorithm crypto.Hash) ([]byte, error)
EvalAuthPath aka Compute Unicity Tree Certificate.
The shardTreeRoot is output of the CompShardTreeCert function.
func (*UnicityTreeCertificate) GetVersion ¶
func (utc *UnicityTreeCertificate) GetVersion() Version
func (*UnicityTreeCertificate) IsValid ¶
func (utc *UnicityTreeCertificate) IsValid(partition PartitionID) error
func (*UnicityTreeCertificate) MarshalCBOR ¶
func (utc *UnicityTreeCertificate) MarshalCBOR() ([]byte, error)
func (*UnicityTreeCertificate) UnmarshalCBOR ¶
func (utc *UnicityTreeCertificate) UnmarshalCBOR(data []byte) error
type UnicityTreeData ¶
type UnicityTreeData struct {
Partition PartitionID
ShardTreeRoot []byte // root hash of the partition shard tree
// contains filtered or unexported fields
}
func (*UnicityTreeData) AddToHasher ¶
func (t *UnicityTreeData) AddToHasher(hasher abhash.Hasher)
func (*UnicityTreeData) Key ¶
func (t *UnicityTreeData) Key() []byte
type UnitData ¶
type UnitData interface {
Versioned
Write(hasher abhash.Hasher)
SummaryValueInput() uint64
Copy() UnitData
Owner() []byte
}
UnitData is a generic data type for the unit state.
type UnitID ¶
type UnitID []byte
UnitID is the extended identifier, combining the type and the unit identifiers.
func (UnitID) MarshalText ¶
func (UnitID) TypeMustBe ¶
func (uid UnitID) TypeMustBe(typeID uint32, pdr *PartitionDescriptionRecord) error
func (*UnitID) UnmarshalText ¶
type UnitStateProof ¶
type UnitStateProof struct {
Version Version `json:"version"`
UnitID UnitID `json:"unitId"`
UnitValue uint64 `json:"unitValue,string"` // V0 - data summary of type PD.V
UnitLedgerHash hex.Bytes `json:"unitLedgerHash"` // x_ - previous state hash of type H ∪ {⊥}
UnitTreeCert *UnitTreeCert `json:"unitTreeCert"`
StateTreeCert *StateTreeCert `json:"stateTreeCert"`
UnicityCertificate TaggedCBOR `json:"unicityCert"`
// contains filtered or unexported fields
}
func (*UnitStateProof) CalculateStateTreeOutput ¶
func (*UnitStateProof) GetVersion ¶
func (u *UnitStateProof) GetVersion() Version
func (*UnitStateProof) IsValid ¶
func (u *UnitStateProof) IsValid() error
func (*UnitStateProof) MarshalCBOR ¶
func (u *UnitStateProof) MarshalCBOR() ([]byte, error)
func (*UnitStateProof) UnmarshalCBOR ¶
func (u *UnitStateProof) UnmarshalCBOR(data []byte) error
func (*UnitStateProof) Verify ¶
func (u *UnitStateProof) Verify(algorithm crypto.Hash, unitState *UnitState, ucv UnicityCertificateValidator, shardConfHash []byte) error
type UnitStateWithProof ¶
type UnitStateWithProof struct {
State *UnitState
Proof *UnitStateProof
// contains filtered or unexported fields
}
func (*UnitStateWithProof) UnmarshalUnitData ¶
func (up *UnitStateWithProof) UnmarshalUnitData(v any) error