Skip to content

Commit

Permalink
Merge branch 'main' of github.com:lidofinance/alerting-forta into fea…
Browse files Browse the repository at this point in the history
…t/mellow-alerts
  • Loading branch information
katamarinaki committed Dec 10, 2024
2 parents 908a601 + bf3f0ca commit ad46085
Show file tree
Hide file tree
Showing 467 changed files with 11,482 additions and 79,071 deletions.
7 changes: 0 additions & 7 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
* @lidofinance/community-staking
/ethereum-huge-tx/ @lidofinance/lido-analytics
/ethereum-steth/ @lidofinance/lido-eth-protocol
/storage-watcher/ @lidofinance/lido-eth-protocol
/l2-bridge-arbitrum/ @lidofinance/lido-eth-protocol
/l2-bridge-ethereum/ @lidofinance/lido-eth-protocol
/l2-bridge-optimism/ @lidofinance/lido-eth-protocol
/l2-bridge-base/ @lidofinance/lido-eth-protocol
/l2-bridge-zksync/ @lidofinance/lido-eth-protocol
/l2-bridge-mantle/ @lidofinance/lido-eth-protocol
/l2-bridge-linea/ @lidofinance/lido-eth-protocol
/l2-bridge-scroll/ @lidofinance/lido-eth-protocol
/ethereum-financial/ @lidofinance/lido-eth-protocol
/arb-subgraph/ @lidofinance/lido-si
/ethereum-governance/ @lidofinance/lido-dao-ops-team
/mellow-vaults/ @lidofinance/lido-dao-ops-team
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@ jobs:
- name: Setup prettier
run: npm install prettier@^3.2.5

- name: Setup prettier import plugin
run: npm install prettier-plugin-organize-imports@^4.0.0

- name: Check formatting with prettier
run: npx prettier --check .
15 changes: 0 additions & 15 deletions .github/workflows/test-ethereum-financial.yml

This file was deleted.

15 changes: 0 additions & 15 deletions .github/workflows/test-ethereum-steth.yml

This file was deleted.

15 changes: 0 additions & 15 deletions .github/workflows/test-l2-bridge-arbitrum.yml

This file was deleted.

15 changes: 0 additions & 15 deletions .github/workflows/test-l2-bridge-base.yml

This file was deleted.

15 changes: 0 additions & 15 deletions .github/workflows/test-l2-bridge-optimism.yml

This file was deleted.

15 changes: 0 additions & 15 deletions .github/workflows/test-l2-bridge-scroll.yml

This file was deleted.

15 changes: 0 additions & 15 deletions .github/workflows/test-storage-watcher.yml

This file was deleted.

7 changes: 7 additions & 0 deletions bsc-adi-governance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ Alerts about events on the CrossChainExecutor
**Alerts:**

- 🚨🚨🚨 BSC a.DI: Guardians updated
- 🚨🚨🚨 BSC a.DI: Proxy admin changed
- 🚨🚨🚨 BSC a.DI: Proxy upgraded
- 🚨🚨🚨 BSC a.DI: Contract owner set to EOA 🚨🚨🚨
- 🚨 BSC a.DI: Contract owner set to address not in whitelist
- 🚨 BSC a.DI: Allowed Bridges quorum updated
- 🚨 BSC a.DI: Allowed bridges set updated
- ⚠️ BSC a.DI: Message hasn’t achieved a quorum after 1 hour
- ⚠️ BSC a.DI: Cross-chain executor delay updated
- ⚠️ BSC a.DI: Cross-chain executor Grace Period updated
- ⚠️ BSC a.DI: Cross-chain executor Min Delay updated
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions bsc-adi-governance/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@
"eslint-plugin-jest": "^27.6.0",
"eslint-plugin-prettier": "^5.0.1",
"husky": "^8.0.3",
"jest": "^27.0.6",
"jest": "^29.7.0",
"nodemon": "^2.0.8",
"prettier": "^3.1.0",
"ts-jest": "^27.0.3",
"ts-jest": "^29.2.4",
"typechain": "^8.3.2",
"typescript": "^5.3.2"
},
Expand Down
18 changes: 11 additions & 7 deletions bsc-adi-governance/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ export function initialize(): Initialize {
process.exit(1)
}

