-
Notifications
You must be signed in to change notification settings - Fork 16
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
Changes from 6 commits
f56670e
3e033ff
f8416cd
c988207
c7bc6d8
0aa1d2d
7e621d3
e51f862
c604ab9
852340c
cde3993
02e97ec
0837829
7c8f64f
cb35a68
1e2185e
d57e9a8
c9277a3
3220036
9346ac9
b6579c9
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 |
---|---|---|
|
@@ -141,8 +141,10 @@ func (b *brokerExt) serve(name string, server *grpc.Server, deps ...resource) (u | |
|
||
func (b *brokerExt) closeAll(deps ...resource) { | ||
for _, d := range deps { | ||
if err := d.Close(); err != nil { | ||
b.Logger.Error(fmt.Sprintf("Error closing %s", d.name), "err", err) | ||
if d.Closer != nil { | ||
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. handle case when the resource is declared but not initialized 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. 🤔 This doesn't feel like it should be necessary, and I wonder if this will hide incorrect instantiations in the future. How come you had to add this? 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. |
||
if err := d.Close(); err != nil { | ||
b.Logger.Error(fmt.Sprintf("Error closing %s", d.name), "err", err) | ||
} | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,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, &dataSourceServer{impl: dataSource}) | ||
|
@@ -53,6 +53,18 @@ func (m *PluginMedianClient) NewMedianFactory(ctx context.Context, provider type | |
} | ||
deps.Add(juelsPerFeeCoinDataSourceRes) | ||
|
||
var gasPriceDataSourceID uint32 | ||
if gasPrice != nil { | ||
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. gasPrice may be nil if none is required for the chain |
||
var gasPriceDataSourceRes resource | ||
gasPriceDataSourceID, gasPriceDataSourceRes, err = m.serveNew("GasPriceDataSource", func(s *grpc.Server) { | ||
pb.RegisterDataSourceServer(s, &dataSourceServer{impl: gasPrice}) | ||
}) | ||
if err != nil { | ||
return 0, nil, err | ||
} | ||
deps.Add(gasPriceDataSourceRes) | ||
} | ||
|
||
var ( | ||
providerID uint32 | ||
providerRes resource | ||
|
@@ -87,6 +99,7 @@ func (m *PluginMedianClient) NewMedianFactory(ctx context.Context, provider type | |
MedianProviderID: providerID, | ||
DataSourceID: dataSourceID, | ||
JuelsPerFeeCoinDataSourceID: juelsPerFeeCoinDataSourceID, | ||
GasPriceDataSourceID: gasPriceDataSourceID, | ||
ErrorLogID: errorLogID, | ||
}) | ||
if err != nil { | ||
|
@@ -131,25 +144,37 @@ func (m *pluginMedianServer) NewMedianFactory(ctx context.Context, request *pb.N | |
juelsRes := resource{juelsConn, "JuelsPerFeeCoinDataSource"} | ||
juelsPerFeeCoin := newDataSourceClient(juelsConn) | ||
|
||
var gasPriceRes resource | ||
var gasPrice *dataSourceClient | ||
if request.GasPriceDataSourceID != 0 { | ||
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 = newDataSourceClient(gasPriceConn) | ||
} | ||
|
||
providerConn, err := m.dial(request.MedianProviderID) | ||
if err != nil { | ||
m.closeAll(dsRes, juelsRes) | ||
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 | ||
} | ||
|
||
|
@@ -222,6 +247,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 | ||
|
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.
temp change: will get removed and bumped when libocr gets updated