From 538e3ab77a9435b1ad78b3e6cec82a90ded92a39 Mon Sep 17 00:00:00 2001 From: wonjoon Date: Tue, 14 Jan 2025 15:25:30 +0900 Subject: [PATCH] chore: print logs between upgradeContainers and RunNodeResource to check mounted --- test/e2e/configurer/upgrade.go | 128 +++++++++++++++++------------- test/e2e/containers/containers.go | 25 ++++++ test/e2e/initialization/export.go | 4 +- test/e2e/initialization/node.go | 19 +---- 4 files changed, 103 insertions(+), 73 deletions(-) diff --git a/test/e2e/configurer/upgrade.go b/test/e2e/configurer/upgrade.go index 77eb3f16..18fd0306 100644 --- a/test/e2e/configurer/upgrade.go +++ b/test/e2e/configurer/upgrade.go @@ -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" @@ -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 { @@ -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 @@ -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 } diff --git a/test/e2e/containers/containers.go b/test/e2e/containers/containers.go index b6863d1e..403b6c1d 100644 --- a/test/e2e/containers/containers.go +++ b/test/e2e/containers/containers.go @@ -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" @@ -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, diff --git a/test/e2e/initialization/export.go b/test/e2e/initialization/export.go index 3b27aca5..e4ab0622 100644 --- a/test/e2e/initialization/export.go +++ b/test/e2e/initialization/export.go @@ -2,6 +2,8 @@ package initialization import ( "fmt" + + "github.com/babylonlabs-io/babylon/privval" ) type ChainMeta struct { @@ -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 { diff --git a/test/e2e/initialization/node.go b/test/e2e/initialization/node.go index 7a632430..3b3f9f8a 100644 --- a/test/e2e/initialization/node.go +++ b/test/e2e/initialization/node.go @@ -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" @@ -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(), @@ -293,7 +276,7 @@ func (n *internalNode) export() *Node { PrivateKey: n.privateKey.Bytes(), PeerId: n.peerId, IsValidator: n.isValidator, - TempBlsInfo: tempBlsInfo, + ConsensusKey: n.consensusKey, } }