mirror of
https://github.com/scroll-tech/scroll.git
synced 2026-04-23 03:00:50 -04:00
fix(bridge): fix fetching too many blocks (#63)
This commit is contained in:
@@ -93,6 +93,8 @@ func (r *Watcher) Stop() {
|
||||
r.stop <- true
|
||||
}
|
||||
|
||||
const contractEventsBlocksFetchLimit = int64(10)
|
||||
|
||||
// FetchContractEvent pull latest event logs from given contract address and save in DB
|
||||
func (r *Watcher) fetchContractEvent(blockHeight uint64) error {
|
||||
fromBlock := int64(r.processedMsgHeight) + 1
|
||||
@@ -102,6 +104,10 @@ func (r *Watcher) fetchContractEvent(blockHeight uint64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
if toBlock > fromBlock+contractEventsBlocksFetchLimit {
|
||||
toBlock = fromBlock + contractEventsBlocksFetchLimit - 1
|
||||
}
|
||||
|
||||
// warning: uint int conversion...
|
||||
query := ethereum.FilterQuery{
|
||||
FromBlock: big.NewInt(fromBlock), // inclusive
|
||||
|
||||
@@ -116,6 +116,8 @@ func (w *WatcherClient) Stop() {
|
||||
w.stopCh <- struct{}{}
|
||||
}
|
||||
|
||||
const blockResultsFetchLimit = uint64(10)
|
||||
|
||||
// try fetch missing blocks if inconsistent
|
||||
func (w *WatcherClient) tryFetchRunningMissingBlocks(ctx context.Context, backTrackFrom uint64) error {
|
||||
// Get newest block in DB. must have blocks at that time.
|
||||
@@ -130,6 +132,11 @@ func (w *WatcherClient) tryFetchRunningMissingBlocks(ctx context.Context, backTr
|
||||
backTrackTo = uint64(heightInDB)
|
||||
}
|
||||
|
||||
// note that backTrackFrom >= backTrackTo because we are doing backtracking
|
||||
if backTrackFrom > backTrackTo+blockResultsFetchLimit {
|
||||
backTrackFrom = backTrackTo + blockResultsFetchLimit
|
||||
}
|
||||
|
||||
// start backtracking
|
||||
heights := []uint64{}
|
||||
toSkipped := []*types.BlockResult{}
|
||||
@@ -178,6 +185,8 @@ func (w *WatcherClient) tryFetchRunningMissingBlocks(ctx context.Context, backTr
|
||||
return nil
|
||||
}
|
||||
|
||||
const contractEventsBlocksFetchLimit = int64(10)
|
||||
|
||||
// FetchContractEvent pull latest event logs from given contract address and save in DB
|
||||
func (w *WatcherClient) fetchContractEvent(blockHeight uint64) error {
|
||||
fromBlock := int64(w.processedMsgHeight) + 1
|
||||
@@ -187,6 +196,10 @@ func (w *WatcherClient) fetchContractEvent(blockHeight uint64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
if toBlock > fromBlock+contractEventsBlocksFetchLimit {
|
||||
toBlock = fromBlock + contractEventsBlocksFetchLimit - 1
|
||||
}
|
||||
|
||||
// warning: uint int conversion...
|
||||
query := ethereum.FilterQuery{
|
||||
FromBlock: big.NewInt(fromBlock), // inclusive
|
||||
|
||||
Reference in New Issue
Block a user