partition

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: AGPL-3.0 Imports: 40 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DefaultT1Timeout                   = 750 * time.Millisecond
	DefaultReplicationMaxBlocks uint64 = 1000
	DefaultReplicationMaxTx     uint32 = 10000
)
View Source
const (
	UnknownLeader = ""
)

Variables

View Source
var (
	ErrTxSystemIsNil = errors.New("transaction system is nil")
	ErrGenesisIsNil  = errors.New("genesis is nil")
)
View Source
var ErrEncryptionPubKeyIsNil = errors.New("encryption public key is nil")
View Source
var (
	ErrIndexNotFound = errors.New("index not found")
)
View Source
var ErrNodeDoesNotHaveLatestBlock = errors.New("recovery needed, node does not have the latest block")
View Source
var ErrSignerIsNil = errors.New("signer is nil")
View Source
var ErrStateIsNil = errors.New("state is nil")
View Source
var ErrTxTimeout = errors.New("transaction has timed out")

Functions

func NewNodeGenesis

func NewNodeGenesis(state *state.State, opts ...GenesisOption) (*genesis.PartitionNode, error)

NewNodeGenesis creates a new genesis.PartitionNode from the given inputs. This function creates the first block certification request by calling the TransactionSystem.EndBlock function. Must contain PeerID, signer, and system identifier and public encryption key configuration:

   pn, err := NewNodeGenesis(
					txSystem,
					WithPeerID(myPeerID),
					WithSigningKey(signer),
					WithSystemIdentifier(sysID),
					WithEncryptionPubKey(encPubKey),
				)

This function must be called by all partition nodes in the network.

func ReadUnitProofIndex

func ReadUnitProofIndex(db keyvaluedb.KeyValueDB, unitID []byte, txOrderHash []byte) (*types.UnitDataAndProof, error)

Types

type BlockAndState

type BlockAndState struct {
	Block *types.Block
	State UnitAndProof
}

type BlockProposalValidator

type BlockProposalValidator interface {
	// Validate validates the given blockproposal.BlockProposal. Returns an error if given block proposal
	// is not valid.
	Validate(bp *blockproposal.BlockProposal, nodeSignatureVerifier crypto.Verifier) error
}

BlockProposalValidator is used to validate block proposals.

func NewDefaultBlockProposalValidator

func NewDefaultBlockProposalValidator(
	systemDescription *genesis.SystemDescriptionRecord,
	rootTrust map[string]crypto.Verifier,
	algorithm gocrypto.Hash,
) (BlockProposalValidator, error)

NewDefaultBlockProposalValidator creates a new instance of default BlockProposalValidator.

type DefaultBlockProposalValidator

type DefaultBlockProposalValidator struct {
	// contains filtered or unexported fields
}

DefaultBlockProposalValidator is a default implementation of UnicityCertificateValidator.

func (*DefaultBlockProposalValidator) Validate

func (bpv *DefaultBlockProposalValidator) Validate(bp *blockproposal.BlockProposal, nodeSignatureVerifier crypto.Verifier) error

type DefaultLeaderSelector

type DefaultLeaderSelector struct {
	// contains filtered or unexported fields
}

DefaultLeaderSelector is used to select a leader from the validator pool.

func NewDefaultLeaderSelector

func NewDefaultLeaderSelector() *DefaultLeaderSelector

func (*DefaultLeaderSelector) GetLeader

func (l *DefaultLeaderSelector) GetLeader() peer.ID

func (*DefaultLeaderSelector) IsLeader

func (l *DefaultLeaderSelector) IsLeader(peerID peer.ID) bool

IsLeader returns true it the given peer is the leader and must propose the next block.

func (*DefaultLeaderSelector) LeaderFunc

func (l *DefaultLeaderSelector) LeaderFunc(uc *types.UnicityCertificate, validators []peer.ID) peer.ID

LeaderFunc calculates new leader from Unicity Certificate. For details see Yellowpaper Algorithm 1 "State and Initialization" - "function leaderfunc(uc)" description.

func (*DefaultLeaderSelector) UpdateLeader

func (l *DefaultLeaderSelector) UpdateLeader(uc *types.UnicityCertificate, validators []peer.ID)

UpdateLeader updates the leader (next block proposer). If input is nil then leader is set to UnknownLeader.

type DefaultTxValidator

type DefaultTxValidator struct {
	// contains filtered or unexported fields
}

func (*DefaultTxValidator) Validate

func (dtv *DefaultTxValidator) Validate(tx *types.TransactionOrder, latestBlockNumber uint64) error

type DefaultUnicityCertificateValidator

