Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/datum_stratum.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ void datum_stratum_v1_socket_thread_loop(T_DATUM_THREAD_DATA *my) {
for(i=0;i<my->app->max_clients_thread;i++) {
m = my->client_data[i].app_client_data;
if (my->client_data[i].fd && m->subscribed) {
send_mining_notify(&my->client_data[i],false,false,false);
send_mining_notify(&my->client_data[i], datum_stratum_notify_replaces_job(job->job_state, true), false, false);
}
}

Expand Down Expand Up @@ -558,7 +558,7 @@ void datum_stratum_v1_socket_thread_loop(T_DATUM_THREAD_DATA *my) {
for(i=0;i<my->app->max_clients_thread;i++) {
m = my->client_data[i].app_client_data;
if (my->client_data[i].fd && m->subscribed) {
send_mining_notify(&my->client_data[i],false,false,false);
send_mining_notify(&my->client_data[i], datum_stratum_notify_replaces_job(job->job_state, true), false, false);
}
}

Expand All @@ -584,7 +584,7 @@ void datum_stratum_v1_socket_thread_loop(T_DATUM_THREAD_DATA *my) {
for(i=0;i<my->app->max_clients_thread;i++) {
m = my->client_data[i].app_client_data;
if (my->client_data[i].fd && m->subscribed) {
send_mining_notify(&my->client_data[i],false,false,false);
send_mining_notify(&my->client_data[i], datum_stratum_notify_replaces_job(job->job_state, sdata->last_was_empty), false, false);
}
}
} else {
Expand Down Expand Up @@ -1438,6 +1438,16 @@ unsigned int datum_stratum_coinbase_index(
return miner->coinbase_selection;
}

bool datum_stratum_notify_replaces_job(int job_state, bool opening_job_still_current) {
/* State 2's second send is the template. State 4 is the split.
* State 5 replaces only while miners are still on the opening job.
* The paced refresh passes opening_job_still_current false. */
if (job_state == JOB_STATE_EMPTY_PLUS && opening_job_still_current) return true;
if (job_state == JOB_STATE_FULL_PRIORITY_WAIT_COINBASER) return true;
if (job_state == JOB_STATE_FULL_NORMAL_WAIT_COINBASER && opening_job_still_current) return true;
return false;
}

int send_mining_notify(T_DATUM_CLIENT_DATA *c, bool clean, bool quickdiff, bool new_block) {
// send the current job to the miner

Expand Down
5 changes: 5 additions & 0 deletions src/datum_stratum.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ extern T_DATUM_STRATUM_JOB *global_cur_stratum_jobs[MAX_STRATUM_JOBS];
const char *datum_stratum_mod_username(const char *username_s, char *username_buf, size_t username_buf_sz, uint16_t share_rnd, const char *modname, size_t modname_len);

int send_mining_notify(T_DATUM_CLIENT_DATA *c, bool clean, bool quickdiff, bool new_block);
/* True when this notify replaces the job miners are hashing.
* The opening job is 0 transactions and 1 pool output. The template reply
* and the split reply replace it. A later refresh does not. The replaced
* job is not marked stale, so shares already submitted still count. */
bool datum_stratum_notify_replaces_job(int job_state, bool opening_job_still_current);
void update_stratum_job(T_DATUM_TEMPLATE_DATA *block_template, bool new_block, int job_state);
void datum_stratum_job_refresh_blake2b(T_DATUM_STRATUM_JOB *s);
bool datum_stratum_job_blake2b_commitment_from_txn(const T_DATUM_STRATUM_JOB *s, const unsigned char *cb_txn, size_t cb_len, unsigned char target_pot, bool subsidy_only, unsigned char *commitment);
Expand Down
14 changes: 14 additions & 0 deletions src/datum_stratum_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,21 @@ void datum_stratum_mod_username_tests() {
datum_test(0 == strcmp(res, "def.ghi"));
}

static void datum_stratum_notify_replaces_job_tests(void) {
/* Template reply and split reply replace the opening job. */
datum_test(datum_stratum_notify_replaces_job(JOB_STATE_EMPTY_PLUS, true));
datum_test(datum_stratum_notify_replaces_job(JOB_STATE_FULL_PRIORITY_WAIT_COINBASER, false));
datum_test(datum_stratum_notify_replaces_job(JOB_STATE_FULL_PRIORITY_WAIT_COINBASER, true));
/* The opening job itself is not this path, and a normal refresh stays alongside. */
datum_test(!datum_stratum_notify_replaces_job(JOB_STATE_EMPTY_ONLY, true));
datum_test(!datum_stratum_notify_replaces_job(JOB_STATE_EMPTY_PLUS, false));
datum_test(!datum_stratum_notify_replaces_job(JOB_STATE_FULL_NORMAL_WAIT_COINBASER, false));
datum_test(datum_stratum_notify_replaces_job(JOB_STATE_FULL_NORMAL_WAIT_COINBASER, true));
datum_test(!datum_stratum_notify_replaces_job(JOB_STATE_FULL_PRIORITY, false));
}

void datum_stratum_tests(void) {
datum_stratum_notify_replaces_job_tests();
datum_stratum_mod_username_tests();
datum_stratum_minimum_difficulty_configure_tests();
datum_stratum_string_request_id_tests();
Expand Down
Loading