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 Nov 21, 2024
1 parent fea251a commit fe82924
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 48 deletions.
12 changes: 7 additions & 5 deletions api/grpc/relay/relay.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions relay/auth/authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ type RequestAuthenticator interface {
origin string,
request *pb.GetChunksRequest,
now time.Time) error

// PreloadCache preloads the key cache with the public keys of all operators that are currently indexed.
PreloadCache() error
}

// authenticationTimeout is used to track the expiration of an auth.
Expand Down Expand Up @@ -65,16 +62,23 @@ func NewRequestAuthenticator(
return nil, fmt.Errorf("failed to create key cache: %w", err)
}

return &requestAuthenticator{
authenticator := &requestAuthenticator{
ics: ics,
authenticatedClients: make(map[string]struct{}),
authenticationTimeouts: make([]*authenticationTimeout, 0),
authenticationTimeoutDuration: authenticationTimeoutDuration,
keyCache: keyCache,
}, nil
}

err = authenticator.preloadCache()
if err != nil {
return nil, fmt.Errorf("failed to preload cache: %w", err)
}

return authenticator, nil
}

func (a *requestAuthenticator) PreloadCache() error {
func (a *requestAuthenticator) preloadCache() error {
blockNumber, err := a.ics.GetCurrentBlockNumber()
if err != nil {
return fmt.Errorf("failed to get current block number: %w", err)
Expand Down
8 changes: 4 additions & 4 deletions relay/auth/authenticator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func TestValidRequest(t *testing.T) {
}
ics, err := mock.NewChainDataMock(stakes)
require.NoError(t, err)
ics.Mock.On("GetCurrentBlockNumber").Return(uint(0), nil)

timeout := 10 * time.Second

Expand All @@ -67,7 +68,6 @@ func TestValidRequest(t *testing.T) {

now := time.Now()

ics.Mock.On("GetCurrentBlockNumber").Return(uint(0), nil)
err = authenticator.AuthenticateGetChunksRequest(
"foobar",
request,
Expand Down Expand Up @@ -116,6 +116,7 @@ func TestAuthenticationSavingDisabled(t *testing.T) {
}
ics, err := mock.NewChainDataMock(stakes)
require.NoError(t, err)
ics.Mock.On("GetCurrentBlockNumber").Return(uint(0), nil)

// This disables saving of authentication results.
timeout := time.Duration(0)
Expand All @@ -130,7 +131,6 @@ func TestAuthenticationSavingDisabled(t *testing.T) {

now := time.Now()

ics.Mock.On("GetCurrentBlockNumber").Return(uint(0), nil)
err = authenticator.AuthenticateGetChunksRequest(
"foobar",
request,
Expand Down Expand Up @@ -161,6 +161,7 @@ func TestNonExistingClient(t *testing.T) {
}
ics, err := mock.NewChainDataMock(stakes)
require.NoError(t, err)
ics.Mock.On("GetCurrentBlockNumber").Return(uint(0), nil)

timeout := 10 * time.Second

Expand All @@ -172,7 +173,6 @@ func TestNonExistingClient(t *testing.T) {
request := randomGetChunksRequest()
request.OperatorId = invalidOperatorID

ics.Mock.On("GetCurrentBlockNumber").Return(uint(0), nil)
err = authenticator.AuthenticateGetChunksRequest(
"foobar",
request,
Expand All @@ -191,6 +191,7 @@ func TestBadSignature(t *testing.T) {
}
ics, err := mock.NewChainDataMock(stakes)
require.NoError(t, err)
ics.Mock.On("GetCurrentBlockNumber").Return(uint(0), nil)

timeout := 10 * time.Second

Expand All @@ -203,7 +204,6 @@ func TestBadSignature(t *testing.T) {

now := time.Now()

ics.Mock.On("GetCurrentBlockNumber").Return(uint(0), nil)
err = authenticator.AuthenticateGetChunksRequest(
"foobar",
request,
Expand Down
7 changes: 4 additions & 3 deletions relay/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"github.com/Layr-Labs/eigenda/common"
"github.com/Layr-Labs/eigenda/common/aws"
"github.com/Layr-Labs/eigenda/common/geth"
"github.com/Layr-Labs/eigenda/core/thegraph"
core "github.com/Layr-Labs/eigenda/core/v2"
"github.com/Layr-Labs/eigenda/relay"
"github.com/Layr-Labs/eigenda/relay/cmd/flags"
"github.com/Layr-Labs/eigenda/relay/limiter"
"github.com/urfave/cli"
"time"
)

// Config is the configuration for the relay Server.
Expand All @@ -31,10 +31,11 @@ type Config struct {
// RelayConfig is the configuration for the relay.
RelayConfig relay.Config

// Configuration for the graph indexer.
EthClientConfig geth.EthClientConfig
IndexerPullInterval time.Duration
BLSOperatorStateRetrieverAddr string
EigenDAServiceManagerAddr string
ChainStateConfig thegraph.Config
}

func NewConfig(ctx *cli.Context) (Config, error) {
Expand Down Expand Up @@ -84,9 +85,9 @@ func NewConfig(ctx *cli.Context) (Config, error) {
AuthenticationDisabled: ctx.Bool(flags.AuthenticationDisabledFlag.Name),
},
EthClientConfig: geth.ReadEthClientConfig(ctx),
IndexerPullInterval: ctx.Duration(flags.IndexerPullIntervalFlag.Name),
BLSOperatorStateRetrieverAddr: ctx.String(flags.BlsOperatorStateRetrieverAddrFlag.Name),
EigenDAServiceManagerAddr: ctx.String(flags.EigenDAServiceManagerAddrFlag.Name),
ChainStateConfig: thegraph.ReadCLIConfig(ctx),
}
for i, id := range relayIDs {
config.RelayConfig.RelayIDs[i] = core.RelayKey(id)
Expand Down
27 changes: 2 additions & 25 deletions relay/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import (
"github.com/Layr-Labs/eigenda/common/geth"
"github.com/Layr-Labs/eigenda/core"
coreeth "github.com/Layr-Labs/eigenda/core/eth"
coreindexer "github.com/Layr-Labs/eigenda/core/indexer"
"github.com/Layr-Labs/eigenda/indexer"
"github.com/Layr-Labs/eigenda/core/thegraph"
"github.com/Layr-Labs/eigensdk-go/logging"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/rpc"
"log"
"os"

Expand Down Expand Up @@ -98,11 +96,6 @@ func RunRelay(ctx *cli.Context) error {
}

func buildICS(logger logging.Logger, config *Config) (core.IndexedChainState, error) {
rpcClient, err := rpc.Dial(config.EthClientConfig.RPCURLs[0])
if err != nil {
return nil, fmt.Errorf("failed to create rpc client: %w", err)
}

client, err := geth.NewMultiHomingClient(config.EthClientConfig, gethcommon.Address{}, logger)
if err != nil {
logger.Error("Cannot create chain.Client", "err", err)
Expand All @@ -114,24 +107,8 @@ func buildICS(logger logging.Logger, config *Config) (core.IndexedChainState, er
return nil, fmt.Errorf("failed to create eth writer: %w", err)
}

idx, err := coreindexer.CreateNewIndexer(
&indexer.Config{
PullInterval: config.IndexerPullInterval,
},
client,
rpcClient,
config.EigenDAServiceManagerAddr,
logger,
)
if err != nil {
return nil, fmt.Errorf("failed to create indexer: %w", err)
}

cs := coreeth.NewChainState(tx, client)
ics, err := coreindexer.NewIndexedChainState(cs, idx)
if err != nil {
return nil, fmt.Errorf("failed to create indexed chain state: %w", err)
}
ics := thegraph.MakeIndexedChainState(config.ChainStateConfig, cs, logger)

return ics, nil
}
5 changes: 0 additions & 5 deletions relay/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,6 @@ func NewServer(
if err != nil {
return nil, fmt.Errorf("error creating authenticator: %w", err)
}

err = authenticator.PreloadCache()
if err != nil {
return nil, fmt.Errorf("error preloading operator key cache: %w", err)
}
}

return &Server{
Expand Down

0 comments on commit fe82924

Please sign in to comment.