Skip to content

Commit

Permalink
Merge branch 'main' into failed-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fionnachan authored Oct 17, 2023
2 parents 38544d7 + 382dd9e commit 4de6dfd
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 28 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@arbitrum/sdk",
"version": "3.1.9",
"version": "3.1.12",
"description": "Typescript library client-side interactions with Arbitrum",
"author": "Offchain Labs, Inc.",
"license": "Apache-2.0",
Expand Down Expand Up @@ -49,6 +49,7 @@
"@ethersproject/address": "^5.0.8",
"@ethersproject/bignumber": "^5.1.1",
"@ethersproject/bytes": "^5.0.8",
"async-mutex": "^0.4.0",
"ethers": "^5.1.0"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export {
} from './lib/dataEntities/networks'
export { InboxTools } from './lib/inbox/inbox'
export { EventFetcher } from './lib/utils/eventFetcher'
export { ArbitrumProvider } from './lib/utils/arbProvider'
export * as constants from './lib/dataEntities/constants'
export { L2ToL1MessageStatus } from './lib/dataEntities/message'
export {
Expand Down
36 changes: 36 additions & 0 deletions src/lib/dataEntities/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,42 @@ export const l2Networks: L2Networks = {
nitroGenesisL1Block: 0,
depositTimeout: 1800000,
},
23011913: {
chainID: 23011913,
confirmPeriodBlocks: 20,
ethBridge: {
bridge: '0x35aa95ac4747D928E2Cd42FE4461F6D9d1826346',
inbox: '0xe1e3b1CBaCC870cb6e5F4Bdf246feB6eB5cD351B',
outbox: '0x98fcA8bFF38a987B988E54273Fa228A52b62E43b',
rollup: '0x94db9E36d9336cD6F9FfcAd399dDa6Cc05299898',
sequencerInbox: '0x00A0F15b79d1D3e5991929FaAbCF2AA65623530c',
},
explorerUrl: 'https://stylus-testnet-explorer.arbitrum.io',
isArbitrum: true,
isCustom: false,
name: 'Stylus Testnet',
partnerChainID: 421614,
retryableLifetimeSeconds: SEVEN_DAYS_IN_SECONDS,
tokenBridge: {
l1CustomGateway: '0xd624D491A5Bc32de52a2e1481846752213bF7415',
l1ERC20Gateway: '0x7348Fdf6F3e090C635b23D970945093455214F3B',
l1GatewayRouter: '0x0057892cb8bb5f1cE1B3C6f5adE899732249713f',
l1MultiCall: '0xBEbe3BfBF52FFEA965efdb3f14F2101c0264c940',
l1ProxyAdmin: '0xB9E77732f32831f09e2a50D6E71B2Cca227544bf',
l1Weth: '0x980B62Da83eFf3D4576C647993b0c1D7faf17c73',
l1WethGateway: '0x39845e4a230434D218b907459a305eBA61A790d4',
l2CustomGateway: '0xF6dbB0e312dF4652d59ce405F5E00CC3430f19c5',
l2ERC20Gateway: '0xe027f79CE40a1eF8e47B51d0D46Dc4ea658C5860',
l2GatewayRouter: '0x4c3a1f7011F02Fe4769fC704359c3696a6A60D89',
l2Multicall: '0xEb4A260FD16aaf18c04B1aeaDFE20E622e549bd3',
l2ProxyAdmin: '0xE914c0d417E8250d0237d2F4827ed3612e6A9C3B',
l2Weth: '0x61Dc4b961D2165623A25EB775260785fE78BD37C',
l2WethGateway: '0x7021B4Edd9f047772242fc948441d6e0b9121175',
},
nitroGenesisBlock: 0,
nitroGenesisL1Block: 0,
depositTimeout: 900000,
},
}

