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

Change PluginMedian Interface #166

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/smartcontractkit/libocr => github.com/augustbleeds/libocr v0.0.0-20240222154448-6050883e1800

replace (
// until merged upstream: https://github.com/hashicorp/go-plugin/pull/257
github.com/hashicorp/go-plugin => github.com/smartcontractkit/go-plugin v0.0.0-20240208201424-b3b91517de16
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/Microsoft/hcsshim v0.9.4 h1:mnUj0ivWy6UzbB1uLFqKR6F+ZyiDc7j4iGgHTpO+5+I=
github.com/Microsoft/hcsshim v0.9.4/go.mod h1:7pLA8lDk46WKDWlVsENo92gC0XFa8rbKfyFRBqxEbCc=
github.com/augustbleeds/libocr v0.0.0-20240222154448-6050883e1800 h1:eXMkGNE9kfAYyAEBlzjL53ax4klanSS+v4zOhNfuE2M=
github.com/augustbleeds/libocr v0.0.0-20240222154448-6050883e1800/go.mod h1:kC0qmVPUaVkFqGiZMNhmRmjdphuUmeyLEdlWFOQzFWI=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
Expand Down Expand Up @@ -272,8 +274,6 @@ github.com/smartcontractkit/go-plugin v0.0.0-20240208201424-b3b91517de16 h1:TFe+
github.com/smartcontractkit/go-plugin v0.0.0-20240208201424-b3b91517de16/go.mod h1:lBS5MtSSBZk0SHc66KACcjjlU6WzEVP/8pwz68aMkCI=
github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f h1:hgJif132UCdjo8u43i7iPN1/MFnu49hv7lFGFftCHKU=
github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f/go.mod h1:MvMXoufZAtqExNexqi4cjrNYE9MefKddKylxjS+//n0=
github.com/smartcontractkit/libocr v0.0.0-20240112202000-6359502d2ff1 h1:3y9WsXkZ5lxFrmfH7DQHs/q308lylKId5l/3VC0QAdM=
github.com/smartcontractkit/libocr v0.0.0-20240112202000-6359502d2ff1/go.mod h1:kC0qmVPUaVkFqGiZMNhmRmjdphuUmeyLEdlWFOQzFWI=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
Expand Down
28 changes: 23 additions & 5 deletions pkg/loop/internal/median.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewPluginMedianClient(broker Broker, brokerCfg BrokerConfig, conn *grpc.Cli
return &PluginMedianClient{PluginClient: pc, median: pb.NewPluginMedianClient(pc), ServiceClient: NewServiceClient(pc.BrokerExt, pc)}
}

func (m *PluginMedianClient) NewMedianFactory(ctx context.Context, provider types.MedianProvider, dataSource, juelsPerFeeCoin median.DataSource, errorLog types.ErrorLog) (types.ReportingPluginFactory, error) {
func (m *PluginMedianClient) NewMedianFactory(ctx context.Context, provider types.MedianProvider, dataSource, juelsPerFeeCoin, gasPrice median.DataSource, errorLog types.ErrorLog) (types.ReportingPluginFactory, error) {
cc := m.NewClientConn("MedianPluginFactory", func(ctx context.Context) (id uint32, deps Resources, err error) {
dataSourceID, dsRes, err := m.ServeNew("DataSource", func(s *grpc.Server) {
pb.RegisterDataSourceServer(s, median_internal.NewDataSourceServer(dataSource))
Expand All @@ -56,6 +56,14 @@ func (m *PluginMedianClient) NewMedianFactory(ctx context.Context, provider type
}
deps.Add(juelsPerFeeCoinDataSourceRes)

gasPriceDataSourceID, gasPriceDataSourceRes, err := m.ServeNew("GasPriceDataSource", func(s *grpc.Server) {
pb.RegisterDataSourceServer(s, median_internal.NewDataSourceServer(gasPrice))
})
if err != nil {
return 0, nil, err
}
deps.Add(gasPriceDataSourceRes)

var (
providerID uint32
providerRes Resource
Expand Down Expand Up @@ -98,6 +106,7 @@ func (m *PluginMedianClient) NewMedianFactory(ctx context.Context, provider type
MedianProviderID: providerID,
DataSourceID: dataSourceID,
JuelsPerFeeCoinDataSourceID: juelsPerFeeCoinDataSourceID,
GasPriceDataSourceID: gasPriceDataSourceID,
ErrorLogID: errorLogID,
})
if err != nil {
Expand Down Expand Up @@ -142,25 +151,33 @@ func (m *pluginMedianServer) NewMedianFactory(ctx context.Context, request *pb.N
juelsRes := Resource{juelsConn, "JuelsPerFeeCoinDataSource"}
juelsPerFeeCoin := median_internal.NewDataSourceClient(juelsConn)

providerConn, err := m.Dial(request.MedianProviderID)
gasPriceConn, err := m.Dial(request.GasPriceDataSourceID)
if err != nil {
m.CloseAll(dsRes, juelsRes)
return nil, ErrConnDial{Name: "GasPriceDataSource", ID: request.GasPriceDataSourceID, Err: err}
}
gasPriceRes := Resource{gasPriceConn, "GasPriceDataSource"}
gasPrice := median_internal.NewDataSourceClient(gasPriceConn)

providerConn, err := m.Dial(request.MedianProviderID)
if err != nil {
m.CloseAll(dsRes, juelsRes, gasPriceRes)
return nil, ErrConnDial{Name: "MedianProvider", ID: request.MedianProviderID, Err: err}
}
providerRes := Resource{providerConn, "MedianProvider"}
provider := newMedianProviderClient(m.BrokerExt, providerConn)

errorLogConn, err := m.Dial(request.ErrorLogID)
if err != nil {
m.CloseAll(dsRes, juelsRes, providerRes)
m.CloseAll(dsRes, juelsRes, gasPriceRes, providerRes)
return nil, ErrConnDial{Name: "ErrorLog", ID: request.ErrorLogID, Err: err}
}
errorLogRes := Resource{errorLogConn, "ErrorLog"}
errorLog := NewErrorLogClient(errorLogConn)

factory, err := m.impl.NewMedianFactory(ctx, provider, dataSource, juelsPerFeeCoin, errorLog)
factory, err := m.impl.NewMedianFactory(ctx, provider, dataSource, juelsPerFeeCoin, gasPrice, errorLog)
if err != nil {
m.CloseAll(dsRes, juelsRes, providerRes, errorLogRes)
m.CloseAll(dsRes, juelsRes, gasPriceRes, providerRes, errorLogRes)
return nil, err
}

Expand Down Expand Up @@ -251,6 +268,7 @@ func (r *reportCodecClient) BuildReport(observations []median.ParsedAttributedOb
Value: pb.NewBigIntFromInt(o.Value),
JulesPerFeeCoin: pb.NewBigIntFromInt(o.JuelsPerFeeCoin),
Observer: uint32(o.Observer),
GasPrice: pb.NewBigIntFromInt(o.GasPrice),
})
}
var reply *pb.BuildReportReply
Expand Down
3 changes: 3 additions & 0 deletions pkg/loop/internal/median/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ func (d *DataSourceClient) Observe(ctx context.Context, timestamp types.ReportTi
reply, err := d.grpc.Observe(ctx, &pb.ObserveRequest{
ReportTimestamp: pb.ReportTimestampToPb(timestamp),
})

if err != nil {
return nil, err
}

return reply.Value.Int(), nil
}

Expand All @@ -50,6 +52,7 @@ func (d *DataSourceServer) Observe(ctx context.Context, request *pb.ObserveReque
return nil, err
}
val, err := d.impl.Observe(ctx, timestamp)

if err != nil {
return nil, err
}
Expand Down
Loading
Loading