From 6b44d223cfe752f940352bc28baf27c0c39ef514 Mon Sep 17 00:00:00 2001 From: wonjoon Date: Mon, 13 Jan 2025 13:39:44 +0900 Subject: [PATCH 01/15] feat: add bls-password option in create-bls-key --- cmd/babylond/cmd/create_bls_key.go | 18 ++++++++++++------ testutil/datagen/btc_blockchain.go | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/cmd/babylond/cmd/create_bls_key.go b/cmd/babylond/cmd/create_bls_key.go index 6a6b62ea..c6da4dc9 100644 --- a/cmd/babylond/cmd/create_bls_key.go +++ b/cmd/babylond/cmd/create_bls_key.go @@ -14,6 +14,10 @@ import ( "github.com/babylonlabs-io/babylon/privval" ) +const ( + FlagPassword = "bls-password" +) + func CreateBlsKeyCmd() *cobra.Command { bech32PrefixAccAddr := appparams.Bech32PrefixAccAddr @@ -43,23 +47,25 @@ $ babylond create-bls-key %s1f5tnl46mk4dfp4nx3n2vnrvyw2h2ydz6ykhk3r --home ./ return err } - return CreateBlsKey(homeDir, addr) + var password string + password, _ = cmd.Flags().GetString(FlagPassword) + if password == "" { + password = privval.GetBlsPassword() + } + return CreateBlsKey(homeDir, password, addr) }, } cmd.Flags().String(flags.FlagHome, app.DefaultNodeHome, "The node home directory") - + cmd.Flags().String(FlagPassword, "", "The password for the BLS key. If a flag is set, the non-empty password should be provided. If a flag is not set, the password will be read from the prompt.") return cmd } -func CreateBlsKey(home string, addr sdk.AccAddress) error { - +func CreateBlsKey(home, password string, addr sdk.AccAddress) error { blsCfg := privval.DefaultBlsConfig() keyPath := filepath.Join(home, blsCfg.BlsKeyFile()) passwordPath := filepath.Join(home, blsCfg.BlsPasswordFile()) - password := privval.GetBlsPassword() - privval.GenBlsPV(keyPath, passwordPath, password, addr.String()) return nil } diff --git a/testutil/datagen/btc_blockchain.go b/testutil/datagen/btc_blockchain.go index d963e50e..da0a207d 100644 --- a/testutil/datagen/btc_blockchain.go +++ b/testutil/datagen/btc_blockchain.go @@ -104,7 +104,7 @@ func GenRandomBtcdBlockWithTransactions( var proofs []*btcctypes.BTCSpvProof - for i, _ := range msgTxs { + for i := range msgTxs { headerBytes := bbn.NewBTCHeaderBytesFromBlockHeader(header) proof, err := btcctypes.SpvProofFromHeaderAndTransactions(&headerBytes, txBytes, uint(i)) if err != nil { From 83477287c5c5cb8b076d76f0bc7ff1608f5000a9 Mon Sep 17 00:00:00 2001 From: wonjoon Date: Mon, 13 Jan 2025 15:12:41 +0900 Subject: [PATCH 02/15] chore: remove defer in SetupTestPrivSigner for error resolve --- testutil/signer/private.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/testutil/signer/private.go b/testutil/signer/private.go index 8d1d4538..58ad5f79 100644 --- a/testutil/signer/private.go +++ b/testutil/signer/private.go @@ -21,9 +21,9 @@ func SetupTestPrivSigner() (*signer.PrivSigner, error) { if err != nil { return nil, err } - defer func() { - _ = os.RemoveAll(nodeDir) - }() + // defer func() { + // _ = os.RemoveAll(nodeDir) + // }() // generate a privSigner if err := GeneratePrivSigner(nodeDir); err != nil { From 5ce268ef266c626e16b415efd1dafa246d67bd02 Mon Sep 17 00:00:00 2001 From: wonjoon Date: Mon, 13 Jan 2025 15:30:19 +0900 Subject: [PATCH 03/15] chore: change testnet way --- testutil/datagen/init_val.go | 8 +++++--- testutil/signer/private.go | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/testutil/datagen/init_val.go b/testutil/datagen/init_val.go index 10ee141c..704df0fb 100644 --- a/testutil/datagen/init_val.go +++ b/testutil/datagen/init_val.go @@ -2,6 +2,7 @@ package datagen import ( "fmt" + "path/filepath" cfg "github.com/cometbft/cometbft/config" "github.com/cometbft/cometbft/crypto/ed25519" @@ -40,10 +41,11 @@ func InitializeNodeValidatorFilesFromMnemonic(config *cfg.Config, mnemonic strin // bls config blsCfg := privval.DefaultBlsConfig() - blsCfg.SetRoot(config.RootDir) + // blsCfg.SetRoot(config.RootDir) + + blsKeyFile := filepath.Join(config.RootDir, blsCfg.BlsKeyFile()) + blsPasswordFile := filepath.Join(config.RootDir, blsCfg.BlsPasswordFile()) - blsKeyFile := blsCfg.BlsKeyFile() - blsPasswordFile := blsCfg.BlsPasswordFile() if err := privval.IsValidFilePath(blsKeyFile, blsPasswordFile); err != nil { return "", nil, err } diff --git a/testutil/signer/private.go b/testutil/signer/private.go index 58ad5f79..8d1d4538 100644 --- a/testutil/signer/private.go +++ b/testutil/signer/private.go @@ -21,9 +21,9 @@ func SetupTestPrivSigner() (*signer.PrivSigner, error) { if err != nil { return nil, err } - // defer func() { - // _ = os.RemoveAll(nodeDir) - // }() + defer func() { + _ = os.RemoveAll(nodeDir) + }() // generate a privSigner if err := GeneratePrivSigner(nodeDir); err != nil { From 9b9261c01667bbde5ffe13632454308b89b4fc0c Mon Sep 17 00:00:00 2001 From: wonjoon Date: Mon, 13 Jan 2025 19:50:15 +0900 Subject: [PATCH 04/15] chore: update to resolve e2e test error --- privval/bls.go | 8 +++++++ test/e2e/configurer/upgrade.go | 6 +++++ test/e2e/initialization/export.go | 1 + test/e2e/initialization/node.go | 27 ++++++++++++++++++++++ testutil/signer/private_test.go | 37 +++++++++++++++++++++++++++++++ 5 files changed, 79 insertions(+) create mode 100644 testutil/signer/private_test.go diff --git a/privval/bls.go b/privval/bls.go index e990db8e..16753582 100644 --- a/privval/bls.go +++ b/privval/bls.go @@ -131,6 +131,14 @@ func (k *BlsPVKey) Save(password, addr string) { } } +func (k *BlsPVKey) GetKeyFilePath() string { + return k.filePath +} + +func (k *BlsPVKey) GetPasswordFilePath() string { + return k.passwordPath +} + // ------------------------------------------------------------------------------- // ---------------------------- BLS Config --------------------------------------- // ------------------------------------------------------------------------------- diff --git a/test/e2e/configurer/upgrade.go b/test/e2e/configurer/upgrade.go index 123a3924..c724625a 100644 --- a/test/e2e/configurer/upgrade.go +++ b/test/e2e/configurer/upgrade.go @@ -18,6 +18,7 @@ import ( "github.com/babylonlabs-io/babylon/app" appparams "github.com/babylonlabs-io/babylon/app/params" + "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" @@ -257,6 +258,11 @@ func (uc *UpgradeConfigurer) upgradeContainers(chainConfig *chain.Config, propHe uc.containerManager.CurrentTag = "latest" for _, node := range chainConfig.NodeConfigs { + // node.BlsKey + tempBlsInfo := node.TempBlsInfo + + // generate BLS key + privval.GenBlsPV(tempBlsInfo.KeyFilePath, tempBlsInfo.PasswordFilePath, tempBlsInfo.Password, tempBlsInfo.DelegatorAddress) if err := node.Run(); err != nil { return err } diff --git a/test/e2e/initialization/export.go b/test/e2e/initialization/export.go index 6c741a4c..75273914 100644 --- a/test/e2e/initialization/export.go +++ b/test/e2e/initialization/export.go @@ -19,6 +19,7 @@ type Node struct { PrivateKey []byte `json:"privateKey"` PeerId string `json:"peerId"` IsValidator bool `json:"isValidator"` + TempBlsInfo *TempBlsInfo } type Chain struct { diff --git a/test/e2e/initialization/node.go b/test/e2e/initialization/node.go index d148c0d0..98785300 100644 --- a/test/e2e/initialization/node.go +++ b/test/e2e/initialization/node.go @@ -34,6 +34,8 @@ import ( babylonApp "github.com/babylonlabs-io/babylon/app" 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" @@ -51,6 +53,14 @@ type internalNode struct { isValidator bool } +type TempBlsInfo struct { + PrivateKey bls12381.PrivateKey + Password string + DelegatorAddress string + KeyFilePath string + PasswordFilePath string +} + func newNode(chain *internalChain, nodeConfig *NodeConfig) (*internalNode, error) { node := &internalNode{ chain: chain, @@ -257,6 +267,22 @@ func (n *internalNode) export() *Node { panic("pub key should be correct") } + blsKey := n.consensusKey.BlsPVKey + + tempBlsInfo := func(blsPvKey privval.BlsPVKey) TempBlsInfo { + password, err := erc2335.LoadPaswordFromFile(blsKey.GetPasswordFilePath()) + if err != nil { + panic(err) + } + return TempBlsInfo{ + PrivateKey: blsPvKey.PrivKey, + Password: password, + KeyFilePath: blsKey.GetKeyFilePath(), + PasswordFilePath: blsKey.GetPasswordFilePath(), + DelegatorAddress: blsPvKey.DelegatorAddress, + } + }(blsKey) + return &Node{ Name: n.moniker, ConfigDir: n.configDir(), @@ -267,6 +293,7 @@ func (n *internalNode) export() *Node { PrivateKey: n.privateKey.Bytes(), PeerId: n.peerId, IsValidator: n.isValidator, + TempBlsInfo: &tempBlsInfo, } } diff --git a/testutil/signer/private_test.go b/testutil/signer/private_test.go new file mode 100644 index 00000000..6f72f9ee --- /dev/null +++ b/testutil/signer/private_test.go @@ -0,0 +1,37 @@ +package signer + +import ( + "path/filepath" + "testing" + + "github.com/babylonlabs-io/babylon/crypto/erc2335" + "github.com/babylonlabs-io/babylon/privval" + cmtconfig "github.com/cometbft/cometbft/config" + cmtprivval "github.com/cometbft/cometbft/privval" + "github.com/test-go/testify/assert" +) + +func TestGeneratePrivSigner(t *testing.T) { + nodeDir := t.TempDir() + + nodeCfg := cmtconfig.DefaultConfig() + blsCfg := privval.DefaultBlsConfig() + + pvKeyFile := filepath.Join(nodeDir, nodeCfg.PrivValidatorKeyFile()) + pvStateFile := filepath.Join(nodeDir, nodeCfg.PrivValidatorStateFile()) + blsKeyFile := filepath.Join(nodeDir, blsCfg.BlsKeyFile()) + blsPasswordFile := filepath.Join(nodeDir, blsCfg.BlsPasswordFile()) + + err := privval.IsValidFilePath(pvKeyFile, pvStateFile, blsKeyFile, blsPasswordFile) + assert.NoError(t, err) + + cometPV := cmtprivval.GenFilePV(pvKeyFile, pvStateFile) + cometPV.Key.Save() + cometPV.LastSignState.Save() + + privval.GenBlsPV(blsKeyFile, blsPasswordFile, "password", "") + + password, err := erc2335.LoadPaswordFromFile(blsPasswordFile) + assert.NoError(t, err) + t.Logf("password: %s", password) +} From f10b817ee364ad072cf11aa1ab10ce5099b27361 Mon Sep 17 00:00:00 2001 From: wonjoon Date: Mon, 13 Jan 2025 20:14:51 +0900 Subject: [PATCH 05/15] chore: fix error nil pointer --- test/e2e/configurer/upgrade.go | 7 ++++++- test/e2e/initialization/export.go | 2 +- test/e2e/initialization/node.go | 14 +++++++------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/test/e2e/configurer/upgrade.go b/test/e2e/configurer/upgrade.go index c724625a..b34a6070 100644 --- a/test/e2e/configurer/upgrade.go +++ b/test/e2e/configurer/upgrade.go @@ -23,6 +23,7 @@ import ( "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" + cmtos "github.com/cometbft/cometbft/libs/os" ) type UpgradeSettings struct { @@ -262,7 +263,11 @@ func (uc *UpgradeConfigurer) upgradeContainers(chainConfig *chain.Config, propHe tempBlsInfo := node.TempBlsInfo // generate BLS key - privval.GenBlsPV(tempBlsInfo.KeyFilePath, tempBlsInfo.PasswordFilePath, tempBlsInfo.Password, tempBlsInfo.DelegatorAddress) + if cmtos.FileExists(tempBlsInfo.KeyFilePath) { + privval.LoadBlsPV(tempBlsInfo.KeyFilePath, tempBlsInfo.PasswordFilePath) + } else { + privval.GenBlsPV(tempBlsInfo.KeyFilePath, tempBlsInfo.PasswordFilePath, tempBlsInfo.Password, tempBlsInfo.DelegatorAddress) + } if err := node.Run(); err != nil { return err } diff --git a/test/e2e/initialization/export.go b/test/e2e/initialization/export.go index 75273914..3b27aca5 100644 --- a/test/e2e/initialization/export.go +++ b/test/e2e/initialization/export.go @@ -19,7 +19,7 @@ type Node struct { PrivateKey []byte `json:"privateKey"` PeerId string `json:"peerId"` IsValidator bool `json:"isValidator"` - TempBlsInfo *TempBlsInfo + TempBlsInfo TempBlsInfo } type Chain struct { diff --git a/test/e2e/initialization/node.go b/test/e2e/initialization/node.go index 98785300..7a632430 100644 --- a/test/e2e/initialization/node.go +++ b/test/e2e/initialization/node.go @@ -269,17 +269,17 @@ func (n *internalNode) export() *Node { blsKey := n.consensusKey.BlsPVKey - tempBlsInfo := func(blsPvKey privval.BlsPVKey) TempBlsInfo { - password, err := erc2335.LoadPaswordFromFile(blsKey.GetPasswordFilePath()) + tempBlsInfo := func(k privval.BlsPVKey) TempBlsInfo { + password, err := erc2335.LoadPaswordFromFile(k.GetPasswordFilePath()) if err != nil { panic(err) } return TempBlsInfo{ - PrivateKey: blsPvKey.PrivKey, + PrivateKey: k.PrivKey, Password: password, - KeyFilePath: blsKey.GetKeyFilePath(), - PasswordFilePath: blsKey.GetPasswordFilePath(), - DelegatorAddress: blsPvKey.DelegatorAddress, + KeyFilePath: k.GetKeyFilePath(), + PasswordFilePath: k.GetPasswordFilePath(), + DelegatorAddress: k.DelegatorAddress, } }(blsKey) @@ -293,7 +293,7 @@ func (n *internalNode) export() *Node { PrivateKey: n.privateKey.Bytes(), PeerId: n.peerId, IsValidator: n.isValidator, - TempBlsInfo: &tempBlsInfo, + TempBlsInfo: tempBlsInfo, } } From 1ef5f16d18d6a75c8d37350a9979400e9d3c37cb Mon Sep 17 00:00:00 2001 From: wonjoon Date: Mon, 13 Jan 2025 20:27:36 +0900 Subject: [PATCH 06/15] chore: update 1 --- test/e2e/configurer/upgrade.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/e2e/configurer/upgrade.go b/test/e2e/configurer/upgrade.go index b34a6070..a31c0f87 100644 --- a/test/e2e/configurer/upgrade.go +++ b/test/e2e/configurer/upgrade.go @@ -262,6 +262,10 @@ func (uc *UpgradeConfigurer) upgradeContainers(chainConfig *chain.Config, propHe // node.BlsKey tempBlsInfo := node.TempBlsInfo + if err := privval.IsValidFilePath(tempBlsInfo.KeyFilePath, tempBlsInfo.PasswordFilePath); err != nil { + return err + } + // generate BLS key if cmtos.FileExists(tempBlsInfo.KeyFilePath) { privval.LoadBlsPV(tempBlsInfo.KeyFilePath, tempBlsInfo.PasswordFilePath) From d9e8f65ad6874c0938b148da85fef43c3afcf44d Mon Sep 17 00:00:00 2001 From: wonjoon Date: Mon, 13 Jan 2025 20:47:09 +0900 Subject: [PATCH 07/15] chore: test2 --- privval/util.go | 2 +- test/e2e/configurer/upgrade.go | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/privval/util.go b/privval/util.go index 80224058..213230cb 100644 --- a/privval/util.go +++ b/privval/util.go @@ -11,7 +11,7 @@ func IsValidFilePath(paths ...string) error { // Check file path of bls key for _, path := range paths { if path == "" { - return fmt.Errorf("filePath for bls key not set") + return fmt.Errorf("filePath is not set completely") } if err := cmtos.EnsureDir(filepath.Dir(path), 0777); err != nil { return fmt.Errorf("failed to ensure key path dir: %w", err) diff --git a/test/e2e/configurer/upgrade.go b/test/e2e/configurer/upgrade.go index a31c0f87..f0a33074 100644 --- a/test/e2e/configurer/upgrade.go +++ b/test/e2e/configurer/upgrade.go @@ -262,16 +262,21 @@ func (uc *UpgradeConfigurer) upgradeContainers(chainConfig *chain.Config, propHe // node.BlsKey tempBlsInfo := node.TempBlsInfo - if err := privval.IsValidFilePath(tempBlsInfo.KeyFilePath, tempBlsInfo.PasswordFilePath); err != nil { + 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 { return err } // generate BLS key - if cmtos.FileExists(tempBlsInfo.KeyFilePath) { - privval.LoadBlsPV(tempBlsInfo.KeyFilePath, tempBlsInfo.PasswordFilePath) + if cmtos.FileExists(keyFilePath) { + privval.LoadBlsPV(keyFilePath, passwordFilePath) } else { - privval.GenBlsPV(tempBlsInfo.KeyFilePath, tempBlsInfo.PasswordFilePath, tempBlsInfo.Password, tempBlsInfo.DelegatorAddress) + privval.GenBlsPV(keyFilePath, passwordFilePath, tempBlsInfo.Password, tempBlsInfo.DelegatorAddress) } + if err := node.Run(); err != nil { return err } From 0308bbd1f4ac68fa434711c8c918dc3e284ee9bd Mon Sep 17 00:00:00 2001 From: wonjoon Date: Mon, 13 Jan 2025 21:09:02 +0900 Subject: [PATCH 08/15] chore: test 3 --- test/e2e/configurer/upgrade.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/test/e2e/configurer/upgrade.go b/test/e2e/configurer/upgrade.go index f0a33074..d0f9fec4 100644 --- a/test/e2e/configurer/upgrade.go +++ b/test/e2e/configurer/upgrade.go @@ -23,7 +23,9 @@ import ( "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" ) type UpgradeSettings struct { @@ -260,7 +262,7 @@ func (uc *UpgradeConfigurer) upgradeContainers(chainConfig *chain.Config, propHe for _, node := range chainConfig.NodeConfigs { // node.BlsKey - tempBlsInfo := node.TempBlsInfo + // tempBlsInfo := node.TempBlsInfo blsCfg := privval.DefaultBlsConfig() keyFilePath := filepath.Join(node.ConfigDir, blsCfg.BlsKeyFile()) @@ -274,7 +276,19 @@ func (uc *UpgradeConfigurer) upgradeContainers(chainConfig *chain.Config, propHe if cmtos.FileExists(keyFilePath) { privval.LoadBlsPV(keyFilePath, passwordFilePath) } else { - privval.GenBlsPV(keyFilePath, passwordFilePath, tempBlsInfo.Password, tempBlsInfo.DelegatorAddress) + 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 { From 46dec5cc85ed3d0e4dbaa58798101c2aeb435361 Mon Sep 17 00:00:00 2001 From: wonjoon Date: Mon, 13 Jan 2025 21:41:35 +0900 Subject: [PATCH 09/15] chore: fix --- test/e2e/configurer/upgrade.go | 82 ++++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 28 deletions(-) diff --git a/test/e2e/configurer/upgrade.go b/test/e2e/configurer/upgrade.go index d0f9fec4..77eb3f16 100644 --- a/test/e2e/configurer/upgrade.go +++ b/test/e2e/configurer/upgrade.go @@ -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" @@ -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" ) @@ -254,6 +258,54 @@ 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) @@ -261,36 +313,10 @@ func (uc *UpgradeConfigurer) upgradeContainers(chainConfig *chain.Config, propHe 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 } From 538e3ab77a9435b1ad78b3e6cec82a90ded92a39 Mon Sep 17 00:00:00 2001 From: wonjoon Date: Tue, 14 Jan 2025 15:25:30 +0900 Subject: [PATCH 10/15] 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, } } From cd106b65af211406578749f6e0d1baafc480ae6d Mon Sep 17 00:00:00 2001 From: wonjoon Date: Tue, 14 Jan 2025 15:45:43 +0900 Subject: [PATCH 11/15] chore: add more logs --- test/e2e/initialization/chain.go | 23 +++++++++++++++++++++++ test/e2e/initialization/node.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/test/e2e/initialization/chain.go b/test/e2e/initialization/chain.go index d782f140..696e5e96 100644 --- a/test/e2e/initialization/chain.go +++ b/test/e2e/initialization/chain.go @@ -1,5 +1,11 @@ package initialization +import ( + "log" + + cmtos "github.com/cometbft/cometbft/libs/os" +) + const ( keyringPassphrase = "testpassphrase" keyringAppName = "testnet" @@ -26,6 +32,23 @@ func (c *internalChain) export() *Chain { exportNodes := make([]*Node, 0, len(c.nodes)) for _, v := range c.nodes { exportNodes = append(exportNodes, v.export()) + + // ======= TESTING START ======= + log.Print("==> export()") + log.Print("=> v.export().ConfigDir: ", v.export().ConfigDir) + + if cmtos.FileExists(v.export().ConsensusKey.BlsPVKey.GetKeyFilePath()) { + log.Print("=> file exists: blsKeyFile: ", v.export().ConsensusKey.BlsPVKey.GetKeyFilePath()) + } else { + log.Print("=> file does not exist: blsKeyFile: ", v.export().ConsensusKey.BlsPVKey.GetKeyFilePath()) + } + + if cmtos.FileExists(v.export().ConsensusKey.BlsPVKey.GetPasswordFilePath()) { + log.Print("=> file exists: blsPasswordFile: ", v.export().ConsensusKey.BlsPVKey.GetPasswordFilePath()) + } else { + log.Print("=> file does not exist: blsPasswordFile: ", v.export().ConsensusKey.BlsPVKey.GetPasswordFilePath()) + } + // ======= TESTING END ======= } return &Chain{ diff --git a/test/e2e/initialization/node.go b/test/e2e/initialization/node.go index 3b3f9f8a..d3e8a90b 100644 --- a/test/e2e/initialization/node.go +++ b/test/e2e/initialization/node.go @@ -3,6 +3,7 @@ package initialization import ( "encoding/json" "fmt" + "log" "os" "path" "path/filepath" @@ -37,6 +38,7 @@ import ( "github.com/babylonlabs-io/babylon/crypto/bls12381" "github.com/babylonlabs-io/babylon/privval" "github.com/babylonlabs-io/babylon/test/e2e/util" + cmtos "github.com/cometbft/cometbft/libs/os" cmtprivval "github.com/cometbft/cometbft/privval" ) @@ -207,6 +209,34 @@ func (n *internalNode) createConsensusKey() error { CometPVKey: filePV.Key, BlsPVKey: blsPV.Key, } + + // ======= TESTING START ======= + log.Print("==> createConsensusKey()") + if cmtos.FileExists(pvKeyFile) { + log.Print("=> file exists: pvKeyFile: ", pvKeyFile) + } else { + log.Print("=> file does not exist: pvKeyFile: ", pvKeyFile) + } + + if cmtos.FileExists(blsPasswordFile) { + log.Print("=> file exists: blsPasswordFile: ", blsPasswordFile) + } else { + log.Print("=> file does not exist: blsPasswordFile: ", blsPasswordFile) + } + + if cmtos.FileExists(blsKeyFile) { + log.Print("=> file exists: blsKeyFile: ", blsKeyFile) + } else { + log.Print("=> file does not exist: blsKeyFile: ", blsKeyFile) + } + + if cmtos.FileExists(blsPasswordFile) { + log.Print("=> file exists: blsPasswordFile: ", blsPasswordFile) + } else { + log.Print("=> file does not exist: blsPasswordFile: ", blsPasswordFile) + } + // ======= TESTING END ======= + return nil } From 9443d1bc31449560366ef4fa9912b4161d87a9e3 Mon Sep 17 00:00:00 2001 From: wonjoon Date: Tue, 14 Jan 2025 16:31:29 +0900 Subject: [PATCH 12/15] chore: add create in RunNodeResource and log --- test/e2e/containers/containers.go | 51 ++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/test/e2e/containers/containers.go b/test/e2e/containers/containers.go index 403b6c1d..88a18401 100644 --- a/test/e2e/containers/containers.go +++ b/test/e2e/containers/containers.go @@ -13,9 +13,9 @@ import ( "testing" "time" - "github.com/babylonlabs-io/babylon/crypto/erc2335" "github.com/babylonlabs-io/babylon/privval" - cmtos "github.com/cometbft/cometbft/libs/os" + cmtcfg "github.com/cometbft/cometbft/config" + cmtprivval "github.com/cometbft/cometbft/privval" "github.com/ory/dockertest/v3" "github.com/ory/dockertest/v3/docker" "github.com/stretchr/testify/require" @@ -272,21 +272,44 @@ func (m *Manager) RunNodeResource(chainId string, containerName, valCondifDir st 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 ======= + + // ======= CREATE KEY DIRECTLY START ======= + cmtKeyFile := filepath.Join(valCondifDir, cmtcfg.DefaultConfig().PrivValidatorKeyFile()) + cmtStateFile := filepath.Join(valCondifDir, cmtcfg.DefaultConfig().PrivValidatorStateFile()) 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) + + log.Print("=> cmtKeyFile: ", cmtKeyFile) + log.Print("=> cmtStateFile: ", cmtStateFile) + log.Print("=> blsKeyFile: ", blsKeyFile) + log.Print("=> blsPasswordFile: ", blsPasswordFile) + + if err := privval.IsValidFilePath(cmtKeyFile, cmtStateFile, blsKeyFile, blsPasswordFile); err != nil { + return nil, err } - // ======= TESTING END ======= + + filePV := cmtprivval.GenFilePV(cmtKeyFile, cmtStateFile) + filePV.Key.Save() + filePV.LastSignState.Save() + + blsPV := privval.GenBlsPV(blsKeyFile, blsPasswordFile, "password", "") + blsPV.Key.Save("password", "") + // ======= CREATE KEY DIRECTLY END ======= runOpts := &dockertest.RunOptions{ Name: containerName, From dacbf29bfed7a89751ec10f7d24af88a9b2c8bfc Mon Sep 17 00:00:00 2001 From: wonjoon Date: Tue, 14 Jan 2025 17:07:26 +0900 Subject: [PATCH 13/15] chore: error check in RunNodeResource --- test/e2e/containers/containers.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/e2e/containers/containers.go b/test/e2e/containers/containers.go index 88a18401..ff506b75 100644 --- a/test/e2e/containers/containers.go +++ b/test/e2e/containers/containers.go @@ -288,7 +288,7 @@ func (m *Manager) RunNodeResource(chainId string, containerName, valCondifDir st // } // ======= TESTING END ======= - // ======= CREATE KEY DIRECTLY START ======= + // ======= CREATE KEY DIRECTLY ======= cmtKeyFile := filepath.Join(valCondifDir, cmtcfg.DefaultConfig().PrivValidatorKeyFile()) cmtStateFile := filepath.Join(valCondifDir, cmtcfg.DefaultConfig().PrivValidatorStateFile()) blsKeyFile := filepath.Join(valCondifDir, privval.DefaultBlsConfig().BlsKeyFile()) @@ -307,9 +307,9 @@ func (m *Manager) RunNodeResource(chainId string, containerName, valCondifDir st filePV.Key.Save() filePV.LastSignState.Save() - blsPV := privval.GenBlsPV(blsKeyFile, blsPasswordFile, "password", "") - blsPV.Key.Save("password", "") - // ======= CREATE KEY DIRECTLY END ======= + privval.GenBlsPV(blsKeyFile, blsPasswordFile, "password", "") + + // ======= CREATE KEY DIRECTLY ======= runOpts := &dockertest.RunOptions{ Name: containerName, From ffd11f33bb0e9365ed5098a8e67029a686f43994 Mon Sep 17 00:00:00 2001 From: wonjoon Date: Tue, 14 Jan 2025 17:20:11 +0900 Subject: [PATCH 14/15] chore: test 2 --- test/e2e/containers/containers.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/e2e/containers/containers.go b/test/e2e/containers/containers.go index ff506b75..736814f0 100644 --- a/test/e2e/containers/containers.go +++ b/test/e2e/containers/containers.go @@ -299,10 +299,19 @@ func (m *Manager) RunNodeResource(chainId string, containerName, valCondifDir st log.Print("=> blsKeyFile: ", blsKeyFile) log.Print("=> blsPasswordFile: ", blsPasswordFile) + // Remove existing files if they exist + for _, file := range []string{cmtKeyFile, cmtStateFile, blsKeyFile, blsPasswordFile} { + if err := os.RemoveAll(file); err != nil { + log.Printf("Failed to remove file %s: %v", file, err) + return nil, err + } + } + if err := privval.IsValidFilePath(cmtKeyFile, cmtStateFile, blsKeyFile, blsPasswordFile); err != nil { return nil, err } + // Generate new keys filePV := cmtprivval.GenFilePV(cmtKeyFile, cmtStateFile) filePV.Key.Save() filePV.LastSignState.Save() From a8326e9d3b8973668bb0e5891aa94baf232566fa Mon Sep 17 00:00:00 2001 From: wonjoon Date: Tue, 14 Jan 2025 17:53:45 +0900 Subject: [PATCH 15/15] chore: logic test --- test/e2e/containers/containers.go | 41 ++++++++++--------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/test/e2e/containers/containers.go b/test/e2e/containers/containers.go index 736814f0..8f4b5eb7 100644 --- a/test/e2e/containers/containers.go +++ b/test/e2e/containers/containers.go @@ -15,6 +15,7 @@ import ( "github.com/babylonlabs-io/babylon/privval" cmtcfg "github.com/cometbft/cometbft/config" + cmtos "github.com/cometbft/cometbft/libs/os" cmtprivval "github.com/cometbft/cometbft/privval" "github.com/ory/dockertest/v3" "github.com/ory/dockertest/v3/docker" @@ -271,21 +272,6 @@ func (m *Manager) RunNodeResource(chainId string, containerName, valCondifDir st // ======= 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 ======= // ======= CREATE KEY DIRECTLY ======= @@ -299,25 +285,24 @@ func (m *Manager) RunNodeResource(chainId string, containerName, valCondifDir st log.Print("=> blsKeyFile: ", blsKeyFile) log.Print("=> blsPasswordFile: ", blsPasswordFile) - // Remove existing files if they exist - for _, file := range []string{cmtKeyFile, cmtStateFile, blsKeyFile, blsPasswordFile} { - if err := os.RemoveAll(file); err != nil { - log.Printf("Failed to remove file %s: %v", file, err) + if !cmtos.FileExists(cmtKeyFile) { + if err := privval.IsValidFilePath(cmtKeyFile, cmtStateFile); err != nil { return nil, err } + log.Print("=> file not exists: cmtKeyFile: ", cmtKeyFile) + log.Print("=> create new cometPv and save to file") + cmtprivval.GenFilePV(cmtKeyFile, cmtStateFile).Save() } - if err := privval.IsValidFilePath(cmtKeyFile, cmtStateFile, blsKeyFile, blsPasswordFile); err != nil { - return nil, err + if !cmtos.FileExists(blsKeyFile) { + if err := privval.IsValidFilePath(blsKeyFile, blsPasswordFile); err != nil { + return nil, err + } + log.Print("=> file not exists: blsKeyFile: ", blsKeyFile) + log.Print("=> create new blsPv and save to file") + privval.GenBlsPV(blsKeyFile, blsPasswordFile, "password", "") } - // Generate new keys - filePV := cmtprivval.GenFilePV(cmtKeyFile, cmtStateFile) - filePV.Key.Save() - filePV.LastSignState.Save() - - privval.GenBlsPV(blsKeyFile, blsPasswordFile, "password", "") - // ======= CREATE KEY DIRECTLY ======= runOpts := &dockertest.RunOptions{