Skip to content

Commit

Permalink
changes as per review
Browse files Browse the repository at this point in the history
  • Loading branch information
aarshkshah1992 committed Sep 16, 2024
1 parent 432e09a commit af9bc23
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 50 deletions.
24 changes: 0 additions & 24 deletions chain/index/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,6 @@ func (si *SqliteIndexer) GetEventsForFilter(ctx context.Context, f *EventFilter,
return ces, nil
}

if err := si.sanityCheckFilter(ctx, f); err != nil {
return nil, xerrors.Errorf("event filter is invalid: %w", err)
}

values, query := makePrefillFilterQuery(f, excludeReverted)

stmt, err := si.db.Prepare(query)
Expand Down Expand Up @@ -403,26 +399,6 @@ func (si *SqliteIndexer) GetEventsForFilter(ctx context.Context, f *EventFilter,
return ces, nil
}

func (si *SqliteIndexer) sanityCheckFilter(ctx context.Context, f *EventFilter) error {
head := si.cs.GetHeaviestTipSet()

if f.TipsetCid != cid.Undef {
ts, err := si.cs.GetTipSetByCid(ctx, f.TipsetCid)
if err != nil {
return xerrors.Errorf("failed to get tipset by cid: %w", err)
}
if ts.Height() >= head.Height() {
return xerrors.New("cannot ask for events for a tipset >= head")
}
}

if f.MinHeight >= head.Height() || f.MaxHeight >= head.Height() {
return xerrors.New("cannot ask for events for a tipset >= head")
}

return nil
}

func makePrefillFilterQuery(f *EventFilter, excludeReverted bool) ([]any, string) {
clauses := []string{}
values := []any{}
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ func ImportChain(ctx context.Context, r repo.Repo, fname string, snapshot bool)
return xerrors.Errorf("invalid config for repo, got: %T", c)
}

