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
8 changes: 1 addition & 7 deletions pkg/lumera/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,7 @@ type lumeraClient struct {
}

// newClient creates a new Lumera client with provided options
func newClient(ctx context.Context, opts ...Option) (Client, error) {
cfg := DefaultConfig()

// Apply all options
for _, opt := range opts {
opt(cfg)
}
func newClient(ctx context.Context, cfg *Config) (Client, error) {

// Create a single gRPC connection to be shared by all modules
conn, err := newGRPCConnection(ctx, cfg.GRPCAddr)
Expand Down
32 changes: 21 additions & 11 deletions pkg/lumera/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package lumera

import (
"time"
"fmt"

"github.com/cosmos/cosmos-sdk/crypto/keyring"
)
Expand All @@ -14,22 +14,32 @@ type Config struct {
// ChainID is the ID of the chain
ChainID string

// Timeout is the default request timeout
Timeout time.Duration

// keyring is the keyring conf for the node sign & verify
keyring keyring.Keyring

// KeyName is the name of the key to use for signing
KeyName string
}

// DefaultConfig returns a default configuration
func DefaultConfig() *Config {
return &Config{
GRPCAddr: "localhost:9090",
ChainID: "lumera",
Timeout: 30,
KeyName: "",
func NewConfig(grpcAddr, chainID string, keyName string, keyring keyring.Keyring) (*Config, error) {

if grpcAddr == "" {
return nil, fmt.Errorf("grpcAddr cannot be empty")
}
if chainID == "" {
return nil, fmt.Errorf("chainID cannot be empty")
}
if keyring == nil {
return nil, fmt.Errorf("keyring cannot be nil")
}
if keyName == "" {
return nil, fmt.Errorf("keyName cannot be empty")
}

return &Config{
GRPCAddr: grpcAddr,
ChainID: chainID,
keyring: keyring,
KeyName: keyName,
}, nil
}
4 changes: 3 additions & 1 deletion pkg/lumera/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"google.golang.org/grpc/credentials/insecure"
)

const DefaultTimeout = 30 * time.Second

// Connection defines the interface for a client connection
type Connection interface {
Close() error
Expand All @@ -22,7 +24,7 @@ type grpcConnection struct {

// newGRPCConnection creates a new gRPC connection
func newGRPCConnection(ctx context.Context, addr string) (Connection, error) {
dialCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
dialCtx, cancel := context.WithTimeout(ctx, DefaultTimeout)
defer cancel()

// Note: Cosmos SDK doesn't support TLS for gRPC so we use insecure credentials
Expand Down
4 changes: 2 additions & 2 deletions pkg/lumera/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ type Client interface {
}

// NewClient creates a new Lumera client with provided options
func NewClient(ctx context.Context, opts ...Option) (Client, error) {
return newClient(ctx, opts...)
func NewClient(ctx context.Context, config *Config) (Client, error) {
return newClient(ctx, config)
}
45 changes: 0 additions & 45 deletions pkg/lumera/options.go

This file was deleted.

36 changes: 7 additions & 29 deletions sdk/adapters/lumera/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package lumera
import (
"context"
"fmt"
"time"

"github.com/LumeraProtocol/supernode/sdk/log"

Expand All @@ -27,8 +26,8 @@ type Client interface {
type ConfigParams struct {
GRPCAddr string
ChainID string
Timeout time.Duration
KeyName string
Keyring keyring.Keyring
}

type Adapter struct {
Expand All @@ -37,40 +36,19 @@ type Adapter struct {
}

// NewAdapter creates a new Adapter with dependencies explicitly injected
func NewAdapter(ctx context.Context, config ConfigParams, kr keyring.Keyring, logger log.Logger) (Client, error) {
func NewAdapter(ctx context.Context, config ConfigParams, logger log.Logger) (Client, error) {
// Set default logger if nil
if logger == nil {
logger = log.NewNoopLogger()
}

logger.Debug(ctx, "Creating Lumera adapter",
"grpcAddr", config.GRPCAddr,
"chainID", config.ChainID,
"timeout", config.Timeout)

// Create client options from the config
options := []lumeraclient.Option{
lumeraclient.WithGRPCAddr(config.GRPCAddr),
}

if config.ChainID != "" {
options = append(options, lumeraclient.WithChainID(config.ChainID))
}

if config.Timeout > 0 {
options = append(options, lumeraclient.WithTimeout(config.Timeout))
}

if kr != nil {
options = append(options, lumeraclient.WithKeyring(kr))
}

if config.KeyName != "" {
options = append(options, lumeraclient.WithKeyName(config.KeyName))
lumeraConfig, err := lumeraclient.NewConfig(config.GRPCAddr, config.ChainID, config.KeyName, config.Keyring)
if err != nil {
logger.Error(ctx, "Failed to create Lumera config", "error", err)
return nil, fmt.Errorf("failed to create Lumera config: %w", err)
}

// Initialize the client
client, err := lumeraclient.NewClient(ctx, options...)
client, err := lumeraclient.NewClient(ctx, lumeraConfig)
if err != nil {
logger.Error(ctx, "Failed to initialize Lumera client", "error", err)
return nil, fmt.Errorf("failed to initialize Lumera client: %w", err)
Expand Down
3 changes: 1 addition & 2 deletions sdk/task/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ func NewManager(ctx context.Context, config config.Config, logger log.Logger, kr
lumera.ConfigParams{
GRPCAddr: config.Lumera.GRPCAddr,
ChainID: config.Lumera.ChainID,
Timeout: config.Lumera.Timeout,
KeyName: config.Lumera.KeyName,
Keyring: kr,
},
kr,
logger)

if err != nil {
Expand Down
17 changes: 5 additions & 12 deletions supernode/cmd/supernode.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"os"
"time"

"github.com/LumeraProtocol/supernode/p2p"
"github.com/LumeraProtocol/supernode/pkg/logtrace"
Expand Down Expand Up @@ -132,19 +131,13 @@ func initLumeraClient(ctx context.Context, config *config.Config, kr keyring.Key
return nil, fmt.Errorf("config is nil")
}

logtrace.Info(ctx, "Initializing Lumera client", logtrace.Fields{
"grpc_addr": config.LumeraClientConfig.GRPCAddr,
"chain_id": config.LumeraClientConfig.ChainID,
"timeout": config.LumeraClientConfig.Timeout,
})

lumeraConfig, err := lumera.NewConfig(config.LumeraClientConfig.GRPCAddr, config.LumeraClientConfig.ChainID, config.SupernodeConfig.KeyName, kr)
if err != nil {
return nil, fmt.Errorf("failed to create Lumera config: %w", err)
}
return lumera.NewClient(
ctx,
lumera.WithGRPCAddr(config.LumeraClientConfig.GRPCAddr),
lumera.WithChainID(config.LumeraClientConfig.ChainID),
lumera.WithTimeout(time.Duration(config.LumeraClientConfig.Timeout)*time.Second),
lumera.WithKeyring(kr),
lumera.WithKeyName(config.SupernodeConfig.KeyName),
lumeraConfig,
)
}

Expand Down