Skip to content

Commit

Permalink
chore: print logs between upgradeContainers and RunNodeResource to ch…
Browse files Browse the repository at this point in the history
…eck mounted
  • Loading branch information
wnjoon committed Jan 14, 2025
1 parent 46dec5c commit 538e3ab
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 73 deletions.
128 changes: 74 additions & 54 deletions test/e2e/configurer/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"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 @@ -21,15 +19,13 @@ 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"
cmtprivval "github.com/cometbft/cometbft/privval"
cmtos "github.com/cometbft/cometbft/libs/os"
)

type UpgradeSettings struct {
Expand Down Expand Up @@ -258,53 +254,53 @@ 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 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
Expand All @@ -313,10 +309,34 @@ func (uc *UpgradeConfigurer) upgradeContainers(chainConfig *chain.Config, propHe
uc.containerManager.CurrentTag = "latest"

for _, node := range chainConfig.NodeConfigs {
if err := saveFilesToVolume(node); err != nil {
return err
// ======= TESTING START =======
log.Print("==> upgradeContainers()")
log.Print("=> node.ConfigDir: ", node.ConfigDir)

var keyIs, pwIs bool

log.Print("=> bls")
if cmtos.FileExists(node.ConsensusKey.BlsPVKey.GetKeyFilePath()) {
log.Print("=> file exists: node.ConsensusKey.BlsPVKey.GetKeyFilePath(): ", node.ConsensusKey.BlsPVKey.GetKeyFilePath())
keyIs = true
} else {
log.Print("=> file does not exist: node.ConsensusKey.BlsPVKey.GetKeyFilePath(): ", node.ConsensusKey.BlsPVKey.GetKeyFilePath())
keyIs = false
}

if cmtos.FileExists(node.ConsensusKey.BlsPVKey.GetPasswordFilePath()) {
log.Print("=> file exists: node.ConsensusKey.BlsPVKey.GetPasswordFilePath(): ", node.ConsensusKey.BlsPVKey.GetPasswordFilePath())
pwIs = true
} else {
log.Print("=> file does not exist: node.ConsensusKey.BlsPVKey.GetPasswordFilePath(): ", node.ConsensusKey.BlsPVKey.GetPasswordFilePath())
pwIs = false
}

if keyIs && pwIs {
pv := privval.LoadBlsPV(node.ConsensusKey.BlsPVKey.GetKeyFilePath(), node.ConsensusKey.BlsPVKey.GetPasswordFilePath())
log.Print("bls pv: ", pv)
}
// ======= TESTING END =======
if err := node.Run(); err != nil {
return err
}
Expand Down
25 changes: 25 additions & 0 deletions test/e2e/containers/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ import (
"context"
"errors"
"fmt"
"log"
"os"
"path/filepath"
"regexp"
"strings"
"testing"
"time"

"github.com/babylonlabs-io/babylon/crypto/erc2335"
"github.com/babylonlabs-io/babylon/privval"
cmtos "github.com/cometbft/cometbft/libs/os"
"github.com/ory/dockertest/v3"
"github.com/ory/dockertest/v3/docker"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -263,6 +268,26 @@ func (m *Manager) RunNodeResource(chainId string, containerName, valCondifDir st
return nil, err
}

// ======= TESTING START =======
log.Print("==> RunNodeResource()")
log.Print("=> valCondifDir: ", valCondifDir)

blsKeyFile := filepath.Join(valCondifDir, privval.DefaultBlsConfig().BlsKeyFile())
blsPasswordFile := filepath.Join(valCondifDir, privval.DefaultBlsConfig().BlsPasswordFile())
if cmtos.FileExists(blsKeyFile) {
log.Print("=> file exists: blsPasswordFile: ", blsPasswordFile)

passwd, err := erc2335.LoadPaswordFromFile(blsPasswordFile)
if err != nil {
log.Print("=> failed to load password: ", err.Error())
return nil, err
}
log.Print("=> loaded password: ", passwd)
} else {
log.Print("=> file not exists: blsPasswordFile: ", blsPasswordFile)
}
// ======= TESTING END =======

runOpts := &dockertest.RunOptions{
Name: containerName,
Repository: m.CurrentRepository,
Expand Down
4 changes: 3 additions & 1 deletion test/e2e/initialization/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package initialization

import (
"fmt"

"github.com/babylonlabs-io/babylon/privval"
)

type ChainMeta struct {
Expand All @@ -19,7 +21,7 @@ type Node struct {
PrivateKey []byte `json:"privateKey"`
PeerId string `json:"peerId"`
IsValidator bool `json:"isValidator"`
TempBlsInfo TempBlsInfo
ConsensusKey privval.WrappedFilePVKey
}

type Chain struct {
Expand Down
19 changes: 1 addition & 18 deletions test/e2e/initialization/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
appparams "github.com/babylonlabs-io/babylon/app/params"
"github.com/babylonlabs-io/babylon/cmd/babylond/cmd"
"github.com/babylonlabs-io/babylon/crypto/bls12381"
"github.com/babylonlabs-io/babylon/crypto/erc2335"
"github.com/babylonlabs-io/babylon/privval"
"github.com/babylonlabs-io/babylon/test/e2e/util"
cmtprivval "github.com/cometbft/cometbft/privval"
Expand Down Expand Up @@ -267,22 +266,6 @@ func (n *internalNode) export() *Node {
panic("pub key should be correct")
}

blsKey := n.consensusKey.BlsPVKey

tempBlsInfo := func(k privval.BlsPVKey) TempBlsInfo {
password, err := erc2335.LoadPaswordFromFile(k.GetPasswordFilePath())
if err != nil {
panic(err)
}
return TempBlsInfo{
PrivateKey: k.PrivKey,
Password: password,
KeyFilePath: k.GetKeyFilePath(),
PasswordFilePath: k.GetPasswordFilePath(),
DelegatorAddress: k.DelegatorAddress,
}
}(blsKey)

return &Node{
Name: n.moniker,
ConfigDir: n.configDir(),
Expand All @@ -293,7 +276,7 @@ func (n *internalNode) export() *Node {
PrivateKey: n.privateKey.Bytes(),
PeerId: n.peerId,
IsValidator: n.isValidator,
TempBlsInfo: tempBlsInfo,
ConsensusKey: n.consensusKey,
}
}

Expand Down

0 comments on commit 538e3ab

Please sign in to comment.