Skip to content
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

Merged
merged 3 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
57 changes: 41 additions & 16 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ import (
// slinky oracle dependencies
oraclepreblock "github.com/skip-mev/slinky/abci/preblock/oracle"
oracleproposals "github.com/skip-mev/slinky/abci/proposals"
"github.com/skip-mev/slinky/abci/strategies/aggregator"
compression "github.com/skip-mev/slinky/abci/strategies/codec"
"github.com/skip-mev/slinky/abci/strategies/currencypair"
"github.com/skip-mev/slinky/abci/ve"
Expand Down Expand Up @@ -582,6 +583,7 @@ func NewInitiaApp(
runtime.NewKVStoreService(keys[forwardingtypes.StoreKey]),
runtime.NewTransientStoreService(tkeys[forwardingtypes.TransientStoreKey]),
appheaderinfo.NewHeaderInfoService(),
runtime.ProvideEventService(),
authorityAddr,
app.AccountKeeper,
app.BankKeeper,
Expand Down Expand Up @@ -1150,12 +1152,17 @@ func NewInitiaApp(
app.SetPrepareProposal(oracleProposalHandler.PrepareProposalHandler())
app.SetProcessProposal(oracleProposalHandler.ProcessProposalHandler())

// Create the aggregation function that will be used to aggregate oracle data
// from each validator.
aggregatorFn := voteweighted.MedianFromContext(
app.Logger(),
stakingkeeper.NewCompatibilityKeeper(app.StakingKeeper),
voteweighted.DefaultPowerThreshold,
)

app.oraclePreBlockHandler = oraclepreblock.NewOraclePreBlockHandler(
app.Logger(),
voteweighted.MedianFromContext(
app.Logger(),
stakingkeeper.NewCompatibilityKeeper(app.StakingKeeper),
voteweighted.DefaultPowerThreshold),
aggregatorFn,
app.OracleKeeper,
serviceMetrics,
currencypair.NewHashCurrencyPairStrategy(app.OracleKeeper),
Expand All @@ -1169,18 +1176,42 @@ func NewInitiaApp(
),
)

// see app.PreBlocker
// app.SetPreBlocker(oraclePreBlockHandler.WrappedPreBlocker(app.ModuleManager))

// Create the vote extensions handler that will be used to extend and verify
// vote extensions (i.e. oracle data).
cps := currencypair.NewDeltaCurrencyPairStrategy(app.OracleKeeper)
veCodec := compression.NewCompressionVoteExtensionCodec(
compression.NewDefaultVoteExtensionCodec(),
compression.NewZLibCompressor(),
)
extCommitCodec := compression.NewCompressionExtendedCommitCodec(
compression.NewDefaultExtendedCommitCodec(),
compression.NewZStdCompressor(),
)

// Create the vote extensions handler that will be used to extend and verify
// vote extensions (i.e. oracle data).
voteExtensionsHandler := ve.NewVoteExtensionHandler(
app.Logger(),
app.OracleClient,
time.Second,
currencypair.NewHashCurrencyPairStrategy(app.OracleKeeper),
compression.NewCompressionVoteExtensionCodec(
compression.NewDefaultVoteExtensionCodec(),
compression.NewZLibCompressor(),
cps,
veCodec,
aggregator.NewOraclePriceApplier(
aggregator.NewDefaultVoteAggregator(
app.Logger(),
aggregatorFn,
// we need a separate price strategy here, so that we can optimistically apply the latest prices
// and extend our vote based on these prices
currencypair.NewDeltaCurrencyPairStrategy(app.OracleKeeper),
),
app.OracleKeeper,
veCodec,
extCommitCodec,
app.Logger(),
),
app.oraclePreBlockHandler.PreBlocker(),
serviceMetrics,
)
app.SetExtendVoteHandler(voteExtensionsHandler.ExtendVoteHandler())
Expand Down Expand Up @@ -1272,13 +1303,7 @@ func (app *InitiaApp) Name() string { return app.BaseApp.Name() }

// PreBlocker application updates every pre block
func (app *InitiaApp) PreBlocker(ctx sdk.Context, req *abci.RequestFinalizeBlock) (*sdk.ResponsePreBlock, error) {
res, err := app.ModuleManager.PreBlock(ctx)
if err != nil {
return nil, err
}

_, err = app.oraclePreBlockHandler.PreBlocker()(ctx, req)
return res, err
return app.oraclePreBlockHandler.WrappedPreBlocker(app.ModuleManager)(ctx, req)
}

// BeginBlocker application updates every begin block
Expand Down
69 changes: 64 additions & 5 deletions app/oracle/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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)
}

Check warning on line 194 in app/oracle/client.go

View check run for this annotation

Codecov / codecov/patch

app/oracle/client.go#L185-L194

Added lines #L185 - L194 were not covered by tests
}
Comment on lines +185 to +195
Copy link

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

[warning] 185-194: app/oracle/client.go#L185-L194
Added lines #L185 - L194 were not covered by tests

}()

// wait for either the context to close or the dial to complete
Expand All @@ -198,10 +206,61 @@
return fmt.Errorf("failed to dial oracle gRPC server: %w", err)
}

c.mutex.Lock()

Check warning on line 209 in app/oracle/client.go

View check run for this annotation

Codecov / codecov/patch

app/oracle/client.go#L209

Added line #L209 was not covered by tests
c.client = oracleservertypes.NewOracleClient(conn)
c.conn = conn
c.mutex.Unlock()

Check warning on line 212 in app/oracle/client.go

View check run for this annotation

Codecov / codecov/patch

app/oracle/client.go#L212

Added line #L212 was not covered by tests

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))
}()

Check warning on line 232 in app/oracle/client.go

View check run for this annotation

Codecov / codecov/patch

app/oracle/client.go#L223-L232

Added lines #L223 - L232 were not covered by tests

// 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")
}

Check warning on line 240 in app/oracle/client.go

View check run for this annotation

Codecov / codecov/patch

app/oracle/client.go#L235-L240

Added lines #L235 - L240 were not covered by tests

return c.client.MarketMap(ctx, req, grpc.WaitForReady(true))

Check warning on line 242 in app/oracle/client.go

View check run for this annotation

Codecov / codecov/patch

app/oracle/client.go#L242

Added line #L242 was not covered by tests
}

// 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))
}()

Check warning on line 255 in app/oracle/client.go

View check run for this annotation

Codecov / codecov/patch

app/oracle/client.go#L246-L255

Added lines #L246 - L255 were not covered by tests

// 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")
}

Check warning on line 263 in app/oracle/client.go

View check run for this annotation

Codecov / codecov/patch

app/oracle/client.go#L258-L263

Added lines #L258 - L263 were not covered by tests

return c.client.Version(ctx, req, grpc.WaitForReady(true))

Check warning on line 265 in app/oracle/client.go

View check run for this annotation

Codecov / codecov/patch

app/oracle/client.go#L265

Added line #L265 was not covered by tests
}
Comment on lines +246 to +266
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add tests for the Version method.

The Version method is 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

[warning] 246-255: app/oracle/client.go#L246-L255
Added lines #L246 - L255 were not covered by tests


[warning] 258-263: app/oracle/client.go#L258-L263
Added lines #L258 - L263 were not covered by tests


[warning] 265-265: app/oracle/client.go#L265
Added line #L265 was not covered by tests

Loading
Loading