fix: reduce amount of infura requests
This commit is contained in:
parent
ae30f2e704
commit
ca52b93e50
1 changed files with 7 additions and 17 deletions
|
|
@ -4,8 +4,6 @@ const base = require('../geth/base')
|
||||||
const T = require('../../../time')
|
const T = require('../../../time')
|
||||||
const { BALANCE_FETCH_SPEED_MULTIPLIER } = require('../../../constants')
|
const { BALANCE_FETCH_SPEED_MULTIPLIER } = require('../../../constants')
|
||||||
|
|
||||||
const REGULAR_TX_POLLING = 5 * T.seconds
|
|
||||||
|
|
||||||
const NAME = 'infura'
|
const NAME = 'infura'
|
||||||
|
|
||||||
function run (account) {
|
function run (account) {
|
||||||
|
|
@ -27,21 +25,13 @@ function shouldGetStatus (tx) {
|
||||||
const timePassedSinceTx = Date.now() - new Date(tx.created)
|
const timePassedSinceTx = Date.now() - new Date(tx.created)
|
||||||
const timePassedSinceReq = Date.now() - new Date(txsCache.get(tx.id).lastReqTime)
|
const timePassedSinceReq = Date.now() - new Date(txsCache.get(tx.id).lastReqTime)
|
||||||
|
|
||||||
// Allow for infura to gradually lower the amount of requests based on the time passed since the transaction
|
if (timePassedSinceTx < 3 * T.minutes) return _.isNil(txsCache.get(tx.id).res) || timePassedSinceReq > 10 * T.seconds
|
||||||
// Until first 5 minutes - 1/2 regular polling speed
|
if (timePassedSinceTx < 5 * T.minutes) return _.isNil(txsCache.get(tx.id).res) || timePassedSinceReq > 20 * T.seconds
|
||||||
// Until first 10 minutes - 1/4 regular polling speed
|
if (timePassedSinceTx < 30 * T.minutes) return _.isNil(txsCache.get(tx.id).res) || timePassedSinceReq > T.minute
|
||||||
// Until first hour - 1/8 polling speed
|
if (timePassedSinceTx < 1 * T.hour) return _.isNil(txsCache.get(tx.id).res) || timePassedSinceReq > 2 * T.minute
|
||||||
// Until first two hours - 1/12 polling speed
|
if (timePassedSinceTx < 3 * T.hours) return _.isNil(txsCache.get(tx.id).res) || timePassedSinceReq > 5 * T.minute
|
||||||
// Until first four hours - 1/16 polling speed
|
if (timePassedSinceTx < 1 * T.day) return _.isNil(txsCache.get(tx.id).res) || timePassedSinceReq > T.hour
|
||||||
// Until first day - 1/24 polling speed
|
return _.isNil(txsCache.get(tx.id).res) || timePassedSinceReq > T.hour
|
||||||
// After first day - 1/32 polling speed
|
|
||||||
if (timePassedSinceTx < 5 * T.minutes) return _.isNil(txsCache.get(tx.id).res) || timePassedSinceReq > 2 * REGULAR_TX_POLLING
|
|
||||||
if (timePassedSinceTx < 10 * T.minutes) return _.isNil(txsCache.get(tx.id).res) || timePassedSinceReq > 4 * REGULAR_TX_POLLING
|
|
||||||
if (timePassedSinceTx < 1 * T.hour) return _.isNil(txsCache.get(tx.id).res) || timePassedSinceReq > 8 * REGULAR_TX_POLLING
|
|
||||||
if (timePassedSinceTx < 2 * T.hours) return _.isNil(txsCache.get(tx.id).res) || timePassedSinceReq > 12 * REGULAR_TX_POLLING
|
|
||||||
if (timePassedSinceTx < 4 * T.hours) return _.isNil(txsCache.get(tx.id).res) || timePassedSinceReq > 16 * REGULAR_TX_POLLING
|
|
||||||
if (timePassedSinceTx < 1 * T.day) return _.isNil(txsCache.get(tx.id).res) || timePassedSinceReq > 24 * REGULAR_TX_POLLING
|
|
||||||
return _.isNil(txsCache.get(tx.id).res) || timePassedSinceReq > 32 * REGULAR_TX_POLLING
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override geth's getStatus function to allow for different polling timing
|
// Override geth's getStatus function to allow for different polling timing
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue