Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
interface
Commits
f2dfc570
Unverified
Commit
f2dfc570
authored
Jul 08, 2021
by
Moody Salem
Committed by
GitHub
Jul 08, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: retry calls that return header not found errors (#2004)
parent
318252b6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
22 deletions
+12
-22
updater.tsx
src/state/multicall/updater.tsx
+12
-22
No files found.
src/state/multicall/updater.tsx
View file @
f2dfc570
...
@@ -17,32 +17,23 @@ const DEFAULT_GAS_REQUIRED = 1_000_000
...
@@ -17,32 +17,23 @@ const DEFAULT_GAS_REQUIRED = 1_000_000
* Fetches a chunk of calls, enforcing a minimum block number constraint
* Fetches a chunk of calls, enforcing a minimum block number constraint
* @param multicall multicall contract to fetch against
* @param multicall multicall contract to fetch against
* @param chunk chunk of calls to make
* @param chunk chunk of calls to make
* @param
minBlockNumber minimum block number of the result set
* @param
blockNumber block number passed as the block tag in the eth_call
*/
*/
async
function
fetchChunk
(
async
function
fetchChunk
(
multicall
:
UniswapInterfaceMulticall
,
multicall
:
UniswapInterfaceMulticall
,
chunk
:
Call
[],
chunk
:
Call
[],
minBlockNumber
:
number
):
Promise
<
{
results
:
{
success
:
boolean
;
returnData
:
string
}[]
// note we are not using this returned block number because layer 2 multicalls do not consistently return the L2 block number
// instead we are relying on the blockTag parameter and assume the returned data is at least as new as that block number
blockNumber
:
number
blockNumber
:
number
}
>
{
):
Promise
<
{
success
:
boolean
;
returnData
:
string
}[]
>
{
console
.
debug
(
'
Fetching chunk
'
,
chunk
,
minBlockNumber
)
console
.
debug
(
'
Fetching chunk
'
,
chunk
,
blockNumber
)
let
resultsBlockNumber
:
number
let
results
:
{
success
:
boolean
;
returnData
:
string
}[]
try
{
try
{
const
{
blockNumber
,
returnData
}
=
await
multicall
.
callStatic
.
multicall
(
const
{
returnData
}
=
await
multicall
.
callStatic
.
multicall
(
chunk
.
map
((
obj
)
=>
({
chunk
.
map
((
obj
)
=>
({
target
:
obj
.
address
,
target
:
obj
.
address
,
callData
:
obj
.
callData
,
callData
:
obj
.
callData
,
gasLimit
:
obj
.
gasRequired
??
DEFAULT_GAS_REQUIRED
,
gasLimit
:
obj
.
gasRequired
??
DEFAULT_GAS_REQUIRED
,
})),
})),
{
blockTag
:
minB
lockNumber
}
{
blockTag
:
b
lockNumber
}
)
)
resultsBlockNumber
=
blockNumber
.
toNumber
()
results
=
returnData
if
(
process
.
env
.
NODE_ENV
===
'
development
'
)
{
if
(
process
.
env
.
NODE_ENV
===
'
development
'
)
{
returnData
.
forEach
(({
gasUsed
,
returnData
,
success
},
i
)
=>
{
returnData
.
forEach
(({
gasUsed
,
returnData
,
success
},
i
)
=>
{
...
@@ -60,16 +51,15 @@ async function fetchChunk(
...
@@ -60,16 +51,15 @@ async function fetchChunk(
}
}
})
})
}
}
return returnData
} catch (error) {
} catch (error) {
console.debug('Failed to fetch chunk', error)
if (error.code === -32000 || error.message?.indexOf('header not found') !== -1) {
throw new RetryableError(`
header
not
found
for
block
number
$
{
blockNumber
}
`)
}
console.error('Failed to fetch chunk', error)
throw error
throw error
}
}
if (resultsBlockNumber < minBlockNumber) {
const retryMessage = `
Fetched
results
for
old
block
number
:
$
{
resultsBlockNumber
.
toString
()}
vs
.
$
{
minBlockNumber
}
`
console.debug(retryMessage)
throw new RetryableError(retryMessage)
}
return { results, blockNumber: resultsBlockNumber }
}
}
/**
/**
...
@@ -190,7 +180,7 @@ export default function Updater(): null {
...
@@ -190,7 +180,7 @@ export default function Updater(): null {
maxWait: 2500,
maxWait: 2500,
})
})
promise
promise
.then((
{ results: returnData }
) => {
.then((
returnData
) => {
// accumulates the length of all previous indices
// accumulates the length of all previous indices
const firstCallKeyIndex = chunkedCalls.slice(0, index).reduce<number>((memo, curr) => memo + curr.length, 0)
const firstCallKeyIndex = chunkedCalls.slice(0, index).reduce<number>((memo, curr) => memo + curr.length, 0)
const lastCallKeyIndex = firstCallKeyIndex + returnData.length
const lastCallKeyIndex = firstCallKeyIndex + returnData.length
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment