refactor(jd-client): robust error handling for initialization and retry logic#456
refactor(jd-client): robust error handling for initialization and retry logic#456nulllpc wants to merge 1 commit into
Conversation
90ed53b to
a541334
Compare
Shourya742
left a comment
There was a problem hiding this comment.
Overall approach looks good.
3d9b16b to
aaece78
Compare
|
Hi @Shourya742 I updated my PR accordingly, I reviewed the changes made in #467 and I think my changes still align well with changes there and the comment you made here |
Shourya742
left a comment
There was a problem hiding this comment.
Changes look okay to me. As a rule of thumb, avoid adding side effects in combinators. Once we fix this, I will approve it.
|
I addressed all comments, please review again @Shourya742 |
|
@nulllpc once you fix the clippy and fmt nits, I’ll approve. Nice work. |
|
All done! Let's get this merged, this is my first PR for sv2. Thanks for your reviews @Shourya742 |
|
@nulllpc can you squash the commits. |
7979589 to
f3c949c
Compare
|
Done! @Shourya742 I double-checked commit message as well |
f3c949c to
42587c2
Compare
|
Hi @Shourya742 can we merge this PR, are we waiting for sth? |
105844a to
7af9c03
Compare
|
@nulllpc CI is failing here, I guess you need to rebase it and fix issues. |
aa97b02 to
7779c3f
Compare
|
Hi @GitGab19, I updated the PR, it's ready for review now |
| _ = tokio::time::sleep(Duration::from_secs(1)) => {} | ||
| } | ||
|
|
||
| if e.action == Action::Shutdown { |
There was a problem hiding this comment.
Can you add a short comment here explaining why we need this if statement?
There was a problem hiding this comment.
So basically try_initialize_single can return either a fallback or shutdown signal. The rationale here is to catch the shutdown signal and then fail fast, instead of retrying again. Before, it was passing only JDCErrorKind so we wouldn't be able to differentiate between a shutdown and a fallback signal. This is the same as @Shourya742 explained here: https://github.com/stratum-mining/sv2-apps/pull/456/changes#r3224976497
There was a problem hiding this comment.
Ok, can you write a short comment explaining that though?
| Err(e) => { | ||
| tracing::error!("Failed to initialize upstream: {:?}", e); | ||
| mode.set_solo_mining(); | ||
| } |
There was a problem hiding this comment.
Probably the same check explained in https://github.com/stratum-mining/sv2-apps/pull/456/changes#r3225801560 should be done here?
What do you think @Shourya742 ?
There was a problem hiding this comment.
I realized that when we fallback to solo mining here, we only set the mode but we do not set the upstream_state. Is this intentional or a bug? @Shourya742
There was a problem hiding this comment.
It is already set in the fallback branch for the channel manager, so we don't need an assignment here
There was a problem hiding this comment.
Ok, I see ChannelManager::new() initiates with upstream state as solo mining so technically it still works, but I think it's better to be explicit here. What do you think @Shourya742 @GitGab19
There was a problem hiding this comment.
Not really. I’m going to refactor the startup and fallback code soon anyway to make it more streamlined, so it’s not really needed right now.
There was a problem hiding this comment.
Cool, thanks for the explanation
panicking Replaces several `expect()` and `unwrap()` calls in `JobDeclaratorClient::start` with proper error propagation using `Result`. - Updated `start()` signature to return `JDCError<JobDeclarationClient>`. - Introduced `InitializationError(String)` variant to `JDCErrorKind` to preserve context from formerly panicking calls. - Updated `main.rs` and integration tests to handle the new `Result` type - Avoid blindly falling back to solo mining - Return proper error when template receiver fail to start - Fix clippy and fmt checks
7779c3f to
3287d6c
Compare
|
I resolved all comments @Shourya742 @GitGab19 Please check again when you have time |
|
Tests are failing because they still expect setup to fallback to solo mining, I'll adjust the tests accordingly |
#168
This PR attempts to improve error handling for JDC by addressing some low-hanging improvements:
expect()andunwrap()calls inJobDeclaratorClient::startwith proper error propagation usingResult.Changes:
start()signature to returnJDCError<JobDeclarationClient>.InitializationError(String)variant toJDCErrorKindto preserve context from formerly panicking calls.main.rsand integration tests to handle the newResulttypetry_initialize_singleis updated to inspect theActionfrom sub-component errors and return a fullJDCErrorwith either aShutdownorFallbackaction.initialize_jdnow checkse.action. It immediately propagates fatalShutdownerrors up tostart()while continuing to retry onFallbackerrors.Actionenum now derivesPartialEqandEqto enable this logic.JDCResulttype alias.