• Polygon zkEVM节点代码解析


    1. 引言

    前序博客:

    相关代码:

    在这里插入图片描述
    Polygon zkEVM节点提供的主要服务模块有:

    • 1)JSON-RPC服务
    • 2)Sequencer服务
    • 3)Aggregator服务
    • 4)Synchronizer服务
    • 5)Broadcast服务

    2. JSON-RPC服务

    以太坊JSON-RPC接口Polygon zkEVM中的JSON-RPC接口 对比情况为:

    序号RPC接口名以太坊Hermez 2.0备注
    1GetBlockByHash✔️✔️
    2GetBlockByNumber✔️✔️
    3GetBlockTransactionCountByHash✔️✔️
    4GetBlockTransactionCountByNumber✔️✔️
    5getUncleCountByBlockHash✔️✔️
    6getUncleCountByBlockNumber✔️✔️
    7ChainId✔️✔️
    8Syncing✔️✔️
    9Coinbase✔️
    10Accounts✔️
    11BlockNumber✔️✔️
    12Call✔️✔️
    13EstimateGas✔️✔️
    14CreateAccessList✔️EIP-2930:新交易类型,需以更贵的方式访问清单(地址或storage keys)外的内容。
    15GasPrice✔️✔️
    16MaxPriorityFeePerGas✔️
    17FeeHistory✔️
    18NewFilter✔️✔️
    19NewBlockFilter✔️✔️
    20NewPendingTransactionFilter✔️✔️
    21UninstallFilter✔️✔️
    22GetFilterChanges✔️✔️
    23GetFilterLogs✔️✔️
    24GetLogs✔️✔️
    25Mining✔️
    26Hashrate✔️
    27GetWork✔️
    28SubmitWork✔️
    29SubmitHashrate✔️
    30Sign✔️
    31SignTransaction✔️
    32GetBalance✔️✔️
    33GetStorageAt✔️✔️
    34GetTransactionCount✔️✔️
    35GetCode✔️✔️
    36GetProof✔️
    37SendTransaction✔️
    38SendRawTransaction✔️✔️
    39GetTransactionByHash✔️✔️
    40GetTransactionByBlockHashAndIndex✔️✔️
    41GetTransactionByBlockNumberAndIndex✔️✔️
    42GetTransactionReceipt✔️✔️
    43GetCompilers✔️✔️
    44GetUncleByBlockHashAndIndex✔️✔️
    45GetUncleByBlockNumberAndIndex✔️✔️
    46ProtocolVersion✔️✔️

    Hermez 2.0(zkEVM)除实现了以上与以太坊兼容的RPC接口之外,还额外实现了一些与state交互、与pool交互的接口

    // jsonRPCTxPool contains the methods required to interact with the tx pool.
    type jsonRPCTxPool interface {
    	AddTx(ctx context.Context, tx types.Transaction) error
    	GetPendingTxs(ctx context.Context, isClaims bool, limit uint64) ([]pool.Transaction, error)
    	GetGasPrice(ctx context.Context) (uint64, error)
    	GetPendingTxHashesSince(ctx context.Context, since time.Time) ([]common.Hash, error)
    }
    
    // gasPriceEstimator contains the methods required to interact with gas price estimator
    type gasPriceEstimator interface {
    	GetAvgGasPrice(ctx context.Context) (*big.Int, error)
    }
    
    // stateInterface gathers the methods required to interact with the state.
    type stateInterface interface {
    	BeginStateTransaction(ctx context.Context) (pgx.Tx, error)
    
    	GetLastConsolidatedL2BlockNumber(ctx context.Context, dbTx pgx.Tx) (uint64, error)
    	GetTransactionByHash(ctx context.Context, transactionHash common.Hash, dbTx pgx.Tx) (*types.Transaction, error)
    	GetTransactionReceipt(ctx context.Context, transactionHash common.Hash, dbTx pgx.Tx) (*types.Receipt, error)
    	GetLastL2BlockNumber(ctx context.Context, dbTx pgx.Tx) (uint64, error)
    	GetLastL2Block(ctx context.Context, dbTx pgx.Tx) (*types.Block, error)
    	GetLastL2BlockHeader(ctx context.Context, dbTx pgx.Tx) (*types.Header, error)
    	EstimateGas(transaction *types.Transaction, senderAddress common.Address) (uint64, error)
    	GetBalance(ctx context.Context, address common.Address, blockNumber uint64, dbTx pgx.Tx) (*big.Int, error)
    	GetL2BlockByHash(ctx context.Context, hash common.Hash, dbTx pgx.Tx) (*types.Block, error)
    	GetL2BlockByNumber(ctx context.Context, blockNumber uint64, dbTx pgx.Tx) (*types.Block, error)
    	GetCode(ctx context.Context, address common.Address, blockNumber uint64, dbTx pgx.Tx) ([]byte, error)
    	GetStorageAt(ctx context.Context, address common.Address, position *big.Int, blockNumber uint64, dbTx pgx.Tx) (*big.Int, error)
    	GetSyncingInfo(ctx context.Context, dbTx pgx.Tx) (state.SyncingInfo, error)
    	GetTransactionByL2BlockHashAndIndex(ctx context.Context, blockHash common.Hash, index uint64, dbTx pgx.Tx) (*types.Transaction, error)
    	GetTransactionByL2BlockNumberAndIndex(ctx context.Context, blockNumber uint64, index uint64, dbTx pgx.Tx) (*types.Transaction, error)
    	GetNonce(ctx context.Context, address common.Address, blockNumber uint64, dbTx pgx.Tx) (uint64, error)
    	GetL2BlockHeaderByNumber(ctx context.Context, blockNumber uint64, dbTx pgx.Tx) (*types.Header, error)
    	GetL2BlockTransactionCountByHash(ctx context.Context, hash common.Hash, dbTx pgx.Tx) (uint64, error)
    	GetL2BlockTransactionCountByNumber(ctx context.Context, blockNumber uint64, dbTx pgx.Tx) (uint64, error)
    	GetLogs(ctx context.Context, fromBlock uint64, toBlock uint64, addresses []common.Address, topics [][]common.Hash, blockHash *common.Hash, since *time.Time, dbTx pgx.Tx) ([]*types.Log, error)
    	GetL2BlockHashesSince(ctx context.Context, since time.Time, dbTx pgx.Tx) ([]common.Hash, error)
    	DebugTransaction(ctx context.Context, transactionHash common.Hash, tracer string) (*runtime.ExecutionResult, error)
    	ProcessUnsignedTransaction(ctx context.Context, tx *types.Transaction, senderAddress common.Address, blockNumber uint64, dbTx pgx.Tx) *runtime.ExecutionResult
    	IsL2BlockConsolidated(ctx context.Context, blockNumber int, dbTx pgx.Tx) (bool, error)
    	IsL2BlockVirtualized(ctx context.Context, blockNumber int, dbTx pgx.Tx) (bool, error)
    }
    
    type storageInterface interface {
    	NewLogFilter(filter LogFilter) (uint64, error)
    	NewBlockFilter() (uint64, error)
    	NewPendingTransactionFilter() (uint64, error)
    	GetFilter(filterID uint64) (*Filter, error)
    	UpdateFilterLastPoll(filterID uint64) error
    	UninstallFilter(filterID uint64) (bool, error)
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52

    3. Sequencer服务

    在这里插入图片描述
    在这里插入图片描述
    当前代码库中,暂未实现permissionless sequencer功能,ProofOfEfficiency.sol合约中也暂未实现registerSequencer等接口。

    参考资料

    [1] Ethereum JSON-RPC Specification
    [2] PoE
    [3] zkProver debugging
    [4] Hermez 1.5 - Merkle Tree spec
    [5] PoE - 1.5

    附录:Polygon Hermez 2.0 zkEVM系列博客

  • 相关阅读:
    Android Studio的debug和release模式及签名配置
    R语言ggplot2可视化:使用ggplot2可视化散点图、在geom_point参数中设置show_legend参数为FALSE配置不显示图例信息
    2022河南萌新联赛第(二)场:河南理工大学 I - 22数
    前后端联调统一校验规则
    香港电信级中立机房服务器租赁服务——跨境互联新篇章
    【路径规划】基于matlab AI抗疫服务移动机器人路径规划系统【含Matlab源码 2096期】
    java计算机毕业设计springboot+vue网络体检服务系统
    easy_see
    使用消息队列 queue 实现数据通信
    牛牛截图控件与利洽远程控制产品升级-支持证书自动升级
  • 原文地址:https://blog.csdn.net/mutourend/article/details/126409344