Skip to content

Commit

Permalink
Merge pull request #168 from lidofinance/develop
Browse files Browse the repository at this point in the history
Merge into main from develop
  • Loading branch information
AnnaSila authored Apr 19, 2024
2 parents 461a5fb + b2df151 commit 787ae9d
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,4 @@ To create a new release:
1. When you need to release, go to Repo → Releases.
1. Publish the desired release draft manually by clicking the edit button - this release is now the `Latest Published`.
1. After publication, the action to create a release bump will be triggered automatically.
1.
31 changes: 30 additions & 1 deletion modules/wagmiConfig/appWagmiConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,32 @@ import getConfig from 'next/config'
import { getRpcUrlDefault } from 'modules/config'
import { CHAINS } from '@lido-sdk/constants'

export const holesky = {
id: CHAINS.Holesky,
name: 'Holesky',
network: 'holesky',
nativeCurrency: {
decimals: 18,
name: 'holeskyETH',
symbol: 'ETH',
},
rpcUrls: {
public: { http: [getRpcUrlDefault(CHAINS.Holesky)] },
default: { http: [getRpcUrlDefault(CHAINS.Holesky)] },
},
blockExplorers: {
etherscan: { name: 'holesky', url: 'https://holesky.etherscan.io/' },
default: { name: 'holesky', url: 'https://holesky.etherscan.io/' },
},
testnet: true,
contracts: {
multicall3: {
address: '0xcA11bde05977b3631167028862bE2a173976CA11',
blockCreated: 77,
},
},
} as const

const { publicRuntimeConfig } = getConfig()

let supportedChainIds: number[] = []
Expand All @@ -19,7 +45,10 @@ if (publicRuntimeConfig.supportedChains != null) {
supportedChainIds = [parseInt(publicRuntimeConfig.defaultChain)]
}

const wagmiChainsArray = Object.values(wagmiChains)
const wagmiChainsArray = Object.values({
...wagmiChains,
[CHAINS.Holesky]: holesky,
})
const supportedChains = wagmiChainsArray.filter(
chain =>
// Temporary wagmi fix, need to hardcode it to not affect non-wagmi wallets
Expand Down
89 changes: 82 additions & 7 deletions pages/api/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ import type { NextApiRequest, NextApiResponse } from 'next'
const { serverRuntimeConfig } = getConfig()
const { rpcUrls_1, rpcUrls_5, rpcUrls_17000 } = serverRuntimeConfig

interface IRpcRequest {
method: string
params: any[]
id: number
jsonrpc: '2.0'
}
interface IRpcResponse {
jsonrpc: '2.0'
id: number
result: any[]
}
const isLogsRequest = (item: any) => item?.method === 'eth_getLogs'
const hasResult = (item: any) => item.data?.result?.length > 0

export default async function rpc(req: NextApiRequest, res: NextApiResponse) {
const RPC_URLS: Record<number, string[]> = {
[CHAINS.Mainnet]: rpcUrls_1,
Expand All @@ -30,13 +44,74 @@ export default async function rpc(req: NextApiRequest, res: NextApiResponse) {
const chainId = parseChainId(String(req.query.chainId))
const urls = RPC_URLS[chainId]

const requested = await fetchWithFallback(urls, chainId, {
method: 'POST',
// Next by default parses our body for us, we don't want that here
body: JSON.stringify(req.body),
})
const rpcReq = (chainUrls: string[]) =>
fetchWithFallback(chainUrls, chainId, {
method: 'POST',
// Next by default parses our body for us, we don't want that here
body: JSON.stringify(req.body),
headers: {
'Content-type': 'application/json',
},
})

const needCompareWithFallback = req.body.some(isLogsRequest) // assign false to off comparison
const requests: [Promise<Response>, Promise<Response | null>] =
urls[1] && needCompareWithFallback
? [rpcReq(urls), rpcReq([urls[1]]).catch(() => null)]
: [rpcReq(urls), Promise.resolve(null)]

const [requested, requestedFb] = await Promise.all(requests)

const responded: IRpcResponse[] = await requested.json()

// this part for detecting issue with loose answer to eth_getLogs request
if (requestedFb) {
const respondedFb: IRpcResponse[] = await requestedFb.json()
const mixed = req.body.filter(isLogsRequest).map((item: IRpcRequest) => ({
req: item,
res: [
{
data: responded.find(resp => resp.id === item.id),
date: requested.headers.get('date'),
trace: requested.headers.get('x-drpc-trace-id'),
},
{
data: respondedFb.find(resp => resp.id === item.id),
date: requestedFb.headers.get('date'),
trace: requestedFb.headers.get('x-drpc-trace-id'),
},
],
}))

mixed.forEach((item: any) => {
let index = -1
let message = 'no blockers'
index = !hasResult(item.res[0]) && hasResult(item.res[1]) ? 0 : index
index = hasResult(item.res[0]) && !hasResult(item.res[1]) ? 1 : index

if (index != -1) {
message = 'One chain loose rpc logs'
}

if (!hasResult(item.res[0]) && !hasResult(item.res[1])) {
index = 1
message = 'Both chains loose rpc logs'
}

const responded = await requested.json()
if (index != -1) {
const { data, date, trace } = item.res[index]
console.info({
message,
urlIndex: index,
chainId,
date,
trace,
req: item.req,
res: data,
})
}
})
}

res.status(requested.status).json(responded)

Expand All @@ -49,6 +124,6 @@ export default async function rpc(req: NextApiRequest, res: NextApiResponse) {
error instanceof Error ? error.message : 'Something went wrong',
error,
)
res.status(500).send({ error: 'Something went wrong!' })
res.status(500).send({ error: 'Something went wrong' })
}
}

0 comments on commit 787ae9d

Please sign in to comment.