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
0c2dee8a
Commit
0c2dee8a
authored
Jul 27, 2023
by
Maurelian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(chain-mon): Add backwards walk to find last finalized block
parent
e7946239
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
4 deletions
+48
-4
helpers.ts
packages/chain-mon/src/wd-mon/helpers.ts
+41
-0
service.ts
packages/chain-mon/src/wd-mon/service.ts
+7
-4
No files found.
packages/chain-mon/src/wd-mon/helpers.ts
0 → 100644
View file @
0c2dee8a
import
{
Provider
}
from
'
@ethersproject/abstract-provider
'
import
{
Logger
}
from
'
@eth-optimism/common-ts
'
/**
* Finds
*
* @param
* @param
* @param
* @returns
*/
export
const
getLastFinalizedBlock
=
async
(
l1RpcProvider
:
Provider
,
faultProofWindow
:
number
,
logger
:
Logger
):
Promise
<
number
>
=>
{
let
guessWindowStartBlock
try
{
const
l1Block
=
await
l1RpcProvider
.
getBlock
(
'
latest
'
)
// The time corresponding to the start of the FPW, based on the current block.
const
windowStartTime
=
l1Block
.
timestamp
-
faultProofWindow
// Use the FPW to find the block number that is the start of the FPW.
guessWindowStartBlock
=
l1Block
.
number
-
faultProofWindow
/
12
let
block
=
await
l1RpcProvider
.
getBlock
(
guessWindowStartBlock
)
while
(
block
.
timestamp
>
windowStartTime
)
{
guessWindowStartBlock
--
block
=
await
l1RpcProvider
.
getBlock
(
guessWindowStartBlock
)
}
return
block
.
number
}
catch
(
err
)
{
logger
.
fatal
(
'
error when calling querying for block
'
,
{
errors
:
err
,
})
throw
new
Error
(
`unable to find block number
${
guessWindowStartBlock
||
'
latest
'
}
`
)
}
}
packages/chain-mon/src/wd-mon/service.ts
View file @
0c2dee8a
...
...
@@ -13,6 +13,7 @@ import { Event } from 'ethers'
import
dateformat
from
'
dateformat
'
import
{
version
}
from
'
../../package.json
'
import
{
getLastFinalizedBlock
as
getLastFinalizedBlock
}
from
'
./helpers
'
type
Options
=
{
l1RpcProvider
:
Provider
...
...
@@ -117,10 +118,12 @@ export class WithdrawalMonitor extends BaseServiceV2<Options, Metrics, State> {
// Set the start block number.
if
(
this
.
options
.
startBlockNumber
===
-
1
)
{
// We default to starting from the earliest block still in the fault proof window.
const
l1BlockNumber
=
await
this
.
options
.
l1RpcProvider
.
getBlockNumber
()
this
.
state
.
highestUncheckedBlockNumber
=
l1BlockNumber
-
this
.
state
.
faultProofWindow
/
12
// We default to starting from the last finalized block.
this
.
state
.
highestUncheckedBlockNumber
=
await
getLastFinalizedBlock
(
this
.
options
.
l1RpcProvider
,
this
.
state
.
faultProofWindow
,
this
.
logger
)
}
else
{
this
.
state
.
highestUncheckedBlockNumber
=
this
.
options
.
startBlockNumber
}
...
...
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