Skip to content

Commit

Permalink
fix default value for fromBlock when calling eth_getLogs (#3124)
Browse files Browse the repository at this point in the history
  • Loading branch information
tclemos authored Jan 23, 2024
1 parent fc27c52 commit 811e945
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 1 addition & 2 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,6 @@ func waitSignal(cancelFuncs []context.CancelFunc) {
}

func newState(ctx context.Context, c *config.Config, l2ChainID uint64, forkIDIntervals []state.ForkIDInterval, sqlDB *pgxpool.Pool, eventLog *event.EventLog, needsExecutor, needsStateTree bool) *state.State {
stateDb := state.NewPostgresStorage(c.State, sqlDB)

// Executor
var executorClient executor.ExecutorServiceClient
if needsExecutor {
Expand All @@ -492,6 +490,7 @@ func newState(ctx context.Context, c *config.Config, l2ChainID uint64, forkIDInt
MaxNativeBlockHashBlockRange: c.RPC.MaxNativeBlockHashBlockRange,
}

stateDb := state.NewPostgresStorage(stateCfg, sqlDB)
st := state.NewState(stateCfg, stateDb, executorClient, stateTree, eventLog)
return st
}
Expand Down
9 changes: 9 additions & 0 deletions jsonrpc/endpoints_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ func (e *EthEndpoints) GetFilterChanges(filterID string) (interface{}, types.Err
case FilterTypeLog:
{
filterParameters := filter.Parameters.(LogFilter)
if filterParameters.FromBlock == nil {
bn := types.BlockNumber(0)
filterParameters.FromBlock = &bn
}
filterParameters.Since = &filter.LastPoll

resInterface, err := e.internalGetLogs(context.Background(), nil, filterParameters)
Expand Down Expand Up @@ -482,6 +486,11 @@ func (e *EthEndpoints) GetLogs(filter LogFilter) (interface{}, types.Error) {
}

func (e *EthEndpoints) internalGetLogs(ctx context.Context, dbTx pgx.Tx, filter LogFilter) (interface{}, types.Error) {
if filter.FromBlock == nil {
l := types.LatestBlockNumber
filter.FromBlock = &l
}

fromBlockNumber, toBlockNumber, rpcErr := filter.GetNumericBlockNumbers(ctx, e.cfg, e.state, e.etherman, dbTx)
if rpcErr != nil {
return nil, rpcErr
Expand Down

0 comments on commit 811e945

Please sign in to comment.