From c6b93da05d4718f7af5db04e1eb4bdea1f5545e7 Mon Sep 17 00:00:00 2001 From: Lukasz Klimek <842586+lklimek@users.noreply.github.com> Date: Mon, 23 Sep 2024 17:02:07 +0200 Subject: [PATCH] test(e2e): consensus version updates --- abci/example/kvstore/config.go | 2 ++ test/e2e/app/app.go | 16 +++++++++++++++- test/e2e/networks/rotate.toml | 1 - test/e2e/pkg/testnet.go | 17 +++++++++-------- test/e2e/tests/validator_test.go | 29 +++++++++++++++++++---------- 5 files changed, 45 insertions(+), 20 deletions(-) diff --git a/abci/example/kvstore/config.go b/abci/example/kvstore/config.go index 4edebf81a1..c359c9e7a4 100644 --- a/abci/example/kvstore/config.go +++ b/abci/example/kvstore/config.go @@ -70,6 +70,8 @@ type Config struct { ChainLockUpdates map[string]string `toml:"chainlock_updates"` PrivValServerType string `toml:"privval_server_type"` InitAppInitialCoreHeight uint32 `toml:"init_app_core_chain_locked_height"` + // ConsenusVersionUpdates is a map of heights to consensus version ; ONLY SUPPORTED BY e2e.Application + ConsenusVersionUpdates map[string]int32 `toml:"consensus_version_updates"` } func DefaultConfig(dir string) Config { diff --git a/test/e2e/app/app.go b/test/e2e/app/app.go index 29121647f4..4043af9e52 100644 --- a/test/e2e/app/app.go +++ b/test/e2e/app/app.go @@ -62,6 +62,20 @@ func NewApplication(cfg kvstore.Config, opts ...kvstore.OptFunc) (*Application, return nil, err } + for h, ver := range cfg.ConsenusVersionUpdates { + height, err := strconv.Atoi(h) + if err != nil { + return nil, fmt.Errorf("consensus_version_updates: failed to parse height %s: %w", h, err) + } + params := types1.ConsensusParams{ + Version: &types1.VersionParams{ + ConsensusVersion: types1.VersionParams_ConsensusVersion(ver), + AppVersion: kvstore.ProtocolVersion, + }, + } + app.AddConsensusParamsUpdate(params, int64(height)) + } + return &app, nil } @@ -146,7 +160,7 @@ func (app *Application) VerifyVoteExtension(_ context.Context, req *abci.Request } if app.cfg.VoteExtensionDelayMS != 0 { - time.Sleep(time.Duration(app.cfg.VoteExtensionDelayMS) * time.Millisecond) + time.Sleep(time.Duration(app.cfg.VoteExtensionDelayMS) * time.Millisecond) //#nosec G115 } app.logger.Info("verified vote extension value", "req", req, "nums", nums) diff --git a/test/e2e/networks/rotate.toml b/test/e2e/networks/rotate.toml index d386beb898..84a6c2d150 100644 --- a/test/e2e/networks/rotate.toml +++ b/test/e2e/networks/rotate.toml @@ -96,7 +96,6 @@ validator08 = 100 validator10 = 100 validator11 = 100 - [consensus_version_updates] 1070 = 1 diff --git a/test/e2e/pkg/testnet.go b/test/e2e/pkg/testnet.go index 61ad677410..9fd67dba2a 100644 --- a/test/e2e/pkg/testnet.go +++ b/test/e2e/pkg/testnet.go @@ -429,13 +429,6 @@ func LoadTestnet(file string) (*Testnet, error) { testnet.ValidatorUpdates[int64(height)] = valUpdate testnet.ThresholdPublicKeyUpdates[int64(height)] = ld.ThresholdPubKey testnet.QuorumHashUpdates[int64(height)] = quorumHash - if cpUpdate, ok := manifest.ConsensusVersionUpdates[strconv.Itoa(height)]; ok { - h, err := strconv.Atoi(heightStr) - if err != nil { - return nil, fmt.Errorf("invalid consensus version update height %q: %w", height, err) - } - testnet.ConsensusVersionUpdates[int64(h)] = cpUpdate - } } chainLockSetHeights := make([]int, 0, len(manifest.ChainLockUpdates)) @@ -450,7 +443,7 @@ func LoadTestnet(file string) (*Testnet, error) { sort.Ints(chainLockSetHeights) - // Set up validator updates. + // Set up chainlock updates. for _, height := range chainLockSetHeights { heightStr := strconv.FormatInt(int64(height), 10) chainLockHeight := manifest.ChainLockUpdates[heightStr] @@ -458,6 +451,14 @@ func LoadTestnet(file string) (*Testnet, error) { fmt.Printf("Set chainlock at height %d / core height is %d\n", height, chainLockHeight) } + for heightStr, cpUpdate := range manifest.ConsensusVersionUpdates { + height, err := strconv.Atoi(heightStr) + if err != nil { + return nil, fmt.Errorf("invalid consensus version update height %q: %w", height, err) + } + testnet.ConsensusVersionUpdates[int64(height)] = cpUpdate + } + return testnet, testnet.Validate() } diff --git a/test/e2e/tests/validator_test.go b/test/e2e/tests/validator_test.go index b816440861..3bee02aeca 100644 --- a/test/e2e/tests/validator_test.go +++ b/test/e2e/tests/validator_test.go @@ -3,7 +3,6 @@ package e2e_test import ( "bytes" "context" - "fmt" "testing" "github.com/dashpay/dashd-go/btcjson" @@ -203,20 +202,30 @@ func newValidatorSchedule(testnet e2e.Testnet) *validatorSchedule { consensusVersionUpdates: testnet.ConsensusVersionUpdates, } } -func (s *validatorSchedule) consensusVersionUpdate() { - ver, ok := s.consensusVersionUpdates[s.height] - if !ok && s.height-1 > 0 { - ver = s.consensusVersions[s.height-1] + +func (s *validatorSchedule) consensusVersionUpdate() int32 { + var version int32 + ok := false + + // find last consensus params + for h := s.height; h > 0 && !ok; h-- { + if version, ok = s.consensusVersions[h]; !ok { + var updatedVersion int32 + if updatedVersion, ok = s.consensusVersionUpdates[h]; ok { + version = updatedVersion + s.consensusVersions[h] = version + } + } } - s.consensusVersions[s.height] = ver + // save it + s.consensusVersions[s.height] = version + + return version } func (s *validatorSchedule) ConsensusParams() types.ConsensusParams { - ver, ok := s.consensusVersions[s.height] - if !ok { - panic(fmt.Errorf("consensus version not set for height %d", s.height)) - } + ver := s.consensusVersionUpdate() cp := *types.DefaultConsensusParams() cp.Version.ConsensusVersion = ver