const agents: string[] = [app.crossChainControllerSrv.getName(), app.crossChainExecutorWatcherSrv.getName()]
const agents: string[] = [
app.crossChainControllerSrv.getName(),
app.crossChainExecutorWatcherSrv.getName(),
app.bscAclChangesSrv.getName(),
]

metadata.agents = '[' + agents.toString() + ']'

await app.findingsRW.write([
Expand All @@ -55,28 +60,27 @@ export function initialize(): Initialize {
}
}

let isHandleBlockRunning: boolean = false
export const handleBlock = (): HandleBlock => {
return async function (blockEvent: BlockEvent): Promise<Finding[]> {
console.log(`#BSC block: ${blockEvent.block.number}`)
const startTime = new Date().getTime()
if (isHandleBlockRunning) {
return []
}

isHandleBlockRunning = true
const app = await App.getInstance()

const findings: Finding[] = []
const findingsAsync = await app.findingsRW.read()
if (findingsAsync.length > 0) {
findings.push(...findingsAsync)
}
const [crossChainControllerFindings, bscAclChangesFindings] = await Promise.all([
app.crossChainControllerSrv.handleBlock(blockEvent),
app.bscAclChangesSrv.handleBlock(blockEvent),
])
findings.push(...crossChainControllerFindings, ...bscAclChangesFindings)

app.healthChecker.check(findings)

console.log(elapsedTime('handleBlock', startTime) + '\n')
isHandleBlockRunning = false
return findings
}
}
Expand Down
4 changes: 4 additions & 0 deletions bsc-adi-governance/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as Winston from 'winston'
import { BSCProvider } from './clients/bsc_provider'
import { EventWatcherSrv } from './services/event-watcher/EventWatcher.srv'
import { CrossChainControllerSrv } from './services/cross-chain-controller/CrossChainController.srv'
import { AclChangesSrv } from './services/acl-changes/AclChanges.srv'
import { DataRW } from './utils/mutex'
import { BorderTime, HealthChecker, MaxNumberErrorsPerBorderTime } from './services/health-checker/health-checker.srv'
import { CROSS_CHAIN_CONTROLLER_ADDRESS, CROSS_CHAIN_EXECUTOR_ADDRESS } from './utils/constants'
Expand All @@ -13,6 +14,7 @@ export type Container = {
bscClient: BSCProvider
crossChainControllerSrv: CrossChainControllerSrv
crossChainExecutorWatcherSrv: EventWatcherSrv
bscAclChangesSrv: AclChangesSrv
findingsRW: DataRW<Finding>
healthChecker: HealthChecker
}
Expand Down Expand Up @@ -42,11 +44,13 @@ export class App {
getCrossChainExecutorEvents(CROSS_CHAIN_EXECUTOR_ADDRESS),
logger,
)
const bscAclChangesSrv = new AclChangesSrv(logger, bscClient)

App.instance = {
bscClient,
crossChainControllerSrv,
crossChainExecutorWatcherSrv,
bscAclChangesSrv,
findingsRW: new DataRW([]),
healthChecker: new HealthChecker(BorderTime, MaxNumberErrorsPerBorderTime),
}
Expand Down
86 changes: 85 additions & 1 deletion bsc-adi-governance/src/clients/bsc_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import { retryAsync } from 'ts-retry'
import { ICRossChainControllerClient } from '../services/cross-chain-controller/CrossChainController.srv'
import { NetworkError } from '../utils/errors'
import { BaseAdapter__factory, CrossChainController } from '../generated'
import { CROSS_CHAIN_CONTROLLER_ADDRESS } from '../utils/constants'
import { IAclChangesClient } from '../services/acl-changes/AclChanges.srv'

const DELAY_IN_500MS = 500
const ATTEMPTS_5 = 5
const MAINNET_CHAIN_ID = 1

export class BSCProvider implements ICRossChainControllerClient {
export class BSCProvider implements ICRossChainControllerClient, IAclChangesClient {
private jsonRpcProvider: ethers.providers.JsonRpcProvider
private crossChainControllerRunner: CrossChainController

Expand Down Expand Up @@ -85,4 +87,86 @@ export class BSCProvider implements ICRossChainControllerClient {
return E.left(new NetworkError(e, `Could not get bridge adapters list from CrossChainController contract`))
}
}

public async getEnvelopeStateByIds(envelopeIds: string[]): Promise<E.Either<Error, Map<string, number>>> {
try {
const out = new Map<string, number>()
await Promise.all(
envelopeIds.map(async (envelopeId) => {
const status = await this.crossChainControllerRunner['getEnvelopeState(bytes32)'](envelopeId)
out.set(envelopeId, status)
}),
)
return E.right(out)
} catch (e) {
return E.left(new NetworkError(e, `Could not get bridge adapters list from CrossChainController contract`))
}
}

public async getReceivedEnvelopeIds(fromBlock: number, toBlock: number): Promise<E.Either<Error, string[]>> {
try {
const results = await retryAsync(
async () => {
const keccakEvent = ethers.utils.keccak256(
ethers.utils.toUtf8Bytes('TransactionReceived(bytes32,bytes32,uint256,(uint256,bytes),address,uint8)'),
)
const address = CROSS_CHAIN_CONTROLLER_ADDRESS
return this.jsonRpcProvider.getLogs({
fromBlock: `0x${fromBlock.toString(16)}`,
toBlock: `0x${toBlock.toString(16)}`,
address,
topics: [keccakEvent, null, '0x0000000000000000000000000000000000000000000000000000000000000001', null],
})
},
{ delay: DELAY_IN_500MS, maxTry: ATTEMPTS_5 },
)
const iface = new ethers.utils.Interface([
'event TransactionReceived(bytes32 transactionId, bytes32 indexed envelopeId, uint256 indexed originChainId, (uint256,bytes), address indexed bridgeAdapter, uint8 confirmations)',
])
const out = results.map((result) => iface.parseLog(result))
const res: string[] = out.map((out) => out.args.envelopeId)
return E.right(res)
} catch (e) {
return E.left(new NetworkError(e, `Could not call jsonRpcProvider.getStonksOrderParams`))
}
}
public async getContractOwner(
address: string,
method: string,
currentBlock: number,
): Promise<E.Either<Error, string>> {
/*
getContractOwner calls the method written in the ownershipMethod field in contract description
and returns the owner of the contract address.
*/
try {
const members = await retryAsync(
async (): Promise<string> => {
const abi = [`function ${method}() view returns (address)`]
const contract = new ethers.Contract(address, abi, this.jsonRpcProvider)
return contract.functions[method]({ blockTag: currentBlock })
},
{ delay: DELAY_IN_500MS, maxTry: ATTEMPTS_5 },
)
return E.right(String(members))
} catch (e) {
return E.left(new NetworkError(e, `Could not call ethers.Contract for address ${address}`))
}
}

public async isDeployed(address: string, blockNumber?: number): Promise<E.Either<Error, boolean>> {
try {
const result = await retryAsync(
async (): Promise<boolean> => {
const code = await this.jsonRpcProvider.getCode(address, blockNumber)
return code !== '0x'
},
{ delay: DELAY_IN_500MS, maxTry: ATTEMPTS_5 },
)

return E.right(result)
} catch (e) {
return E.left(new NetworkError(e, `Could not call jsonRpcProvider.getCode for address ${address}`))
}
}
}
Loading

0 comments on commit ad46085

Please sign in to comment.