Arbitrum 的 Nitro 项目启动和交易执行源码解析

一. 交易执行细节

1 合约部署

在节点启动之前,会先去部署 L1 上的合约,L2 上的合约是预部署的,接口部分有 solidity 来编写,实现是由 go 代码来实现的,合约实现对应的 go 代码为 precompiles 项目的代码目录,接口定义为 /nitro/contracts/src/precompiles 的代码。

2.1 L1 上的合约部署

合约部署代码入口为/nitro/cmd/deploy/deploy.go,
调用链:arbnode.DeployOnL1 -> deployRollupCreator -> deployBridgeCreator deployChallengeFactory DeployRollupAdminLogic DeployRollupUserLogic
核心代码示例如下

 deployPtr, err := arbnode.DeployOnL1(
   ctx,
   l1client,
   l1TransactionOpts,
   sequencerAddress,
   *authorizevalidators,
   headerReaderConfig,
   machineConfig,
   arbnode.GenerateRollupConfig(*prod, common.HexToHash(*wasmmoduleroot), ownerAddress, l2ChainId, loserEscrowAddress),
)
rollupCreator, rollupCreatorAddress, validatorUtils, validatorWalletCreator, err := deployRollupCreator(ctx, l1Reader, deployAuth)
if err != nil {
   return nil, fmt.Errorf("error deploying rollup creator: %w", err)
}
func deployRollupCreator(ctx context.Context, l1Reader *headerreader.HeaderReader, auth *bind.TransactOpts) (*rollupgen.RollupCreator, common.Address, common.Address, common.Address, error) {
   bridgeCreator, err := deployBridgeCreator(ctx, l1Reader, auth)
   if err != nil {
      return nil, common.Address{}, common.Address{}, common.Address{}, err
   }

   ospEntryAddr, challengeManagerAddr, err := deployChallengeFactory(ctx, l1Reader, auth)
   if err != nil {
      return nil, common.Address{}, common.Address{}, common.Address{}, err
   }
   ......

1.2 L2 上的合约部署

预部署合约, 执行 docker exec nitro_sequencer_1 cat /config/deployment.json 的时候会去部署一些合约, 部署生成的合约如下:

{
  "l1Network": {
    "blockTime": 10,
    "chainID": 1337,
    "explorerUrl": "",
    "isCustom": true,
    "name": "EthLocal",
    "partnerChainIDs": [
      412346,
      412346
    ],
    "rpcURL": "http://localhost:8545"
  },
  "l2Network": {
    "chainID": 412346,
    "confirmPeriodBlocks": 20,
    "ethBridge": {
      "bridge": "0x815b0ce130aa4c1db18ba0c4c92fcfbf6062ab08",
      "inbox": "0x07061a11d42da58c7bd08ddbf4ef6e60232ba966",
      "outbox": "0xE7098C657B3Ee7c92939f20A4E308efCdd656163",
      "rollup": "0x532016aa3f129f35214559723aa7a0faa435f7ce",
      "sequencerInbox": "0xda7b4b25cac35e41f62cf79744b7e4d50f177b64"
    },
    "explorerUrl": "",
    "isArbitrum": true,
    "isCustom": true,
    "name": "ArbLocal",
    "partnerChainID": 1337,
    "rpcURL": "http://localhost:8547",
    "retryableLifetimeSeconds": 604800,
    "depositTimeout": 900000,
    "tokenBridge": {
      "l1CustomGateway": "0xDe67138B609Fbca38FcC2673Bbc5E33d26C5B584",
      "l1ERC20Gateway": "0x0Bdb0992B3872DF911260BfB60D72607eb22d5d4",
      "l1GatewayRouter": "0x4535771b8D5C43100f126EdACfEc7eb60d391312",
      "l1MultiCall": "0x36BeF5fD671f2aA8686023dE4797A7dae3082D5F",
      "l1ProxyAdmin": "0xF7818cd5f5Dc379965fD1C66b36C0C4D788E7cDB",
      "l1Weth": "0x24067223381F042fF36fb87818196dB4D2C56E9B",
      "l1WethGateway": "0xBa3d12E370a4b592AAF0CA1EF09971D196c27aAd",
      "l2CustomGateway": "0x0Bdb0992B3872DF911260BfB60D72607eb22d5d4",
      "l2ERC20Gateway": "0x4535771b8D5C43100f126EdACfEc7eb60d391312",
      "l2GatewayRouter": "0xF7818cd5f5Dc379965fD1C66b36C0C4D788E7cDB",
      "l2Multicall": "0x14a00f381A870878Ae6A055C656520FF2Cbff985",
      "l2ProxyAdmin": "0x8c366Cfd28bC93729e14Da4fcf94d20862A7f266",
      "l2Weth": "0x9b890cA9dE3D317b16
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

The_Web3_社区

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值