区块链中文技术社区 - Polygon
type: channel
link: https://bcskill.com/index.php/category/Polygon/
items: 跨链桥跨链过程中数据变化
items: polygon cdk aggregator 报execution reverted (0x09bde339)
items: polygon cdk Aggregator使用SequencerPrivateKey的时机
items: polygon da 判断DA服务是否正常
items: polygon cdk sequence sender 发送 sequenceBatchesValidium的时机
items: polygon cdk 查看最新提交L1batch num
items: CDK 部署或重置后第一笔交易
items: error: latest Synced BlockNumber (7089137) is higher than the latest Proposed block (1008) in the network
items: polygon cdk 跨链桥交易处理流程分析
items: 因RPC限速导致sequence-sender异常退出

跨链桥跨链过程中数据变化
type: item
date: 2024-11-19T19:02:11+08:00
description: 发起的两笔跨链交易 （L1->L2） https://sepolia.etherscan.io/tx/0xd2db346f588d3eb9c90b0a9da2e8382d5c3275916288131f3701ae62bae56c44 https://sepolia.etherscan.io/tx/0x13a2ac45a973524d704463fe16d4d8e3410efc09cf6d3e53b6052c8a17ece4a4 bridge_db=# select * FROM sync.block; id | block_num | block_hash | parent_hash | network_id | received_at ----+-----------+--------------------------------------------------------------------+--------------------------------------------------------------------+------------+------------------------ 0 | | \x5c7830 | | | 1970-01-01 00:00:00+00 1 | 7092388 | \xe984c5267a0e675df842c9ad91a1d0825080cfc581791250955a7a7dd41b71ab | \x5fcd8aa7d9b8650488fcfcf93db2c2dfb03100d02e2e0f927b0ee8d758dfb2b4 | 0 | 2024-11-17 01:21:24+00 2 | 7092528 | \xcd588c08198efdbe40a4bfc731f906594dd0e80f78acff528a84bf36c8341f03 | \xec136b1e2d7fe0fd4fdb4c4c11cb1b5cc578c97e26d6073652a1d31702b12999 | 0 | 2024-11-17 01:51:36+00 bridge_db=# SELECT * FROM sync.deposit; leaf_type | network_id | orig_net | orig_addr | amount | dest_net | dest_addr | block_id | deposit_cnt | tx_hash | metadata | id | ready_for_claim -----------+------------+----------+--------------------------------------------+------------------------+----------+--------------------------------------------+----------+-------------+--------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----+----------------- 0 | 0 | 0 | \x3ec3d234625cde1e0f3267014e26e193610e50ac | 1000000000000000000000 | 1 | \xc2df13b6ad0753e0547a318f65f99ac62aec6e2b | 1 | 0 | \xd2db346f588d3eb9c90b0…

polygon cdk aggregator 报execution reverted (0x09bde339)
type: item
date: 2024-11-18T17:59:00+08:00
description: 错误信息 2024-11-18T08:36:32.892Z ERROR ethtxmanager/ethtxmanager.go:270 failed to estimate gas: execution reverted (0x09bde339), data: 1489ed1000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000520000000000000000000000000000000000000000000000000000000000000000cbec6bce507ef87ba7cb1adaca9d65f2791bfc03cc77c6602c4e6f7be7eb23e100000000000000000000000047ce1498ae40c634d60314f447816a2184602a7a20227cbcef731b6cbdc0edd5850c63dc7fbc27fb58d12cd4d08298799cf66a0512c230867d3375a1f4669e7267dad2c31ebcddbaccea6abd67798ceae35ae7611c665b6069339e6812d015e239594aa71c4e217288e374448c358f6459e057c91ad2ef514570b5dea21508e214430daadabdd23433820000fe98b1c6fa81d5c512b86fbf87bd7102775f8ef1da7e8014dc7aab225503237c7927c032e589e9a01a0eab9fda82ffe834c2a4977f36cc9bcb1f2327bdac5fb48ffbeb9656efcdf70d2656c328903e9fb96e4e3f470c447b3053cc68d68cf0ad317fe10aa7f254222e47ea07f3c1c3aacb74e5926a67262f261c1ed3120576ab877b49a81fb8aac51431858662af6b1a8138a44e9d0812d032340369459ccc98b109347cc874c7202dceecc3dbb09d7f9e5658f1ca3a92d22be1fa28f9945205d853e2c866d9b649301ac9857b07b92e4865283d3d5e2b711ea5f85cb2da71965382ece050508d3d008bbe4df5458f70bd3e1bfcc50b34222b43cd28cbe39a3bab6e464664a742161df99c607638e415ced49d0cd719518539ed5f561f81d07fe40d3ce85508e0332465313e60ad9ae271d580022ffca4fbe4d72d38d18e7a6e20d020a1d1e5a8f411291ab95521386fa538ddfe6a391d4a3669cc64c40f07895f031550b32f7d73205a69c214a8ef3cdf996c495e3fd24c00873f30ea6b2bfabfd38de1c3da357d1fefe203573fdad22f675cb5cfabbec0a041b1b31274f70193da8e90cfc4d6dc054c7cd26d09c1dadd064ec52b6ddcfa0cb144d65d9e131c0c88f8004f90d363034d839aa7760167b5302c36d2c2f6714b41782070b10c51c178bd923182d28502f36e19b079b190008c46d19c399331fd60b6b6bde898bd1dd0a71ee7ec7ff7124cc3d374846614389e7b5975b77c4059bc42b810673dbb6f8b951e5b636bdf24afd2a3cbe96ce8600e8a79731b4a56c697596e0bff7b73f413bdbc75069b002b00…

