-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[BCI-3989][core] - CR methods err when service unstarted #14123
Changes from 28 commits
111057c
6f8ed23
0074a33
2132bf0
53adad8
bf588c7
2cce774
e8b366e
7fa91e6
ed83615
fa2d416
4b2e503
7184150
1e41db4
add59d8
db99f56
7fde790
83c2559
52e3313
b0c3305
46d0c84
deb2d30
8a7054d
2aa2ee3
c63bcc6
733e0e0
894835e
d7153ac
be1d2c8
46d7e32
4ea601d
19a0268
a0344e4
5f45f15
482bb8b
5c93499
0e8f75f
2eb9b0d
6381bcd
f8d149d
160ea54
0272eec
d945744
017380c
7448064
6fc175f
2a236da
e42f6dd
3bff641
917add2
732f4c0
ca2124d
19ac700
f13379f
ec4dcbd
3684bde
eaa8149
e06b1d1
d6e2d43
cadbc0f
2715354
9b8be2f
8ddc56c
8095ff8
872fd3c
00044c6
e1792e9
76ed985
218f3cd
d8e1c2b
37c892c
3fcbbf6
56b0f5f
e569a69
36e4489
c83a850
40d2cc1
e96d20c
07c8f01
b22ad6b
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"chainlink": minor | ||
--- | ||
|
||
chainReader methods return err when called and service is not started yet. #internal |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,10 +40,12 @@ type chainReader struct { | |
bindings | ||
codec commontypes.RemoteCodec | ||
commonservices.StateMachine | ||
isStarted bool | ||
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. You should be able to access the started state in the 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. Thanks for this! Looks cleaner. I was trying to replicate the way txm components do 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. addressed here: |
||
} | ||
|
||
var _ ChainReaderService = (*chainReader)(nil) | ||
var _ commontypes.ContractTypeProvider = &chainReader{} | ||
var errServiceNotStarted = errors.New("ContractReader service not started") | ||
|
||
// NewChainReaderService is a constructor for ChainReader, returns nil if there is any error | ||
// Note that the ChainReaderService returned does not support anonymous events. | ||
|
@@ -141,31 +143,47 @@ func (cr *chainReader) Name() string { return cr.lggr.Name() } | |
|
||
// Start registers polling filters if contracts are already bound. | ||
func (cr *chainReader) Start(ctx context.Context) error { | ||
if cr.isStarted { | ||
return nil | ||
} | ||
|
||
return cr.StartOnce("ChainReader", func() error { | ||
return cr.bindings.ForEach(ctx, func(c context.Context, cb *contractBinding) error { | ||
err := cr.bindings.ForEach(ctx, func(c context.Context, cb *contractBinding) error { | ||
for _, rb := range cb.readBindings { | ||
if err := rb.Register(ctx); err != nil { | ||
return err | ||
} | ||
} | ||
return cb.Register(ctx, cr.lp) | ||
}) | ||
if err == nil { | ||
cr.isStarted = true | ||
} | ||
return err | ||
}) | ||
} | ||
|
||
// Close unregisters polling filters for bound contracts. | ||
func (cr *chainReader) Close() error { | ||
if !cr.isStarted { | ||
return nil | ||
} | ||
|
||
return cr.StopOnce("ChainReader", func() error { | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Second) | ||
defer cancel() | ||
return cr.bindings.ForEach(ctx, func(c context.Context, cb *contractBinding) error { | ||
err := cr.bindings.ForEach(ctx, func(c context.Context, cb *contractBinding) error { | ||
for _, rb := range cb.readBindings { | ||
if err := rb.Unregister(ctx); err != nil { | ||
return err | ||
} | ||
} | ||
return cb.Unregister(ctx, cr.lp) | ||
}) | ||
if err == nil { | ||
cr.isStarted = false | ||
} | ||
return err | ||
}) | ||
} | ||
|
||
|
@@ -176,6 +194,10 @@ func (cr *chainReader) HealthReport() map[string]error { | |
} | ||
|
||
func (cr *chainReader) GetLatestValue(ctx context.Context, contractName, method string, confidenceLevel primitives.ConfidenceLevel, params, returnVal any) error { | ||
if !cr.isStarted { | ||
return errServiceNotStarted | ||
} | ||
|
||
b, err := cr.bindings.GetReadBinding(contractName, method) | ||
if err != nil { | ||
return err | ||
|
@@ -185,6 +207,10 @@ func (cr *chainReader) GetLatestValue(ctx context.Context, contractName, method | |
} | ||
|
||
func (cr *chainReader) BatchGetLatestValues(ctx context.Context, request commontypes.BatchGetLatestValuesRequest) (commontypes.BatchGetLatestValuesResult, error) { | ||
if !cr.isStarted { | ||
return nil, errServiceNotStarted | ||
} | ||
|
||
return cr.bindings.BatchGetLatestValues(ctx, request) | ||
} | ||
|
||
|
@@ -193,6 +219,10 @@ func (cr *chainReader) Bind(ctx context.Context, bindings []commontypes.BoundCon | |
} | ||
|
||
func (cr *chainReader) QueryKey(ctx context.Context, contractName string, filter query.KeyFilter, limitAndSort query.LimitAndSort, sequenceDataType any) ([]commontypes.Sequence, error) { | ||
if !cr.isStarted { | ||
return nil, errServiceNotStarted | ||
} | ||
|
||
b, err := cr.bindings.GetReadBinding(contractName, filter.Key) | ||
if err != nil { | ||
return nil, err | ||
|
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.
Shouldn't it be started in
func (s *registrySyncer) Start(ctx context.Context) error {
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.
func (s *registrySyncer) Start(ctx context.Context) error
callsfunc (s *registrySyncer) syncLoop()
that callsfunc (s *registrySyncer) Sync(ctx context.Context, isInitialSync bool) error
which initializes the CR.I added these lines to start the CR service right after this initialization
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.
Why is it better to have the initialization here, rather than in
(*registrySyncer).Start
? Isn't that just contributing to this problem in the first place?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.
What do you mean by
this problem
?There's a note in the
newReader
func that says why this is achieved this way: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.
I added these lines as we are now enforcing
CR
service to be inStarted
state before calling the methods. Thissyncer
was not starting the service previously and that's why we got some tests failing but now they are passing with this changeThere 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.
If all dependencies are
Started
before anything that uses them, then there is no need to be defensive about checking internally ifStart
has been called. But I see that there is a good reason to defer in this case.