Skip to content

Commit

Permalink
Made suggested changes.
Browse files Browse the repository at this point in the history
Signed-off-by: Cody Littley <[email protected]>
  • Loading branch information
cody-littley committed Dec 20, 2024
1 parent 20216c4 commit 3c325ef
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 21 deletions.
6 changes: 3 additions & 3 deletions api/clients/mock/static_request_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import (
"github.com/Layr-Labs/eigenda/node/auth"
)

var _ clients.RequestSigner = &staticRequestSigner{}
var _ clients.DispersalRequestSigner = &staticRequestSigner{}

// StaticRequestSigner is a RequestSigner that signs requests with a static key (i.e. it doesn't use AWS KMS).
// StaticRequestSigner is a DispersalRequestSigner that signs requests with a static key (i.e. it doesn't use AWS KMS).
// Useful for testing.
type staticRequestSigner struct {
key *ecdsa.PrivateKey
}

func NewStaticRequestSigner(key *ecdsa.PrivateKey) clients.RequestSigner {
func NewStaticRequestSigner(key *ecdsa.PrivateKey) clients.DispersalRequestSigner {
return &staticRequestSigner{
key: key,
}
Expand Down
7 changes: 4 additions & 3 deletions api/clients/v2/node_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package clients
import (
"context"
"fmt"
"github.com/Layr-Labs/eigenda/node/auth"
"sync"

commonpb "github.com/Layr-Labs/eigenda/api/grpc/common/v2"
Expand All @@ -27,14 +28,14 @@ type nodeClient struct {
config *NodeClientConfig
initOnce sync.Once
conn *grpc.ClientConn
requestSigner RequestSigner
requestSigner DispersalRequestSigner

dispersalClient nodegrpc.DispersalClient
}

var _ NodeClient = (*nodeClient)(nil)

func NewNodeClient(config *NodeClientConfig, requestSigner RequestSigner) (NodeClient, error) {
func NewNodeClient(config *NodeClientConfig, requestSigner DispersalRequestSigner) (NodeClient, error) {
if config == nil || config.Hostname == "" || config.Port == "" {
return nil, fmt.Errorf("invalid config: %v", config)
}
Expand Down Expand Up @@ -70,7 +71,7 @@ func (c *nodeClient) StoreChunks(ctx context.Context, batch *corev2.Batch) (*cor
},
BlobCertificates: blobCerts,
},
DisperserID: 0, // this will need to be updated dispersers are decentralized
DisperserID: auth.EigenLabsDisperserID, // this will need to be updated when dispersers are decentralized
}

if c.requestSigner != nil {
Expand Down
12 changes: 6 additions & 6 deletions api/clients/v2/request_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ import (
"github.com/aws/aws-sdk-go-v2/service/kms"
)

// RequestSigner encapsulates the logic for signing GetChunks requests.
type RequestSigner interface {
// DispersalRequestSigner encapsulates the logic for signing GetChunks requests.
type DispersalRequestSigner interface {
// SignStoreChunksRequest signs a StoreChunksRequest. Does not modify the request
// (i.e. it does not insert the signature).
SignStoreChunksRequest(ctx context.Context, request *grpc.StoreChunksRequest) ([]byte, error)
}

var _ RequestSigner = &requestSigner{}
var _ DispersalRequestSigner = &requestSigner{}

type requestSigner struct {
keyID string
publicKey *ecdsa.PublicKey
keyManager *kms.Client
}

// NewRequestSigner creates a new RequestSigner.
func NewRequestSigner(
// NewDispersalRequestSigner creates a new DispersalRequestSigner.
func NewDispersalRequestSigner(
ctx context.Context,
region string,
endpoint string,
keyID string) (RequestSigner, error) {
keyID string) (DispersalRequestSigner, error) {

keyManager := kms.New(kms.Options{
Region: region,
Expand Down
2 changes: 1 addition & 1 deletion api/clients/v2/request_signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestRequestSigning(t *testing.T) {
request := auth.RandomStoreChunksRequest(rand)
request.Signature = nil

signer, err := NewRequestSigner(context.Background(), region, localstackHost, keyID)
signer, err := NewDispersalRequestSigner(context.Background(), region, localstackHost, keyID)
require.NoError(t, err)

// Test a valid signature.
Expand Down
6 changes: 5 additions & 1 deletion core/eth/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -948,8 +948,12 @@ func (t *Reader) GetDisperserAddress(ctx context.Context, disperserID uint32) (g
},
disperserID)

var defaultAddress gethcommon.Address
if err != nil {
return gethcommon.Address{}, fmt.Errorf("failed to get disperser address: %w", err)
return defaultAddress, fmt.Errorf("failed to get disperser address: %w", err)
}
if address == defaultAddress {
return defaultAddress, fmt.Errorf("disperser with id %d not found", disperserID)
}

return address, nil
Expand Down
3 changes: 3 additions & 0 deletions disperser/cmd/controller/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,8 @@ func NewConfig(ctx *cli.Context) (Config, error) {
EigenDAServiceManagerAddr: ctx.GlobalString(flags.EigenDAServiceManagerFlag.Name),
MetricsPort: ctx.GlobalInt(flags.MetricsPortFlag.Name),
}
if !config.DisperserStoreChunksSigningDisabled && config.DisperserKMSKeyID == "" {
return Config{}, fmt.Errorf("DisperserKMSKeyID is required when StoreChunks() signing is enabled")
}
return config, nil
}
8 changes: 5 additions & 3 deletions disperser/cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,11 @@ func RunController(ctx *cli.Context) error {
}
}

var requestSigner clients.RequestSigner
if !config.DisperserStoreChunksSigningDisabled {
requestSigner, err = clients.NewRequestSigner(
var requestSigner clients.DispersalRequestSigner
if config.DisperserStoreChunksSigningDisabled {
logger.Warn("StoreChunks() signing is disabled")
} else {
requestSigner, err = clients.NewDispersalRequestSigner(
context.Background(),
config.AwsClientConfig.Region,
config.AwsClientConfig.EndpointURL,
Expand Down
4 changes: 2 additions & 2 deletions disperser/controller/node_client_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ type NodeClientManager interface {
type nodeClientManager struct {
// nodeClients is a cache of node clients keyed by socket address
nodeClients *lru.Cache[string, clients.NodeClient]
requestSigner clients.RequestSigner
requestSigner clients.DispersalRequestSigner
logger logging.Logger
}

var _ NodeClientManager = (*nodeClientManager)(nil)

func NewNodeClientManager(
cacheSize int,
requestSigner clients.RequestSigner,
requestSigner clients.DispersalRequestSigner,
logger logging.Logger) (NodeClientManager, error) {

closeClient := func(socket string, value clients.NodeClient) {
Expand Down
2 changes: 1 addition & 1 deletion node/auth/authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func NewRequestAuthenticator(

func (a *requestAuthenticator) preloadCache(ctx context.Context, now time.Time) error {
// this will need to be updated for decentralized dispersers
_, err := a.getDisperserKey(ctx, now, 0)
_, err := a.getDisperserKey(ctx, now, EigenLabsDisperserID)
if err != nil {
return fmt.Errorf("failed to get operator key: %w", err)
}
Expand Down
3 changes: 3 additions & 0 deletions node/auth/request_signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import (
"hash"
)

// EigenLabsDisperserID is the ID of the disperser that is managed by Eigen Labs.
const EigenLabsDisperserID = 0

// SignStoreChunksRequest signs the given StoreChunksRequest with the given private key. Does not
// write the signature into the request.
func SignStoreChunksRequest(key *ecdsa.PrivateKey, request *grpc.StoreChunksRequest) ([]byte, error) {
Expand Down
2 changes: 1 addition & 1 deletion node/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ var (
Usage: "The duration for which a disperser authentication is valid",
Required: false,
EnvVar: common.PrefixEnvVar(EnvVarPrefix, "DISPERSAL_AUTHENTICATION_TIMEOUT"),
Value: 5 * time.Minute,
Value: time.Minute,
}

// Test only, DO NOT USE the following flags in production
Expand Down

0 comments on commit 3c325ef

Please sign in to comment.