Skip to content

Commit

Permalink
Add preloading of keys.
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 20, 2024
1 parent 97cc318 commit fea251a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
20 changes: 20 additions & 0 deletions relay/auth/authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ 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 @@ -71,6 +74,23 @@ func NewRequestAuthenticator(
}, nil
}

func (a *requestAuthenticator) PreloadCache() error {
blockNumber, err := a.ics.GetCurrentBlockNumber()
if err != nil {
return fmt.Errorf("failed to get current block number: %w", err)
}
operators, err := a.ics.GetIndexedOperators(context.Background(), blockNumber)
if err != nil {
return fmt.Errorf("failed to get operators: %w", err)
}

for operatorID, operator := range operators {
a.keyCache.Add(operatorID, operator.PubkeyG2)
}

return nil
}

func (a *requestAuthenticator) AuthenticateGetChunksRequest(
origin string,
request *pb.GetChunksRequest,
Expand Down
5 changes: 5 additions & 0 deletions relay/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ 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 fea251a

Please sign in to comment.