Skip to content

Commit

Permalink
test(e2e): consensus version updates
Browse files Browse the repository at this point in the history
  • Loading branch information
lklimek committed Sep 23, 2024
1 parent 8101f7f commit c6b93da
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 20 deletions.
2 changes: 2 additions & 0 deletions abci/example/kvstore/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 15 additions & 1 deletion test/e2e/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion test/e2e/networks/rotate.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ validator08 = 100
validator10 = 100
validator11 = 100


[consensus_version_updates]

1070 = 1
Expand Down
17 changes: 9 additions & 8 deletions test/e2e/pkg/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -450,14 +443,22 @@ 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]
testnet.ChainLockUpdates[int64(height)] = chainLockHeight
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()
}

Expand Down
29 changes: 19 additions & 10 deletions test/e2e/tests/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package e2e_test
import (
"bytes"
"context"
"fmt"
"testing"

"github.com/dashpay/dashd-go/btcjson"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c6b93da

Please sign in to comment.