Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
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
exchain
nebula
Commits
ed9b67c8
Unverified
Commit
ed9b67c8
authored
May 18, 2023
by
OptimismBot
Committed by
GitHub
May 18, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5727 from ethereum-optimism/hamdi/fault.detector.logging
[fault-detector] extra logging
parents
5b31a02b
cb4f076f
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
96 additions
and
65 deletions
+96
-65
helpers.ts
packages/fault-detector/src/helpers.ts
+38
-12
service.ts
packages/fault-detector/src/service.ts
+58
-53
No files found.
packages/fault-detector/src/helpers.ts
View file @
ed9b67c8
import
{
Contract
,
BigNumber
}
from
'
ethers
'
import
{
Contract
,
BigNumber
}
from
'
ethers
'
import
{
Logger
}
from
'
@eth-optimism/common-ts
'
export
interface
OutputOracle
<
TSubmissionEventArgs
>
{
export
interface
OutputOracle
<
TSubmissionEventArgs
>
{
contract
:
Contract
contract
:
Contract
...
@@ -39,7 +40,7 @@ const getCache = (
...
@@ -39,7 +40,7 @@ const getCache = (
}
=>
{
}
=>
{
if
(
!
caches
[
address
])
{
if
(
!
caches
[
address
])
{
caches
[
address
]
=
{
caches
[
address
]
=
{
highestBlock
:
0
,
highestBlock
:
-
1
,
eventCache
:
new
Map
(),
eventCache
:
new
Map
(),
}
}
}
}
...
@@ -54,15 +55,28 @@ const getCache = (
...
@@ -54,15 +55,28 @@ const getCache = (
* @param filter Event filter to use.
* @param filter Event filter to use.
*/
*/
export
const
updateOracleCache
=
async
<
TSubmissionEventArgs
>
(
export
const
updateOracleCache
=
async
<
TSubmissionEventArgs
>
(
oracle
:
OutputOracle
<
TSubmissionEventArgs
>
oracle
:
OutputOracle
<
TSubmissionEventArgs
>
,
logger
?:
Logger
):
Promise
<
void
>
=>
{
):
Promise
<
void
>
=>
{
const
cache
=
getCache
(
oracle
.
contract
.
address
)
const
cache
=
getCache
(
oracle
.
contract
.
address
)
let
currentBlock
=
cache
.
highestBlock
const
endBlock
=
await
oracle
.
contract
.
provider
.
getBlockNumber
()
const
endingBlock
=
await
oracle
.
contract
.
provider
.
getBlockNumber
()
logger
?.
info
(
'
visiting uncached oracle events for range
'
,
{
let
step
=
endingBlock
-
currentBlock
node
:
'
l1
'
,
cachedUntilBlock
:
cache
.
highestBlock
,
latestBlock
:
endBlock
,
})
let
failures
=
0
let
failures
=
0
while
(
currentBlock
<
endingBlock
)
{
let
currentBlock
=
cache
.
highestBlock
+
1
let
step
=
endBlock
-
currentBlock
while
(
currentBlock
<
endBlock
)
{
try
{
try
{
logger
?.
info
(
'
polling events for range
'
,
{
node
:
'
l1
'
,
startBlock
:
currentBlock
,
blockRangeSize
:
step
,
})
const
events
=
await
oracle
.
contract
.
queryFilter
(
const
events
=
await
oracle
.
contract
.
queryFilter
(
oracle
.
filter
,
oracle
.
filter
,
currentBlock
,
currentBlock
,
...
@@ -83,7 +97,13 @@ export const updateOracleCache = async <TSubmissionEventArgs>(
...
@@ -83,7 +97,13 @@ export const updateOracleCache = async <TSubmissionEventArgs>(
// Update the current block and increase the step size for the next iteration.
// Update the current block and increase the step size for the next iteration.
currentBlock
+=
step
currentBlock
+=
step
step
=
Math
.
ceil
(
step
*
2
)
step
=
Math
.
ceil
(
step
*
2
)
}
catch
{
}
catch
(
err
)
{
logger
?.
error
(
'
error fetching events
'
,
{
err
,
node
:
'
l1
'
,
section
:
'
getLogs
'
,
})
// Might happen if we're querying too large an event range.
// Might happen if we're querying too large an event range.
step
=
Math
.
floor
(
step
/
2
)
step
=
Math
.
floor
(
step
/
2
)
...
@@ -97,13 +117,15 @@ export const updateOracleCache = async <TSubmissionEventArgs>(
...
@@ -97,13 +117,15 @@ export const updateOracleCache = async <TSubmissionEventArgs>(
// We've failed 3 times in a row, we're probably stuck.
// We've failed 3 times in a row, we're probably stuck.
if
(
failures
>=
3
)
{
if
(
failures
>=
3
)
{
logger
?.
fatal
(
'
unable to fetch oracle events
'
,
{
err
})
throw
new
Error
(
'
failed to update event cache
'
)
throw
new
Error
(
'
failed to update event cache
'
)
}
}
}
}
}
}
// Update the highest block.
// Update the highest block.
cache
.
highestBlock
=
endingBlock
cache
.
highestBlock
=
endBlock
logger
?.
info
(
'
done caching oracle events
'
)
}
}
/**
/**
...
@@ -115,7 +137,8 @@ export const updateOracleCache = async <TSubmissionEventArgs>(
...
@@ -115,7 +137,8 @@ export const updateOracleCache = async <TSubmissionEventArgs>(
*/
*/
export
const
findEventForStateBatch
=
async
<
TSubmissionEventArgs
>
(
export
const
findEventForStateBatch
=
async
<
TSubmissionEventArgs
>
(
oracle
:
OutputOracle
<
TSubmissionEventArgs
>
,
oracle
:
OutputOracle
<
TSubmissionEventArgs
>
,
index
:
number
index
:
number
,
logger
?:
Logger
):
Promise
<
PartialEvent
>
=>
{
):
Promise
<
PartialEvent
>
=>
{
const
cache
=
getCache
(
oracle
.
contract
.
address
)
const
cache
=
getCache
(
oracle
.
contract
.
address
)
...
@@ -125,10 +148,12 @@ export const findEventForStateBatch = async <TSubmissionEventArgs>(
...
@@ -125,10 +148,12 @@ export const findEventForStateBatch = async <TSubmissionEventArgs>(
}
}
// Update the event cache if we don't have the event.
// Update the event cache if we don't have the event.
await
updateOracleCache
(
oracle
)
logger
?.
info
(
'
event not cached for index. warming cache...
'
,
{
index
})
await
updateOracleCache
(
oracle
,
logger
)
// Event better be in cache now!
// Event better be in cache now!
if
(
cache
.
eventCache
[
index
]
===
undefined
)
{
if
(
cache
.
eventCache
[
index
]
===
undefined
)
{
logger
?.
fatal
(
'
expected event for index!
'
,
{
index
})
throw
new
Error
(
`unable to find event for batch
${
index
}
`
)
throw
new
Error
(
`unable to find event for batch
${
index
}
`
)
}
}
...
@@ -143,7 +168,8 @@ export const findEventForStateBatch = async <TSubmissionEventArgs>(
...
@@ -143,7 +168,8 @@ export const findEventForStateBatch = async <TSubmissionEventArgs>(
*/
*/
export
const
findFirstUnfinalizedStateBatchIndex
=
async
<
TSubmissionEventArgs
>
(
export
const
findFirstUnfinalizedStateBatchIndex
=
async
<
TSubmissionEventArgs
>
(
oracle
:
OutputOracle
<
TSubmissionEventArgs
>
,
oracle
:
OutputOracle
<
TSubmissionEventArgs
>
,
fpw
:
number
fpw
:
number
,
logger
?:
Logger
):
Promise
<
number
>
=>
{
):
Promise
<
number
>
=>
{
const
latestBlock
=
await
oracle
.
contract
.
provider
.
getBlock
(
'
latest
'
)
const
latestBlock
=
await
oracle
.
contract
.
provider
.
getBlock
(
'
latest
'
)
const
totalBatches
=
(
await
oracle
.
getTotalElements
()).
toNumber
()
const
totalBatches
=
(
await
oracle
.
getTotalElements
()).
toNumber
()
...
@@ -153,7 +179,7 @@ export const findFirstUnfinalizedStateBatchIndex = async <TSubmissionEventArgs>(
...
@@ -153,7 +179,7 @@ export const findFirstUnfinalizedStateBatchIndex = async <TSubmissionEventArgs>(
let
hi
=
totalBatches
let
hi
=
totalBatches
while
(
lo
!==
hi
)
{
while
(
lo
!==
hi
)
{
const
mid
=
Math
.
floor
((
lo
+
hi
)
/
2
)
const
mid
=
Math
.
floor
((
lo
+
hi
)
/
2
)
const
event
=
await
findEventForStateBatch
(
oracle
,
mid
)
const
event
=
await
findEventForStateBatch
(
oracle
,
mid
,
logger
)
const
block
=
await
oracle
.
contract
.
provider
.
getBlock
(
event
.
blockNumber
)
const
block
=
await
oracle
.
contract
.
provider
.
getBlock
(
event
.
blockNumber
)
if
(
block
.
timestamp
+
fpw
<
latestBlock
.
timestamp
)
{
if
(
block
.
timestamp
+
fpw
<
latestBlock
.
timestamp
)
{
...
...
packages/fault-detector/src/service.ts
View file @
ed9b67c8
This diff is collapsed.
Click to expand it.
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