if cfg.ChainIndexer.DisableIndexer {
if !cfg.ChainIndexer.EnableIndexer {
log.Info("chain indexer is disabled, not populating index from snapshot")
return nil
}
Expand Down
13 changes: 6 additions & 7 deletions documentation/en/default-lotus-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -294,19 +294,18 @@


[ChainIndexer]
# DisableIndexer controls whether the chain indexer is active.
# EnableIndexer controls whether the chain indexer is active.
# The chain indexer is responsible for indexing tipsets, messages, and events from the chain state.
# It is a crucial component for optimizing Lotus RPC response times.
#
# Default: false (indexer is enabled)
# Default: false (indexer is disabled)
#
# Setting this to true will disable the indexer, which may significantly impact RPC performance.
# It is strongly recommended to keep this set to false unless you have a specific reason to disable it
# and fully understand the implications.
# Setting this to true will enable the indexer, which will significantly improve RPC performance.
# It is strongly recommended to keep this set to true if you are an RPC provider.
#
# type: bool
# env var: LOTUS_CHAININDEXER_DISABLEINDEXER
#DisableIndexer = true
# env var: LOTUS_CHAININDEXER_ENABLEINDEXER
#EnableIndexer = false

# GCRetentionEpochs specifies the number of epochs for which data is retained in the Indexer.
# The garbage collection (GC) process removes data older than this retention period.
Expand Down
2 changes: 1 addition & 1 deletion itests/direct_data_onboard_verified_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func TestOnboardRawPieceVerified_WithActorEvents(t *testing.T) {
// subscribe to actor events up until the current head
initialEventsChan, err := miner.FullNode.SubscribeActorEventsRaw(ctx, &types.ActorEventFilter{
FromHeight: epochPtr(0),
ToHeight: epochPtr(int64(head.Height()) - 1),
ToHeight: epochPtr(int64(head.Height())),
})
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion itests/kit/node_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var DefaultNodeOpts = nodeOpts{
// test defaults

cfg.Fevm.EnableEthRPC = true
cfg.ChainIndexer.DisableIndexer = false
cfg.ChainIndexer.EnableIndexer = true
cfg.Events.MaxFilterHeightRange = math.MaxInt64
cfg.Events.EnableActorEventsAPI = true
cfg.ChainIndexer.ReconcileEmptyIndex = true
Expand Down
4 changes: 2 additions & 2 deletions node/builder_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func ConfigFullNode(c interface{}) Option {
// If the Eth JSON-RPC is enabled, enable storing events at the ChainStore.
// This is the case even if real-time and historic filtering are disabled,
// as it enables us to serve logs in eth_getTransactionReceipt.
If(cfg.Fevm.EnableEthRPC || cfg.Events.EnableActorEventsAPI || !cfg.ChainIndexer.DisableIndexer, Override(StoreEventsKey, modules.EnableStoringEvents)),
If(cfg.Fevm.EnableEthRPC || cfg.Events.EnableActorEventsAPI || cfg.ChainIndexer.EnableIndexer, Override(StoreEventsKey, modules.EnableStoringEvents)),

If(cfg.Wallet.RemoteBackend != "",
Override(new(*remotewallet.RemoteWallet), remotewallet.SetupRemoteWallet(cfg.Wallet.RemoteBackend)),
Expand Down Expand Up @@ -284,7 +284,7 @@ func ConfigFullNode(c interface{}) Option {

ApplyIf(isFullNode,
Override(new(index.Indexer), modules.ChainIndexer(cfg.ChainIndexer)),
If(!cfg.ChainIndexer.DisableIndexer,
If(cfg.ChainIndexer.EnableIndexer,
Override(InitChainIndexerKey, modules.InitChainIndexer),
),
),
Expand Down
2 changes: 1 addition & 1 deletion node/config/def.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func DefaultFullNode() *FullNode {
MaxFilterHeightRange: 2880, // conservative limit of one day
},
ChainIndexer: ChainIndexerConfig{
DisableIndexer: true,
EnableIndexer: false,
GCRetentionEpochs: 0,
ReconcileEmptyIndex: false,
MaxReconcileTipsets: 3 * builtin.EpochsInDay,
Expand Down
11 changes: 5 additions & 6 deletions node/config/doc_gen.go

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

11 changes: 5 additions & 6 deletions node/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,16 +614,15 @@ type EventsConfig struct {
}

type ChainIndexerConfig struct {
// DisableIndexer controls whether the chain indexer is active.
// EnableIndexer controls whether the chain indexer is active.
// The chain indexer is responsible for indexing tipsets, messages, and events from the chain state.
// It is a crucial component for optimizing Lotus RPC response times.
//
// Default: false (indexer is enabled)
// Default: false (indexer is disabled)
//
// Setting this to true will disable the indexer, which may significantly impact RPC performance.
// It is strongly recommended to keep this set to false unless you have a specific reason to disable it
// and fully understand the implications.
DisableIndexer bool
// Setting this to true will enable the indexer, which will significantly improve RPC performance.
// It is strongly recommended to keep this set to true if you are an RPC provider.
EnableIndexer bool

// GCRetentionEpochs specifies the number of epochs for which data is retained in the Indexer.
// The garbage collection (GC) process removes data older than this retention period.
Expand Down
2 changes: 1 addition & 1 deletion node/modules/chainindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

func ChainIndexer(cfg config.ChainIndexerConfig) func(lc fx.Lifecycle, mctx helpers.MetricsCtx, cs *store.ChainStore, r repo.LockedRepo) (index.Indexer, error) {
return func(lc fx.Lifecycle, mctx helpers.MetricsCtx, cs *store.ChainStore, r repo.LockedRepo) (index.Indexer, error) {
if cfg.DisableIndexer {
if !cfg.EnableIndexer {
log.Infof("ChainIndexer is disabled")
return nil, nil
}
Expand Down

0 comments on commit af9bc23

Please sign in to comment.