Skip to content

Commit

Permalink
chore: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wnjoon committed Jan 13, 2025
1 parent 0308bbd commit 46dec5c
Showing 1 changed file with 54 additions and 28 deletions.
82 changes: 54 additions & 28 deletions test/e2e/configurer/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"log"
"os"
"path/filepath"
"sync"
"testing"
"time"

"github.com/cometbft/cometbft/crypto/ed25519"

govv1 "cosmossdk.io/api/cosmos/gov/v1"
sdkmath "cosmossdk.io/math"
upgradetypes "cosmossdk.io/x/upgrade/types"
Expand All @@ -18,13 +21,14 @@ import (

"github.com/babylonlabs-io/babylon/app"
appparams "github.com/babylonlabs-io/babylon/app/params"
"github.com/babylonlabs-io/babylon/crypto/bls12381"
"github.com/babylonlabs-io/babylon/privval"
"github.com/babylonlabs-io/babylon/test/e2e/configurer/chain"
"github.com/babylonlabs-io/babylon/test/e2e/configurer/config"
"github.com/babylonlabs-io/babylon/test/e2e/containers"
"github.com/babylonlabs-io/babylon/test/e2e/initialization"

cmtcfg "github.com/cometbft/cometbft/config"
cmtos "github.com/cometbft/cometbft/libs/os"
cmtprivval "github.com/cometbft/cometbft/privval"
)

Expand Down Expand Up @@ -254,43 +258,65 @@ func (uc *UpgradeConfigurer) runForkUpgrade() {
}
}

func saveFilesToVolume(node *chain.NodeConfig) error {
dir := node.ConfigDir

cmtCfg := cmtcfg.DefaultConfig()
cmtCfg.SetRoot(dir)

cmtKeyFile := cmtCfg.PrivValidatorKeyFile()
cmtStateFile := cmtCfg.PrivValidatorStateFile()

blsCfg := privval.DefaultBlsConfig()
blsCfg.SetRoot(dir)

blsKeyFile := blsCfg.BlsKeyFile()
blsPasswordFile := blsCfg.BlsPasswordFile()

if err := privval.IsValidFilePath(cmtKeyFile, cmtStateFile, blsKeyFile, blsPasswordFile); err != nil {
return err
}

var password string
if node.TempBlsInfo.Password == "" {
log.Print("node.TempBlsInfo.Password is empty")
password = "password"
} else {
password = node.TempBlsInfo.Password
}

var blsPrivKey bls12381.PrivateKey
if node.TempBlsInfo.PrivateKey == nil {
log.Print("node.TempBlsInfo.PrivateKey is empty")
blsPrivKey = bls12381.GenPrivKey()
} else {
blsPrivKey = node.TempBlsInfo.PrivateKey
}
blsPv := privval.NewBlsPV(blsPrivKey, blsKeyFile, blsPasswordFile, node.TempBlsInfo.DelegatorAddress)
blsPv.Key.Save(password, node.TempBlsInfo.DelegatorAddress)

var privKey ed25519.PrivKey
if node.PrivateKey == nil {
log.Print("node.PrivateKey is empty")
privKey = ed25519.GenPrivKey()
} else {
privKey = ed25519.PrivKey(node.PrivateKey)
}
cmtprivval.NewFilePV(privKey, cmtKeyFile, cmtStateFile).Save()
return nil
}

func (uc *UpgradeConfigurer) upgradeContainers(chainConfig *chain.Config, propHeight int64) error {
// upgrade containers to the locally compiled daemon
uc.t.Logf("starting upgrade for chain-id: %s...", chainConfig.Id)
uc.containerManager.CurrentRepository = containers.BabylonContainerName
uc.containerManager.CurrentTag = "latest"

for _, node := range chainConfig.NodeConfigs {
// node.BlsKey
// tempBlsInfo := node.TempBlsInfo

blsCfg := privval.DefaultBlsConfig()
keyFilePath := filepath.Join(node.ConfigDir, blsCfg.BlsKeyFile())
passwordFilePath := filepath.Join(node.ConfigDir, blsCfg.BlsPasswordFile())

if err := privval.IsValidFilePath(keyFilePath, passwordFilePath); err != nil {
if err := saveFilesToVolume(node); err != nil {
return err
}

// generate BLS key
if cmtos.FileExists(keyFilePath) {
privval.LoadBlsPV(keyFilePath, passwordFilePath)
} else {
privval.GenBlsPV(keyFilePath, passwordFilePath, "password", "")
}

cmtCfg := cmtcfg.DefaultConfig()
cmtKeyFile := filepath.Join(node.ConfigDir, cmtCfg.PrivValidatorKeyFile())
cmtStateFile := filepath.Join(node.ConfigDir, cmtCfg.PrivValidatorStateFile())

if cmtos.FileExists(cmtKeyFile) {
cmtprivval.LoadFilePV(cmtKeyFile, cmtStateFile)
} else {
pv := cmtprivval.GenFilePV(cmtKeyFile, cmtStateFile)
pv.Key.Save()
pv.LastSignState.Save()
}

if err := node.Run(); err != nil {
return err
}
Expand Down

0 comments on commit 46dec5c

Please sign in to comment.