Skip to content

Conversation

@coleFD
Copy link
Collaborator

@coleFD coleFD commented Dec 15, 2025

No description provided.

@coleFD coleFD force-pushed the refactor-channels-with-generic-jobs branch from 59e98c7 to 89dd956 Compare December 15, 2025 19:22

/// Returns an owned copy of a stale job from its job ID, if any.
fn get_stale_job(&self, job_id: u32) -> Option<T>;
fn try_validate_job(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I went this route because the current trait kinda nudges you toward having the same structure as DefaultJobStore. In it's most basic form I beleive the JobStore should allow you to:

  1. add an active job
  2. add and activate a future job
  3. make jobs stale
  4. retrieve jobs for validation

The extra methods are bloat imo.
In our case we use timestamp based job ids, and it could be possible---albeit a very low chance---that we have duplicate job_ids. Also, assuming there is access to the underlying JobStore, the user could override share validation to allow for merged mining

@@ -1,6 +1,6 @@
[package]
name = "channels_sv2"
version = "3.0.0"
Copy link
Member

Choose a reason for hiding this comment

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

version 3.0.0 hasn't been published yet, so no need to bump this

see #2010 (comment)

@coleFD coleFD force-pushed the refactor-channels-with-generic-jobs branch from cceca4a to 9d82e95 Compare December 15, 2025 20:52
///
/// Enables creation of new Standard Jobs from NewTemplate messages.
///
/// The `JobContainer` generic parameter allows for smart pointers that wrap `<dyn Job<'a>>` (ie. `Box<dyn Job<'a>>`, `Arc<dyn Job<'a>>`, etc.)
Copy link
Member

Choose a reason for hiding this comment

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

I don't see any JobContainer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

outdated comment. Will remove

@coleFD coleFD force-pushed the refactor-channels-with-generic-jobs branch from bfa271a to 420de90 Compare December 15, 2025 21:14
/// That makes it easy to calculate the coinbase `txid` (instead of `wtxid`) for merkle root
/// calculation.
#[derive(Debug, Clone, PartialEq)]
pub struct EitherJob<'a> {
Copy link
Member

Choose a reason for hiding this comment

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

so why are we going with a concrete type EitherJob?

from the description of #2019 and discussions on #2011 (comment), I was more under the impression that we were going to introduce new traits for Extended and Standard jobs?

Copy link
Collaborator Author

@coleFD coleFD Dec 15, 2025

Choose a reason for hiding this comment

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

I started down that route but it was painful. I realized the only difference between the jobs once they are stored in the channel is a pre-calcuated merkle root so it's easier to just make a single job struct with an optional merkle_root field

Copy link
Collaborator Author

@coleFD coleFD Dec 15, 2025

Choose a reason for hiding this comment

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

Granted, JobStore does still allow Generic jobs that dont have to be EitherJob. We will need to implement our own jobs for merged mining so this is still possible. The EitherJob just makes compatibility easier with this set up

Copy link
Member

Choose a reason for hiding this comment

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

but it was painful.

can you elaborate? what kinds of challenges did you encounter?

Copy link
Collaborator Author

@coleFD coleFD Dec 16, 2025

Choose a reason for hiding this comment

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

Casting from the strong typed result of the JobFactory::new_extended_job or new_standard_job to the trait. Sure we could box the types, but EitherJob seems more elegant to me considering the only difference is a cached merkle_root. I even noticed coinbase_prefix and suffix are calculated for the original calculation of the merkle_root for standard jobs in the JobFactory and then they just get thrown away, which requires rebuilding and serializing the coinbase on every share considering ShareValidationResult::BlockFound requires a serialized coinbase transaction. Seems like a ways to not keep the prefix/suffix and do the same thing as an extended share

Comment on lines +109 to +110
JobIn: Job<'a> + From<EitherJob<'a>> + Clone,
JobOut: Job<'a> + Clone,
Copy link
Member

Choose a reason for hiding this comment

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

what's the rationale behind JobIn vs JobOut?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

future jobs need to be mutable to activate min_ntime, active jobs are immutable. So you can add a future job of type T and then your implementation can wrap that as Arc<T> or Rc<T> if you want when fetching jobs to avoid cloning the full job

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.

2 participants