Documentation ¶
Index ¶
- Constants
- Variables
- func NewNodeGenesis(txSystem txsystem.TransactionSystem, opts ...GenesisOption) (*genesis.PartitionNode, error)
- type BlockProposalValidator
- type DefaultBlockProposalValidator
- type DefaultLeaderSelector
- func (l *DefaultLeaderSelector) GetLeaderID() peer.ID
- func (l *DefaultLeaderSelector) IsCurrentNodeLeader() bool
- func (l *DefaultLeaderSelector) LeaderFunc(uc *types.UnicityCertificate) peer.ID
- func (l *DefaultLeaderSelector) SelfID() peer.ID
- func (l *DefaultLeaderSelector) UpdateLeader(uc *types.UnicityCertificate)
- type DefaultTxValidator
- type DefaultUnicityCertificateValidator
- type GenesisOption
- func WithEncryptionPubKey(encryptionPubKey []byte) GenesisOption
- func WithHashAlgorithm(hashAlgorithm gocrypto.Hash) GenesisOption
- func WithParams(params []byte) GenesisOption
- func WithPeerID(peerID peer.ID) GenesisOption
- func WithSigningKey(signer crypto.Signer) GenesisOption
- func WithSystemIdentifier(systemIdentifier []byte) GenesisOption
- func WithT2Timeout(t2Timeout uint32) GenesisOption
- type LeaderSelector
- type Net
- type Node
- func (n *Node) GetBlock(_ context.Context, blockNr uint64) (*types.Block, error)
- func (n *Node) GetLatestBlock() (_ *types.Block, err error)
- func (n *Node) GetLatestRoundNumber() (uint64, error)
- func (n *Node) GetTransactionRecord(ctx context.Context, hash []byte) (*types.TransactionRecord, *types.TxProof, error)
- func (n *Node) Run(ctx context.Context) error
- func (n *Node) SubmitTx(_ context.Context, tx *types.TransactionOrder) (txOrderHash []byte, err error)
- func (n *Node) SystemIdentifier() []byte
- type NodeOption
- func WithBlockProposalValidator(blockProposalValidator BlockProposalValidator) NodeOption
- func WithBlockStore(blockStore keyvaluedb.KeyValueDB) NodeOption
- func WithEventHandler(eh event.Handler, eventChCapacity int) NodeOption
- func WithLeaderSelector(leaderSelector LeaderSelector) NodeOption
- func WithReplicationParams(maxBlocks uint64, maxTx uint32) NodeOption
- func WithRootAddressAndIdentifier(address multiaddr.Multiaddr, id peer.ID) NodeOption
- func WithT1Timeout(t1Timeout time.Duration) NodeOption
- func WithTxIndexer(txIndexer keyvaluedb.KeyValueDB) NodeOption
- func WithTxValidator(txValidator TxValidator) NodeOption
- func WithUnicityCertificateValidator(unicityCertificateValidator UnicityCertificateValidator) NodeOption
- type TxValidator
- type UnicityCertificateValidator
Constants ¶
const ( DefaultT1Timeout = 750 * time.Millisecond DefaultTxBufferSize = 1000 DefaultReplicationMaxBlocks uint64 = 1000 DefaultReplicationMaxTx uint32 = 10 * DefaultTxBufferSize )
const ( UnknownLeader = "" ErrStrSystemIdentifierIsNil = "system identifier is nil" )
Variables ¶
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") )
var ErrEncryptionPubKeyIsNil = errors.New("encryption public key is nil")
var (
ErrNodeDoesNotHaveLatestBlock = errors.New("recovery needed, node does not have the latest block")
)
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
func (l *DefaultLeaderSelector) LeaderFunc(uc *types.UnicityCertificate) peer.ID
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 ¶
func (ucv *DefaultUnicityCertificateValidator) Validate(uc *types.UnicityCertificate) error
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 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) GetLatestBlock ¶
GetLatestBlock returns current latest block. It's part of the public API exposed by node.
func (*Node) GetLatestRoundNumber ¶ added in v0.2.0
GetLatestRoundNumber returns current round number. It's part of the public API exposed by node.
func (*Node) GetTransactionRecord ¶ added in v0.2.0
func (*Node) SystemIdentifier ¶ added in v0.1.1
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.