-
Notifications
You must be signed in to change notification settings - Fork 228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bump slinky & forwarding module dependencies #238
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,11 +10,13 @@ | |
"cosmossdk.io/log" | ||
|
||
"github.com/skip-mev/slinky/oracle/config" | ||
slinkygrpc "github.com/skip-mev/slinky/pkg/grpc" | ||
oracleclient "github.com/skip-mev/slinky/service/clients/oracle" | ||
"github.com/skip-mev/slinky/service/metrics" | ||
oracleservertypes "github.com/skip-mev/slinky/service/servers/oracle/types" | ||
|
||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/connectivity" | ||
"google.golang.org/grpc/credentials/insecure" | ||
|
||
l2slinky "github.com/initia-labs/OPinit/x/opchild/l2slinky" | ||
|
@@ -172,10 +174,6 @@ | |
grpc.WithTransportCredentials(insecure.NewCredentials()), | ||
} | ||
|
||
if c.blockingDial { | ||
opts = append(opts, grpc.WithBlock()) | ||
} | ||
|
||
// dial the client, but defer to context closure, if necessary | ||
var ( | ||
conn *grpc.ClientConn | ||
|
@@ -184,7 +182,17 @@ | |
) | ||
go func() { | ||
defer close(done) | ||
conn, err = grpc.DialContext(ctx, c.addr, opts...) | ||
conn, err = slinkygrpc.NewClient(c.addr, opts...) | ||
|
||
// attempt to connect + wait for change in connection state | ||
if c.blockingDial { | ||
// connect | ||
conn.Connect() | ||
|
||
if err == nil { | ||
conn.WaitForStateChange(ctx, connectivity.Ready) | ||
} | ||
} | ||
}() | ||
|
||
// wait for either the context to close or the dial to complete | ||
|
@@ -198,10 +206,61 @@ | |
return fmt.Errorf("failed to dial oracle gRPC server: %w", err) | ||
} | ||
|
||
c.mutex.Lock() | ||
c.client = oracleservertypes.NewOracleClient(conn) | ||
c.conn = conn | ||
c.mutex.Unlock() | ||
|
||
c.logger.Info("oracle client started") | ||
|
||
return nil | ||
} | ||
|
||
func (c *GRPCClient) MarketMap( | ||
ctx context.Context, | ||
req *oracleservertypes.QueryMarketMapRequest, | ||
_ ...grpc.CallOption, | ||
) (res *oracleservertypes.QueryMarketMapResponse, err error) { | ||
c.mutex.Lock() | ||
defer c.mutex.Unlock() | ||
|
||
start := time.Now() | ||
defer func() { | ||
// Observe the duration of the call as well as the error. | ||
c.metrics.ObserveOracleResponseLatency(time.Since(start)) | ||
c.metrics.AddOracleResponse(metrics.StatusFromError(err)) | ||
}() | ||
beer-1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// set deadline on the context | ||
ctx, cancel := context.WithTimeout(ctx, c.timeout) | ||
defer cancel() | ||
|
||
if c.client == nil { | ||
return nil, fmt.Errorf("oracle client not started") | ||
} | ||
|
||
return c.client.MarketMap(ctx, req, grpc.WaitForReady(true)) | ||
} | ||
|
||
// Version returns the version of the oracle service. | ||
func (c *GRPCClient) Version(ctx context.Context, req *oracleservertypes.QueryVersionRequest, _ ...grpc.CallOption) (res *oracleservertypes.QueryVersionResponse, err error) { | ||
c.mutex.Lock() | ||
defer c.mutex.Unlock() | ||
|
||
start := time.Now() | ||
defer func() { | ||
// Observe the duration of the call as well as the error. | ||
c.metrics.ObserveOracleResponseLatency(time.Since(start)) | ||
c.metrics.AddOracleResponse(metrics.StatusFromError(err)) | ||
}() | ||
|
||
// set deadline on the context | ||
ctx, cancel := context.WithTimeout(ctx, c.timeout) | ||
defer cancel() | ||
|
||
if c.client == nil { | ||
return nil, fmt.Errorf("oracle client not started") | ||
} | ||
|
||
return c.client.Version(ctx, req, grpc.WaitForReady(true)) | ||
} | ||
Comment on lines
+246
to
+266
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests for the The Do you want me to generate the unit testing code or open a GitHub issue to track this task? ToolsGitHub Check: codecov/patch
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add tests for the
createConnection
method.The changes to the
createConnection
method are not covered by tests. Ensure that unit tests are added to verify its functionality.Do you want me to generate the unit testing code or open a GitHub issue to track this task?
Tools
GitHub Check: codecov/patch