cometdump

package module
v0.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockRecord

type BlockRecord struct {
	BlockID               cmtypes.BlockID
	Block                 *cmtypes.Block
	TxResults             []*abcitypes.ExecTxResult
	FinalizeBlockEvents   []abcitypes.Event
	ValidatorUpdates      []abcitypes.ValidatorUpdate
	ConsensusParamUpdates *cmtproto.ConsensusParams
	BlockResultsAppHash   []byte
}

BlockRecord is a structure that holds the details of a block, including its ID, transactions, events, and other related data. It is used to encode and decode block data in a msgpack format.

func BlockRecordFromRPCResults

func BlockRecordFromRPCResults(block *coretypes.ResultBlock, blockResults *coretypes.ResultBlockResults) *BlockRecord

BlockRecordFromRPCResults creates a BlockRecord from the given ResultBlock and ResultBlockResults.

func (*BlockRecord) DecodeMsgpack

func (b *BlockRecord) DecodeMsgpack(dec *msgpack.Decoder) error

DecodeMsgpack decodes the Block from a msgpack format.

func (*BlockRecord) EncodeMsgpack

func (b *BlockRecord) EncodeMsgpack(enc *msgpack.Encoder) error

EncodeMsgpack encodes the Block into a msgpack format.

func (*BlockRecord) ToResultBlock

func (b *BlockRecord) ToResultBlock() (*coretypes.ResultBlock, error)

ToResultBlock converts the resultBlockProto back to a ResultBlock.

func (*BlockRecord) ToResultBlockResults

func (b *BlockRecord) ToResultBlockResults() (*coretypes.ResultBlockResults, error)

ToResultBlockResults converts the Block to a ResultBlockResults.

type Chunk

type Chunk struct {
	FromHeight int64
	ToHeight   int64
}

Chunk represents a range of blocks in the store. It contains the start and end heights of the chunk.

func (Chunk) Len

func (c Chunk) Len() int64

Len returns the length of the chunk, which is the number of blocks it contains.

func (Chunk) String

func (c Chunk) String() string

String implements the Stringer interface.

type Chunks

type Chunks []Chunk

Chunks is a slice of Chunk objects.

func (Chunks) EndHeight

func (Chunks Chunks) EndHeight() int64

EndHeight returns the end height of the last chunk in the list.

func (Chunks) FindForHeight

func (chunks Chunks) FindForHeight(height int64) (Chunk, bool)

FindForHeight returns the chunk that contains the given height. If no chunk is found, it returns an error.

func (Chunks) StartHeight

func (Chunks Chunks) StartHeight() int64

StartHeight returns the start height of the first chunk in the list.

type NoNodesAvailableError

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

NoNodesAvailableError is returned when no nodes are available for the given height range.

func (*NoNodesAvailableError) Error

func (e *NoNodesAvailableError) Error() string

func (*NoNodesAvailableError) Range

func (e *NoNodesAvailableError) Range() (int64, int64)

Range returns the height range for which no nodes are available.

type Store

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

Store represents a directory where blocks are stored as chunks of data.

func Open

func Open(path string) (*Store, error)

Open initializes a new Store at the specified path or returns an existing one. If the directory does not exist, it will be created. It also acquires a lock on the directory to prevent concurrent access.

func (*Store) BlockAt

func (s *Store) BlockAt(height int64) (*BlockRecord, error)

BlockAt retrieves a block record by its height from the store.

func (*Store) Blocks

func (s *Store) Blocks() iter.Seq2[*BlockRecord, error]

Blocks returns an iterator which iterates over all BlockRecords in the store with order

func (*Store) Sync

func (s *Store) Sync(ctx context.Context, conf SyncConfig) error

Sync fetches blocks up until the latest block height (or a specific height if provided) and stores them in the store directory.

type SyncConfig

type SyncConfig struct {
	// Remotes is a list of node RPC endpoints to connect to.
	Remotes []string
	// ExpandRemotes indicates whether to expand the remotes by querying the chain network info.
	ExpandRemotes bool
	// VersionConstraint is a semantic version constraint for app versions of the nodes.
	VersionConstraint *semver.Constraints
	// UseLatestVersion indicates whether to use the nodes with the latest application version.
	UseLatestVersion bool
	// ChunkSize is the number of blocks to put in each file/chunk.
	ChunkSize int
	// Height is the height up to which store should be synced.
	// If 0, it will fetch up to the latest block height.
	Height int64
	// FetchSize is the number of blocks to fetch in each RPC call.
	FetchSize int
	// NumWorkers is the number of concurrent workers to fetch blocks.
	NumWorkers int
	// OutputChan is a channel that can be optionally used to receive the BlockRecords as they are stored.
	OutputChan chan *BlockRecord
	// Logger is the logger to use for logging during the sync process.
	Logger *slog.Logger
}

SyncConfig defines config for the Sync method.

func DefaultSyncConfig

func DefaultSyncConfig(remotes ...string) SyncConfig

DefaultSyncConfig provides default options for the Sync method.

func (SyncConfig) WithExpandRemotes

func (c SyncConfig) WithExpandRemotes(expand bool) SyncConfig

WithExpandRemotes sets whether to expand the remotes by querying the chain network info.

func (SyncConfig) WithHeight

func (c SyncConfig) WithHeight(height int64) SyncConfig

WithHeight sets the height up to which blocks should be fetched.

func (SyncConfig) WithLogger

func (conf SyncConfig) WithLogger(logger *slog.Logger) SyncConfig

WithLogger sets the logger for the sync operation.

func (SyncConfig) WithUseLatestVersion

func (c SyncConfig) WithUseLatestVersion(useLatest bool) SyncConfig

WithUseLatestVersion indicates whether to use the latest version of the remote.

func (SyncConfig) WithVersionConstraint

func (c SyncConfig) WithVersionConstraint(constraint string) SyncConfig

WithVersionConstraint sets a version constraint for the remotes.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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