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
7fe5de7c
Commit
7fe5de7c
authored
May 17, 2023
by
Hamdi Allam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
service log statements
parent
03db6af2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
51 deletions
+55
-51
helpers.ts
packages/fault-detector/src/helpers.ts
+1
-1
service.ts
packages/fault-detector/src/service.ts
+54
-50
No files found.
packages/fault-detector/src/helpers.ts
View file @
7fe5de7c
...
@@ -62,7 +62,7 @@ export const updateOracleCache = async <TSubmissionEventArgs>(
...
@@ -62,7 +62,7 @@ export const updateOracleCache = async <TSubmissionEventArgs>(
const
endBlock
=
await
oracle
.
contract
.
provider
.
getBlockNumber
()
const
endBlock
=
await
oracle
.
contract
.
provider
.
getBlockNumber
()
logger
?.
info
(
'
visiting uncached oracle events for range
'
,
{
logger
?.
info
(
'
visiting uncached oracle events for range
'
,
{
node
:
'
l1
'
,
node
:
'
l1
'
,
cached
Til
lBlock
:
cache
.
highestBlock
,
cached
Unti
lBlock
:
cache
.
highestBlock
,
latestBlock
:
endBlock
,
latestBlock
:
endBlock
,
})
})
...
...
packages/fault-detector/src/service.ts
View file @
7fe5de7c
...
@@ -72,7 +72,7 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
...
@@ -72,7 +72,7 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
startBatchIndex
:
{
startBatchIndex
:
{
validator
:
validators
.
num
,
validator
:
validators
.
num
,
default
:
-
1
,
default
:
-
1
,
desc
:
'
Batch index to start checking from
'
,
desc
:
'
Batch index to start checking from
. For bedrock chains, this is the L2 height to start from
'
,
public
:
true
,
public
:
true
,
},
},
bedrock
:
{
bedrock
:
{
...
@@ -238,25 +238,27 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
...
@@ -238,25 +238,27 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
}
}
// Populate the event cache.
// Populate the event cache.
this
.
logger
.
info
(
`warming event cache, this might take a while...`
)
this
.
logger
.
info
(
'
warming event cache, this might take a while...
'
)
await
updateOracleCache
(
this
.
state
.
oo
)
await
updateOracleCache
(
this
.
state
.
oo
,
this
.
logger
)
// Figure out where to start syncing from.
// Figure out where to start syncing from.
if
(
this
.
options
.
startBatchIndex
===
-
1
)
{
if
(
this
.
options
.
startBatchIndex
===
-
1
)
{
this
.
logger
.
info
(
`finding appropriate starting height`
)
this
.
logger
.
info
(
'
finding appropriate starting unfinalized batch
'
)
const
firstUnfinalized
=
await
findFirstUnfinalizedStateBatchIndex
(
const
firstUnfinalized
=
await
findFirstUnfinalizedStateBatchIndex
(
this
.
state
.
oo
,
this
.
state
.
oo
,
this
.
state
.
fpw
this
.
state
.
fpw
,
this
.
logger
)
)
// We may not have an unfinalized batches in the case where no batches have been submitted
// We may not have an unfinalized batches in the case where no batches have been submitted
// for the entire duration of the FPW. We generally do not expect this to happen on mainnet,
// for the entire duration of the FPW. We generally do not expect this to happen on mainnet,
// but it happens often on testnets because the FPW is very short.
// but it happens often on testnets because the FPW is very short.
if
(
firstUnfinalized
===
undefined
)
{
if
(
firstUnfinalized
===
undefined
)
{
this
.
logger
.
info
(
`no unfinalized batches found, starting from latest`
)
this
.
logger
.
info
(
'
no unfinalized batches found. skipping all batches.
'
)
this
.
state
.
currentBatchIndex
=
(
// `getTotalElements - 1` is the last batch. So the current count of batches
await
this
.
state
.
oo
.
getTotalElements
()
// represents the next expected batch to be published
).
toNumber
()
const
totalBatches
=
await
this
.
state
.
oo
.
getTotalElements
()
this
.
state
.
currentBatchIndex
=
totalBatches
.
toNumber
()
}
else
{
}
else
{
this
.
state
.
currentBatchIndex
=
firstUnfinalized
this
.
state
.
currentBatchIndex
=
firstUnfinalized
}
}
...
@@ -285,34 +287,32 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
...
@@ -285,34 +287,32 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
let
latestBatchIndex
:
number
let
latestBatchIndex
:
number
try
{
try
{
latestBatchIndex
=
(
await
this
.
state
.
oo
.
getTotalElements
()).
toNumber
()
latestBatchIndex
=
(
await
this
.
state
.
oo
.
getTotalElements
()).
toNumber
()
-
1
}
catch
(
err
)
{
}
catch
(
err
)
{
this
.
logger
.
error
(
`got error when connecting to node`
,
{
this
.
logger
.
error
(
'
failed to query total # of batches
'
,
{
error
:
err
,
error
:
err
,
node
:
'
l1
'
,
node
:
'
l1
'
,
section
:
'
getTotal
Batche
s
'
,
section
:
'
getTotal
Element
s
'
,
})
})
this
.
metrics
.
nodeConnectionFailures
.
inc
({
this
.
metrics
.
nodeConnectionFailures
.
inc
({
layer
:
'
l1
'
,
layer
:
'
l1
'
,
section
:
'
getTotal
Batche
s
'
,
section
:
'
getTotal
Element
s
'
,
})
})
await
sleep
(
15000
)
await
sleep
(
15000
)
return
return
}
}
if
(
this
.
state
.
currentBatchIndex
>=
latestBatchIndex
)
{
if
(
this
.
state
.
currentBatchIndex
>
latestBatchIndex
)
{
this
.
logger
.
info
(
'
batch index is ahead of L1. waiting...
'
,
{
batchIndex
:
this
.
state
.
currentBatchIndex
,
latestBatchIndex
,
})
await
sleep
(
15000
)
await
sleep
(
15000
)
return
return
}
else
{
this
.
metrics
.
highestBatchIndex
.
set
(
{
type
:
'
known
'
,
},
latestBatchIndex
)
}
}
this
.
logger
.
info
(
`checking batch`
,
{
this
.
metrics
.
highestBatchIndex
.
set
({
type
:
'
known
'
},
latestBatchIndex
)
this
.
logger
.
info
(
'
checking batch
'
,
{
batchIndex
:
this
.
state
.
currentBatchIndex
,
batchIndex
:
this
.
state
.
currentBatchIndex
,
latestIndex
:
latestBatchIndex
,
latestIndex
:
latestBatchIndex
,
})
})
...
@@ -321,13 +321,15 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
...
@@ -321,13 +321,15 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
try
{
try
{
event
=
await
findEventForStateBatch
(
event
=
await
findEventForStateBatch
(
this
.
state
.
oo
,
this
.
state
.
oo
,
this
.
state
.
currentBatchIndex
this
.
state
.
currentBatchIndex
,
this
.
logger
)
)
}
catch
(
err
)
{
}
catch
(
err
)
{
this
.
logger
.
error
(
`got error when connecting to node`
,
{
this
.
logger
.
error
(
'
failed to fetch event associated the batch
'
,
{
error
:
err
,
error
:
err
,
node
:
'
l1
'
,
node
:
'
l1
'
,
section
:
'
findEventForStateBatch
'
,
section
:
'
findEventForStateBatch
'
,
batchIndex
:
this
.
state
.
currentBatchIndex
,
})
})
this
.
metrics
.
nodeConnectionFailures
.
inc
({
this
.
metrics
.
nodeConnectionFailures
.
inc
({
layer
:
'
l1
'
,
layer
:
'
l1
'
,
...
@@ -341,7 +343,7 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
...
@@ -341,7 +343,7 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
try
{
try
{
latestBlock
=
await
this
.
options
.
l2RpcProvider
.
getBlockNumber
()
latestBlock
=
await
this
.
options
.
l2RpcProvider
.
getBlockNumber
()
}
catch
(
err
)
{
}
catch
(
err
)
{
this
.
logger
.
error
(
`got error when connecting to node`
,
{
this
.
logger
.
error
(
'
failed to query L2 block height
'
,
{
error
:
err
,
error
:
err
,
node
:
'
l2
'
,
node
:
'
l2
'
,
section
:
'
getBlockNumber
'
,
section
:
'
getBlockNumber
'
,
...
@@ -355,27 +357,29 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
...
@@ -355,27 +357,29 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
}
}
if
(
this
.
options
.
bedrock
)
{
if
(
this
.
options
.
bedrock
)
{
if
(
latestBlock
<
event
.
args
.
l2BlockNumber
.
toNumber
())
{
const
outputBlockNumber
=
event
.
args
.
l2BlockNumber
.
toNumber
()
this
.
logger
.
info
(
`node is behind, waiting for sync`
,
{
if
(
latestBlock
<
outputBlockNumber
)
{
batchEnd
:
event
.
args
.
l2BlockNumber
.
toNumber
(),
this
.
logger
.
info
(
'
L2 node is behind, waiting for sync...
'
,
{
latestBlock
,
l2BlockHeight
:
latestBlock
,
outputBlock
:
outputBlockNumber
,
})
})
return
return
}
}
let
targe
tBlock
:
any
let
outpu
tBlock
:
any
try
{
try
{
targe
tBlock
=
await
(
outpu
tBlock
=
await
(
this
.
options
.
l2RpcProvider
as
ethers
.
providers
.
JsonRpcProvider
this
.
options
.
l2RpcProvider
as
ethers
.
providers
.
JsonRpcProvider
).
send
(
'
eth_getBlockByNumber
'
,
[
).
send
(
'
eth_getBlockByNumber
'
,
[
toRpcHexString
(
event
.
args
.
l2BlockNumber
.
toNumber
()
),
toRpcHexString
(
outputBlockNumber
),
false
,
false
,
])
])
}
catch
(
err
)
{
}
catch
(
err
)
{
this
.
logger
.
error
(
`got error when connecting to node`
,
{
this
.
logger
.
error
(
'
failed to fetch output block
'
,
{
error
:
err
,
error
:
err
,
node
:
'
l2
'
,
node
:
'
l2
'
,
section
:
'
getBlock
'
,
section
:
'
getBlock
'
,
block
:
outputBlockNumber
,
})
})
this
.
metrics
.
nodeConnectionFailures
.
inc
({
this
.
metrics
.
nodeConnectionFailures
.
inc
({
layer
:
'
l2
'
,
layer
:
'
l2
'
,
...
@@ -392,13 +396,14 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
...
@@ -392,13 +396,14 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
).
send
(
'
eth_getProof
'
,
[
).
send
(
'
eth_getProof
'
,
[
this
.
state
.
messenger
.
contracts
.
l2
.
BedrockMessagePasser
.
address
,
this
.
state
.
messenger
.
contracts
.
l2
.
BedrockMessagePasser
.
address
,
[],
[],
toRpcHexString
(
event
.
args
.
l2BlockNumber
.
toNumber
()
),
toRpcHexString
(
outputBlockNumber
),
])
])
}
catch
(
err
)
{
}
catch
(
err
)
{
this
.
logger
.
error
(
`got error when connecting to node`
,
{
this
.
logger
.
error
(
'
failed to fetch message passer proof
'
,
{
error
:
err
,
error
:
err
,
node
:
'
l2
'
,
node
:
'
l2
'
,
section
:
'
getProof
'
,
section
:
'
getProof
'
,
block
:
outputBlockNumber
,
})
})
this
.
metrics
.
nodeConnectionFailures
.
inc
({
this
.
metrics
.
nodeConnectionFailures
.
inc
({
layer
:
'
l2
'
,
layer
:
'
l2
'
,
...
@@ -412,22 +417,22 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
...
@@ -412,22 +417,22 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
[
'
uint256
'
,
'
bytes32
'
,
'
bytes32
'
,
'
bytes32
'
],
[
'
uint256
'
,
'
bytes32
'
,
'
bytes32
'
,
'
bytes32
'
],
[
[
0
,
0
,
targe
tBlock
.
stateRoot
,
outpu
tBlock
.
stateRoot
,
messagePasserProofResponse
.
storageHash
,
messagePasserProofResponse
.
storageHash
,
targe
tBlock
.
hash
,
outpu
tBlock
.
hash
,
]
]
)
)
if
(
outputRoot
!==
event
.
args
.
outputRoot
)
{
if
(
outputRoot
!==
event
.
args
.
outputRoot
)
{
this
.
state
.
diverged
=
true
this
.
state
.
diverged
=
true
this
.
metrics
.
isCurrentlyMismatched
.
set
(
1
)
this
.
metrics
.
isCurrentlyMismatched
.
set
(
1
)
this
.
logger
.
error
(
`state root mismatch`
,
{
this
.
logger
.
error
(
'
state root mismatch
'
,
{
blockNumber
:
targe
tBlock
.
number
,
blockNumber
:
outpu
tBlock
.
number
,
expectedStateRoot
:
event
.
args
.
outputRoot
,
expectedStateRoot
:
event
.
args
.
outputRoot
,
actualStateRoot
:
outputRoot
,
actualStateRoot
:
outputRoot
,
finalizationTime
:
dateformat
(
finalizationTime
:
dateformat
(
new
Date
(
new
Date
(
(
ethers
.
BigNumber
.
from
(
targe
tBlock
.
timestamp
).
toNumber
()
+
(
ethers
.
BigNumber
.
from
(
outpu
tBlock
.
timestamp
).
toNumber
()
+
this
.
state
.
fpw
)
*
this
.
state
.
fpw
)
*
1000
1000
),
),
...
@@ -443,7 +448,7 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
...
@@ -443,7 +448,7 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
event
.
transactionHash
event
.
transactionHash
)
)
}
catch
(
err
)
{
}
catch
(
err
)
{
this
.
logger
.
error
(
`got error when connecting to node`
,
{
this
.
logger
.
error
(
'
failed to require acquire batch transaction
'
,
{
error
:
err
,
error
:
err
,
node
:
'
l1
'
,
node
:
'
l1
'
,
section
:
'
getTransaction
'
,
section
:
'
getTransaction
'
,
...
@@ -466,9 +471,10 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
...
@@ -466,9 +471,10 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
const
batchEnd
=
batchStart
+
batchSize
const
batchEnd
=
batchStart
+
batchSize
if
(
latestBlock
<
batchEnd
)
{
if
(
latestBlock
<
batchEnd
)
{
this
.
logger
.
info
(
`node is behind, waiting for sync`
,
{
this
.
logger
.
info
(
'
L2 node is behind. waiting for sync...
'
,
{
batchEnd
,
batchBlockStart
:
batchStart
,
latestBlock
,
batchBlockEnd
:
batchEnd
,
l2Block
:
latestBlock
,
})
})
return
return
}
}
...
@@ -487,7 +493,7 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
...
@@ -487,7 +493,7 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
false
,
false
,
])
])
}
catch
(
err
)
{
}
catch
(
err
)
{
this
.
logger
.
error
(
`got error when connecting to node`
,
{
this
.
logger
.
error
(
'
failed to query for blocks in batch
'
,
{
error
:
err
,
error
:
err
,
node
:
'
l2
'
,
node
:
'
l2
'
,
section
:
'
getBlockRange
'
,
section
:
'
getBlockRange
'
,
...
@@ -507,7 +513,7 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
...
@@ -507,7 +513,7 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
if
(
blocks
[
i
].
stateRoot
!==
stateRoot
)
{
if
(
blocks
[
i
].
stateRoot
!==
stateRoot
)
{
this
.
state
.
diverged
=
true
this
.
state
.
diverged
=
true
this
.
metrics
.
isCurrentlyMismatched
.
set
(
1
)
this
.
metrics
.
isCurrentlyMismatched
.
set
(
1
)
this
.
logger
.
error
(
`state root mismatch`
,
{
this
.
logger
.
error
(
'
state root mismatch
'
,
{
blockNumber
:
blocks
[
i
].
number
,
blockNumber
:
blocks
[
i
].
number
,
expectedStateRoot
:
blocks
[
i
].
stateRoot
,
expectedStateRoot
:
blocks
[
i
].
stateRoot
,
actualStateRoot
:
stateRoot
,
actualStateRoot
:
stateRoot
,
...
@@ -533,9 +539,7 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
...
@@ -533,9 +539,7 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
timeMs
:
elapsedMs
,
timeMs
:
elapsedMs
,
})
})
this
.
metrics
.
highestBatchIndex
.
set
(
this
.
metrics
.
highestBatchIndex
.
set
(
{
{
type
:
'
checked
'
},
type
:
'
checked
'
,
},
this
.
state
.
currentBatchIndex
this
.
state
.
currentBatchIndex
)
)
...
...
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