Skip to content

Commit 72dc80b

Browse files
authored
[L2EP] Add Scroll Health Check Endpoint (#3331)
* [L2EP] Add Scroll Health Check Endpoint * add in test fixtures * [L2EP] Add response processing func * chore: update type * refactor: process response func * Set Optimism to undefined
1 parent bfd3aa9 commit 72dc80b

File tree

7 files changed

+64
-8
lines changed

7 files changed

+64
-8
lines changed

.changeset/pink-snails-trade.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@chainlink/layer2-sequencer-health-adapter': minor
3+
---
4+
5+
Adds Scroll Healthcheck endpoint

packages/sources/layer2-sequencer-health/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Adapter that checks the Layer 2 Sequencer status
2424
| | `METIS_CHAIN_ID` | The chain id to connect to Metis | | 1088 |
2525
| | `METIS_DELTA` | Maximum time in milliseconds from last seen block to consider Metis sequencer healthy | | 600000 (10 min) |
2626
| | `SCROLL_RPC_ENDPOINT` | Scroll RPC Endpoint | | https://rpc.scroll.io |
27-
| | `SCROLL_HEALTH_ENDPOINT` | Scroll Health Endpoint | | |
27+
| | `SCROLL_HEALTH_ENDPOINT` | Scroll Health Endpoint | | https://venus.scroll.io/v1/sequencer/status |
2828
| | `SCROLL_CHAIN_ID` | The chain id to connect to Scroll | | 534352 |
2929
| | `SCROLL_DELTA` | Maximum time in milliseconds from last seen block to consider Scroll sequencer healthy | | 120000 (2 min) |
3030
| | `STARKWARE_RPC_ENDPOINT` | Starkware RPC Endpoint | | https://starknet-mainnet.public.blastapi.io |

packages/sources/layer2-sequencer-health/schemas/env.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
},
9999
"SCROLL_HEALTH_ENDPOINT": {
100100
"type": "string",
101-
"default": ""
101+
"default": "https://venus.scroll.io/v1/sequencer/status"
102102
},
103103
"SCROLL_CHAIN_ID": {
104104
"required": false,

packages/sources/layer2-sequencer-health/src/config/index.ts

+22-5
Original file line numberDiff line numberDiff line change
@@ -95,36 +95,53 @@ export const CHAIN_DELTA: Record<Networks, number> = {
9595
}
9696

9797
const DEFAULT_METIS_HEALTH_ENDPOINT = 'https://andromeda-healthy.metisdevops.link/health'
98-
export const HEALTH_ENDPOINTS: Record<
98+
const DEFAULT_SCROLL_HEALTH_ENDPOINT = 'https://venus.scroll.io/v1/sequencer/status'
99+
100+
export type HeathEndpoints = Record<
99101
Networks,
100-
{ endpoint: string | undefined; responsePath: string[] }
101-
> = {
102+
{
103+
endpoint: string | undefined
104+
responsePath: string[]
105+
processResponse: (data: unknown) => boolean | undefined
106+
}
107+
>
108+
109+
export const HEALTH_ENDPOINTS: HeathEndpoints = {
102110
[Networks.Arbitrum]: {
103111
endpoint: util.getEnv('ARBITRUM_HEALTH_ENDPOINT'),
104112
responsePath: [],
113+
processResponse: () => undefined,
105114
},
106115
[Networks.Optimism]: {
107116
endpoint: util.getEnv('OPTIMISM_HEALTH_ENDPOINT'),
108117
responsePath: ['healthy'],
118+
processResponse: () => undefined,
109119
},
110120
[Networks.Base]: {
111121
endpoint: util.getEnv('BASE_HEALTH_ENDPOINT'),
112122
responsePath: [],
123+
processResponse: () => undefined,
113124
},
114125
[Networks.Metis]: {
115126
endpoint: util.getEnv('METIS_HEALTH_ENDPOINT') || DEFAULT_METIS_HEALTH_ENDPOINT,
116127
responsePath: ['healthy'],
128+
processResponse: (data: unknown) => defaultProcessResponse(data, Networks.Metis),
117129
},
118130
[Networks.Scroll]: {
119-
endpoint: util.getEnv('SCROLL_HEALTH_ENDPOINT'),
120-
responsePath: [],
131+
endpoint: util.getEnv('SCROLL_HEALTH_ENDPOINT') || DEFAULT_SCROLL_HEALTH_ENDPOINT,
132+
responsePath: ['data', 'health'],
133+
processResponse: (data: unknown) => Requester.getResult(data, ['data', 'health']) == 1,
121134
},
122135
[Networks.Starkware]: {
123136
endpoint: util.getEnv('STARKWARE_HEALTH_ENDPOINT'),
124137
responsePath: [],
138+
processResponse: () => undefined,
125139
},
126140
}
127141

142+
const defaultProcessResponse = (data: unknown, network: Networks) =>
143+
!!Requester.getResult(data, HEALTH_ENDPOINTS[network]?.responsePath)
144+
128145
export interface ExtendedConfig extends Config {
129146
deltaBlocks: number
130147
deltaChain: Record<Networks, number>

packages/sources/layer2-sequencer-health/src/network.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ export const checkSequencerHealth: NetworkHealthCheck = async (
4545
const response = await Requester.request({
4646
url: HEALTH_ENDPOINTS[network]?.endpoint,
4747
})
48-
const isHealthy = !!Requester.getResult(response.data, HEALTH_ENDPOINTS[network]?.responsePath)
48+
49+
// If the network has a custom response processing function, use it
50+
const isHealthy = HEALTH_ENDPOINTS[network].processResponse(response.data)
51+
4952
Logger.info(
5053
`[${network}] Health endpoint for network ${network} returned a ${
5154
isHealthy ? 'healthy' : 'unhealthy'

packages/sources/layer2-sequencer-health/test/integration/fixtures.ts

+28
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ export const mockResponseSuccessHealth = (): void => {
1515
'Vary',
1616
'Origin',
1717
])
18+
19+
nock('https://venus.scroll.io/v1/sequencer/status')
20+
.get('')
21+
.query(() => true)
22+
.reply(200, () => ({ errcode: 0, errmsg: '', data: { health: 1 } }), [
23+
'Content-Type',
24+
'application/json',
25+
'Connection',
26+
'close',
27+
'Vary',
28+
'Accept-Encoding',
29+
'Vary',
30+
'Origin',
31+
])
1832
}
1933

2034
export const mockResponseSuccessBlock = (): void => {
@@ -106,6 +120,20 @@ export const mockResponseFailureHealth = (): void => {
106120
'Vary',
107121
'Origin',
108122
])
123+
124+
nock('https://venus.scroll.io/v1/sequencer/status')
125+
.get('')
126+
.query(() => true)
127+
.reply(200, () => ({ errcode: 1, errmsg: 'Mock Error Message', data: { health: 2 } }), [
128+
'Content-Type',
129+
'application/json',
130+
'Connection',
131+
'close',
132+
'Vary',
133+
'Accept-Encoding',
134+
'Vary',
135+
'Origin',
136+
])
109137
}
110138

111139
export const mockResponseFailureBlock = (): void => {

packages/sources/layer2-sequencer-health/test/integration/onchainSuccess.test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ describe('execute', () => {
203203
describe('scroll network', () => {
204204
it('should return success when all methods succeed', async () => {
205205
mockResponseSuccessBlock()
206+
mockResponseSuccessHealth()
206207

207208
const data: AdapterRequest = {
208209
id,
@@ -216,6 +217,7 @@ describe('execute', () => {
216217

217218
it('should return transaction submission is successful', async () => {
218219
mockResponseFailureBlock()
220+
mockResponseSuccessHealth()
219221

220222
const data: AdapterRequest = {
221223
id,
@@ -230,6 +232,7 @@ describe('execute', () => {
230232

231233
it('should return failure if tx not required even if it would be successful', async () => {
232234
mockResponseFailureBlock()
235+
mockResponseFailureHealth()
233236

234237
const data: AdapterRequest = {
235238
id,

0 commit comments

Comments
 (0)