Skip to content

Commit

Permalink
feat: l2-bridge-arb iterate over l1
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyWh1te committed Jul 15, 2024
1 parent 77c808d commit 880745f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 29 deletions.
43 changes: 16 additions & 27 deletions l2-bridge-arbitrum/src/clients/arbitrum_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,10 @@ export class ArbitrumClient implements IMonitorWithdrawalsClient, IL2BridgeBalan

const extraOffset = 20
while (leftTimestamp <= rightTimestamp) {
if (direction == Direction.Right && left === right) {
right += extraOffset
} else if (direction == Direction.Left && left === right) {
if (left === right) {
if (left === right) {
if (direction == Direction.Right) {
right += extraOffset
} else {
left -= extraOffset
}
}
Expand All @@ -393,32 +393,21 @@ export class ArbitrumClient implements IMonitorWithdrawalsClient, IL2BridgeBalan
}

let out = firstHit
if (direction == Direction.Right) {
while (out.timestamp === target) {
const finalBlock = await this.getL2BlockDto(out.number + 1)
if (E.isLeft(finalBlock)) {
return E.right(out)
}

if (finalBlock.right.timestamp > target) {
break
}

out = finalBlock.right
while (out.timestamp === target) {
const lookingBlock = direction == Direction.Right ? out.number + 1 : out.number - 1
const finalBlock = await this.getL2BlockDto(lookingBlock)
if (E.isLeft(finalBlock)) {
return E.right(out)
}
} else if (direction == Direction.Left) {
while (out.timestamp === target) {
const finalBlock = await this.getL2BlockDto(out.number - 1)
if (E.isLeft(finalBlock)) {
return E.right(out)
}

if (finalBlock.right.timestamp < target) {
break
}

out = finalBlock.right
if (direction == Direction.Right && finalBlock.right.timestamp > target) {
break
}
if (direction == Direction.Left && finalBlock.right.timestamp < target) {
break
}

out = finalBlock.right
}

return E.right(out)
Expand Down
2 changes: 1 addition & 1 deletion l2-bridge-arbitrum/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const main = async () => {

const logger: Winston.Logger = Winston.createLogger({
format: config.logFormat === 'simple' ? Winston.format.simple() : Winston.format.json(),
transports: [new Winston.transports.Console(), new Winston.transports.File({ filename: 'combined.log' })],
transports: [new Winston.transports.Console()],
})

const defaultRegistry = promClient
Expand Down
2 changes: 1 addition & 1 deletion l2-bridge-arbitrum/src/utils/time.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const SECONDS_60 = 60
export const SECONDS_768 = 120
export const SECONDS_768 = 768

export function formatTime(timeInMillis: number): string {
const seconds = (timeInMillis / 1000).toFixed(3)
Expand Down

0 comments on commit 880745f

Please sign in to comment.