add aggregateSig flag (#3438)

* add aggregateSig flag

* add flag to valid

* revert import change

* enable agg sig at epoch 233 for shard 3 in mainnet

* fix consensus nil

* revert agg sig epoch logic

* fix test
pull/3440/head
Rongjian Lan 4 years ago committed by GitHub
parent 94ecc99e7b
commit bae5be68da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      cmd/harmony/config.go
  2. 1
      cmd/harmony/default.go
  3. 12
      cmd/harmony/flags.go
  4. 8
      cmd/harmony/flags_test.go
  5. 4
      cmd/harmony/main.go
  6. 6
      consensus/consensus_service.go

@ -61,6 +61,7 @@ type generalConfig struct {
type consensusConfig struct { type consensusConfig struct {
MinPeers int MinPeers int
AggregateSig bool
} }
type blsConfig struct { type blsConfig struct {

@ -90,6 +90,7 @@ var defaultLogContext = logContext{
var defaultConsensusConfig = consensusConfig{ var defaultConsensusConfig = consensusConfig{
MinPeers: 6, MinPeers: 6,
AggregateSig: true,
} }
const ( const (

@ -92,6 +92,7 @@ var (
// consensusValidFlags are flags that are effective // consensusValidFlags are flags that are effective
consensusValidFlags = []cli.Flag{ consensusValidFlags = []cli.Flag{
consensusMinPeersFlag, consensusMinPeersFlag,
consensusAggregateSigFlag,
legacyConsensusMinPeersFlag, legacyConsensusMinPeersFlag,
} }
@ -746,6 +747,11 @@ var (
DefValue: defaultConsensusConfig.MinPeers, DefValue: defaultConsensusConfig.MinPeers,
Hidden: true, Hidden: true,
} }
consensusAggregateSigFlag = cli.BoolFlag{
Name: "consensus.aggregate-sig",
Usage: "(multi-key) aggregate bls signatures before sending",
DefValue: defaultConsensusConfig.AggregateSig,
}
legacyDelayCommitFlag = cli.StringFlag{ legacyDelayCommitFlag = cli.StringFlag{
Name: "delay_commit", Name: "delay_commit",
Usage: "how long to delay sending commit messages in consensus, ex: 500ms, 1s", 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) { func applyConsensusFlags(cmd *cobra.Command, config *harmonyConfig) {
if cli.HasFlagsChanged(cmd, consensusValidFlags) { if config.Consensus == nil && cli.HasFlagsChanged(cmd, consensusValidFlags) {
cfg := getDefaultConsensusConfigCopy() cfg := getDefaultConsensusConfigCopy()
config.Consensus = &cfg config.Consensus = &cfg
} }
@ -776,6 +782,10 @@ func applyConsensusFlags(cmd *cobra.Command, config *harmonyConfig) {
} else if cli.IsFlagChanged(cmd, legacyConsensusMinPeersFlag) { } else if cli.IsFlagChanged(cmd, legacyConsensusMinPeersFlag) {
config.Consensus.MinPeers = cli.GetIntFlagValue(cmd, legacyConsensusMinPeersFlag) config.Consensus.MinPeers = cli.GetIntFlagValue(cmd, legacyConsensusMinPeersFlag)
} }
if cli.IsFlagChanged(cmd, consensusAggregateSigFlag) {
config.Consensus.AggregateSig = cli.GetBoolFlagValue(cmd, consensusAggregateSigFlag)
}
} }
// transaction pool flags // transaction pool flags

@ -68,6 +68,7 @@ func TestHarmonyFlags(t *testing.T) {
}, },
Consensus: &consensusConfig{ Consensus: &consensusConfig{
MinPeers: 6, MinPeers: 6,
AggregateSig: true,
}, },
BLSKeys: blsConfig{ BLSKeys: blsConfig{
KeyDir: "./.hmy/blskeys", KeyDir: "./.hmy/blskeys",
@ -600,15 +601,18 @@ func TestConsensusFlags(t *testing.T) {
expConfig: nil, expConfig: nil,
}, },
{ {
args: []string{"--consensus.min-peers", "10"}, args: []string{"--consensus.min-peers", "10", "--consensus.aggregate-sig=false"},
expConfig: &consensusConfig{ 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{ expConfig: &consensusConfig{
MinPeers: 10, MinPeers: 10,
AggregateSig: true,
}, },
}, },
} }

@ -575,12 +575,16 @@ func setupConsensusAndNode(hc harmonyConfig, nodeConfig *nodeconfig.ConfigType)
// Parse minPeers from harmonyConfig // Parse minPeers from harmonyConfig
var minPeers int var minPeers int
var aggregateSig bool
if hc.Consensus != nil { if hc.Consensus != nil {
minPeers = hc.Consensus.MinPeers minPeers = hc.Consensus.MinPeers
aggregateSig = hc.Consensus.AggregateSig
} else { } else {
minPeers = defaultConsensusConfig.MinPeers minPeers = defaultConsensusConfig.MinPeers
aggregateSig = defaultConsensusConfig.AggregateSig
} }
currentConsensus.MinPeers = minPeers currentConsensus.MinPeers = minPeers
currentConsensus.AggregateSig = aggregateSig
blacklist, err := setupBlacklist(hc) blacklist, err := setupBlacklist(hc)
if err != nil { if err != nil {

@ -313,10 +313,8 @@ func (consensus *Consensus) UpdateConsensusInformation() Mode {
consensus.BlockPeriod = 5 * time.Second consensus.BlockPeriod = 5 * time.Second
// Enable aggregate sig at epoch 1000 for mainnet, at epoch 53000 for testnet, and always for other nets. // 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) || 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) {
consensus.AggregateSig = true consensus.AggregateSig = true
} }

Loading…
Cancel
Save