partition

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2023 License: AGPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

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

	ErrStrSystemIdentifierIsNil = "system identifier is nil"
)

Variables

View Source
var (
	ErrTxSystemIsNil       = errors.New("transaction system is nil")
	ErrPeerIsNil           = errors.New("peer is nil")
	ErrGenesisIsNil        = errors.New("genesis is nil")
	ErrInvalidRootHash     = errors.New("tx system root hash does not equal to genesis file hash")
	ErrInvalidSummaryValue = errors.New("tx system summary value does not equal to genesis file summary value")
)
View Source
var ErrEncryptionPubKeyIsNil = errors.New("encryption public key is nil")
View Source
var (
	ErrNodeDoesNotHaveLatestBlock = errors.New("recovery needed, node does not have the latest block")
)
View Source
var ErrSignerIsNil = errors.New("signer is nil")

Functions

func NewNodeGenesis

func NewNodeGenesis(txSystem txsystem.TransactionSystem, 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.

Types

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(self *network.Peer, systemIdentifier []byte) (*DefaultLeaderSelector, error)

func (*DefaultLeaderSelector) GetLeaderID

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

func (*DefaultLeaderSelector) IsCurrentNodeLeader

func (l *DefaultLeaderSelector) IsCurrentNodeLeader() bool

IsCurrentNodeLeader returns true it current node is the leader and must propose the next block.

func (*DefaultLeaderSelector) LeaderFunc added in v0.2.0

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

func (*DefaultLeaderSelector) SelfID

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

func (*DefaultLeaderSelector) UpdateLeader

func (l *DefaultLeaderSelector) UpdateLeader(uc *types.UnicityCertificate)

UpdateLeader updates the 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 []byte) GenesisOption

func WithT2Timeout

func WithT2Timeout(t2Timeout uint32) GenesisOption

type LeaderSelector

type LeaderSelector interface {
	UpdateLeader(uc *types.UnicityCertificate)
	LeaderFunc(uc *types.UnicityCertificate) peer.ID
	IsCurrentNodeLeader() bool
	GetLeaderID() peer.ID
	SelfID() peer.ID
}

type Net

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

Net provides an interface for sending messages to and receiving messages from other nodes in the network.

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 New

func New(
	peer *network.Peer,
	signer crypto.Signer,
	txSystem txsystem.TransactionSystem,
	genesis *genesis.PartitionGenesis,
	net Net,
	nodeOptions ...NodeOption,
) (*Node, error)

New 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:

  n, err := New(
 	peer,
		signer,
		txSystem,
		genesis,
		net,
		WithTxValidator(myTxValidator)),
		WithUnicityCertificateValidator(ucValidator),
		WithBlockProposalValidator(blockProposalValidator),
		WithLeaderSelector(leaderSelector),
		WithBlockStore(blockStore),
		WithT1Timeout(250*time.Millisecond),
  )

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;
  • the state of the transaction system must be equal to the state that was used to generate genesis file.

func (*Node) GetBlock

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

func (*Node) GetLatestBlock

func (n *Node) GetLatestBlock() (_ *types.Block, err error)

GetLatestBlock returns current latest block. It's part of the public API exposed by node.

func (*Node) GetLatestRoundNumber added in v0.2.0

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

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

func (*Node) GetTransactionRecord added in v0.2.0

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

func (*Node) Run added in v0.2.0

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

func (*Node) SubmitTx

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

func (*Node) SystemIdentifier added in v0.1.1

func (n *Node) SystemIdentifier() []byte

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 WithReplicationParams added in v0.1.2

func WithReplicationParams(maxBlocks uint64, maxTx uint32) NodeOption

func WithRootAddressAndIdentifier

func WithRootAddressAndIdentifier(address multiaddr.Multiaddr, id peer.ID) NodeOption

func WithT1Timeout

func WithT1Timeout(t1Timeout time.Duration) NodeOption

func WithTxIndexer added in v0.2.0

func WithTxIndexer(txIndexer keyvaluedb.KeyValueDB) NodeOption

func WithTxValidator

func WithTxValidator(txValidator TxValidator) NodeOption

func WithUnicityCertificateValidator

func WithUnicityCertificateValidator(unicityCertificateValidator UnicityCertificateValidator) NodeOption

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 []byte) (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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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