diff --git a/cmd/harmony/config.go b/cmd/harmony/config.go index 8ac68238b..057db6293 100644 --- a/cmd/harmony/config.go +++ b/cmd/harmony/config.go @@ -60,7 +60,8 @@ type generalConfig struct { } type consensusConfig struct { - MinPeers int + MinPeers int + AggregateSig bool } type blsConfig struct { diff --git a/cmd/harmony/default.go b/cmd/harmony/default.go index b63ddf879..5a4e92247 100644 --- a/cmd/harmony/default.go +++ b/cmd/harmony/default.go @@ -89,7 +89,8 @@ var defaultLogContext = logContext{ } var defaultConsensusConfig = consensusConfig{ - MinPeers: 6, + MinPeers: 6, + AggregateSig: true, } const ( diff --git a/cmd/harmony/flags.go b/cmd/harmony/flags.go index 5a063926e..25a246248 100644 --- a/cmd/harmony/flags.go +++ b/cmd/harmony/flags.go @@ -92,6 +92,7 @@ var ( // consensusValidFlags are flags that are effective consensusValidFlags = []cli.Flag{ consensusMinPeersFlag, + consensusAggregateSigFlag, legacyConsensusMinPeersFlag, } @@ -746,6 +747,11 @@ var ( DefValue: defaultConsensusConfig.MinPeers, Hidden: true, } + consensusAggregateSigFlag = cli.BoolFlag{ + Name: "consensus.aggregate-sig", + Usage: "(multi-key) aggregate bls signatures before sending", + DefValue: defaultConsensusConfig.AggregateSig, + } legacyDelayCommitFlag = cli.StringFlag{ Name: "delay_commit", Usage: "how long to delay sending commit messages in consensus, ex: 500ms, 1s", @@ -766,7 +772,7 @@ var ( ) func applyConsensusFlags(cmd *cobra.Command, config *harmonyConfig) { - if cli.HasFlagsChanged(cmd, consensusValidFlags) { + if config.Consensus == nil && cli.HasFlagsChanged(cmd, consensusValidFlags) { cfg := getDefaultConsensusConfigCopy() config.Consensus = &cfg } @@ -776,6 +782,10 @@ func applyConsensusFlags(cmd *cobra.Command, config *harmonyConfig) { } else if cli.IsFlagChanged(cmd, legacyConsensusMinPeersFlag) { config.Consensus.MinPeers = cli.GetIntFlagValue(cmd, legacyConsensusMinPeersFlag) } + + if cli.IsFlagChanged(cmd, consensusAggregateSigFlag) { + config.Consensus.AggregateSig = cli.GetBoolFlagValue(cmd, consensusAggregateSigFlag) + } } // transaction pool flags diff --git a/cmd/harmony/flags_test.go b/cmd/harmony/flags_test.go index 8194e8334..bf82335b9 100644 --- a/cmd/harmony/flags_test.go +++ b/cmd/harmony/flags_test.go @@ -67,7 +67,8 @@ func TestHarmonyFlags(t *testing.T) { Port: 9800, }, Consensus: &consensusConfig{ - MinPeers: 6, + MinPeers: 6, + AggregateSig: true, }, BLSKeys: blsConfig{ KeyDir: "./.hmy/blskeys", @@ -600,15 +601,18 @@ func TestConsensusFlags(t *testing.T) { expConfig: nil, }, { - args: []string{"--consensus.min-peers", "10"}, + args: []string{"--consensus.min-peers", "10", "--consensus.aggregate-sig=false"}, expConfig: &consensusConfig{ - MinPeers: 10, + MinPeers: 10, + AggregateSig: false, }, }, { - args: []string{"--delay_commit", "10ms", "--block_period", "5", "--min_peers", "10"}, + args: []string{"--delay_commit", "10ms", "--block_period", "5", "--min_peers", "10", + "--consensus.aggregate-sig=true"}, expConfig: &consensusConfig{ - MinPeers: 10, + MinPeers: 10, + AggregateSig: true, }, }, } diff --git a/cmd/harmony/main.go b/cmd/harmony/main.go index 0c3e69c90..b07699d80 100644 --- a/cmd/harmony/main.go +++ b/cmd/harmony/main.go @@ -575,12 +575,16 @@ func setupConsensusAndNode(hc harmonyConfig, nodeConfig *nodeconfig.ConfigType) // Parse minPeers from harmonyConfig var minPeers int + var aggregateSig bool if hc.Consensus != nil { minPeers = hc.Consensus.MinPeers + aggregateSig = hc.Consensus.AggregateSig } else { minPeers = defaultConsensusConfig.MinPeers + aggregateSig = defaultConsensusConfig.AggregateSig } currentConsensus.MinPeers = minPeers + currentConsensus.AggregateSig = aggregateSig blacklist, err := setupBlacklist(hc) if err != nil { diff --git a/consensus/consensus_service.go b/consensus/consensus_service.go index 9f889b03d..4cac709c7 100644 --- a/consensus/consensus_service.go +++ b/consensus/consensus_service.go @@ -313,10 +313,8 @@ func (consensus *Consensus) UpdateConsensusInformation() Mode { consensus.BlockPeriod = 5 * time.Second - // Enable aggregate sig at epoch 1000 for mainnet, at epoch 53000 for testnet, and always for other nets. - if (consensus.Blockchain.Config().ChainID == params.MainnetChainID && curEpoch.Cmp(big.NewInt(1000)) > 0) || - (consensus.Blockchain.Config().ChainID == params.TestnetChainID && curEpoch.Cmp(big.NewInt(54500)) > 0) || - (consensus.Blockchain.Config().ChainID != params.MainnetChainID && consensus.Blockchain.Config().ChainID != params.TestChainID) { + // Disable aggregate sig at epoch TBD for mainnet (for other net, it's default to true) + if consensus.Blockchain.Config().ChainID == params.MainnetChainID && curEpoch.Cmp(big.NewInt(1000)) >= 0 { consensus.AggregateSig = true }