type DefaultUnicityCertificateValidator struct {
	// contains filtered or unexported fields
}

DefaultUnicityCertificateValidator is a default implementation of UnicityCertificateValidator.

func (*DefaultUnicityCertificateValidator) Validate

type GenesisOption

type GenesisOption func(c *genesisConf)

func WithEncryptionPubKey

func WithEncryptionPubKey(encryptionPubKey []byte) GenesisOption

func WithHashAlgorithm

func WithHashAlgorithm(hashAlgorithm gocrypto.Hash) GenesisOption

func WithParams

func WithParams(params []byte) GenesisOption

func WithPeerID

func WithPeerID(peerID peer.ID) GenesisOption

func WithSigningKey

func WithSigningKey(signer crypto.Signer) GenesisOption

func WithSystemIdentifier

func WithSystemIdentifier(systemIdentifier types.SystemID) GenesisOption

func WithT2Timeout

func WithT2Timeout(t2Timeout uint32) GenesisOption

type IndexReader added in v0.4.0

type IndexReader interface {
	GetOwnerUnits(ownerID []byte) ([]types.UnitID, error)
}

type IndexWriter added in v0.4.0

type IndexWriter interface {
	LoadState(s txsystem.StateReader) error
	IndexBlock(b *types.Block, s StateProvider) error
}

type LeaderSelector

type LeaderSelector interface {
	UpdateLeader(uc *types.UnicityCertificate, validators []peer.ID)
	LeaderFunc(uc *types.UnicityCertificate, validators []peer.ID) peer.ID
	IsLeader(peer peer.ID) bool
	GetLeader() peer.ID
}

type Node

type Node struct {
	// contains filtered or unexported fields
}

Node represents a member in the partition and implements an instance of a specific TransactionSystem. Partition is a distributed system, it consists of either a set of shards, or one or more partition nodes.

func NewNode

func NewNode(
	ctx context.Context,
	peerConf *network.PeerConfiguration,
	signer crypto.Signer,
	txSystem txsystem.TransactionSystem,
	genesis *genesis.PartitionGenesis,
	network ValidatorNetwork,
	observe Observability,
	nodeOptions ...NodeOption,
) (*Node, error)

NewNode creates a new instance of the partition node. All parameters expect the nodeOptions are required. Functions implementing the NodeOption interface can be used to override default configuration values.

The following restrictions apply to the inputs:

  • the network peer and signer must use the same keys that were used to generate node genesis file;

func (*Node) GetBlock

func (n *Node) GetBlock(_ context.Context, blockNr uint64) (*types.Block, error)

func (*Node) GetLatestRoundNumber

func (n *Node) GetLatestRoundNumber(ctx context.Context) (uint64, error)

GetLatestRoundNumber returns the round number of the latest seen UC. It's part of the public API exposed by node.

func (*Node) GetPeer

func (n *Node) GetPeer() *network.Peer

func (*Node) GetTransactionRecord

func (n *Node) GetTransactionRecord(ctx context.Context, hash []byte) (*types.TransactionRecord, *types.TxProof, error)

func (*Node) LatestBlockNumber

func (n *Node) LatestBlockNumber() (uint64, error)

LatestBlockNumber returns the latest committed round number. It's part of the public API exposed by node.

func (*Node) Run

func (n *Node) Run(ctx context.Context) error

func (*Node) SubmitTx

func (n *Node) SubmitTx(ctx context.Context, tx *types.TransactionOrder) (txOrderHash []byte, err error)

func (*Node) SystemIdentifier

func (n *Node) SystemIdentifier() types.SystemID

func (*Node) TransactionSystemState added in v0.4.0

func (n *Node) TransactionSystemState() txsystem.StateReader

type NodeOption

type NodeOption func(c *configuration)

func WithBlockProposalValidator

func WithBlockProposalValidator(blockProposalValidator BlockProposalValidator) NodeOption

func WithBlockStore

func WithBlockStore(blockStore keyvaluedb.KeyValueDB) NodeOption

func WithEventHandler

func WithEventHandler(eh event.Handler, eventChCapacity int) NodeOption

func WithLeaderSelector

func WithLeaderSelector(leaderSelector LeaderSelector) NodeOption

func WithOwnerIndex added in v0.4.0

func WithOwnerIndex(ownerIndexer *OwnerIndexer) NodeOption

func WithProofIndex

func WithProofIndex(db keyvaluedb.KeyValueDB, history uint64) NodeOption

func WithReplicationParams

func WithReplicationParams(maxBlocks uint64, maxTx uint32) NodeOption

func WithT1Timeout

func WithT1Timeout(t1Timeout time.Duration) NodeOption

