Skip to content

Commit

Permalink
Manual backport of #2066 to v0.38.x (#2067)
Browse files Browse the repository at this point in the history
Backport of #2066, addressing #2065 on branch `v0.38.x`

The reason for the back to be manual is the many conflicts (which have
already been solved).

---

#### PR checklist

- [ ] Tests written/updated
- [ ] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments

---------

Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
  • Loading branch information
sergio-mena and melekes authored Jan 22, 2024
1 parent 3c2034f commit 68ada7c
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- `[e2e]` Add manifest option `VoteExtensionsUpdateHeight` to test
vote extension activation via `InitChain` and `FinalizeBlock`.
Also, extend the manifest generator to produce different values
of this new option
([\#2065](https://github.com/cometbft/cometbft/pull/2065))
43 changes: 39 additions & 4 deletions test/e2e/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ type Config struct {
CheckTxDelay time.Duration `toml:"check_tx_delay"`
FinalizeBlockDelay time.Duration `toml:"finalize_block_delay"`
VoteExtensionDelay time.Duration `toml:"vote_extension_delay"`

// VoteExtensionsEnableHeight configures the first height during which
// the chain will use and require vote extension data to be present
// in precommit messages.
VoteExtensionsEnableHeight int64 `toml:"vote_extensions_enable_height"`

// VoteExtensionsUpdateHeight configures the height at which consensus
// param VoteExtensionsEnableHeight will be set.
// -1 denotes it is set at genesis.
// 0 denotes it is set at InitChain.
VoteExtensionsUpdateHeight int64 `toml:"vote_extensions_update_height"`
}

func DefaultConfig(dir string) *Config {
Expand Down Expand Up @@ -136,6 +147,23 @@ func (app *Application) Info(context.Context, *abci.RequestInfo) (*abci.Response
}, nil
}

func (app *Application) updateVoteExtensionEnableHeight(currentHeight int64) *cmtproto.ConsensusParams {
var params *cmtproto.ConsensusParams
if app.cfg.VoteExtensionsUpdateHeight == currentHeight {
app.logger.Info("enabling vote extensions on the fly",
"current_height", currentHeight,
"enable_height", app.cfg.VoteExtensionsEnableHeight)
params = &cmtproto.ConsensusParams{
Abci: &cmtproto.ABCIParams{
VoteExtensionsEnableHeight: app.cfg.VoteExtensionsEnableHeight,
},
}
app.logger.Info("updating VoteExtensionsHeight in app_state", "height", app.cfg.VoteExtensionsEnableHeight)
app.state.Set(prefixReservedKey+suffixVoteExtHeight, strconv.FormatInt(app.cfg.VoteExtensionsEnableHeight, 10))
}
return params
}

// Info implements ABCI.
func (app *Application) InitChain(_ context.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error) {
var err error
Expand All @@ -161,8 +189,12 @@ func (app *Application) InitChain(_ context.Context, req *abci.RequestInitChain)
}
}
}

params := app.updateVoteExtensionEnableHeight(0)