const getNetwork = async (
Expand Down
64 changes: 62 additions & 2 deletions src/lib/message/L2ToL1MessageNitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { NodeInterface__factory } from '../abi/factories/NodeInterface__factory'

import { L2ToL1TxEvent } from '../abi/ArbSys'
import { ContractTransaction, Overrides } from 'ethers'
import { Mutex } from 'async-mutex'
import { EventFetcher, FetchedEvent } from '../utils/eventFetcher'
import { ArbSdkError } from '../dataEntities/errors'
import {
Expand Down Expand Up @@ -61,6 +62,64 @@ const ASSERTION_CREATED_PADDING = 50
// expected number of L1 blocks that it takes for a validator to confirm an L1 block after the node deadline is passed
const ASSERTION_CONFIRMED_PADDING = 20

const l2BlockRangeCache: { [key in string]: (number | undefined)[] } = {}
const mutex = new Mutex()

function getL2BlockRangeCacheKey({
l2ChainId,
l1BlockNumber,
}: {
l2ChainId: number
l1BlockNumber: number
}) {
return `${l2ChainId}-${l1BlockNumber}`
}

function setL2BlockRangeCache(key: string, value: (number | undefined)[]) {
l2BlockRangeCache[key] = value
}

async function getBlockRangesForL1BlockWithCache({
l1Provider,
l2Provider,
forL1Block,
}: {
l1Provider: JsonRpcProvider
l2Provider: JsonRpcProvider
forL1Block: number
}) {
const l2ChainId = (await l2Provider.getNetwork()).chainId
const key = getL2BlockRangeCacheKey({
l2ChainId,
l1BlockNumber: forL1Block,
})

if (l2BlockRangeCache[key]) {
return l2BlockRangeCache[key]
}

// implements a lock that only fetches cache once
const release = await mutex.acquire()

// if cache has been acquired while awaiting the lock
if (l2BlockRangeCache[key]) {
release()
return l2BlockRangeCache[key]
}

try {
const l2BlockRange = await getBlockRangesForL1Block({
forL1Block,
provider: l1Provider,
})
setL2BlockRangeCache(key, l2BlockRange)
} finally {
release()
}

return l2BlockRangeCache[key]
}

/**
* Base functionality for nitro L2->L1 messages
*/
Expand Down Expand Up @@ -212,9 +271,10 @@ export class L2ToL1MessageReaderNitro extends L2ToL1MessageNitro {
// If L1 is Arbitrum, then L2 is an Orbit chain.
if (await isArbitrumChain(this.l1Provider)) {
try {
const l2BlockRange = await getBlockRangesForL1Block({
const l2BlockRange = await getBlockRangesForL1BlockWithCache({
l1Provider: this.l1Provider as JsonRpcProvider,
l2Provider: l2Provider as JsonRpcProvider,
forL1Block: createdAtBlock.toNumber(),
provider: this.l1Provider as JsonRpcProvider,
})
const startBlock = l2BlockRange[0]
const endBlock = l2BlockRange[1]
Expand Down
64 changes: 39 additions & 25 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1723,6 +1723,13 @@ async-eventemitter@^0.2.4:
dependencies:
async "^2.4.0"

async-mutex@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/async-mutex/-/async-mutex-0.4.0.tgz#ae8048cd4d04ace94347507504b3cf15e631c25f"
integrity sha512-eJFZ1YhRR8UN8eBLoNzcDPcy/jqjsg6I1AP+KvWQX80BqOSW1oJPJXDylPUEeMr2ZQvHgnQ//Lp6f3RQ1zI7HA==
dependencies:
tslib "^2.4.0"

async@^2.4.0:
version "2.6.4"
resolved "https://registry.yarnpkg.com/async/-/async-2.6.4.tgz#706b7ff6084664cd7eae713f6f965433b5504221"
Expand Down Expand Up @@ -1987,17 +1994,17 @@ cbor@^8.0.0:
nofilter "^3.1.0"

chai@^4.2.0:
version "4.3.6"
resolved "https://registry.yarnpkg.com/chai/-/chai-4.3.6.tgz#ffe4ba2d9fa9d6680cc0b370adae709ec9011e9c"
integrity sha512-bbcp3YfHCUzMOvKqsztczerVgBKSsEijCySNlHHbX3VG1nskvqjz5Rfso1gGwD6w6oOV3eI60pKuMOV5MV7p3Q==
version "4.3.10"
resolved "https://registry.yarnpkg.com/chai/-/chai-4.3.10.tgz#d784cec635e3b7e2ffb66446a63b4e33bd390384"
integrity sha512-0UXG04VuVbruMUYbJ6JctvH0YnC/4q3/AkT18q4NaITo91CUm0liMS9VqzT9vZhVQ/1eqPanMWjBM+Juhfb/9g==
dependencies:
assertion-error "^1.1.0"
check-error "^1.0.2"
deep-eql "^3.0.1"
get-func-name "^2.0.0"
loupe "^2.3.1"
check-error "^1.0.3"
deep-eql "^4.1.3"
get-func-name "^2.0.2"
loupe "^2.3.6"
pathval "^1.1.1"
type-detect "^4.0.5"
type-detect "^4.0.8"

chalk@^2.0.0, chalk@^2.3.0, chalk@^2.4.2:
version "2.4.2"
Expand All @@ -2016,10 +2023,12 @@ chalk@^4.0.0, chalk@^4.1.0, chalk@^4.1.2:
ansi-styles "^4.1.0"
supports-color "^7.1.0"

check-error@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/check-error/-/check-error-1.0.2.tgz#574d312edd88bb5dd8912e9286dd6c0aed4aac82"
integrity sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=
check-error@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/check-error/-/check-error-1.0.3.tgz#a6502e4312a7ee969f646e83bb3ddd56281bd694"
integrity sha512-iKEoDYaRmd1mxM90a2OEfWhjsjPpYPuQ+lMYsoxB126+t8fw7ySEO48nmDg5COTjxDI65/Y2OWpeEHk3ZOe8zg==
dependencies:
get-func-name "^2.0.2"

cheerio-select@^2.1.0:
version "2.1.0"
Expand Down Expand Up @@ -2329,10 +2338,10 @@ decamelize@^4.0.0:
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-4.0.0.tgz#aa472d7bf660eb15f3494efd531cab7f2a709837"
integrity sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ==

deep-eql@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-3.0.1.tgz#dfc9404400ad1c8fe023e7da1df1c147c4b444df"
integrity sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==
deep-eql@^4.1.3:
version "4.1.3"
resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-4.1.3.tgz#7c7775513092f7df98d8df9996dd085eb668cc6d"
integrity sha512-WaEtAOpRA1MQ0eohqZjpGD8zdI0Ovsm8mmFhaDN8dvDZzyoUMcYDnf5Y6iu7HTXxf8JDS23qWa4a+hKCDyOPzw==
dependencies:
type-detect "^4.0.0"

Expand Down Expand Up @@ -3085,10 +3094,10 @@ get-caller-file@^2.0.1, get-caller-file@^2.0.5:
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e"
integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==

get-func-name@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/get-func-name/-/get-func-name-2.0.0.tgz#ead774abee72e20409433a066366023dd6887a41"
integrity sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=
get-func-name@^2.0.0, get-func-name@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/get-func-name/-/get-func-name-2.0.2.tgz#0d7cf20cd13fda808669ffa88f4ffc7a3943fc41"
integrity sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ==

get-intrinsic@^1.0.2:
version "1.1.1"
Expand Down Expand Up @@ -3854,10 +3863,10 @@ [email protected]:
chalk "^4.1.0"
is-unicode-supported "^0.1.0"

loupe@^2.3.1:
version "2.3.4"
resolved "https://registry.yarnpkg.com/loupe/-/loupe-2.3.4.tgz#7e0b9bffc76f148f9be769cb1321d3dcf3cb25f3"
integrity sha512-OvKfgCC2Ndby6aSTREl5aCCPTNIzlDfQZvZxNUrBrihDhL3xcrYegTblhmEiCrg2kKQz4XsFIaemE5BF4ybSaQ==
loupe@^2.3.6:
version "2.3.6"
resolved "https://registry.yarnpkg.com/loupe/-/loupe-2.3.6.tgz#76e4af498103c532d1ecc9be102036a21f787b53"
integrity sha512-RaPMZKiMy8/JruncMU5Bt6na1eftNoo++R4Y+N2FrxkDVTrGvcyzFTsaGif4QTeKESheMGegbhw6iUAq+5A8zA==
dependencies:
get-func-name "^2.0.0"

Expand Down Expand Up @@ -5190,6 +5199,11 @@ tslib@^1.13.0, tslib@^1.8.1, tslib@^1.9.3:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==

tslib@^2.4.0:
version "2.6.2"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.2.tgz#703ac29425e7b37cd6fd456e92404d46d1f3e4ae"
integrity sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==

tslint@^6.1.3:
version "6.1.3"
resolved "https://registry.yarnpkg.com/tslint/-/tslint-6.1.3.tgz#5c23b2eccc32487d5523bd3a470e9aa31789d904"
Expand Down Expand Up @@ -5245,7 +5259,7 @@ type-check@^0.4.0, type-check@~0.4.0:
dependencies:
prelude-ls "^1.2.1"

type-detect@^4.0.0, type-detect@^4.0.5:
type-detect@^4.0.0, type-detect@^4.0.8:
version "4.0.8"
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c"
integrity sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==
Expand Down

0 comments on commit 4de6dfd

Please sign in to comment.