Skip to content

Commit

Permalink
feat: Support quorum config for aggregator (#95)
Browse files Browse the repository at this point in the history
* add QuorumNums config

* use config quorumNumbers
  • Loading branch information
fyInALT authored Apr 5, 2024
1 parent 6593326 commit 767169b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
9 changes: 9 additions & 0 deletions aggregator/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,15 @@ func (agg *AggregatorService) sendNewTask(alertHash message.Bytes32, taskIndex t
agg.logger.Error("GetQuorumCountByBlockNumber failed", "err", err)
return nil, err
}
agg.logger.Info("get quorumNumbers from layer1", "quorumNumbers", fmt.Sprintf("%v", quorumNumbers))

if len(quorumNumbers) < len(agg.cfg.QuorumNums) {
agg.logger.Error("the cfg quorum numbers is larger to the layer1, it will commit failed")
return nil, fmt.Errorf("the quorum numbers is larger to the layer1 %v, expected %v", agg.cfg.QuorumNums, quorumNumbers)
}

// just use config value
quorumNumbers = agg.cfg.QuorumNums

quorumThresholdPercentages, err := agg.avsReader.GetQuorumThresholdPercentages(context.Background(), uint32(referenceBlockNumber), quorumNumbers)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions config-files/aggregator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ layer1_chain_id: 31337

# the layer2 chain id
layer2_chain_id: 0

# the QuorumNums we use, just no change
quorum_nums: [0]
19 changes: 19 additions & 0 deletions core/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Config struct {
AggregatorGRPCServerIpPortAddr string
Layer1ChainId uint32
Layer2ChainId uint32
QuorumNums types.QuorumNums
// json:"-" skips this field when marshaling (only used for logging to stdout), since SignerFn doesnt implement marshalJson
SignerFn signerv2.SignerFn `json:"-"`
PrivateKey *ecdsa.PrivateKey `json:"-"`
Expand All @@ -57,6 +58,7 @@ type ConfigRaw struct {
AggregatorGRPCServerIpPortAddr string `yaml:"aggregator_grpc_server_ip_port_address"`
Layer1ChainId uint32 `yaml:"layer1_chain_id"`
Layer2ChainId uint32 `yaml:"layer2_chain_id"`
QuorumNums []uint8 `yaml:"quorum_nums"`
}

// These are read from DeploymentFileFlag
Expand Down Expand Up @@ -182,6 +184,22 @@ func NewConfig(ctx *cli.Context) (*Config, error) {
}
txMgr := txmgr.NewSimpleTxManager(txSender, ethRpcClient, logger, aggregatorAddr)

quorumNums := make([]types.QuorumNum, len(configRaw.QuorumNums))
for i, quorumNum := range configRaw.QuorumNums {
quorumNums[i] = types.QuorumNum(quorumNum)
}

if len(quorumNums) == 0 {
// default use zero
logger.Warn("not quorumNums, just use [0]")
quorumNums = []types.QuorumNum{types.QuorumNum(0)}
}
logger.Info(
"the quorumNums",
"quorumNums", fmt.Sprintf("%#v", quorumNums),
"raw", fmt.Sprintf("%#v", configRaw.QuorumNums),
)

config := &Config{
Logger: logger,
EthWsRpcUrl: configRaw.EthWsUrl,
Expand All @@ -198,6 +216,7 @@ func NewConfig(ctx *cli.Context) (*Config, error) {
AggregatorAddress: aggregatorAddr,
Layer1ChainId: configRaw.Layer1ChainId,
Layer2ChainId: configRaw.Layer2ChainId,
QuorumNums: quorumNums,
}
config.validate()
return config, nil
Expand Down

0 comments on commit 767169b

Please sign in to comment.