@@ -1746,28 +1746,21 @@ export abstract class BaseProvider extends AbstractProvider {
1746
1746
await this . _isBlockCanonical ( txFromCache . blockHash , txFromCache . blockNumber )
1747
1747
) return txFromCache ;
1748
1748
1749
- // make sure there is no gap between subql and cache
1750
- await this . _checkSubqlHeight ( this . blockCache . cachedBlockHashes . length ) ;
1749
+ await this . _checkSubqlHeight ( ) ;
1751
1750
1752
1751
const txFromSubql = await this . subql ?. getTxReceiptByHash ( txHash ) ;
1753
1752
return txFromSubql
1754
1753
? subqlReceiptAdapter ( txFromSubql )
1755
1754
: null ;
1756
1755
} ;
1757
1756
1758
- _checkSubqlHeight = async ( _maxMissedBlockCount : number ) : Promise < number > => {
1757
+ // make sure there is no gap between subql and cache
1758
+ _checkSubqlHeight = async ( ) : Promise < number > => {
1759
1759
if ( ! this . subql ) return ;
1760
1760
1761
- /* ---------------
1762
- usually subql is delayed for a couple blocks
1763
- so it doesn't make sense to check too small range (less than 5 block)
1764
- this can also prevent throwing error when provider just started
1765
- --------------- */
1766
- const SUBQL_DELAYED_OK_RANGE = 5 ;
1767
- const maxMissedBlockCount = Math . max ( SUBQL_DELAYED_OK_RANGE , _maxMissedBlockCount ) ;
1768
-
1761
+ const maxMissedBlockCount = this . blockCache . cachedBlockHashes . length ;
1769
1762
const lastProcessedHeight = await this . subql . getLastProcessedHeight ( ) ;
1770
- const minSubqlHeight = await this . bestBlockNumber - maxMissedBlockCount ;
1763
+ const minSubqlHeight = await this . finalizedBlockNumber - maxMissedBlockCount ;
1771
1764
if ( lastProcessedHeight < minSubqlHeight ) {
1772
1765
return logger . throwError (
1773
1766
'subql indexer height is less than the minimum height required' ,
@@ -1776,7 +1769,7 @@ export abstract class BaseProvider extends AbstractProvider {
1776
1769
lastProcessedHeight,
1777
1770
minSubqlHeight,
1778
1771
maxMissedBlockCount,
1779
- curHeight : await this . bestBlockNumber ,
1772
+ curFinalizedHeight : await this . finalizedBlockNumber ,
1780
1773
}
1781
1774
) ;
1782
1775
}
@@ -1826,10 +1819,8 @@ export abstract class BaseProvider extends AbstractProvider {
1826
1819
} ;
1827
1820
1828
1821
_getSubqlMissedLogs = async ( toBlock : number , filter : SanitizedLogFilter ) : Promise < Log [ ] > => {
1829
- const SUBQL_MAX_MISSED_BLOCKS = 20 ;
1830
-
1831
1822
const targetBlock = await this . _getMaxTargetBlock ( toBlock ) ;
1832
- const lastProcessedHeight = await this . _checkSubqlHeight ( SUBQL_MAX_MISSED_BLOCKS ) ;
1823
+ const lastProcessedHeight = await this . _checkSubqlHeight ( ) ; // all missed logs should be in cache
1833
1824
const missedBlockCount = targetBlock - lastProcessedHeight ;
1834
1825
if ( missedBlockCount <= 0 ) return [ ] ;
1835
1826
@@ -1839,7 +1830,6 @@ export abstract class BaseProvider extends AbstractProvider {
1839
1830
1840
1831
await this . _waitForCache ( targetBlock ) ;
1841
1832
1842
- // all logs should be in cache since missedBlockCount <= 20
1843
1833
// no need to filter by blocknumber anymore, since these logs are from missedBlocks directly
1844
1834
return missedBlockHashes
1845
1835
. map ( this . blockCache . getLogsAtBlock . bind ( this ) )
0 commit comments