storage

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCommitFailed = errors.New("commit failed")
)

Functions

This section is empty.

Types

type BlockStore

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

func New

func New(hashAlgo crypto.Hash, db PersistentStore, orchestration Orchestration, log *slog.Logger) (block *BlockStore, err error)

func NewFromState

func NewFromState(hash crypto.Hash, block *abdrc.CommittedBlock, db PersistentStore, orchestration Orchestration, log *slog.Logger) (*BlockStore, error)

func (*BlockStore) Add

func (x *BlockStore) Add(block *rctypes.BlockData, verifier IRChangeReqVerifier) ([]byte, error)

Add adds new round state to pipeline and returns the new state root hash a.k.a. execStateID

func (*BlockStore) Block

func (x *BlockStore) Block(round uint64) (*ExecutedBlock, error)

Block returns block for given round. When store doesn't have block for the round it returns error.

func (*BlockStore) GetCertificate

func (*BlockStore) GetCertificates

func (x *BlockStore) GetCertificates() []*types.UnicityCertificate

func (*BlockStore) GetDB

func (x *BlockStore) GetDB() PersistentStore

func (*BlockStore) GetHighQc

func (x *BlockStore) GetHighQc() *rctypes.QuorumCert

func (*BlockStore) GetLastTC

func (x *BlockStore) GetLastTC() (*rctypes.TimeoutCert, error)

func (*BlockStore) GetState

func (x *BlockStore) GetState() (*abdrc.StateMsg, error)

func (*BlockStore) IsChangeInProgress

func (x *BlockStore) IsChangeInProgress(partition types.PartitionID, shard types.ShardID) *types.InputRecord

IsChangeInProgress - return input record if shard has a pending IR change in the pipeline or nil if no change is currently in the pipeline.

func (*BlockStore) ProcessQc

func (*BlockStore) ProcessTc

func (x *BlockStore) ProcessTc(tc *rctypes.TimeoutCert) (rErr error)

func (*BlockStore) ReadLastVote

func (x *BlockStore) ReadLastVote() (any, error)

ReadLastVote returns last sent vote message by this node

func (*BlockStore) ShardInfo

func (x *BlockStore) ShardInfo(partition types.PartitionID, shard types.ShardID) *ShardInfo

func (*BlockStore) StoreLastVote

func (x *BlockStore) StoreLastVote(vote any) error

StoreLastVote stores last sent vote message by this node

type BlockTree

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

func NewBlockTree

func NewBlockTree(bDB PersistentStore, orchestration Orchestration) (*BlockTree, error)

func NewBlockTreeWithRootBlock

func NewBlockTreeWithRootBlock(block *ExecutedBlock, bDB PersistentStore) (*BlockTree, error)

NewBlockTreeWithRootBlock creates BlockTree with given block as root node.

Intended use-case is for recovery - acquire latest committed block and build on that state.

func (*BlockTree) Add

func (bt *BlockTree) Add(block *ExecutedBlock) error

Add adds new leaf to the block tree

func (*BlockTree) Commit

func (bt *BlockTree) Commit(commitQc *abdrc.QuorumCert) ([]*certification.CertificationResponse, error)

Commit commits block for round and prunes all preceding blocks from the tree, the committed block becomes the new root of the tree. It returns new certificates generated by the block (ie only for those shards which did have change in progress).

func (*BlockTree) CurrentState

func (bt *BlockTree) CurrentState() (*rcnet.StateMsg, error)

func (*BlockTree) FindBlock

func (bt *BlockTree) FindBlock(round uint64) (*ExecutedBlock, error)

func (*BlockTree) GetAllUncommittedNodes

func (bt *BlockTree) GetAllUncommittedNodes() []*ExecutedBlock

func (*BlockTree) HighQc

func (bt *BlockTree) HighQc() *abdrc.QuorumCert

func (*BlockTree) InsertQc

func (bt *BlockTree) InsertQc(qc *abdrc.QuorumCert) error

func (*BlockTree) RemoveLeaf

func (bt *BlockTree) RemoveLeaf(round uint64) error

RemoveLeaf removes leaf node if it is not root node

func (*BlockTree) Root

func (bt *BlockTree) Root() *ExecutedBlock

type BoltDB

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

Implementation of persistent storage for the BlockTree and SafetyModule using bbolt database.

func NewBoltStorage

func NewBoltStorage(file string) (db BoltDB, err error)

func (BoltDB) Close

func (db BoltDB) Close() error

func (BoltDB) GetHighestQcRound

func (db BoltDB) GetHighestQcRound() (round uint64)

func (BoltDB) GetHighestVotedRound

func (db BoltDB) GetHighestVotedRound() (round uint64)

func (BoltDB) LoadBlocks

func (db BoltDB) LoadBlocks() (blocks []*ExecutedBlock, err error)

LoadBlocks returns all the blocks in the database. The list is sorted in descending order of round number.

func (BoltDB) ReadLastTC

func (db BoltDB) ReadLastTC() (tc *rctypes.TimeoutCert, _ error)

func (BoltDB) ReadLastVote

func (db BoltDB) ReadLastVote() (msg any, err error)

func (BoltDB) SetHighestQcRound

func (db BoltDB) SetHighestQcRound(qcRound, votedRound uint64) error

func (BoltDB) SetHighestVotedRound

func (db BoltDB) SetHighestVotedRound(round uint64) error

func (BoltDB) WriteBlock

func (db BoltDB) WriteBlock(block *ExecutedBlock, root bool) error

