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
b6e4d067
Commit
b6e4d067
authored
Jun 22, 2023
by
Kevin Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove the OutputOracle interface.
parent
c4910baa
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
64 deletions
+26
-64
helpers.ts
packages/fault-detector/src/helpers.ts
+13
-20
service.ts
packages/fault-detector/src/service.ts
+8
-30
helpers.spec.ts
packages/fault-detector/test/helpers.spec.ts
+5
-14
No files found.
packages/fault-detector/src/helpers.ts
View file @
b6e4d067
import
{
Contract
,
BigNumber
}
from
'
ethers
'
import
{
Contract
}
from
'
ethers
'
import
{
Logger
}
from
'
@eth-optimism/common-ts
'
import
{
Logger
}
from
'
@eth-optimism/common-ts
'
export
interface
OutputOracle
{
contract
:
Contract
filter
:
any
getTotalElements
:
()
=>
Promise
<
BigNumber
>
getEventIndex
:
(
args
:
any
)
=>
BigNumber
}
/**
/**
* Partial event interface, meant to reduce the size of the event cache to avoid
* Partial event interface, meant to reduce the size of the event cache to avoid
* running out of memory.
* running out of memory.
...
@@ -55,11 +48,11 @@ const getCache = (
...
@@ -55,11 +48,11 @@ const getCache = (
* @param filter Event filter to use.
* @param filter Event filter to use.
*/
*/
export
const
updateOracleCache
=
async
(
export
const
updateOracleCache
=
async
(
oracle
:
OutputOracle
,
oracle
:
Contract
,
logger
?:
Logger
logger
?:
Logger
):
Promise
<
void
>
=>
{
):
Promise
<
void
>
=>
{
const
cache
=
getCache
(
oracle
.
contract
.
address
)
const
cache
=
getCache
(
oracle
.
address
)
const
endBlock
=
await
oracle
.
contract
.
provider
.
getBlockNumber
()
const
endBlock
=
await
oracle
.
provider
.
getBlockNumber
()
logger
?.
info
(
'
visiting uncached oracle events for range
'
,
{
logger
?.
info
(
'
visiting uncached oracle events for range
'
,
{
node
:
'
l1
'
,
node
:
'
l1
'
,
cachedUntilBlock
:
cache
.
highestBlock
,
cachedUntilBlock
:
cache
.
highestBlock
,
...
@@ -77,15 +70,15 @@ export const updateOracleCache = async (
...
@@ -77,15 +70,15 @@ export const updateOracleCache = async (
blockRangeSize
:
step
,
blockRangeSize
:
step
,
})
})
const
events
=
await
oracle
.
contract
.
queryFilter
(
const
events
=
await
oracle
.
queryFilter
(
oracle
.
filter
,
oracle
.
filter
s
.
OutputProposed
()
,
currentBlock
,
currentBlock
,
currentBlock
+
step
currentBlock
+
step
)
)
// Throw the events into the cache.
// Throw the events into the cache.
for
(
const
event
of
events
)
{
for
(
const
event
of
events
)
{
cache
.
eventCache
[
oracle
.
getEventIndex
(
event
.
args
)
.
toNumber
()]
=
{
cache
.
eventCache
[
event
.
args
.
l2OutputIndex
.
toNumber
()]
=
{
blockNumber
:
event
.
blockNumber
,
blockNumber
:
event
.
blockNumber
,
transactionHash
:
event
.
transactionHash
,
transactionHash
:
event
.
transactionHash
,
args
:
event
.
args
,
args
:
event
.
args
,
...
@@ -134,11 +127,11 @@ export const updateOracleCache = async (
...
@@ -134,11 +127,11 @@ export const updateOracleCache = async (
* @returns Event corresponding to the batch.
* @returns Event corresponding to the batch.
*/
*/
export
const
findEventForStateBatch
=
async
(
export
const
findEventForStateBatch
=
async
(
oracle
:
OutputOracle
,
oracle
:
Contract
,
index
:
number
,
index
:
number
,
logger
?:
Logger
logger
?:
Logger
):
Promise
<
PartialEvent
>
=>
{
):
Promise
<
PartialEvent
>
=>
{
const
cache
=
getCache
(
oracle
.
contract
.
address
)
const
cache
=
getCache
(
oracle
.
address
)
// Try to find the event in cache first.
// Try to find the event in cache first.
if
(
cache
.
eventCache
[
index
])
{
if
(
cache
.
eventCache
[
index
])
{
...
@@ -165,12 +158,12 @@ export const findEventForStateBatch = async (
...
@@ -165,12 +158,12 @@ export const findEventForStateBatch = async (
* @returns Starting state root batch index.
* @returns Starting state root batch index.
*/
*/
export
const
findFirstUnfinalizedStateBatchIndex
=
async
(
export
const
findFirstUnfinalizedStateBatchIndex
=
async
(
oracle
:
OutputOracle
,
oracle
:
Contract
,
fpw
:
number
,
fpw
:
number
,
logger
?:
Logger
logger
?:
Logger
):
Promise
<
number
>
=>
{
):
Promise
<
number
>
=>
{
const
latestBlock
=
await
oracle
.
contract
.
provider
.
getBlock
(
'
latest
'
)
const
latestBlock
=
await
oracle
.
provider
.
getBlock
(
'
latest
'
)
const
totalBatches
=
(
await
oracle
.
getTotalElements
()).
toNumber
()
const
totalBatches
=
(
await
oracle
.
nextOutputIndex
()).
toNumber
()
// Perform a binary search to find the next batch that will pass the challenge period.
// Perform a binary search to find the next batch that will pass the challenge period.
let
lo
=
0
let
lo
=
0
...
@@ -178,7 +171,7 @@ export const findFirstUnfinalizedStateBatchIndex = async (
...
@@ -178,7 +171,7 @@ export const findFirstUnfinalizedStateBatchIndex = async (
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
,
logger
)
const
event
=
await
findEventForStateBatch
(
oracle
,
mid
,
logger
)
const
block
=
await
oracle
.
contract
.
provider
.
getBlock
(
event
.
blockNumber
)
const
block
=
await
oracle
.
provider
.
getBlock
(
event
.
blockNumber
)
if
(
block
.
timestamp
+
fpw
<
latestBlock
.
timestamp
)
{
if
(
block
.
timestamp
+
fpw
<
latestBlock
.
timestamp
)
{
lo
=
mid
+
1
lo
=
mid
+
1
...
...
packages/fault-detector/src/service.ts
View file @
b6e4d067
...
@@ -16,7 +16,7 @@ import {
...
@@ -16,7 +16,7 @@ import {
OEL1ContractsLike
,
OEL1ContractsLike
,
}
from
'
@eth-optimism/sdk
'
}
from
'
@eth-optimism/sdk
'
import
{
Provider
}
from
'
@ethersproject/abstract-provider
'
import
{
Provider
}
from
'
@ethersproject/abstract-provider
'
import
{
ethers
}
from
'
ethers
'
import
{
Contract
,
ethers
}
from
'
ethers
'
import
dateformat
from
'
dateformat
'
import
dateformat
from
'
dateformat
'
import
{
version
}
from
'
../package.json
'
import
{
version
}
from
'
../package.json
'
...
@@ -24,7 +24,6 @@ import {
...
@@ -24,7 +24,6 @@ import {
findFirstUnfinalizedStateBatchIndex
,
findFirstUnfinalizedStateBatchIndex
,
findEventForStateBatch
,
findEventForStateBatch
,
PartialEvent
,
PartialEvent
,
OutputOracle
,
updateOracleCache
,
updateOracleCache
,
}
from
'
./helpers
'
}
from
'
./helpers
'
...
@@ -33,8 +32,6 @@ type Options = {
...
@@ -33,8 +32,6 @@ type Options = {
l2RpcProvider
:
Provider
l2RpcProvider
:
Provider
startBatchIndex
:
number
startBatchIndex
:
number
optimismPortalAddress
?:
string
optimismPortalAddress
?:
string
bedrock
:
boolean
stateCommitmentChainAddress
?:
string
}
}
type
Metrics
=
{
type
Metrics
=
{
...
@@ -45,7 +42,7 @@ type Metrics = {
...
@@ -45,7 +42,7 @@ type Metrics = {
type
State
=
{
type
State
=
{
faultProofWindow
:
number
faultProofWindow
:
number
outputOracle
:
OutputOracle
outputOracle
:
Contract
messenger
:
CrossChainMessenger
messenger
:
CrossChainMessenger
currentBatchIndex
:
number
currentBatchIndex
:
number
diverged
:
boolean
diverged
:
boolean
...
@@ -82,19 +79,6 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
...
@@ -82,19 +79,6 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
desc
:
'
[Custom OP Chains] Deployed OptimismPortal contract address. Used to retrieve necessary info for ouput verification
'
,
desc
:
'
[Custom OP Chains] Deployed OptimismPortal contract address. Used to retrieve necessary info for ouput verification
'
,
public
:
true
,
public
:
true
,
},
},
// Deprecated options.
bedrock
:
{
validator
:
validators
.
bool
,
default
:
true
,
desc
:
'
[Deprecated, must be set to true] Whether or not the service is running against a Bedrock chain
'
,
public
:
false
,
},
stateCommitmentChainAddress
:
{
validator
:
validators
.
str
,
default
:
ethers
.
constants
.
AddressZero
,
desc
:
'
[Deprecated, must be set to 0x0] Deployed StateCommitmentChain contract address. Used to fetch necessary info for output verification.
'
,
public
:
false
,
},
},
},
metricsSpec
:
{
metricsSpec
:
{
highestBatchIndex
:
{
highestBatchIndex
:
{
...
@@ -210,13 +194,7 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
...
@@ -210,13 +194,7 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
`fault proof window is
${
this
.
state
.
faultProofWindow
}
seconds`
`fault proof window is
${
this
.
state
.
faultProofWindow
}
seconds`
)
)
const
outputOracle
=
this
.
state
.
messenger
.
contracts
.
l1
.
L2OutputOracle
this
.
state
.
outputOracle
=
this
.
state
.
messenger
.
contracts
.
l1
.
L2OutputOracle
this
.
state
.
outputOracle
=
{
contract
:
outputOracle
,
filter
:
outputOracle
.
filters
.
OutputProposed
(),
getTotalElements
:
async
()
=>
outputOracle
.
nextOutputIndex
(),
getEventIndex
:
(
args
)
=>
args
.
l2OutputIndex
,
}
// 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...
'
)
...
@@ -236,7 +214,7 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
...
@@ -236,7 +214,7 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
// but it happens often on testnets because the FAULTPROOFWINDOW is very short.
// but it happens often on testnets because the FAULTPROOFWINDOW is very short.
if
(
firstUnfinalized
===
undefined
)
{
if
(
firstUnfinalized
===
undefined
)
{
this
.
logger
.
info
(
'
no unfinalized batches found. skipping all batches.
'
)
this
.
logger
.
info
(
'
no unfinalized batches found. skipping all batches.
'
)
const
totalBatches
=
await
this
.
state
.
outputOracle
.
getTotalElements
()
const
totalBatches
=
await
this
.
state
.
outputOracle
.
nextOutputIndex
()
this
.
state
.
currentBatchIndex
=
totalBatches
.
toNumber
()
-
1
this
.
state
.
currentBatchIndex
=
totalBatches
.
toNumber
()
-
1
}
else
{
}
else
{
this
.
state
.
currentBatchIndex
=
firstUnfinalized
this
.
state
.
currentBatchIndex
=
firstUnfinalized
...
@@ -266,17 +244,17 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
...
@@ -266,17 +244,17 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
let
latestBatchIndex
:
number
let
latestBatchIndex
:
number
try
{
try
{
const
totalBatches
=
await
this
.
state
.
outputOracle
.
getTotalElements
()
const
totalBatches
=
await
this
.
state
.
outputOracle
.
nextOutputIndex
()
latestBatchIndex
=
totalBatches
.
toNumber
()
-
1
latestBatchIndex
=
totalBatches
.
toNumber
()
-
1
}
catch
(
err
)
{
}
catch
(
err
)
{
this
.
logger
.
error
(
'
failed to query total # of batches
'
,
{
this
.
logger
.
error
(
'
failed to query total # of batches
'
,
{
error
:
err
,
error
:
err
,
node
:
'
l1
'
,
node
:
'
l1
'
,
section
:
'
getTotalElements
'
,
section
:
'
nextOutputIndex
'
,
})
})
this
.
metrics
.
nodeConnectionFailures
.
inc
({
this
.
metrics
.
nodeConnectionFailures
.
inc
({
layer
:
'
l1
'
,
layer
:
'
l1
'
,
section
:
'
getTotalElements
'
,
section
:
'
nextOutputIndex
'
,
})
})
await
sleep
(
15000
)
await
sleep
(
15000
)
return
return
...
@@ -410,7 +388,7 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
...
@@ -410,7 +388,7 @@ export class FaultDetector extends BaseServiceV2<Options, Metrics, State> {
new
Date
(
new
Date
(
(
ethers
.
BigNumber
.
from
(
outputBlock
.
timestamp
).
toNumber
()
+
(
ethers
.
BigNumber
.
from
(
outputBlock
.
timestamp
).
toNumber
()
+
this
.
state
.
faultProofWindow
)
*
this
.
state
.
faultProofWindow
)
*
1000
1000
),
),
'
mmmm dS, yyyy, h:MM:ss TT
'
'
mmmm dS, yyyy, h:MM:ss TT
'
),
),
...
...
packages/fault-detector/test/helpers.spec.ts
View file @
b6e4d067
...
@@ -8,7 +8,6 @@ import { expect } from './setup'
...
@@ -8,7 +8,6 @@ import { expect } from './setup'
import
{
import
{
findEventForStateBatch
,
findEventForStateBatch
,
findFirstUnfinalizedStateBatchIndex
,
findFirstUnfinalizedStateBatchIndex
,
OutputOracle
,
}
from
'
../src
'
}
from
'
../src
'
describe
(
'
helpers
'
,
()
=>
{
describe
(
'
helpers
'
,
()
=>
{
...
@@ -29,7 +28,6 @@ describe('helpers', () => {
...
@@ -29,7 +28,6 @@ describe('helpers', () => {
})
})
let
L2OutputOracle
:
Contract
let
L2OutputOracle
:
Contract
let
oracle
:
OutputOracle
beforeEach
(
async
()
=>
{
beforeEach
(
async
()
=>
{
L2OutputOracle
=
await
getContractFactory
(
'
L2OutputOracle
'
,
signer
).
deploy
(
L2OutputOracle
=
await
getContractFactory
(
'
L2OutputOracle
'
,
signer
).
deploy
(
deployConfig
.
l2OutputOracleSubmissionInterval
,
deployConfig
.
l2OutputOracleSubmissionInterval
,
...
@@ -40,13 +38,6 @@ describe('helpers', () => {
...
@@ -40,13 +38,6 @@ describe('helpers', () => {
deployConfig
.
l2OutputOracleChallenger
,
deployConfig
.
l2OutputOracleChallenger
,
deployConfig
.
finalizationPeriodSeconds
deployConfig
.
finalizationPeriodSeconds
)
)
oracle
=
{
contract
:
L2OutputOracle
,
filter
:
L2OutputOracle
.
filters
.
OutputProposed
(),
getTotalElements
:
async
()
=>
L2OutputOracle
.
nextOutputIndex
(),
getEventIndex
:
(
args
:
any
)
=>
args
.
l2OutputIndex
,
}
})
})
describe
(
'
findEventForStateBatch
'
,
()
=>
{
describe
(
'
findEventForStateBatch
'
,
()
=>
{
...
@@ -70,7 +61,7 @@ describe('helpers', () => {
...
@@ -70,7 +61,7 @@ describe('helpers', () => {
})
})
it
(
'
should return the event
'
,
async
()
=>
{
it
(
'
should return the event
'
,
async
()
=>
{
const
event
=
await
findEventForStateBatch
(
o
racle
,
0
)
const
event
=
await
findEventForStateBatch
(
L2OutputO
racle
,
0
)
expect
(
event
.
args
.
l2OutputIndex
).
to
.
equal
(
0
)
expect
(
event
.
args
.
l2OutputIndex
).
to
.
equal
(
0
)
})
})
...
@@ -79,7 +70,7 @@ describe('helpers', () => {
...
@@ -79,7 +70,7 @@ describe('helpers', () => {
describe
(
'
when the event does not exist
'
,
()
=>
{
describe
(
'
when the event does not exist
'
,
()
=>
{
it
(
'
should throw an error
'
,
async
()
=>
{
it
(
'
should throw an error
'
,
async
()
=>
{
await
expect
(
await
expect
(
findEventForStateBatch
(
o
racle
,
0
)
findEventForStateBatch
(
L2OutputO
racle
,
0
)
).
to
.
eventually
.
be
.
rejectedWith
(
'
unable to find event for batch
'
)
).
to
.
eventually
.
be
.
rejectedWith
(
'
unable to find event for batch
'
)
})
})
})
})
...
@@ -126,7 +117,7 @@ describe('helpers', () => {
...
@@ -126,7 +117,7 @@ describe('helpers', () => {
it
(
'
should find the first batch older than the FPW
'
,
async
()
=>
{
it
(
'
should find the first batch older than the FPW
'
,
async
()
=>
{
const
first
=
await
findFirstUnfinalizedStateBatchIndex
(
const
first
=
await
findFirstUnfinalizedStateBatchIndex
(
o
racle
,
L2OutputO
racle
,
deployConfig
.
finalizationPeriodSeconds
deployConfig
.
finalizationPeriodSeconds
)
)
...
@@ -168,7 +159,7 @@ describe('helpers', () => {
...
@@ -168,7 +159,7 @@ describe('helpers', () => {
it
(
'
should return zero
'
,
async
()
=>
{
it
(
'
should return zero
'
,
async
()
=>
{
const
first
=
await
findFirstUnfinalizedStateBatchIndex
(
const
first
=
await
findFirstUnfinalizedStateBatchIndex
(
o
racle
,
L2OutputO
racle
,
deployConfig
.
finalizationPeriodSeconds
deployConfig
.
finalizationPeriodSeconds
)
)
...
@@ -218,7 +209,7 @@ describe('helpers', () => {
...
@@ -218,7 +209,7 @@ describe('helpers', () => {
it
(
'
should return undefined
'
,
async
()
=>
{
it
(
'
should return undefined
'
,
async
()
=>
{
const
first
=
await
findFirstUnfinalizedStateBatchIndex
(
const
first
=
await
findFirstUnfinalizedStateBatchIndex
(
o
racle
,
L2OutputO
racle
,
deployConfig
.
finalizationPeriodSeconds
deployConfig
.
finalizationPeriodSeconds
)
)
...
...
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