every node needs a key pair (#488)

* added panic if there is no key pair that can be used for the node (keystore or trustwallet)
* renamed GetValidatorAddress to GetNodeAddress
* fixed lib/test/e2e failing test case. The issue is an internal race condition of the unit test network in case of 1 node. Moving to two nodes solves the issue with the test case. In case of 1 validator, the first chain interaction happens before the address environment variables are set

Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
Jürgen Eckel 2024-11-26 15:31:39 +01:00 committed by GitHub
parent 90381166e6
commit aec55171f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 68 additions and 47 deletions

View File

@ -2,6 +2,7 @@ package config
import (
"encoding/json"
"errors"
"os"
"sync"
@ -91,54 +92,61 @@ func (config *Config) SetPlanetmintConfig(planetmintconfig interface{}) {
}
}
// GetValidatorAddress retrieves the validator address through multiple methods
func (config *Config) GetValidatorAddress() string {
// Check environment variable first
if envAddr := os.Getenv(ValAddr); envAddr != "" {
return envAddr
// GetNodeAddress retrieves the validator address through multiple methods
func (config *Config) GetNodeAddress() (address string) {
var err error
// Check environment variable first <- this is used for test cases only
if address = os.Getenv(ValAddr); address != "" {
return
}
libConfig := lib.GetConfig()
// Handle no Trust Wallet connected scenario
if libConfig.GetSerialPort() == "" {
return getDefaultValidatorAddress(libConfig)
address, err = getKeyringAddress(libConfig)
} else { // Handle Trust Wallet connected scenario
address, err = getTrustWalletAddress(libConfig)
}
// Handle Trust Wallet connected scenario
return getTrustWalletValidatorAddress(libConfig)
if err != nil {
msg := "Cannot get node address. Please configure a Trust Wallet or define at least one key pair in the utilized keyring."
newError := errors.New(msg + ": " + err.Error())
panic(newError)
}
return address
}
// getDefaultValidatorAddress retrieves the default validator address
func getDefaultValidatorAddress(libConfig *lib.Config) string {
// getKeyringAddress retrieves the default validator address
func getKeyringAddress(libConfig *lib.Config) (address string, err error) {
defaultRecord, err := libConfig.GetDefaultValidatorRecord()
if err != nil {
logger.GetLogger(logger.ERROR).Error("msg", err.Error())
return ""
return
}
addr, err := defaultRecord.GetAddress()
if err != nil {
logger.GetLogger(logger.ERROR).Error("msg", err.Error())
return ""
return
}
return addr.String()
address = addr.String()
return
}
// getTrustWalletValidatorAddress retrieves validator address from Trust Wallet
func getTrustWalletValidatorAddress(libConfig *lib.Config) string {
// getTrustWalletAddress retrieves validator address from Trust Wallet
func getTrustWalletAddress(libConfig *lib.Config) (address string, err error) {
connector, err := trustwallet.NewTrustWalletConnector(libConfig.GetSerialPort())
if err != nil {
logger.GetLogger(logger.ERROR).Error("msg", err.Error())
return ""
return
}
keys, err := connector.GetPlanetmintKeys()
if err != nil {
logger.GetLogger(logger.ERROR).Error("msg", err.Error())
return ""
return
}
return keys.PlanetmintAddress
address = keys.PlanetmintAddress
return
}

4
go.mod
View File

@ -6,7 +6,7 @@ require (
cosmossdk.io/api v0.3.1
cosmossdk.io/depinject v1.0.0-alpha.4
cosmossdk.io/errors v1.0.1
cosmossdk.io/math v1.2.0
cosmossdk.io/math v1.4.0
cosmossdk.io/simapp v0.0.0-20230323161446-0af178d721ff
github.com/btcsuite/btcd v0.24.0
github.com/btcsuite/btcd/btcutil v1.1.5
@ -39,7 +39,7 @@ require (
google.golang.org/grpc v1.60.1
gopkg.in/yaml.v2 v2.4.0
gotest.tools v2.2.0+incompatible
sigs.k8s.io/yaml v1.3.0
sigs.k8s.io/yaml v1.4.0
)
require (

8
go.sum
View File

@ -194,8 +194,8 @@ cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0=
cosmossdk.io/errors v1.0.1/go.mod h1:MeelVSZThMi4bEakzhhhE/CKqVv3nOJDA25bIqRDu/U=
cosmossdk.io/log v1.3.0 h1:L0Z0XstClo2kOU4h3V1iDoE5Ji64sg5HLOogzGg67Oo=
cosmossdk.io/log v1.3.0/go.mod h1:HIDyvWLqZe2ovlWabsDN4aPMpY/nUEquAhgfTf2ZzB8=
cosmossdk.io/math v1.2.0 h1:8gudhTkkD3NxOP2YyyJIYYmt6dQ55ZfJkDOaxXpy7Ig=
cosmossdk.io/math v1.2.0/go.mod h1:l2Gnda87F0su8a/7FEKJfFdJrM0JZRXQaohlgJeyQh0=
cosmossdk.io/math v1.4.0 h1:XbgExXFnXmF/CccPPEto40gOO7FpWu9yWNAZPN3nkNQ=
cosmossdk.io/math v1.4.0/go.mod h1:O5PkD4apz2jZs4zqFdTr16e1dcaQCc5z6lkEnrrppuk=
cosmossdk.io/simapp v0.0.0-20230323161446-0af178d721ff h1:P1ialzTepD1oxdNPYc5N8Eggq3RdejZq3cJs8YYMs9Y=
cosmossdk.io/simapp v0.0.0-20230323161446-0af178d721ff/go.mod h1:AKzx6Mb544LjJ9RHmGFHjY9rEOLiUAi8I0F727TR0dY=
cosmossdk.io/tools/rosetta v0.2.1 h1:ddOMatOH+pbxWbrGJKRAawdBkPYLfKXutK9IETnjYxw=
@ -1731,6 +1731,6 @@ rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=

View File

@ -5,10 +5,10 @@ go 1.22
require (
github.com/cometbft/cometbft v0.37.4
github.com/cosmos/cosmos-sdk v0.47.8
github.com/planetmint/planetmint-go v0.11.1
github.com/planetmint/planetmint-go v0.12.8
github.com/stretchr/testify v1.9.0
go.bug.st/serial v1.6.2
sigs.k8s.io/yaml v1.3.0
sigs.k8s.io/yaml v1.4.0
)
require (
@ -22,7 +22,7 @@ require (
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/errors v1.0.1 // indirect
cosmossdk.io/log v1.3.0 // indirect
cosmossdk.io/math v1.2.0 // indirect
cosmossdk.io/math v1.4.0 // indirect
cosmossdk.io/simapp v0.0.0-20230323161446-0af178d721ff // indirect
cosmossdk.io/tools/rosetta v0.2.1 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
@ -74,7 +74,6 @@ require (
github.com/felixge/httpsnoop v1.0.2 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/getsentry/sentry-go v0.23.0 // indirect
github.com/gin-gonic/gin v1.9.1 // indirect
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
@ -145,6 +144,10 @@ require (
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/rddl-network/elements-rpc v1.2.1 // indirect
github.com/rddl-network/go-utils v0.2.3 // indirect
github.com/rddl-network/rddl-claim-service v0.3.2 // indirect
github.com/rddl-network/rddl-claim-service/client v0.0.6 // indirect
github.com/rddl-network/shamir-coordinator-service v0.7.7 // indirect
github.com/rddl-network/shamir-coordinator-service/client v0.1.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/rs/cors v1.8.3 // indirect
github.com/rs/zerolog v1.31.0 // indirect
@ -189,3 +192,5 @@ require (
nhooyr.io/websocket v1.8.6 // indirect
pgregory.net/rapid v0.5.5 // indirect
)
replace github.com/planetmint/planetmint-go => ../

View File

@ -194,8 +194,8 @@ cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0=
cosmossdk.io/errors v1.0.1/go.mod h1:MeelVSZThMi4bEakzhhhE/CKqVv3nOJDA25bIqRDu/U=
cosmossdk.io/log v1.3.0 h1:L0Z0XstClo2kOU4h3V1iDoE5Ji64sg5HLOogzGg67Oo=
cosmossdk.io/log v1.3.0/go.mod h1:HIDyvWLqZe2ovlWabsDN4aPMpY/nUEquAhgfTf2ZzB8=
cosmossdk.io/math v1.2.0 h1:8gudhTkkD3NxOP2YyyJIYYmt6dQ55ZfJkDOaxXpy7Ig=
cosmossdk.io/math v1.2.0/go.mod h1:l2Gnda87F0su8a/7FEKJfFdJrM0JZRXQaohlgJeyQh0=
cosmossdk.io/math v1.4.0 h1:XbgExXFnXmF/CccPPEto40gOO7FpWu9yWNAZPN3nkNQ=
cosmossdk.io/math v1.4.0/go.mod h1:O5PkD4apz2jZs4zqFdTr16e1dcaQCc5z6lkEnrrppuk=
cosmossdk.io/simapp v0.0.0-20230323161446-0af178d721ff h1:P1ialzTepD1oxdNPYc5N8Eggq3RdejZq3cJs8YYMs9Y=
cosmossdk.io/simapp v0.0.0-20230323161446-0af178d721ff/go.mod h1:AKzx6Mb544LjJ9RHmGFHjY9rEOLiUAi8I0F727TR0dY=
cosmossdk.io/tools/rosetta v0.2.1 h1:ddOMatOH+pbxWbrGJKRAawdBkPYLfKXutK9IETnjYxw=
@ -896,8 +896,8 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
github.com/planetmint/planetmint-go v0.11.1 h1:9gxa2W4BZCFXfP5uclcmkOOFNCVkC23T7F25U8mFY0w=
github.com/planetmint/planetmint-go v0.11.1/go.mod h1:hhLYp/3EAP4ruiMLY1hZIjIz/0lrfut1ZuhxKlEt7QM=
github.com/planetmint/planetmint-go v0.12.8 h1:KkRF0fwVNVq+/sqIn/XJQ10zXr9ZeeeEGExtsoM9844=
github.com/planetmint/planetmint-go v0.12.8/go.mod h1:yeMws4unLKASCjojExUOEgRs4JDrGbifvZSq81d4KPU=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
@ -943,6 +943,14 @@ github.com/rddl-network/elements-rpc v1.2.1 h1:clE3daxNPJJ1EDiAkTSlXUM2+gakmLHxW
github.com/rddl-network/elements-rpc v1.2.1/go.mod h1:9a71Z7xja4rFMXa+ssUMLAF9VIZVPz2jZRB1hTS9Ey4=
github.com/rddl-network/go-utils v0.2.3 h1:STiiyZVkFjovjMAyKK1IsqvVED14mRHoXFIDVbwxlFQ=
github.com/rddl-network/go-utils v0.2.3/go.mod h1:jLOkVBK/xjfVyY0d4gs1pkafTXF3mYA7ZIE68QXau5o=
github.com/rddl-network/rddl-claim-service v0.3.2 h1:Cp8FV40y9mwTbjVNlFrZ02QT+HZWD1pSsWaE5MLYAmc=
github.com/rddl-network/rddl-claim-service v0.3.2/go.mod h1:RLg6AcNL790WuAl3AYoxFGkuuwKP3t3IiBfhOYOcwdo=
github.com/rddl-network/rddl-claim-service/client v0.0.6 h1:GLqj8RMozFPVUvPQGRLBH2yGV+VHRuUCXTWaf+4wxFo=
github.com/rddl-network/rddl-claim-service/client v0.0.6/go.mod h1:CFAfupB5XogWqVsb6ndsLU97feGs4oUqlGI4WRff3zU=
github.com/rddl-network/shamir-coordinator-service v0.7.7 h1:hszDZZnqBdeiOEBWlnSK2lKIJEbWclX6cchYDazpvIU=
github.com/rddl-network/shamir-coordinator-service v0.7.7/go.mod h1:g3JnQlzKQWtnp4ZA7VtD/4N0GKpFWrW0ANHqged7M/g=
github.com/rddl-network/shamir-coordinator-service/client v0.1.0 h1:o8oZzvGSAyTto5hSkNRr2KvilhwWiqGbL70HRg4aKhA=
github.com/rddl-network/shamir-coordinator-service/client v0.1.0/go.mod h1:dhxYyhmU71iv32WqS6S+6Pm/Lsb5/d0KVn2MVTq5Jfk=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
@ -1734,6 +1742,6 @@ rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=

View File

@ -11,6 +11,6 @@ import (
func TestE2ELibTestSuite(t *testing.T) {
t.Parallel()
cfg := network.LoaderDefaultConfig()
cfg.NumValidators = 1
cfg.NumValidators = 2
suite.Run(t, NewE2ETestSuite(cfg))
}

View File

@ -64,7 +64,7 @@ func (mms *MqttMonitor) setNumDBElements(numElements int64) {
func getClientID() string {
conf := config.GetConfig()
return "monitor-" + conf.GetValidatorAddress()
return "monitor-" + conf.GetNodeAddress()
}
func (mms *MqttMonitor) lazyLoadMonitorMQTTClient() util.MQTTClientI {

View File

@ -51,7 +51,7 @@ func buildSignBroadcastTx(goCtx context.Context, loggingContext string, sendingV
func SendInitReissuance(goCtx context.Context, proposerAddress string, txUnsigned string, blockHeight int64,
firstIncludedPop int64, lastIncludedPop int64) {
sendingValidatorAddress := config.GetConfig().GetValidatorAddress()
sendingValidatorAddress := config.GetConfig().GetNodeAddress()
msg := daotypes.NewMsgReissueRDDLProposal(sendingValidatorAddress, proposerAddress, txUnsigned, blockHeight,
firstIncludedPop, lastIncludedPop)
loggingContext := "reissuance proposal"
@ -59,14 +59,14 @@ func SendInitReissuance(goCtx context.Context, proposerAddress string, txUnsigne
}
func SendReissuanceResult(goCtx context.Context, proposerAddress string, txID string, blockHeight int64) {
sendingValidatorAddress := config.GetConfig().GetValidatorAddress()
sendingValidatorAddress := config.GetConfig().GetNodeAddress()
msg := daotypes.NewMsgReissueRDDLResult(sendingValidatorAddress, proposerAddress, txID, blockHeight)
loggingContext := "reissuance result"
buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg)
}
func SendDistributionRequest(goCtx context.Context, distribution daotypes.DistributionOrder) {
sendingValidatorAddress := config.GetConfig().GetValidatorAddress()
sendingValidatorAddress := config.GetConfig().GetNodeAddress()
msg := daotypes.NewMsgDistributionRequest(sendingValidatorAddress, &distribution)
loggingContext := "distribution request"
buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg)
@ -74,35 +74,35 @@ func SendDistributionRequest(goCtx context.Context, distribution daotypes.Distri
func SendDistributionResult(goCtx context.Context, lastPoP int64, daoTxID string, invTxID string,
popTxID string, earlyInvestorTxID string, strategicTxID string) {
sendingValidatorAddress := config.GetConfig().GetValidatorAddress()
sendingValidatorAddress := config.GetConfig().GetNodeAddress()
msg := daotypes.NewMsgDistributionResult(sendingValidatorAddress, lastPoP, daoTxID, invTxID, popTxID, earlyInvestorTxID, strategicTxID)
loggingContext := "distribution result"
buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg)
}
func SendLiquidAssetRegistration(goCtx context.Context, notarizedAsset machinetypes.LiquidAsset) {
sendingValidatorAddress := config.GetConfig().GetValidatorAddress()
sendingValidatorAddress := config.GetConfig().GetNodeAddress()
msg := machinetypes.NewMsgNotarizeLiquidAsset(sendingValidatorAddress, &notarizedAsset)
loggingContext := "notarize liquid asset"
buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg)
}
func SendInitPoP(goCtx context.Context, challenger string, challengee string, blockHeight int64) {
sendingValidatorAddress := config.GetConfig().GetValidatorAddress()
sendingValidatorAddress := config.GetConfig().GetNodeAddress()
msg := daotypes.NewMsgInitPop(sendingValidatorAddress, sendingValidatorAddress, challenger, challengee, blockHeight)
loggingContext := "PoP"
buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg)
}
func SendUpdateRedeemClaim(goCtx context.Context, beneficiary string, id uint64, txID string) {
sendingValidatorAddress := config.GetConfig().GetValidatorAddress()
sendingValidatorAddress := config.GetConfig().GetNodeAddress()
msg := daotypes.NewMsgUpdateRedeemClaim(sendingValidatorAddress, beneficiary, txID, id)
loggingContext := "redeem claim"
buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg)
}
func SendTokens(goCtx context.Context, beneficiary sdk.AccAddress, amount uint64, denominator string) {
sendingValidatorAddress := config.GetConfig().GetValidatorAddress()
sendingValidatorAddress := config.GetConfig().GetNodeAddress()
coin := sdk.NewCoin(denominator, sdk.NewIntFromUint64(amount))
coins := sdk.NewCoins(coin)

View File

@ -49,7 +49,7 @@ func LazyLoadMQTTClient() {
}
opts := mqtt.NewClientOptions().AddBroker(uri)
opts.SetClientID(conf.GetValidatorAddress())
opts.SetClientID(conf.GetNodeAddress())
opts.SetUsername(conf.MqttUser)
opts.SetPassword(conf.MqttPassword)
if conf.MqttTLS {