Skip to content

Commit

Permalink
feat: a new ChainIndexer to index tipsets, messages and events (#12421)
Browse files Browse the repository at this point in the history
* chain index complete for msgs and txns

* dont need observer changes for now

* changes

* fix tests

* fix tests

* use th right context

* index empty tipsets correctly

* implement automated backfilling

* add event indexing and remove all old indices

* fix test

* revert deployment test changes

* revert test changes and better error handling for eth tx index lookups

* fix sql statments naming convention

* address review for Index GC

* more changes as per review

* changes as per review

* fix config

* mark events as reverted during reconciliation

* better reconciliation; pens down and code complete; also reconcile events

* fix tests

* improve config and docs

* improve docs and error handling

* improve read logic

* improve docs

* better logging and handle ennable event storage

* improve logs and index init proc

* better logging

* fix bugs based on calibnet testing

* create sqliite Indices

* gc should be based on epochs

* fix event query

* foreign keys should be enabled on the DB

* reverted tipsets should be removed as part of GC

* release read lock

* make it easy to backfill an empty index using reconciliation

* better docs for reconciliation

* fix conflicts with master

* Apply suggestions from code review

Co-authored-by: Rod Vagg <[email protected]>

* fix go mod

* fix formatting

* revert config changes

* address changes in observer

* remove top level chainindex package

* changes as per review

* changes as per review

* changes as per review

* handle index with reverted tipsets during reconciliation

* changes as per review

* fix type of max reconcile epoch

* changes to reconciliation as per review

* log ipld error

* better logging of progress

* disable chain indexer hydrate from snapshot based on config

* always populate index

* make config easy to reason about

* fix config

* fix messaging

* revert config changes

* Apply suggestions from code review

Co-authored-by: Rod Vagg <[email protected]>

* changes as per review

* make error messages homogenous

* fix indentation

* changes as per review

* feat: recompute tipset to generate missing events if event indexing is enabled (#12463)

* auto repair events

* make jen

* fix leaky abstraction

* better docs for gc retention epoch

* imrpove DB handling (#12485)

* fix conflict

* fix lite node config for indexer

* exclude reverted events from eth get logs if client queries by epoch

* Simply addressing for event lookups in the index.

simply addressing for event lookups

* Apply suggestions from code review

Co-authored-by: Rod Vagg <[email protected]>

* Apply suggestions from code review

Co-authored-by: Rod Vagg <[email protected]>

* fix tests

* Apply suggestions from code review

Co-authored-by: Rod Vagg <[email protected]>

* feat: migration("re-indexing"), backfilling and diasgnostics tooling for the `ChainIndexer` (#12450)

* fix conflicts with chain indexer

* feat: chain indexer todos [skip changelog] (#12462)

* feat: finish todos of validation api

* feat: add indexed data verification with chain store

* feat: address comments and finish TODO

* fix: build issue

* address comments

* fix: ci issue

* Apply suggestions from code review

Co-authored-by: Rod Vagg <[email protected]>

* changes to Index Validation API based on Rodds first review

* build chain indexer API

* improve error handling

* feat: lotus-shed tooling for chain indexer (#12474)

* feat: add lotus-shed command for backfilling chain indexer

* feat: add lotus-shed command for inspecting the chain indexer

* feat: use single lotus-shed command to inspect and backfill

* fix: remove the unused queries

* small changes

* add change log

* backfilling improvements and fixes

* finish chain index validation and backfill tooling

* user documentation for the

* validate from epoch

* Apply suggestions from code review

Suggestions from Steve's read of the user doc.

Co-authored-by: Steve Loeppky <[email protected]>

* changes to user doc as per review

* Apply suggestions from code review

Co-authored-by: Steve Loeppky <[email protected]>

* changes to user doc as per review

* Apply suggestions from code review

Co-authored-by: Steve Loeppky <[email protected]>

* changes as per review

* feat: add event entries count in validation API (#12506)

* feat: add event entry count in validation API

* address comments

* use sqllite defaults (#12504)

* Apply suggestions from code review

Co-authored-by: Steve Loeppky <[email protected]>

* write chain index to a different dir

* Apply suggestions from code review

Co-authored-by: Steve Loeppky <[email protected]>

* fix conflicts

* UX improvements to backfilling

* feat: tests for the chain indexer (#12521)

* ddl tests

* tests for the chain indexer

* finish unit tests for chain indexer

* fix formatting

* cleanup reverted tipsets to avoid db bloat

* fix logging

* test for filter by address

* test gc cascade delete

* fix db locked error during backfilling

* fix var name

* increase db locked timeout

* fix db locked issue

* reduce db lock timeout

* no lock in gc

* reconcile does not need lock

* improved error handling

* Update chain-indexing-overview-for-rpc-providers.md

Doc updates based on @jennijuju feedack.

* Update chain-indexing-overview-for-rpc-providers.MD

Fixes after reviewing 33c1ca1

* better metrics for backfilling

* Update chain/index/chain-indexing-overview-for-rpc-providers.MD

Co-authored-by: Rod Vagg <[email protected]>

* Update chain/index/chain-indexing-overview-for-rpc-providers.MD

Co-authored-by: Rod Vagg <[email protected]>

* Update chain/index/chain-indexing-overview-for-rpc-providers.MD

Co-authored-by: Rod Vagg <[email protected]>

* Update chain/index/chain-indexing-overview-for-rpc-providers.MD

Co-authored-by: Rod Vagg <[email protected]>

* Update chain/index/chain-indexing-overview-for-rpc-providers.MD

Co-authored-by: Rod Vagg <[email protected]>

* Update chain/index/chain-indexing-overview-for-rpc-providers.MD

Co-authored-by: Rod Vagg <[email protected]>

* Update chain/index/chain-indexing-overview-for-rpc-providers.MD

Co-authored-by: Rod Vagg <[email protected]>

* tests for changes to event addressing

* Apply suggestions from code review

Co-authored-by: Rod Vagg <[email protected]>

* changes as per review -> round 1

* Apply suggestions from code review

Co-authored-by: Rod Vagg <[email protected]>

* Apply suggestions from code review

Co-authored-by: Rod Vagg <[email protected]>

* log tipset key cid

* Apply suggestions from code review

Co-authored-by: Rod Vagg <[email protected]>

* Apply suggestions from code review

Co-authored-by: Rod Vagg <[email protected]>

* fix docs

* Apply suggestions from code review

Co-authored-by: Rod Vagg <[email protected]>

* fix tests

* fix tests

* make jen

* fix conflicts

---------

Co-authored-by: Aryan Tikarya <[email protected]>
Co-authored-by: Rod Vagg <[email protected]>
Co-authored-by: Steve Loeppky <[email protected]>

* fix lint

* Apply suggestions from code review

Co-authored-by: Rod Vagg <[email protected]>

* Apply suggestions from code review

Co-authored-by: Rod Vagg <[email protected]>

* remove reverted flag from RPC

* Apply suggestions from code review

Co-authored-by: Rod Vagg <[email protected]>

* fix testing of events and dummy chain store

* remove lotus shed commands for old Indices

* change type of event counts to uint64

* only recompute events if theyre not found

* short-circuit empty events path for older tipsets

* chain indexer must be enabled if ETH RPC is enabled

* change name of message_id column to id in tipset_message table

* only expose SetRecomputeTipSetStateFunc

* dont block on head indexing for reading messages

* document why we're only checking for missing events for a single tipset

* document when we query for reverted events

* simplify event collection

* Apply suggestions from code review

Co-authored-by: Rod Vagg <[email protected]>

* fix test

* change event_id to id in the event table

* change head indexed timeout

* remove deprecated config options

* fail ETH RPC calls if ChainIndexer is disabled

* fix docs

* remove the tipset key cid func from lotus shed

* address review comments

* Apply suggestions from code review

Co-authored-by: Rod Vagg <[email protected]>

* chore(events): remove unnecessary DisableRealTimeFilterAPI (#12610)

* feat(cli): add --quiet to chainindex validate-backfill + cleanups (#12611)

* fix tests

* Apply suggestions from code review

Co-authored-by: Rod Vagg <[email protected]>

* error type for disabled chainindexer

* fix(chainindex): recompute tipset when we find no receipts

* fix(chainindexer): backfilling should halt when chain state data is missing and not backfill parents (#12619)

* fix backfilling UX

* Update chain/index/api.go

Co-authored-by: Rod Vagg <[email protected]>

* address review

---------

Co-authored-by: Rod Vagg <[email protected]>

* reduce log noise

* make jen

* make jen

* docs: finishing chain-indexer-overview-for-operators.md (#12600)

* Followup to PR #12450 for doc updates

This is being used to resolve the unresolved items in #12450 since that PR is unwieldly at this point.

* Incorporated some items and added TODOs based on unresolved items from #12450

* Incorporating more feedback

* Pointing to issue to learn about benefits

* Formatting fixes

* Apply most of the suggestions from @rvagg code review

Co-authored-by: Rod Vagg <[email protected]>

* Incorporating feedback from #12600 (comment)

* Addressing #12600 (comment) and more

* Moved chain-indexer docs to documentation
Renamed
Added ToC

We can move to lotus-docs later

* Update documentation/en/chain-indexer-overview-for-operators.md

Co-authored-by: Rod Vagg <[email protected]>

* Update documentation/en/chain-indexer-overview-for-operators.md

Co-authored-by: Rod Vagg <[email protected]>

* Added upgrade path when importing chain state from a snapshot.

* Typo fixes

* Update documentation/en/chain-indexer-overview-for-operators.md

Co-authored-by: Rod Vagg <[email protected]>

* chore(doc): "regular checks" section for chainindexer docs (#12612)

* Apply suggestions from @rvagg code review

Co-authored-by: Rod Vagg <[email protected]>

* Incorporating @aarshkshah1992 feedback

* Update documentation/en/chain-indexer-overview-for-operators.md

Co-authored-by: Rod Vagg <[email protected]>

---------

Co-authored-by: Rod Vagg <[email protected]>
Co-authored-by: Aarsh Shah <[email protected]>

* remove go mod replace

* remove unnecessary changes from CHANGELOG

* fix test

* compare events AMT root (#12632)

* fix(chainindex): retry transaction if database connection is lost (#12657)

* retry database lost connection

* log context cancellation

* address review

* fix gateway itest: no chainindexer for lite nodes

* fix changelog

---------

Co-authored-by: Rod Vagg <[email protected]>
Co-authored-by: Aryan Tikarya <[email protected]>
Co-authored-by: Steve Loeppky <[email protected]>
  • Loading branch information
4 people authored Oct 31, 2024
1 parent 6a70c6b commit dcc903c
Show file tree
Hide file tree
Showing 83 changed files with 6,724 additions and 5,409 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# UNRELEASED

## New features
- New ChainIndexer subsystem to index Filecoin chain state such as tipsets, messages, events and ETH transactions for accurate and faster RPC responses. The `ChainIndexer` replaces the existing `MsgIndex`, `EthTxHashLookup` and `EventIndex` implementations in Lotus, which [suffer from a multitude of known problems](https://github.com/filecoin-project/lotus/issues/12293). If you are an RPC provider or a node operator who uses or exposes Ethereum and/or events APIs, please refer to the [ChainIndexer documentation for operators](./documentation/en/chain-indexer-overview-for-operators.md) for information on how to enable, configure and use the new Indexer. While there is no automated data migration and one can upgrade and downgrade without backups, there are manual steps that need to be taken to backfill data when upgrading to this Lotus version, or downgrading to the previous version without ChainIndexer. Please be aware that that this feature removes some options in the Lotus configuration file, if these have been set, Lotus will report an error when starting. See the documentation for more information.
- Return a consistent error when encountering null rounds in ETH RPC method calls. ([filecoin-project/lotus#12655](https://github.com/filecoin-project/lotus/pull/12655))
- Reduce size of embedded genesis CAR files by removing WASM actor blocks and compressing with zstd. This reduces the `lotus` binary size by approximately 10 MiB. ([filecoin-project/lotus#12439](https://github.com/filecoin-project/lotus/pull/12439))
- Add ChainSafe operated Calibration archival node to the bootstrap list ([filecoin-project/lotus#12517](https://github.com/filecoin-project/lotus/pull/12517))
Expand Down
31 changes: 31 additions & 0 deletions api/api_full.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,37 @@ type FullNode interface {
Common
Net

// MethodGroup: ChainIndexer
// The ChainIndexer method group contains methods for interacting with the chain indexer.

// ChainValidateIndex validates the integrity of and optionally backfills
// the chain index at a specific epoch.
//
// It can be used to:
//
// 1. Validate the chain index at a specific epoch:
// - Ensures consistency between indexed data and actual chain state
// - Reports any errors found during validation (i.e. the indexed data does not match the actual chain state, missing data, etc.)
//
// 2. Optionally backfill missing data:
// - Backfills data if the index is missing information for the specified epoch
// - Backfilling only occurs when the `backfill` parameter is set to `true`
//
// 3. Detect "holes" in the index:
// - If `backfill` is `false` and the index lacks data for the specified epoch, the API returns an error indicating missing data
//
// Parameters:
// - epoch: The specific chain epoch for which to validate/backfill the index.
// - backfill: A boolean flag indicating whether to attempt backfilling of missing data if the index does not have data for the
// specified epoch.
//
// Returns:
// - *types.IndexValidation: A pointer to an IndexValidation struct containing the results of the validation/backfill.
// - error: An error object if the validation/backfill fails. The error message will contain details about the index
// corruption if the call fails because of an incosistency between indexed data and the actual chain state.
// Note: The API returns an error if the index does not have data for the specified epoch and backfill is set to false.
ChainValidateIndex(ctx context.Context, epoch abi.ChainEpoch, backfill bool) (*types.IndexValidation, error) //perm:write

// MethodGroup: Chain
// The Chain method group contains methods for interacting with the
// blockchain, but that do not require any form of state computation.
Expand Down
15 changes: 15 additions & 0 deletions api/mocks/mock_full.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions api/proxy_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit dcc903c

Please sign in to comment.