Análisis de código de nodo Polygon zkEVM

1. Introducción

Reservar blog:

Código relevante:

inserte la descripción de la imagen aquí
Los principales módulos de servicio proporcionados por los nodos Polygon zkEVM son:

  • 1) servicio JSON-RPC
  • 2) Servicio de secuenciador
  • 3) Servicio de agregador
  • 4) Servicio de sincronizador
  • 5) Servicio de difusión

2. Servicio JSON-RPC

La comparación entre la interfaz Ethereum JSON-RPC y la interfaz JSON-RPC en Polygon zkEVM es la siguiente:

número de serie Nombre de la interfaz RPC Etéreo Hermès 2.0 Observación
1 GetBlockByHash ✔️ ✔️
2 ObtenerBloquePorNúmero ✔️ ✔️
3 GetBlockTransactionCountByHash ✔️ ✔️
4 GetBlockTransactionCountByNumber ✔️ ✔️
5 getUncleCountByBlockHash ✔️ ✔️
6 getUncleCountByBlockNumber ✔️ ✔️
7 ID de cadena ✔️ ✔️
8 Sincronizando ✔️ ✔️
9 base de monedas ✔️
10 cuentas ✔️
11 Número de bloque ✔️ ✔️
12 Llamar ✔️ ✔️
13 EstimarGas ✔️ ✔️
14 CreateAccessList ✔️ EIP-2930: nuevo tipo de transacción que requiere formas más costosas de acceder al contenido fuera de las listas (direcciones o claves de almacenamiento).
15 Precio del gas ✔️ ✔️
dieciséis MaxPriority FeePerGas ✔️
17 Historial de tarifas ✔️
18 Nuevo filtro ✔️ ✔️
19 NuevoBloqueFiltro ✔️ ✔️
20 Nuevo filtro de transacción pendiente ✔️ ✔️
veintiún DesinstalarFiltro ✔️ ✔️
Veintidós ObtenerCambiosFiltro ✔️ ✔️
Veintitres ObtenerFiltrarRegistros ✔️ ✔️
veinticuatro Obtener registros ✔️ ✔️
25 Minería ✔️
26 Tasa de hash ✔️
27 Conseguir trabajo ✔️
28 EnviarTrabajo ✔️
29 EnviarHashrate ✔️
30 Señal ✔️
31 SignTransaction ✔️
32 GetBalance ✔️ ✔️
33 GetStorageAt ✔️ ✔️
34 GetTransactionCount ✔️ ✔️
35 GetCode ✔️ ✔️
36 GetProof ✔️
37 SendTransaction ✔️
38 SendRawTransaction ✔️ ✔️
39 GetTransactionByHash ✔️ ✔️
40 GetTransactionByBlockHashAndIndex ✔️ ✔️
41 GetTransactionByBlockNumberAndIndex ✔️ ✔️
42 GetTransactionReceipt ✔️ ✔️
43 GetCompilers ✔️ ✔️
44 GetUncleByBlockHashAndIndex ✔️ ✔️
45 GetUncleByBlockNumberAndIndex ✔️ ✔️
46 ProtocolVersion ✔️ ✔️

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)
}

3. Sequencer服务

inserte la descripción de la imagen aquí
inserte la descripción de la imagen aquí
当前代码库中,暂未实现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系列博客

Supongo que te gusta

Origin blog.csdn.net/mutourend/article/details/126409344
Recomendado
Clasificación