Documentation ¶
Index ¶
- Constants
- Variables
- func PopulateFromSnapshot(ctx context.Context, path string, cs ChainStore) error
- type ActorToDelegatedAddressFunc
- type ChainStore
- type CollectedEvent
- type EventFilter
- type Indexer
- type MsgInfo
- type RecomputeTipSetStateFunc
- type SqliteIndexer
- func (si *SqliteIndexer) Apply(ctx context.Context, from, to *types.TipSet) error
- func (si *SqliteIndexer) ChainValidateIndex(ctx context.Context, epoch abi.ChainEpoch, backfill bool) (*types.IndexValidation, error)
- func (si *SqliteIndexer) Close() error
- func (si *SqliteIndexer) GetCidFromHash(ctx context.Context, txHash ethtypes.EthHash) (cid.Cid, error)
- func (si *SqliteIndexer) GetEventsForFilter(ctx context.Context, f *EventFilter) ([]*CollectedEvent, error)
- func (si *SqliteIndexer) GetMsgInfo(ctx context.Context, messageCid cid.Cid) (*MsgInfo, error)
- func (si *SqliteIndexer) IndexEthTxHash(ctx context.Context, txHash ethtypes.EthHash, msgCid cid.Cid) error
- func (si *SqliteIndexer) IndexSignedMessage(ctx context.Context, msg *types.SignedMessage) error
- func (si *SqliteIndexer) ReconcileWithChain(ctx context.Context, head *types.TipSet) error
- func (si *SqliteIndexer) Revert(ctx context.Context, from, to *types.TipSet) error
- func (si *SqliteIndexer) SetActorToDelegatedAddresFunc(actorToDelegatedAddresFunc ActorToDelegatedAddressFunc)
- func (si *SqliteIndexer) SetRecomputeTipSetStateFunc(f RecomputeTipSetStateFunc)
- func (si *SqliteIndexer) Start()
Constants ¶
const DefaultDbFilename = "chainindex.db"
Variables ¶
var ErrChainForked = xerrors.New("chain forked")
var ErrClosed = errors.New("index closed")
var ErrNotFound = errors.New("not found in index")
Functions ¶
func PopulateFromSnapshot ¶ added in v1.31.0
func PopulateFromSnapshot(ctx context.Context, path string, cs ChainStore) error
PopulateFromSnapshot initializes and populates the chain index from a snapshot.
This function creates a new Index at the specified path and populates it by using the chain state from the provided ChainStore. It starts from the heaviest tipset and works backwards, indexing each tipset until it reaches the genesis block or encounters a tipset for which it is unable to find messages in the chain store.
Important Notes:
- This function assumes that the snapshot has already been imported into the ChainStore.
- Events are not populated in the index because snapshots do not contain event data, and messages are not re-executed during this process. The resulting index will only contain tipsets and messages.
- This function will delete any existing database at the specified path before creating a new one.
Types ¶
type ActorToDelegatedAddressFunc ¶ added in v1.31.0
type ActorToDelegatedAddressFunc func(ctx context.Context, emitter abi.ActorID, ts *types.TipSet) (address.Address, bool)
ActorToDelegatedAddressFunc is a function type that resolves an actor ID to a DelegatedAddress if one exists for that actor, otherwise returns nil
type ChainStore ¶
type ChainStore interface { MessagesForTipset(ctx context.Context, ts *types.TipSet) ([]types.ChainMsg, error) GetHeaviestTipSet() *types.TipSet GetTipSetByCid(ctx context.Context, tsKeyCid cid.Cid) (*types.TipSet, error) GetTipSetFromKey(ctx context.Context, tsk types.TipSetKey) (*types.TipSet, error) MessagesForBlock(ctx context.Context, b *types.BlockHeader) ([]*types.Message, []*types.SignedMessage, error) ActorStore(ctx context.Context) adt.Store GetTipsetByHeight(ctx context.Context, h abi.ChainEpoch, ts *types.TipSet, prev bool) (*types.TipSet, error) IsStoringEvents() bool }
type CollectedEvent ¶ added in v1.31.0
type CollectedEvent struct { Entries []types.EventEntry EmitterAddr address.Address // address of emitter EventIdx int // index of the event within the list of emitted events in a given tipset Reverted bool Height abi.ChainEpoch TipSetKey types.TipSetKey // tipset that contained the message MsgIdx int // index of the message in the tipset MsgCid cid.Cid // cid of message that produced event }
type EventFilter ¶ added in v1.31.0
type EventFilter struct { MinHeight abi.ChainEpoch // minimum epoch to apply filter or -1 if no minimum MaxHeight abi.ChainEpoch // maximum epoch to apply filter or -1 if no maximum TipsetCid cid.Cid Addresses []address.Address // list of actor addresses that are extpected to emit the event KeysWithCodec map[string][]types.ActorEventBlock // map of key names to a list of alternate values that may match MaxResults int // maximum number of results to collect, 0 is unlimited }
type Indexer ¶ added in v1.31.0
type Indexer interface { Start() ReconcileWithChain(ctx context.Context, currHead *types.TipSet) error IndexSignedMessage(ctx context.Context, msg *types.SignedMessage) error IndexEthTxHash(ctx context.Context, txHash ethtypes.EthHash, c cid.Cid) error SetActorToDelegatedAddresFunc(idToRobustAddrFunc ActorToDelegatedAddressFunc) SetRecomputeTipSetStateFunc(f RecomputeTipSetStateFunc) Apply(ctx context.Context, from, to *types.TipSet) error Revert(ctx context.Context, from, to *types.TipSet) error // Returns (cid.Undef, nil) if the message was not found GetCidFromHash(ctx context.Context, hash ethtypes.EthHash) (cid.Cid, error) // Returns (nil, ErrNotFound) if the message was not found GetMsgInfo(ctx context.Context, m cid.Cid) (*MsgInfo, error) GetEventsForFilter(ctx context.Context, f *EventFilter) ([]*CollectedEvent, error) ChainValidateIndex(ctx context.Context, epoch abi.ChainEpoch, backfill bool) (*types.IndexValidation, error) Close() error }
type MsgInfo ¶
type MsgInfo struct { // the message this record refers to Message cid.Cid // the tipset where this message was included TipSet cid.Cid // the epoch where this message was included Epoch abi.ChainEpoch }
MsgInfo is the Message metadata the index tracks.
type RecomputeTipSetStateFunc ¶ added in v1.31.0
type SqliteIndexer ¶ added in v1.31.0
type SqliteIndexer struct {
// contains filtered or unexported fields
}
func NewSqliteIndexer ¶ added in v1.31.0
func NewSqliteIndexer(path string, cs ChainStore, gcRetentionEpochs int64, reconcileEmptyIndex bool, maxReconcileTipsets uint64) (si *SqliteIndexer, err error)
func (*SqliteIndexer) ChainValidateIndex ¶ added in v1.31.0
func (si *SqliteIndexer) ChainValidateIndex(ctx context.Context, epoch abi.ChainEpoch, backfill bool) (*types.IndexValidation, error)
func (*SqliteIndexer) Close ¶ added in v1.31.0
func (si *SqliteIndexer) Close() error
func (*SqliteIndexer) GetCidFromHash ¶ added in v1.31.0
func (*SqliteIndexer) GetEventsForFilter ¶ added in v1.31.0
func (si *SqliteIndexer) GetEventsForFilter(ctx context.Context, f *EventFilter) ([]*CollectedEvent, error)
GetEventsForFilter returns matching events for the given filter Returns nil, nil if the filter has no matching events Returns nil, ErrNotFound if the filter has no matching events and the tipset is not indexed Returns nil, err for all other errors
func (*SqliteIndexer) GetMsgInfo ¶ added in v1.31.0
func (si *SqliteIndexer) GetMsgInfo(ctx context.Context, messageCid cid.Cid) (*MsgInfo, error)
func (*SqliteIndexer) IndexEthTxHash ¶ added in v1.31.0
func (*SqliteIndexer) IndexSignedMessage ¶ added in v1.31.0
func (si *SqliteIndexer) IndexSignedMessage(ctx context.Context, msg *types.SignedMessage) error
func (*SqliteIndexer) ReconcileWithChain ¶ added in v1.31.0
ReconcileWithChain ensures that the index is consistent with the current chain state. It performs the following steps:
- Checks if the index is empty. If so, it returns immediately as there's nothing to reconcile.
- Finds the lowest non-reverted height in the index.
- Walks backwards from the current chain head until it finds a tipset that exists in the index and is not marked as reverted.
- Sets a boundary epoch just above this found tipset.
- Marks all tipsets above this boundary as reverted, ensuring consistency with the current chain state.
- Applies all missing un-indexed tipsets starting from the last matching tipset b/w index and canonical chain to the current chain head.
This function is crucial for maintaining index integrity, especially after chain reorgs. It ensures that the index accurately reflects the current state of the blockchain.
func (*SqliteIndexer) SetActorToDelegatedAddresFunc ¶ added in v1.31.0
func (si *SqliteIndexer) SetActorToDelegatedAddresFunc(actorToDelegatedAddresFunc ActorToDelegatedAddressFunc)
func (*SqliteIndexer) SetRecomputeTipSetStateFunc ¶ added in v1.31.0
func (si *SqliteIndexer) SetRecomputeTipSetStateFunc(f RecomputeTipSetStateFunc)
func (*SqliteIndexer) Start ¶ added in v1.31.0
func (si *SqliteIndexer) Start()