polygon cdk Aggregator使用SequencerPrivateKey的时机
type: item
date: 2024-11-18T13:42:08+08:00
description: 在Aggregator中有如下配置，需要配置Sequencer的私钥 [Aggregator.SequencerPrivateKey] Path = "/etc/cdk/sequencer.keystore" Password = "password" 查看链代码 if !cfg.SyncModeOnlyEnabled && cfg.SettlementBackend == AggLayer { aggLayerClient = agglayer.NewAggLayerClient(cfg.AggLayerURL) sequencerPrivateKey, err = cdkcommon.NewKeyFromKeystore(cfg.SequencerPrivateKey) if err != nil { return nil, err } } 以下条件时被设置 cfg.SyncModeOnlyEnabled == false cfg.SettlementBackend == AggLayer 查看SequencerPrivateKey使用逻辑 func (a *Aggregator) settleWithAggLayer( ctx context.Context, proof *state.Proof, inputs ethmanTypes.FinalProofInputs) bool { proofStrNo0x := strings.TrimPrefix(inputs.FinalProof.Proof, "0x") proofBytes := common.Hex2Bytes(proofStrNo0x) tx := agglayer.Tx{ LastVerifiedBatch: cdkTypes.ArgUint64(proof.BatchNumber - 1), NewVerifiedBatch: cdkTypes.ArgUint64(proof.BatchNumberFinal), ZKP: agglayer.ZKP{ NewStateRoot: common.BytesToHash(inputs.NewStateRoot), NewLocalExitRoot: common.BytesToHash(inputs.NewLocalExitRoot), Proof: cdkTypes.ArgBytes(proofBytes), }, RollupID: a.etherman.GetRollupId(), } signedTx, err := tx.Sign(a.sequencerPrivateKey) if err != nil { a.logger.Errorf("failed to sign tx: %v", err) a.handleFailureToAddVerifyBatchToBeMonitored(ctx, proof) return false } switch a.cfg.SettlementBackend { case AggLayer: if success := a.settleWithAggLayer(ctx, proof, inputs); !success { continue } default: if success := a.settleDirect(ctx, proof, inputs); !success { continue } } SettlementBackend 配置选项 agglayer l1 (默认) 总结 当使用agglayer结算时，才需要设置SequencerPrivateKey，所以独立部署时Aggregator不需要配置Aggregator.SequencerPrivateKey

polygon da 判断DA服务是否正常
type: item
date: 2024-11-18T13:22:09+08:00
description: 查询DA数据库最新存储的batch高度 select batch_num from data_node.offchain_data ORDER BY batch_num DESC Limit 1; 例如返回 batch_num ----------- 335 再查看最新提交的交易->SequenceBatches时间 https://sepolia.etherscan.io/tx/0x9edf5c7c7a87ca47fd85e3002361d1266028e2f2a08d1bfd4cf1e483f6c19104#eventlog numBatch：335 与数据库中高度一致，则代表DA服务正常

polygon cdk sequence sender 发送 sequenceBatchesValidium的时机
type: item
date: 2024-11-18T12:06:00+08:00
description: 问题 sequencesender长时间未向L1提交batch->sequenceBatchesValidium 与sequencesender模块有关的日志只看到如下 2024-11-18T04:04:13.436Z INFO sequencesender/sequencesender.go:187 batch 312 is not closed yet {"pid": 40, "version": "v0.4.0-beta5", "module": "sequence-sender"} 未看到类似日志 2024-11-18T04:04:13.434Z INFO sequencesender/sequencesender.go:282 updating virtual batch {"pid": 40, "version": "v0.4.0-beta5", "module": "sequence-sender"} 临时重启 重启sequencesender服务后，开始提交 2024-11-18T03:41:32.219Z INFO sequencesender/sequencesender.go:352 sending sequences to L1. From batch 83 to batch 318 {"pid": 40, "version": "v0.4.0-beta5", "module": "sequence-sender"} 2024-11-18T03:41:32.555Z DEBUG ethtxmanager/ethtxmanager.go:482 found 0 monitored tx to process {"pid": 40} 2024-11-18T03:41:32.555Z DEBUG ethtxmanager/ethtxmanager.go:512 found 0 mined monitored tx to process {"pid": 40} 2024-11-18T03:41:33.434Z DEBUG ethtxmanager/ethtxmanager.go:555 found 0 safe monitored tx to process {"pid": 40} 2024-11-18T03:41:33.434Z INFO rpc/batch.go:46 Getting batch 319 from RPC {"pid": 40, "version": "v0.4.0-beta5"} 2024-11-18T03:41:33.435Z INFO rpc/batch.go:93 Getting l2 block timestamp from RPC. Block hash: 0x84fb8a0d5f14d5e0871f6c1488de02c0404ef40724eca3878917631f097a4c51 {"pid": 40, "version": "v0.4.0-beta5"} 2024-11-18T03:41:33.436Z INFO sequencesender/sequencesender.go:187 batch 319 is not closed yet {"pid": 40, "version": "v0.4.0-beta5", "module": "sequence-sender"} 2024-11-18T03:41:35.554Z DEBUG ethtxmanager/ethtxmanager.go:482 found 0 monitored tx to process {"pid": 40} 2024-11-18T03:41:35.554Z DEBUG ethtxmanager/ethtxmanager.go:512 found 0 mined monitored tx to process {"pid": 40} 2024-11-18T03:41:36.567Z DEBUG ethtxmanager/ethtxmanager.go:555 found 0 safe monitored tx to process {"pid": 40} 2024-11-18T03:41:38.557Z DEBUG sync/evmdownloader.go:96 getting events from blocks 7099833 to 7099833 {"pid": 40, "version": "v0.4.0-beta5", "syncer": "l1infotreesync"} 2024-11-18T03:41:39.058Z DEBUG ethtxmanager/ethtxmanag…

polygon cdk 查看最新提交L1batch num
type: item
date: 2024-11-18T11:27:35+08:00
description: 通过RPC curl http://L2RPC访问地址/ \ -X POST \ -H "Content-Type: application/json" \ --data '{"method":"zkevm_virtualBatchNumber","params":[],"id":1,"jsonrpc":"2.0"}' 例如返回 curl http://172.18.39.103:8123/ \ > -X POST \ > -H "Content-Type: application/json" \ > --data '{"method":"zkevm_virtualBatchNumber","params":[],"id":1,"jsonrpc":"2.0"}' {"jsonrpc":"2.0","id":1,"result":"0x52"} 0x52对应10进制为82 https://tool.lu/hexconvert/ 合约逻辑 function sequenceBatchesValidium( ValidiumBatchData[] calldata batches, uint32 l1InfoTreeLeafCount, uint64 maxSequenceTimestamp, bytes32 expectedFinalAccInputHash, address l2Coinbase, bytes calldata dataAvailabilityMessage ) external onlyTrustedSequencer { uint256 batchesNum = batches.length; if (batchesNum == 0) { revert SequenceZeroBatches(); } if (batchesNum > _MAX_VERIFY_BATCHES) { revert ExceedMaxVerifyBatches(); } // Check max sequence timestamp inside of range if ( uint256(maxSequenceTimestamp) > (block.timestamp + TIMESTAMP_RANGE) ) { revert MaxTimestampSequenceInvalid(); } // Update global exit root if there are new deposits bridgeAddress.updateGlobalExitRoot(); // Get global batch variables bytes32 l1InfoRoot = globalExitRootManager.l1InfoRootMap( l1InfoTreeLeafCount ); if (l1InfoRoot == bytes32(0)) { revert L1InfoTreeLeafCountInvalid(); } // Store storage variables in memory, to save gas, because will be overrided multiple times uint64 currentLastForceBatchSequenced = lastForceBatchSequenced; bytes32 currentAccInputHash = lastAccInputHash; // Store in a temporal variable, for avoid access again the storage slot uint64 initLastForceBatchSequenced = currentLastForceBatchSequenced; for (uint256 i = 0; i < batchesNum; i++) { // Load current sequence ValidiumBatchData memory currentBatch = batches[i]; // Check if it's a forced batch if (currentBatch.forcedTimestamp > 0) { currentLastForceBatchSequenced++; // Check forced data matches bytes32 hashedForcedBatchData = keccak256( abi.encodePacked( currentBatch.transactionsHash, currentBatch.forcedG…

CDK 部署或重置后第一笔交易
type: item
date: 2024-11-17T09:40:01+08:00
description: 交易组装 // Add the first batch of the created rollup const newZKEVMContract = (await PolygonconsensusFactory.attach(newZKEVMAddress)) as PolygonZkEVMV2; const batchData = { transactions: await newZKEVMContract.generateInitializeTransaction( rollupID, gasTokenAddress, gasTokenNetwork, gasTokenMetadata as any ), globalExitRoot: globalExitRoot, timestamp: timestampReceipt, sequencer: trustedSequencer, }; outputJson.firstBatchData = batchData; 测试数据 "firstBatchData": { "transactions": "0xf901e480808401c9c38094d66bd4a99f128cab5723ab98443bdda0a8ae65d280b901c4f811bff700000000000000000000000000000000000000000000000000000000000000010000000000000000000000003ec3d234625cde1e0f3267014e26e193610e50ac0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a40d5f56745a118d0906a34e69aec8c0db1cb8fa000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000084d4158546f6b656e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034d4158000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005ca1ab1e0000000000000000000000000000000000000000000000000000000005ca1ab1e1bff", "globalExitRoot": "0xad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5", "timestamp": 1731804000, "sequencer": "0x85472577b11837bC157F45643047Cb86136985f2" } 第一个batch信息为 一笔zkEVM合约初始化交易 globalExitRoot timestamp trustedSequencer

error: latest Synced BlockNumber (7089137) is higher than the latest Proposed block (1008) in the network
type: item
date: 2024-11-17T00:38:00+08:00
description: 问题 cdk 跨链桥启动后，发起一笔跨链复现networkID数据错乱，重启后报错 2024-11-16T14:36:29.512Z INFO cmd/run.go:59 main network id: 0 {"pid": 1, "version": "v0.6.0-RC1"} 2024-11-16T14:36:29.512Z INFO cmd/run.go:64 l2 network id: 0 {"pid": 1, "version": "v0.6.0-RC1"} 2024-11-16T14:36:29.542Z DEBUG cmd/run.go:102 trusted sequencer URL http://172.18.39.103:8123 {"pid": 1, "version": "v0.6.0-RC1"} 2024-11-16T14:36:29.542Z INFO server/server.go:93 gRPC Server is serving at 9090 {"pid": 1, "version": "v0.6.0-RC1"} 2024-11-16T14:36:29.542Z INFO server/server.go:166 Restful Server is serving at 8080 {"pid": 1, "version": "v0.6.0-RC1"} 2024-11-16T14:36:29.548Z INFO synchronizer/synchronizer.go:104 NetworkID: 0, Synchronization started {"pid": 1, "version": "v0.6.0-RC1"} 2024-11-16T14:36:29.549Z DEBUG synchronizer/synchronizer.go:119 NetworkID: 0, initial lastBlockSynced: &{ID:3 BlockNumber:7089137 BlockHash:0xbcb0638af2a8014b561ee72c2f568bda819039ca93f16c7de22896fc1037c1a3 ParentHash:0x919c0185dfa6dbc92fb9e13f535c09130d04d1f980749b952b057ffed68f77b6 NetworkID:0 GlobalExitRoots:[] Deposits:[] Claims:[] Tokens:[] VerifiedBatches:[] ActivateEtrog:[] ReceivedAt:2024-11-16 13:48:00 +0000 UTC} {"pid": 1, "version": "v0.6.0-RC1"} 2024-11-16T14:36:29.549Z DEBUG synchronizer/synchronizer.go:126 NetworkID: 0, syncing... {"pid": 1, "version": "v0.6.0-RC1"} 2024-11-16T14:36:29.550Z INFO synchronizer/synchronizer.go:543 NetworkID: 0, [checkReorg function] Checking Block 7089137 in L1 {"pid": 1, "version": "v0.6.0-RC1"} 2024-11-16T14:36:29.553Z ERROR synchronizer/synchronizer.go:546 networkID: 0, error getting latest block synced from blockchain. Block: 7089137, error: Not found%!(EXTRA string= /src/log/log.go:142 github.com/0xPolygonHermez/zkevm-bridge-service/log.appendStackTraceMaybeArgs() /src/log/log.go:251 github.com/0xPolygonHermez/zkevm-bridge-service/log.Errorf() /src/synchronizer/synchronizer.go:546 github.com/0xPolygonHermez/zkevm-bridge-service/synchronizer.(*ClientSynchronizer).checkReorg() /src/synchron…

polygon cdk 跨链桥交易处理流程分析
type: item
date: 2024-11-16T17:25:00+08:00
description: 数据产生 synchronizer/synchronizer.go func (s *ClientSynchronizer) syncBlocks(lastBlockSynced *etherman.Block) (*etherman.Block, error) { ... blocks, order, err := s.etherMan.GetRollupInfoByBlockRange(s.ctx, fromBlock, &toBlock) etherMan.readEvents func (etherMan *Client) GetRollupInfoByBlockRange(ctx context.Context, fromBlock uint64, toBlock *uint64) ([]Block, map[common.Hash][]Order, error) { // Filter query query := ethereum.FilterQuery{ FromBlock: new(big.Int).SetUint64(fromBlock), Addresses: etherMan.SCAddresses, Topics: [][]common.Hash{{updateGlobalExitRootSignatureHash, updateL1InfoTreeSignatureHash, depositEventSignatureHash, claimEventSignatureHash, oldClaimEventSignatureHash, newWrappedTokenEventSignatureHash, verifyBatchesTrustedAggregatorSignatureHash, rollupManagerVerifyBatchesSignatureHash}}, } if toBlock != nil { query.ToBlock = new(big.Int).SetUint64(*toBlock) } blocks, blocksOrder, err := etherMan.readEvents(ctx, query) if err != nil { return nil, nil, err } return blocks, blocksOrder, nil } func (etherMan *Client) readEvents(ctx context.Context, query ethereum.FilterQuery) ([]Block, map[common.Hash][]Order, error) { logs, err := etherMan.EtherClient.FilterLogs(ctx, query) if err != nil { return nil, nil, err } var blocks []Block blocksOrder := make(map[common.Hash][]Order) for _, vLog := range logs { err := etherMan.processEvent(ctx, vLog, &blocks, &blocksOrder) func (etherMan *Client) processEvent(ctx context.Context, vLog types.Log, blocks *[]Block, blocksOrder *map[common.Hash][]Order) error { switch vLog.Topics[0] { case updateGlobalExitRootSignatureHash: return etherMan.updateGlobalExitRootEvent(ctx, vLog, blocks, blocksOrder) updateGlobalExitRootSignatureHash = crypto.Keccak256Hash([]byte("UpdateGlobalExitRoot(bytes32,bytes32)")) func (etherMan *Client) updateGlobalExitRootEvent(ctx context.Context, vLog types.Log, blocks *[]Block, blocksOrder *map[common.Hash][]Order) error { etherMan.logger.Debug("UpdateGlobalExitRoot event detected. Processin…

因RPC限速导致sequence-sender异常退出
type: item
date: 2024-11-15T20:02:21+08:00
description: 问题 因RPC限速导致sequence-sender异常退出 2024-11-15T11:49:59.657Z ERROR sync/evmdownloader.go:248 error calling FilterLogs to eth client: 429 Too Many Requests: {"id":9,"jsonrpc":"2.0","error":{"code":-32005,"message":"rate limit exceeded"}}{"pid": 40, "version": "v0.4.0-beta5", "syncer": "l1infotreesync"} github.com/0xPolygon/cdk/sync.(*EVMDownloaderImplementation).GetLogs /go/src/github.com/0xPolygon/cdk/sync/evmdownloader.go:248 github.com/0xPolygon/cdk/sync.(*EVMDownloaderImplementation).GetEventsByBlockRange /go/src/github.com/0xPolygon/cdk/sync/evmdownloader.go:184 github.com/0xPolygon/cdk/sync.(*EVMDownloader).Download /go/src/github.com/0xPolygon/cdk/sync/evmdownloader.go:97 2024/11/15 11:49:59 getLogs failed too many times (0) 相关代码 type RetryHandler struct { RetryAfterErrorPeriod time.Duration MaxRetryAttemptsAfterError int } func (h *RetryHandler) Handle(funcName string, attempts int) { if h.MaxRetryAttemptsAfterError > -1 && attempts >= h.MaxRetryAttemptsAfterError { log.Fatalf( "%s failed too many times (%d)", funcName, h.MaxRetryAttemptsAfterError, ) } time.Sleep(h.RetryAfterErrorPeriod) } 解决 在sequence-sender 配置->L1InfoTreeSync下增加两个配置 MaxRetryAttemptsAfterError 总共重试多少次后，异常退出，可以设置一个较大值 RetryAfterErrorPeriod：每次重试的间隔时间