resp := &abci.ResponseInitChain{
AppHash: app.state.GetHash(),
ConsensusParams: params,
AppHash: app.state.GetHash(),
}
if resp.Validators, err = app.validatorUpdates(0); err != nil {
return nil, err
Expand Down Expand Up @@ -219,14 +251,17 @@ func (app *Application) FinalizeBlock(_ context.Context, req *abci.RequestFinali
panic(err)
}

params := app.updateVoteExtensionEnableHeight(req.Height)

if app.cfg.FinalizeBlockDelay != 0 {
time.Sleep(app.cfg.FinalizeBlockDelay)
}

return &abci.ResponseFinalizeBlock{
TxResults: txs,
ValidatorUpdates: valUpdates,
AppHash: app.state.Finalize(),
TxResults: txs,
ValidatorUpdates: valUpdates,
AppHash: app.state.Finalize(),
ConsensusParamUpdates: params,
Events: []abci.Event{
{
Type: "val_updates",
Expand Down
13 changes: 9 additions & 4 deletions test/e2e/generator/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ var (
lightNodePerturbations = probSetChoice{
"upgrade": 0.3,
}
voteExtensionEnableHeightOffset = uniformChoice{int64(0), int64(10), int64(100)}
voteExtensionEnabled = uniformChoice{true, false}
voteExtensionUpdateHeight = uniformChoice{int64(-1), int64(0), int64(1)} // -1: genesis, 0: InitChain, 1: (use offset)
voteExtensionEnabled = weightedChoice{true: 3, false: 1}
voteExtensionHeightOffset = uniformChoice{int64(0), int64(10), int64(100)}
)

type generateConfig struct {
Expand Down Expand Up @@ -147,9 +148,13 @@ func generateTestnet(r *rand.Rand, opt map[string]interface{}, upgradeVersion st
manifest.VoteExtensionDelay = 100 * time.Millisecond
manifest.FinalizeBlockDelay = 500 * time.Millisecond
}

manifest.VoteExtensionsUpdateHeight = voteExtensionUpdateHeight.Choose(r).(int64)
if manifest.VoteExtensionsUpdateHeight == 1 {
manifest.VoteExtensionsUpdateHeight = manifest.InitialHeight + voteExtensionHeightOffset.Choose(r).(int64)
}
if voteExtensionEnabled.Choose(r).(bool) {
manifest.VoteExtensionsEnableHeight = manifest.InitialHeight + voteExtensionEnableHeightOffset.Choose(r).(int64)
baseHeight := max(manifest.VoteExtensionsUpdateHeight+1, manifest.InitialHeight)
manifest.VoteExtensionsEnableHeight = baseHeight + voteExtensionHeightOffset.Choose(r).(int64)
}

var numSeeds, numValidators, numFulls, numLightClients int
Expand Down
1 change: 1 addition & 0 deletions test/e2e/networks/ci.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

ipv6 = true
initial_height = 1000
vote_extensions_update_height = 1004
vote_extensions_enable_height = 1007
evidence = 5
initial_state = { initial01 = "a", initial02 = "b", initial03 = "c" }
Expand Down
42 changes: 23 additions & 19 deletions test/e2e/node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,34 @@ import (

// Config is the application configuration.
type Config struct {
ChainID string `toml:"chain_id"`
Listen string `toml:"listen"`
Protocol string `toml:"protocol"`
Dir string `toml:"dir"`
Mode string `toml:"mode"`
PersistInterval uint64 `toml:"persist_interval"`
SnapshotInterval uint64 `toml:"snapshot_interval"`
RetainBlocks uint64 `toml:"retain_blocks"`
ValidatorUpdates map[string]map[string]uint8 `toml:"validator_update"`
PrivValServer string `toml:"privval_server"`
PrivValKey string `toml:"privval_key"`
PrivValState string `toml:"privval_state"`
KeyType string `toml:"key_type"`
ChainID string `toml:"chain_id"`
Listen string `toml:"listen"`
Protocol string `toml:"protocol"`
Dir string `toml:"dir"`
Mode string `toml:"mode"`
PersistInterval uint64 `toml:"persist_interval"`
SnapshotInterval uint64 `toml:"snapshot_interval"`
RetainBlocks uint64 `toml:"retain_blocks"`
ValidatorUpdates map[string]map[string]uint8 `toml:"validator_update"`
PrivValServer string `toml:"privval_server"`
PrivValKey string `toml:"privval_key"`
PrivValState string `toml:"privval_state"`
KeyType string `toml:"key_type"`
VoteExtensionsEnableHeight int64 `toml:"vote_extensions_enable_height"`
VoteExtensionsUpdateHeight int64 `toml:"vote_extensions_update_height"`
}

// App extracts out the application specific configuration parameters
func (cfg *Config) App() *app.Config {
return &app.Config{
Dir: cfg.Dir,
SnapshotInterval: cfg.SnapshotInterval,
RetainBlocks: cfg.RetainBlocks,
KeyType: cfg.KeyType,
ValidatorUpdates: cfg.ValidatorUpdates,
PersistInterval: cfg.PersistInterval,
Dir: cfg.Dir,
SnapshotInterval: cfg.SnapshotInterval,
RetainBlocks: cfg.RetainBlocks,
KeyType: cfg.KeyType,
ValidatorUpdates: cfg.ValidatorUpdates,
PersistInterval: cfg.PersistInterval,
VoteExtensionsEnableHeight: cfg.VoteExtensionsEnableHeight,
VoteExtensionsUpdateHeight: cfg.VoteExtensionsUpdateHeight,
}
}

Expand Down
15 changes: 10 additions & 5 deletions test/e2e/pkg/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ type Manifest struct {
// testnet via the RPC endpoint of a random node. Default is 0
Evidence int `toml:"evidence"`

// VoteExtensionsEnableHeight configures the first height during which
// the chain will use and require vote extension data to be present
// in precommit messages.
VoteExtensionsEnableHeight int64 `toml:"vote_extensions_enable_height"`

// ABCIProtocol specifies the protocol used to communicate with the ABCI
// application: "unix", "tcp", "grpc", "builtin" or "builtin_connsync".
//
Expand Down Expand Up @@ -93,6 +88,16 @@ type Manifest struct {
// Defaults to false (disabled).
Prometheus bool `toml:"prometheus"`

// VoteExtensionsEnableHeight configures the first height during which
// the chain will use and require vote extension data to be present
// in precommit messages.
VoteExtensionsEnableHeight int64 `toml:"vote_extensions_enable_height"`

// VoteExtensionsUpdateHeight configures the height at which consensus
// param VoteExtensionsEnableHeight will be set.
// -1 denotes it is set at genesis.
// 0 denotes it is set at InitChain.
VoteExtensionsUpdateHeight int64 `toml:"vote_extensions_update_height"`
// Maximum number of peers to which the node gossips transactions
ExperimentalMaxGossipConnectionsToPersistentPeers uint `toml:"experimental_max_gossip_connections_to_persistent_peers"`
ExperimentalMaxGossipConnectionsToNonPersistentPeers uint `toml:"experimental_max_gossip_connections_to_non_persistent_peers"`
Expand Down
33 changes: 33 additions & 0 deletions test/e2e/pkg/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type Testnet struct {
UpgradeVersion string
Prometheus bool
VoteExtensionsEnableHeight int64
VoteExtensionsUpdateHeight int64
ExperimentalMaxGossipConnectionsToPersistentPeers uint
ExperimentalMaxGossipConnectionsToNonPersistentPeers uint
}
Expand Down Expand Up @@ -167,6 +168,7 @@ func NewTestnetFromManifest(manifest Manifest, file string, ifd InfrastructureDa
UpgradeVersion: manifest.UpgradeVersion,
Prometheus: manifest.Prometheus,
VoteExtensionsEnableHeight: manifest.VoteExtensionsEnableHeight,
VoteExtensionsUpdateHeight: manifest.VoteExtensionsUpdateHeight,
ExperimentalMaxGossipConnectionsToPersistentPeers: manifest.ExperimentalMaxGossipConnectionsToPersistentPeers,
ExperimentalMaxGossipConnectionsToNonPersistentPeers: manifest.ExperimentalMaxGossipConnectionsToNonPersistentPeers,
}
Expand Down Expand Up @@ -341,6 +343,37 @@ func (t Testnet) Validate() error {
if len(t.Nodes) == 0 {
return errors.New("network has no nodes")
}
if t.VoteExtensionsUpdateHeight < -1 {
return fmt.Errorf("value of VoteExtensionsUpdateHeight must be positive, 0 (InitChain), "+
"or -1 (Genesis); update height %d", t.VoteExtensionsUpdateHeight)
}
if t.VoteExtensionsEnableHeight < 0 {
return fmt.Errorf("value of VoteExtensionsEnableHeight must be positive, or 0 (disable); "+
"enable height %d", t.VoteExtensionsEnableHeight)
}
if t.VoteExtensionsUpdateHeight > 0 && t.VoteExtensionsUpdateHeight < t.InitialHeight {
return fmt.Errorf("a value of VoteExtensionsUpdateHeight greater than 0 "+
"must not be less than InitialHeight; "+
"update height %d, initial height %d",
t.VoteExtensionsUpdateHeight, t.InitialHeight,
)
}
if t.VoteExtensionsEnableHeight > 0 {
if t.VoteExtensionsEnableHeight < t.InitialHeight {
return fmt.Errorf("a value of VoteExtensionsEnableHeight greater than 0 "+
"must not be less than InitialHeight; "+
"enable height %d, initial height %d",
t.VoteExtensionsEnableHeight, t.InitialHeight,
)
}
if t.VoteExtensionsEnableHeight <= t.VoteExtensionsUpdateHeight {
return fmt.Errorf("a value of VoteExtensionsEnableHeight greater than 0 "+
"must be greater than VoteExtensionsUpdateHeight; "+
"update height %d, enable height %d",
t.VoteExtensionsUpdateHeight, t.VoteExtensionsEnableHeight,
)
}
}
for _, node := range t.Nodes {
if err := node.Validate(t); err != nil {
return fmt.Errorf("invalid node %q: %w", node.Name, err)
Expand Down
34 changes: 19 additions & 15 deletions test/e2e/runner/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ func MakeGenesis(testnet *e2e.Testnet) (types.GenesisDoc, error) {
genesis.ConsensusParams.Version.App = 1
genesis.ConsensusParams.Evidence.MaxAgeNumBlocks = e2e.EvidenceAgeHeight
genesis.ConsensusParams.Evidence.MaxAgeDuration = e2e.EvidenceAgeTime
genesis.ConsensusParams.ABCI.VoteExtensionsEnableHeight = testnet.VoteExtensionsEnableHeight
if testnet.VoteExtensionsUpdateHeight == -1 {
genesis.ConsensusParams.ABCI.VoteExtensionsEnableHeight = testnet.VoteExtensionsEnableHeight
}
for validator, power := range testnet.Validators {
genesis.Validators = append(genesis.Validators, types.GenesisValidator{
Name: validator.Name,
Expand Down Expand Up @@ -260,20 +262,22 @@ func MakeConfig(node *e2e.Node) (*config.Config, error) {
// MakeAppConfig generates an ABCI application config for a node.
func MakeAppConfig(node *e2e.Node) ([]byte, error) {
cfg := map[string]interface{}{
"chain_id": node.Testnet.Name,
"dir": "data/app",
"listen": AppAddressUNIX,
"mode": node.Mode,
"protocol": "socket",
"persist_interval": node.PersistInterval,
"snapshot_interval": node.SnapshotInterval,
"retain_blocks": node.RetainBlocks,
"key_type": node.PrivvalKey.Type(),
"prepare_proposal_delay": node.Testnet.PrepareProposalDelay,
"process_proposal_delay": node.Testnet.ProcessProposalDelay,
"check_tx_delay": node.Testnet.CheckTxDelay,
"vote_extension_delay": node.Testnet.VoteExtensionDelay,
"finalize_block_delay": node.Testnet.FinalizeBlockDelay,
"chain_id": node.Testnet.Name,
"dir": "data/app",
"listen": AppAddressUNIX,
"mode": node.Mode,
"protocol": "socket",
"persist_interval": node.PersistInterval,
"snapshot_interval": node.SnapshotInterval,
"retain_blocks": node.RetainBlocks,
"key_type": node.PrivvalKey.Type(),
"prepare_proposal_delay": node.Testnet.PrepareProposalDelay,
"process_proposal_delay": node.Testnet.ProcessProposalDelay,
"check_tx_delay": node.Testnet.CheckTxDelay,
"vote_extension_delay": node.Testnet.VoteExtensionDelay,
"finalize_block_delay": node.Testnet.FinalizeBlockDelay,
"vote_extensions_enable_height": node.Testnet.VoteExtensionsEnableHeight,
"vote_extensions_update_height": node.Testnet.VoteExtensionsUpdateHeight,
}
switch node.ABCIProtocol {
case e2e.ProtocolUNIX:
Expand Down

0 comments on commit 68ada7c

Please sign in to comment.