diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 522ce2b9..91b84e27 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -74,7 +74,7 @@ jobs: chmod +x ./setup-supernodes.sh ./setup-supernodes.sh all \ ../../supernode/main.go \ - ../system/supernode-data \ + ../system/supernode-data1 \ ../system/config.test-1.yml \ ../system/supernode-data2 \ ../system/config.test-2.yml \ diff --git a/.gitignore b/.gitignore index 69acafc0..c6a92936 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,6 @@ go.work.sum .env /data /tests/system/data -tests/system/supernode-data +tests/system/supernode-data1 tests/system/supernode-data2 tests/system/supernode-data3 \ No newline at end of file diff --git a/Makefile b/Makefile index 3e376427..cd508a86 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ gen-cascade: # Define the paths SUPERNODE_SRC=supernode/main.go -DATA_DIR=tests/system/supernode-data +DATA_DIR=tests/system/supernode-data1 DATA_DIR2=tests/system/supernode-data2 DATA_DIR3=tests/system/supernode-data3 CONFIG_FILE=tests/system/config.test-1.yml @@ -37,7 +37,7 @@ SETUP_SCRIPT=tests/scripts/setup-supernodes.sh install-lumera: @echo "Installing Lumera..." @chmod +x tests/scripts/install-lumera.sh - @sudo tests/scripts/install-lumera.sh + @sudo tests/scripts/install-lumera.sh latest-tag # Setup supernode environments setup-supernodes: @@ -51,6 +51,6 @@ system-test-setup: install-lumera setup-supernodes @if [ -f claims.csv ]; then cp claims.csv ~/; echo "Copied claims.csv to home directory."; fi # Run system tests with complete setup -test-system-full: system-test-setup +test-system-full: @echo "Running system tests..." @cd tests/system && go test -tags=system_test -v . \ No newline at end of file diff --git a/sdk/config/config.go b/sdk/config/config.go index 7653e58e..899ac70d 100644 --- a/sdk/config/config.go +++ b/sdk/config/config.go @@ -2,23 +2,17 @@ package config import ( "errors" - "fmt" - "github.com/LumeraProtocol/supernode/pkg/keyring" + "github.com/LumeraProtocol/lumera/x/lumeraid/securekeyx" cosmoskeyring "github.com/cosmos/cosmos-sdk/crypto/keyring" ) -const ( - DefaultChainID = "lumera-testnet" - DefaultGRPCAddr = "127.0.0.1:9090" - defaultKeyName = "default" -) - // AccountConfig holds peer-to-peer addresses, ports, etc. type AccountConfig struct { LocalCosmosAddress string KeyName string Keyring cosmoskeyring.Keyring + PeerType securekeyx.PeerType } // LumeraConfig wraps all chain-specific dials. @@ -32,71 +26,13 @@ type Config struct { Lumera LumeraConfig } -// Default returns a fully initialized config with default values and an auto-generated keyring -func DefaultConfigWithKr() (Config, error) { - cfg := Config{ - Lumera: LumeraConfig{ - GRPCAddr: DefaultGRPCAddr, - ChainID: DefaultChainID, - }, - } - - return WithKeyring(cfg) -} - -// WithKeyring ensures the config has a keyring, creating one if needed -func WithKeyring(cfg Config) (Config, error) { - // Apply any defaults for zero values - if cfg.Lumera.GRPCAddr == "" { - cfg.Lumera.GRPCAddr = DefaultGRPCAddr - } - if cfg.Lumera.ChainID == "" { - cfg.Lumera.ChainID = DefaultChainID - } - - // Initialize Lumera SDK config - keyring.InitSDKConfig() - - // If keyring is nil, create an in-memory keyring and generate a new account - if cfg.Account.Keyring == nil { - // Set default key name if not provided - keyName := cfg.Account.KeyName - if keyName == "" { - keyName = defaultKeyName - } - - // Create an in-memory keyring - kr, err := keyring.InitKeyring("memory", "") - if err != nil { - return Config{}, fmt.Errorf("failed to create in-memory keyring: %w", err) - } - - // Create a new account with generated mnemonic - _, info, err := keyring.CreateNewAccount(kr, keyName) - if err != nil { - return Config{}, fmt.Errorf("failed to create new account: %w", err) - } - - // Get the address of the new account - addr, err := info.GetAddress() - if err != nil { - return Config{}, fmt.Errorf("failed to get address from account: %w", err) - } - - // Update config with the new keyring and address - cfg.Account.Keyring = kr - cfg.Account.KeyName = keyName - cfg.Account.LocalCosmosAddress = addr.String() - } - - // Validate the config - if err := cfg.Validate(); err != nil { - return Config{}, err +func NewConfig(account AccountConfig, lumera LumeraConfig) Config { + return Config{ + Account: account, + Lumera: lumera, } - return cfg, nil } -// Validate checks the configuration for required fields and valid values. func (c Config) Validate() error { switch { case c.Account.LocalCosmosAddress == "": @@ -105,6 +41,12 @@ func (c Config) Validate() error { return errors.New("config: Lumera.GRPCAddr is required") case c.Lumera.ChainID == "": return errors.New("config: Lumera.ChainID is required") + case c.Account.PeerType == 0: + return errors.New("config: Account.PeerType is required") + case c.Account.KeyName == "": + return errors.New("config: Account.KeyName is required") + case c.Account.Keyring == nil: + return errors.New("config: Account.Keyring is required") default: return nil } diff --git a/sdk/net/factory.go b/sdk/net/factory.go index 7f659b55..3456c999 100644 --- a/sdk/net/factory.go +++ b/sdk/net/factory.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/LumeraProtocol/lumera/x/lumeraid/securekeyx" "github.com/LumeraProtocol/supernode/pkg/net/grpc/client" "github.com/LumeraProtocol/supernode/sdk/adapters/lumera" "github.com/LumeraProtocol/supernode/sdk/log" @@ -14,6 +15,7 @@ import ( // FactoryConfig contains configuration for the ClientFactory type FactoryConfig struct { LocalCosmosAddress string + PeerType securekeyx.PeerType } // ClientFactory creates and manages supernode clients @@ -54,7 +56,7 @@ func (f *ClientFactory) CreateClient(ctx context.Context, supernode lumera.Super "endpoint", supernode.GrpcEndpoint) // Create client with dependencies - client, err := NewSupernodeClient(ctx, f.logger, f.keyring, f.config.LocalCosmosAddress, supernode, f.lumeraClient, + client, err := NewSupernodeClient(ctx, f.logger, f.keyring, f.config, supernode, f.lumeraClient, f.clientOptions) if err != nil { return nil, fmt.Errorf("failed to create supernode client for %s: %w", supernode.CosmosAddress, err) diff --git a/sdk/net/impl.go b/sdk/net/impl.go index 475a6f7e..27713263 100644 --- a/sdk/net/impl.go +++ b/sdk/net/impl.go @@ -31,7 +31,7 @@ var _ SupernodeClient = (*supernodeClient)(nil) // NewSupernodeClient creates a new supernode client func NewSupernodeClient(ctx context.Context, logger log.Logger, keyring keyring.Keyring, - localCosmosAddress string, targetSupernode lumera.Supernode, lumeraClient lumera.Client, + factoryConfig FactoryConfig, targetSupernode lumera.Supernode, lumeraClient lumera.Client, clientOptions *client.ClientOptions, ) (SupernodeClient, error) { // Register ALTS protocols, just like in the test @@ -44,16 +44,20 @@ func NewSupernodeClient(ctx context.Context, logger log.Logger, keyring keyring. if keyring == nil { return nil, fmt.Errorf("keyring cannot be nil") } - if localCosmosAddress == "" { + if factoryConfig.LocalCosmosAddress == "" { return nil, fmt.Errorf("local cosmos address cannot be empty") } + if factoryConfig.PeerType == 0 { + factoryConfig.PeerType = securekeyx.Simplenode + } + // Create client credentials clientCreds, err := ltc.NewClientCreds(<c.ClientOptions{ CommonOptions: ltc.CommonOptions{ Keyring: keyring, - LocalIdentity: localCosmosAddress, - PeerType: securekeyx.Supernode, + LocalIdentity: factoryConfig.LocalCosmosAddress, + PeerType: factoryConfig.PeerType, Validator: lumeraClient, }, }) @@ -67,10 +71,7 @@ func NewSupernodeClient(ctx context.Context, logger log.Logger, keyring keyring. targetSupernode.GrpcEndpoint, ) - logger.Debug(ctx, "Connecting to supernode securely", - "endpoint", targetSupernode.GrpcEndpoint, - "target_id", targetSupernode.CosmosAddress, - "local_id", localCosmosAddress) + logger.Info(ctx, "Connecting to supernode securely", "endpoint", targetSupernode.GrpcEndpoint, "target_id", targetSupernode.CosmosAddress, "local_id", factoryConfig.LocalCosmosAddress, "peer_type", factoryConfig.PeerType) // Use provided client options or defaults options := clientOptions @@ -87,9 +88,7 @@ func NewSupernodeClient(ctx context.Context, logger log.Logger, keyring keyring. targetSupernode.CosmosAddress, err) } - logger.Info(ctx, "Connected to supernode securely", - "address", targetSupernode.CosmosAddress, - "endpoint", targetSupernode.GrpcEndpoint) + logger.Info(ctx, "Connected to supernode securely", "address", targetSupernode.CosmosAddress, "endpoint", targetSupernode.GrpcEndpoint) // Create service clients cascadeClient := supernodeservice.NewCascadeAdapter( diff --git a/sdk/task/cascade.go b/sdk/task/cascade.go index 8d29c575..279a3ea6 100644 --- a/sdk/task/cascade.go +++ b/sdk/task/cascade.go @@ -111,6 +111,7 @@ func (t *CascadeTask) isServing(parent context.Context, sn lumera.Supernode) boo client, err := net.NewClientFactory(ctx, t.logger, t.keyring, t.client, net.FactoryConfig{ LocalCosmosAddress: t.config.Account.LocalCosmosAddress, + PeerType: t.config.Account.PeerType, }).CreateClient(ctx, sn) if err != nil { logtrace.Info(ctx, "Failed to create client for supernode", logtrace.Fields{logtrace.FieldMethod: "isServing"}) @@ -125,6 +126,7 @@ func (t *CascadeTask) isServing(parent context.Context, sn lumera.Supernode) boo func (t *CascadeTask) registerWithSupernodes(ctx context.Context, supernodes lumera.Supernodes) error { factoryCfg := net.FactoryConfig{ LocalCosmosAddress: t.config.Account.LocalCosmosAddress, + PeerType: t.config.Account.PeerType, } clientFactory := net.NewClientFactory(ctx, t.logger, t.keyring, t.client, factoryCfg) diff --git a/tests/scripts/setup-supernodes.sh b/tests/scripts/setup-supernodes.sh index 197223c3..390933d6 100755 --- a/tests/scripts/setup-supernodes.sh +++ b/tests/scripts/setup-supernodes.sh @@ -189,9 +189,9 @@ usage() { echo " - Sets up both primary and secondary nodes in one command" echo "" echo "Examples:" - echo " $0 primary supernode/main.go tests/system/supernode-data tests/system/config.test-1.yml" - echo " $0 secondary tests/system/supernode-data tests/system/supernode-data2 tests/system/config.test-2.yml tests/system/supernode-data3 tests/system/config.test-3.yml" - echo " $0 all supernode/main.go tests/system/supernode-data tests/system/config.test-1.yml tests/system/supernode-data2 tests/system/config.test-2.yml tests/system/supernode-data3 tests/system/config.test-3.yml" + echo " $0 primary supernode/main.go tests/system/supernode-data1 tests/system/config.test-1.yml" + echo " $0 secondary tests/system/supernode-data1 tests/system/supernode-data2 tests/system/config.test-2.yml tests/system/supernode-data3 tests/system/config.test-3.yml" + echo " $0 all supernode/main.go tests/system/supernode-data1 tests/system/config.test-1.yml tests/system/supernode-data2 tests/system/config.test-2.yml tests/system/supernode-data3 tests/system/config.test-3.yml" exit 1 } diff --git a/tests/system/e2e_cascade_test.go b/tests/system/e2e_cascade_test.go index f8b166e9..6db5ff00 100644 --- a/tests/system/e2e_cascade_test.go +++ b/tests/system/e2e_cascade_test.go @@ -58,11 +58,11 @@ func TestCascadeE2E(t *testing.T) { // Network and service configuration constants const ( - raptorQHost = "localhost" // RaptorQ service host - raptorQPort = 50051 // RaptorQ service port - raptorQFilesDir = "./supernode-data/raptorq_files_test" // Directory for RaptorQ files - lumeraGRPCAddr = "localhost:9090" // Lumera blockchain GRPC address - lumeraChainID = "testing" // Lumera chain ID for testing + raptorQHost = "localhost" // RaptorQ service host + raptorQPort = 50051 // RaptorQ service port + raptorQFilesDir = "./supernode-data1/raptorq_files_test" // Directory for RaptorQ files + lumeraGRPCAddr = "localhost:9090" // Lumera blockchain GRPC address + lumeraChainID = "testing" // Lumera chain ID for testing ) // Action request parameters diff --git a/tests/system/rq-utils.go b/tests/system/supernode-utils.go similarity index 97% rename from tests/system/rq-utils.go rename to tests/system/supernode-utils.go index 6d0e1478..cfb3966a 100644 --- a/tests/system/rq-utils.go +++ b/tests/system/supernode-utils.go @@ -17,7 +17,7 @@ func StartAllSupernodes(t *testing.T) []*exec.Cmd { // Data directories for all three supernodes dataDirs := []string{ - filepath.Join(wd, "supernode-data"), + filepath.Join(wd, "supernode-data1"), filepath.Join(wd, "supernode-data2"), filepath.Join(wd, "supernode-data3"), }