From 1b03f063510bfa2f143cfe67558e1129b3fa2e26 Mon Sep 17 00:00:00 2001 From: Yawning Angel Date: Mon, 13 Apr 2020 15:31:40 +0000 Subject: [PATCH] go/consensus/genesis: Make max evidence age block and time based * Rename `max_evidence_age` -> `max_evidence_age_blocks` * Add `max_evidence_age_time` (default 48h) This is obviously breaking. --- .changelog/2834.breaking.2.md | 6 +++++ go/consensus/genesis/genesis.go | 9 ++++--- go/consensus/tendermint/tendermint.go | 4 +-- go/oasis-node/cmd/genesis/genesis.go | 35 +++++++++++++++------------ 4 files changed, 32 insertions(+), 22 deletions(-) create mode 100644 .changelog/2834.breaking.2.md diff --git a/.changelog/2834.breaking.2.md b/.changelog/2834.breaking.2.md new file mode 100644 index 00000000000..9f962f0a2df --- /dev/null +++ b/.changelog/2834.breaking.2.md @@ -0,0 +1,6 @@ +go/consensus/genesis: Make max evidence age block and time based + + * Rename `max_evidence_age` -> `max_evidence_age_blocks` + * Add `max_evidence_age_time` (default 48h) + +This is obviously breaking. diff --git a/go/consensus/genesis/genesis.go b/go/consensus/genesis/genesis.go index 0dc44b72f22..775afa82c02 100644 --- a/go/consensus/genesis/genesis.go +++ b/go/consensus/genesis/genesis.go @@ -20,10 +20,11 @@ type Parameters struct { SkipTimeoutCommit bool `json:"skip_timeout_commit"` EmptyBlockInterval time.Duration `json:"empty_block_interval"` - MaxTxSize uint64 `json:"max_tx_size"` - MaxBlockSize uint64 `json:"max_block_size"` - MaxBlockGas transaction.Gas `json:"max_block_gas"` - MaxEvidenceAge uint64 `json:"max_evidence_age"` + MaxTxSize uint64 `json:"max_tx_size"` + MaxBlockSize uint64 `json:"max_block_size"` + MaxBlockGas transaction.Gas `json:"max_block_gas"` + MaxEvidenceAgeBlocks uint64 `json:"max_evidence_age_blocks"` + MaxEvidenceAgeTime time.Duration `json:"max_evidence_age_time"` // GasCosts are the base transaction gas costs. GasCosts transaction.Costs `json:"gas_costs,omitempty"` diff --git a/go/consensus/tendermint/tendermint.go b/go/consensus/tendermint/tendermint.go index 6a3081d1dfb..be666161dfd 100644 --- a/go/consensus/tendermint/tendermint.go +++ b/go/consensus/tendermint/tendermint.go @@ -1073,8 +1073,8 @@ func genesisToTendermint(d *genesisAPI.Document) (*tmtypes.GenesisDoc, error) { TimeIotaMs: 1000, }, Evidence: tmtypes.EvidenceParams{ - MaxAgeNumBlocks: int64(d.Consensus.Parameters.MaxEvidenceAge), - MaxAgeDuration: 48 * time.Hour, // XXX: Change the tm default? + MaxAgeNumBlocks: int64(d.Consensus.Parameters.MaxEvidenceAgeBlocks), + MaxAgeDuration: d.Consensus.Parameters.MaxEvidenceAgeTime, }, Validator: tmtypes.ValidatorParams{ PubKeyTypes: []string{tmtypes.ABCIPubKeyTypeEd25519}, diff --git a/go/oasis-node/cmd/genesis/genesis.go b/go/oasis-node/cmd/genesis/genesis.go index ef968d24477..55badbd931d 100644 --- a/go/oasis-node/cmd/genesis/genesis.go +++ b/go/oasis-node/cmd/genesis/genesis.go @@ -79,14 +79,15 @@ const ( cfgRoothashDebugBypassStake = "roothash.debug.bypass_stake" // nolint: gosec // Tendermint config flags. - cfgConsensusTimeoutCommit = "consensus.tendermint.timeout_commit" - cfgConsensusSkipTimeoutCommit = "consensus.tendermint.skip_timeout_commit" - cfgConsensusEmptyBlockInterval = "consensus.tendermint.empty_block_interval" - cfgConsensusMaxTxSizeBytes = "consensus.tendermint.max_tx_size" - cfgConsensusMaxBlockSizeBytes = "consensus.tendermint.max_block_size" - cfgConsensusMaxBlockGas = "consensus.tendermint.max_block_gas" - cfgConsensusMaxEvidenceAge = "consensus.tendermint.max_evidence_age" - CfgConsensusGasCostsTxByte = "consensus.gas_costs.tx_byte" + cfgConsensusTimeoutCommit = "consensus.tendermint.timeout_commit" + cfgConsensusSkipTimeoutCommit = "consensus.tendermint.skip_timeout_commit" + cfgConsensusEmptyBlockInterval = "consensus.tendermint.empty_block_interval" + cfgConsensusMaxTxSizeBytes = "consensus.tendermint.max_tx_size" + cfgConsensusMaxBlockSizeBytes = "consensus.tendermint.max_block_size" + cfgConsensusMaxBlockGas = "consensus.tendermint.max_block_gas" + cfgConsensusMaxEvidenceAgeBlocks = "consensus.tendermint.max_evidence_age_blocks" + cfgConsensusMaxEvidenceAgeTime = "consensus.tendermint.max_evidence_age_time" + CfgConsensusGasCostsTxByte = "consensus.gas_costs.tx_byte" // Consensus backend config flag. cfgConsensusBackend = "consensus.backend" @@ -217,13 +218,14 @@ func doInitGenesis(cmd *cobra.Command, args []string) { doc.Consensus = consensusGenesis.Genesis{ Backend: viper.GetString(cfgConsensusBackend), Parameters: consensusGenesis.Parameters{ - TimeoutCommit: viper.GetDuration(cfgConsensusTimeoutCommit), - SkipTimeoutCommit: viper.GetBool(cfgConsensusSkipTimeoutCommit), - EmptyBlockInterval: viper.GetDuration(cfgConsensusEmptyBlockInterval), - MaxTxSize: uint64(viper.GetSizeInBytes(cfgConsensusMaxTxSizeBytes)), - MaxBlockSize: uint64(viper.GetSizeInBytes(cfgConsensusMaxBlockSizeBytes)), - MaxBlockGas: transaction.Gas(viper.GetUint64(cfgConsensusMaxBlockGas)), - MaxEvidenceAge: viper.GetUint64(cfgConsensusMaxEvidenceAge), + TimeoutCommit: viper.GetDuration(cfgConsensusTimeoutCommit), + SkipTimeoutCommit: viper.GetBool(cfgConsensusSkipTimeoutCommit), + EmptyBlockInterval: viper.GetDuration(cfgConsensusEmptyBlockInterval), + MaxTxSize: uint64(viper.GetSizeInBytes(cfgConsensusMaxTxSizeBytes)), + MaxBlockSize: uint64(viper.GetSizeInBytes(cfgConsensusMaxBlockSizeBytes)), + MaxBlockGas: transaction.Gas(viper.GetUint64(cfgConsensusMaxBlockGas)), + MaxEvidenceAgeBlocks: viper.GetUint64(cfgConsensusMaxEvidenceAgeBlocks), + MaxEvidenceAgeTime: viper.GetDuration(cfgConsensusMaxEvidenceAgeTime), GasCosts: transaction.Costs{ consensusGenesis.GasOpTxByte: transaction.Gas(viper.GetUint64(CfgConsensusGasCostsTxByte)), }, @@ -723,7 +725,8 @@ func init() { initGenesisFlags.String(cfgConsensusMaxTxSizeBytes, "32kb", "tendermint maximum transaction size (in bytes)") initGenesisFlags.String(cfgConsensusMaxBlockSizeBytes, "21mb", "tendermint maximum block size (in bytes)") initGenesisFlags.Uint64(cfgConsensusMaxBlockGas, 0, "tendermint max gas used per block") - initGenesisFlags.Uint64(cfgConsensusMaxEvidenceAge, 100000, "tendermint max evidence age (in blocks)") + initGenesisFlags.Uint64(cfgConsensusMaxEvidenceAgeBlocks, 100000, "tendermint max evidence age (in blocks)") + initGenesisFlags.Duration(cfgConsensusMaxEvidenceAgeTime, 48*time.Hour, "tendermint max evidence age (in time)") initGenesisFlags.Uint64(CfgConsensusGasCostsTxByte, 1, "consensus gas costs: each transaction byte") // Consensus backend flag.