partition

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: AGPL-3.0, ISC Imports: 29 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 (
	ErrNodeDoesNotHaveLatestBlock = errors.New("node does not have the latest block")
	ErrStateReverted              = errors.New("state reverted")
)
View Source
var (
	ErrSystemIdentifierIsNil = errors.New("System identifier is nil")
	ErrStrTxIsNil            = "transaction is nil"
)
View Source
var ErrEncryptionPubKeyIsNil = errors.New("encryption public key is nil")
View Source
var ErrInvalidSystemIdentifier = errors.New("system identifier is invalid")
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) LeaderFromUnicitySeal

func (l *DefaultLeaderSelector) LeaderFromUnicitySeal(seal *certificates.UnicitySeal) peer.ID

func (*DefaultLeaderSelector) SelfID

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

func (*DefaultLeaderSelector) UpdateLeader

func (l *DefaultLeaderSelector) UpdateLeader(seal *certificates.UnicitySeal)

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 txsystem.GenericTransaction, 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 *anypb.Any) 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(seal *certificates.UnicitySeal)
	LeaderFromUnicitySeal(seal *certificates.UnicitySeal) peer.ID
	IsCurrentNodeLeader() bool
	GetLeaderID() peer.ID
	SelfID() peer.ID
}

type Net

type Net interface {
	Send(msg network.OutputMessage, receivers []peer.ID) error
	ReceivedChannel() <-chan network.ReceivedMessage
}

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,
		WithContext(context.Background()),
		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) Close

func (n *Node) Close()

Close shuts down the Node component.

func (*Node) GetBlock

func (n *Node) GetBlock(blockNr uint64) (*block.Block, error)

func (*Node) GetLatestBlock

func (n *Node) GetLatestBlock() *block.Block

func (*Node) SubmitTx

func (n *Node) SubmitTx(tx *txsystem.Transaction) 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 store.BlockStore) NodeOption

func WithContext

func WithContext(context context.Context) 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 WithTxValidator

func WithTxValidator(txValidator TxValidator) NodeOption

func WithUnicityCertificateValidator

func WithUnicityCertificateValidator(unicityCertificateValidator UnicityCertificateValidator) NodeOption

type TxValidator

type TxValidator interface {
	Validate(tx txsystem.GenericTransaction, 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 *certificates.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