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

274 Improve handling of issue request execution #276

Merged
merged 14 commits into from
Mar 13, 2023

Conversation

b-yap
Copy link
Contributor

@b-yap b-yap commented Feb 23, 2023

I introduced 1 new structure and enum: LedgerTask and LedgerTaskStatus respectively.

pub enum LedgerTaskStatus {
	NotStarted,
	ProcessSuccess,
	RecoverableError,
	Error(String),
}

pub struct LedgerTask {
	ledger: Ledger,
	task_execution_receiver: Receiver<LedgerTaskStatus>,
	retries_remaining: u8,
	latest_status: LedgerTaskStatus,
}

These should be sufficient enough to make sure that a new task is only run IF and only IF the task failed, and this failure is recoverable.

@b-yap b-yap changed the title Improve handling of issue request execution 274 Improve handling of issue request execution Feb 26, 2023
@b-yap b-yap linked an issue Feb 26, 2023 that may be closed by this pull request
@b-yap b-yap marked this pull request as ready for review February 27, 2023 07:01
Copy link
Member

@ebma ebma left a comment

Choose a reason for hiding this comment

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

I like the changes overall. I added my thoughts on some specifics and would like to have your feedback on this @b-yap

clients/vault/src/issue.rs Outdated Show resolved Hide resolved
clients/wallet/src/lib.rs Outdated Show resolved Hide resolved
clients/wallet/src/task.rs Outdated Show resolved Hide resolved
clients/wallet/src/task.rs Outdated Show resolved Hide resolved
clients/wallet/src/task.rs Outdated Show resolved Hide resolved
Comment on lines 17 to 18
pub struct LedgerTask {
ledger: Ledger,
Copy link
Member

Choose a reason for hiding this comment

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

I think this implementation is so general that in theory, we could generify it so that it is not specific to just 'ledgers' but to anything. You implemented some struct that has some kind of ID (the ledger field) and is able to hold info about its current status, and can retry some number of times.
If we generify the ID passing we could also use this in other contexts. Counter-argument would be that we over-engineer this while we don't need to, but since it's little extra work I would propose we add those changes too. WDYT @b-yap ?

Copy link
Member

Choose a reason for hiding this comment

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

In any case, I would like to rename this. The name would be different if we generify, however.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just changed it to SlotTask because there's no alternate name provided. Do you have any suggestions (even just a temp one would be fine ✌️)?

And yes, creating a generic out of this struct did cross my mind, but I cannot find yet on applying it elsewhere.
Should we create a ticket and explore the "possibilities" from there? 👏 😀

Copy link
Member

Choose a reason for hiding this comment

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

Hmm yeah I honestly don't have a way better name ready for that. Something with 'Observable...Task' could be nice but it's not an observable in the classic sense so also a bit misleading.
I'm fine with keeping that name for now. And you're right, let's only extend the task struct once we found the need to use something similar elsewhere. No need to create a ticket for that I suppose :)

clients/wallet/src/task.rs Outdated Show resolved Hide resolved
clients/wallet/src/task.rs Outdated Show resolved Hide resolved
clients/wallet/src/task.rs Outdated Show resolved Hide resolved
clients/wallet/src/task.rs Show resolved Hide resolved
Comment on lines 175 to 184
// An existing task is found.
if let Some(existing) = processed_map.get_mut(ledger) {
// Only recoverable errors can be given a new task.
return existing.recover_with_new_sender()
}

// Not finding the ledger in the map means there's no existing task for this ledger.
let (sender, receiver) = tokio::sync::oneshot::channel();
tracing::trace!("Creating a task for ledger {}", ledger);

let ledger_task = SlotTask::new(*ledger, receiver);
processed_map.insert(*ledger, ledger_task);

Some(sender)
Copy link
Member

Choose a reason for hiding this comment

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

this is now a bit inconsistent with 'ledger' vs 'slot'
you should probably update the comment and variable name too 😅

Copy link
Member

@ebma ebma left a comment

Choose a reason for hiding this comment

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

It's actually good enough for merging already. You could maybe change the thing I mentioned in the other comment but generally it's ready for merge.

@b-yap b-yap force-pushed the 274-improve-handling-of-issue-request-execution branch from e86585d to 4d77bfe Compare March 9, 2023 19:54
@RustNinja RustNinja self-requested a review March 11, 2023 22:37
@ebma
Copy link
Member

ebma commented Mar 13, 2023

I ran the tests locally and they work, so I'm merging this

@ebma ebma merged commit 129daaf into dev/milestone-3 Mar 13, 2023
@ebma ebma deleted the 274-improve-handling-of-issue-request-execution branch March 13, 2023 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve handling of issue request execution
3 participants