WriteBlock stores "block" into database. If "root" is "true" older blocks (based on round number) will be deleted.

func (BoltDB) WriteTC

func (db BoltDB) WriteTC(tc *rctypes.TimeoutCert) error

func (BoltDB) WriteVote

func (db BoltDB) WriteVote(vote any) (err error)

type ExecutedBlock

type ExecutedBlock struct {
	BlockData  *rctypes.BlockData  // proposed block
	HashAlgo   crypto.Hash         // hash algorithm for the block
	RootHash   hex.Bytes           // resulting root hash
	Qc         *rctypes.QuorumCert // block's quorum certificate (from next view)
	CommitQc   *rctypes.QuorumCert // block's commit certificate
	ShardState ShardStates
	// contains filtered or unexported fields
}

func NewGenesisBlock

func NewGenesisBlock(networkID types.NetworkID, hashAlgo crypto.Hash) (*ExecutedBlock, error)

func NewRootBlock

func NewRootBlock(block *abdrc.CommittedBlock, hash crypto.Hash, orchestration Orchestration) (*ExecutedBlock, error)

func (*ExecutedBlock) Extend

func (x *ExecutedBlock) Extend(newBlock *rctypes.BlockData, verifier IRChangeReqVerifier, orchestration Orchestration, hash crypto.Hash, log *slog.Logger) (*ExecutedBlock, error)

func (*ExecutedBlock) GenerateCertificates

func (x *ExecutedBlock) GenerateCertificates(commitQc *rctypes.QuorumCert) ([]*certification.CertificationResponse, error)

func (*ExecutedBlock) GetParentRound

func (x *ExecutedBlock) GetParentRound() uint64

func (*ExecutedBlock) GetRound

func (x *ExecutedBlock) GetRound() uint64

type IRChangeReqVerifier

type IRChangeReqVerifier interface {
	VerifyIRChangeReq(round uint64, irChReq *rctypes.IRChangeReq) (*types.InputRecord, error)
}

type Orchestration

type Orchestration interface {
	NetworkID() types.NetworkID
	ShardConfig(partition types.PartitionID, shard types.ShardID, rootRound uint64) (*types.PartitionDescriptionRecord, error)
	ShardConfigs(rootRound uint64) (map[types.PartitionShardID]*types.PartitionDescriptionRecord, error)
}

type PersistentStore

type PersistentStore interface {
	LoadBlocks() ([]*ExecutedBlock, error)
	WriteBlock(block *ExecutedBlock, root bool) error

	WriteVote(vote any) error
	ReadLastVote() (msg any, err error)

	WriteTC(tc *rctypes.TimeoutCert) error
	ReadLastTC() (*rctypes.TimeoutCert, error)
}

type ShardInfo

type ShardInfo struct {
	PartitionID   types.PartitionID
	ShardID       types.ShardID
	T2Timeout     time.Duration
	ShardConfHash []byte
	RootHash      []byte // last certified root hash

	// statistical record of the previous epoch. As we only need
	// it for hashing we keep it in serialized representation
	PrevEpochStat types.RawCBOR

	// statistical record of the current epoch
	Stat certification.StatisticalRecord

	// per validator total, invariant fees of the previous epoch
	// but as with statistical record of the previous epoch we need it
	// for hashing so we keep it in serialized representation
	PrevEpochFees types.RawCBOR

	Fees map[string]uint64 // per validator summary fees of the current epoch

	LastCR *certification.CertificationResponse // last response sent to shard

	// latest change request data for creating next certificate
	IR *types.InputRecord
	TR certification.TechnicalRecord
	// contains filtered or unexported fields
}

func NewShardInfo

func NewShardInfo(shardConf *types.PartitionDescriptionRecord, hashAlg crypto.Hash) (*ShardInfo, error)

func (*ShardInfo) GetQuorum

func (si *ShardInfo) GetQuorum() uint64

func (*ShardInfo) GetTotalNodes

func (si *ShardInfo) GetTotalNodes() uint64

func (*ShardInfo) IsValid

func (si *ShardInfo) IsValid() error

func (*ShardInfo) ValidRequest

func (si *ShardInfo) ValidRequest(req *certification.BlockCertificationRequest) error

func (*ShardInfo) Verify

func (si *ShardInfo) Verify(nodeID string, f func(v abcrypto.Verifier) error) error

type ShardSet

type ShardSet map[types.PartitionShardID]struct{}

func (ShardSet) MarshalCBOR

func (ss ShardSet) MarshalCBOR() ([]byte, error)

func (*ShardSet) UnmarshalCBOR

func (ss *ShardSet) UnmarshalCBOR(data []byte) error

type ShardStates

type ShardStates struct {
	States  map[types.PartitionShardID]*ShardInfo
	Changed ShardSet // shards whose state has changed
	// contains filtered or unexported fields
}

func (ShardStates) MarshalCBOR

func (ss ShardStates) MarshalCBOR() ([]byte, error)

func (ShardStates) UnicityTree

func (ss ShardStates) UnicityTree(algo crypto.Hash) (*types.UnicityTree, map[types.PartitionID]types.ShardTree, error)

UnicityTree builds the unicity tree based on the shard states.

func (*ShardStates) UnmarshalCBOR

func (ss *ShardStates) UnmarshalCBOR(data []byte) error

type VoteStore

type VoteStore struct {
	VoteType VoteType
	VoteMsg  types.RawCBOR
}

type VoteType

type VoteType uint8
const (
	Unknown VoteType = iota
	VoteMsg
	TimeoutVoteMsg
)

Jump to

Keyboard shortcuts

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