func WithTxValidator

func WithTxValidator(txValidator TxValidator) NodeOption

func WithUnicityCertificateValidator

func WithUnicityCertificateValidator(unicityCertificateValidator UnicityCertificateValidator) NodeOption

type Observability

type Observability interface {
	TracerProvider() trace.TracerProvider
	Tracer(name string, options ...trace.TracerOption) trace.Tracer
	Meter(name string, opts ...metric.MeterOption) metric.Meter
	PrometheusRegisterer() prometheus.Registerer
	Logger() *slog.Logger
}

type OwnerIndexer

type OwnerIndexer struct {
	// contains filtered or unexported fields
}

OwnerIndexer manages index of unit owners based on txsystem state.

func NewOwnerIndexer

func NewOwnerIndexer(l *slog.Logger) *OwnerIndexer

func (*OwnerIndexer) GetOwnerUnits

func (o *OwnerIndexer) GetOwnerUnits(ownerID []byte) ([]types.UnitID, error)

GetOwnerUnits returns all unit ids for given owner.

func (*OwnerIndexer) IndexBlock added in v0.4.0

func (o *OwnerIndexer) IndexBlock(b *types.Block, s StateProvider) error

IndexBlock updates the index based on current committed state and transactions in a block (changed units).

func (*OwnerIndexer) LoadState

func (o *OwnerIndexer) LoadState(s txsystem.StateReader) error

LoadState fills the index from state.

type ProofIndexer

type ProofIndexer struct {
	// contains filtered or unexported fields
}

func NewProofIndexer

func NewProofIndexer(algo crypto.Hash, db keyvaluedb.KeyValueDB, historySize uint64, l *slog.Logger) *ProofIndexer

func (*ProofIndexer) GetDB

func (p *ProofIndexer) GetDB() keyvaluedb.KeyValueDB

func (*ProofIndexer) Handle

func (p *ProofIndexer) Handle(ctx context.Context, block *types.Block, state UnitAndProof)

func (*ProofIndexer) IndexBlock added in v0.4.0

func (p *ProofIndexer) IndexBlock(ctx context.Context, block *types.Block, state UnitAndProof) error

type StateProvider added in v0.4.0

type StateProvider interface {
	GetUnit(id types.UnitID, committed bool) (*state.Unit, error)
}

type TxIndex

type TxIndex struct {
	RoundNumber  uint64
	TxOrderIndex int
}

func ReadTransactionIndex

func ReadTransactionIndex(db keyvaluedb.KeyValueDB, txOrderHash []byte) (*TxIndex, error)

type TxValidator

type TxValidator interface {
	Validate(tx *types.TransactionOrder, latestBlockNumber uint64) error
}

TxValidator is used to validate generic transactions (e.g. timeouts, system identifiers, etc.). This validator should not contain transaction system specific validation logic.

func NewDefaultTxValidator

func NewDefaultTxValidator(systemIdentifier types.SystemID) (TxValidator, error)

NewDefaultTxValidator creates a new instance of default TxValidator.

type UnicityCertificateValidator

type UnicityCertificateValidator interface {
	// Validate validates the given certificates.UnicityCertificate. Returns an error if given unicity certificate
	// is not valid.
	Validate(uc *types.UnicityCertificate) error
}

UnicityCertificateValidator is used to validate certificates.UnicityCertificate.

func NewDefaultUnicityCertificateValidator

func NewDefaultUnicityCertificateValidator(
	systemDescription *genesis.SystemDescriptionRecord,
	rootTrust map[string]crypto.Verifier,
	algorithm gocrypto.Hash,
) (UnicityCertificateValidator, error)

NewDefaultUnicityCertificateValidator creates a new instance of default UnicityCertificateValidator.

type UnitAndProof

type UnitAndProof interface {
	// GetUnit - access tx system unit state
	GetUnit(id types.UnitID, committed bool) (*state.Unit, error)
	// CreateUnitStateProof - create unit proofs
	CreateUnitStateProof(id types.UnitID, logIndex int) (*types.UnitStateProof, error)
}

UnitAndProof read access to state to access unit and unit proofs

type ValidatorNetwork

type ValidatorNetwork interface {
	Send(ctx context.Context, msg any, receivers ...peer.ID) error
	ReceivedChannel() <-chan any

	AddTransaction(ctx context.Context, tx *types.TransactionOrder) ([]byte, error)
	ForwardTransactions(ctx context.Context, receiver peer.ID)
	ProcessTransactions(ctx context.Context, txProcessor network.TxProcessor)
}

ValidatorNetwork provides an interface for sending and receiving validator network messages.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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