Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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 .
82 changes: 12 additions & 70 deletions sdk/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 == "":
Expand All @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion sdk/net/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
21 changes: 10 additions & 11 deletions sdk/net/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(&ltc.ClientOptions{
CommonOptions: ltc.CommonOptions{
Keyring: keyring,
LocalIdentity: localCosmosAddress,
PeerType: securekeyx.Supernode,
LocalIdentity: factoryConfig.LocalCosmosAddress,
PeerType: factoryConfig.PeerType,
Validator: lumeraClient,
},
})
Expand All @@ -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
Expand All @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions sdk/task/cascade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand All @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions tests/scripts/setup-supernodes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
10 changes: 5 additions & 5 deletions tests/system/e2e_cascade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
Expand Down