欢迎所有爱好区块链技术的人加入。

ARCHIVES / 2006.HTML

polygon cdk Aggregator使用SequencerPrivateKey的时机

Surou Polygon

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

以下条件时被设置

  1. cfg.SyncModeOnlyEnabled == false
  2. 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结算时,才需要设置SequencerPrivateKey,所以独立部署时Aggregator不需要配置Aggregator.SequencerPrivateKey