proper job management
This commit is contained in:
parent
62503f4af8
commit
0931960ac1
@ -337,17 +337,15 @@ void BM1397_set_job_difficulty_mask(int difficulty)
|
|||||||
_send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), job_difficulty_mask, 6, BM1937_SERIALTX_DEBUG);
|
_send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), job_difficulty_mask, 6, BM1937_SERIALTX_DEBUG);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t id = 0;
|
|
||||||
|
|
||||||
uint8_t BM1397_send_work(bm_job_t *next_bm_job)
|
void BM1397_send_work(bm_job_t *next_bm_job, uint8_t job_id)
|
||||||
{
|
{
|
||||||
job_packet job;
|
job_packet job;
|
||||||
// max job number is 128
|
// max job number is 128
|
||||||
// there is still some really weird logic with the job id bits for the asic to sort out
|
// there is still some really weird logic with the job id bits for the asic to sort out
|
||||||
// so we have it limited to 128 and it has to increment by 4
|
// so we have it limited to 128 and it has to increment by 4
|
||||||
id = (id + 4) % 128;
|
|
||||||
|
|
||||||
job.job_id = id;
|
job.job_id = (job_id * 4) % 128;
|
||||||
job.num_midstates = next_bm_job->num_midstates;
|
job.num_midstates = next_bm_job->num_midstates;
|
||||||
memcpy(&job.starting_nonce, &next_bm_job->starting_nonce, 4);
|
memcpy(&job.starting_nonce, &next_bm_job->starting_nonce, 4);
|
||||||
memcpy(&job.nbits, &next_bm_job->target, 4);
|
memcpy(&job.nbits, &next_bm_job->target, 4);
|
||||||
@ -363,8 +361,6 @@ uint8_t BM1397_send_work(bm_job_t *next_bm_job)
|
|||||||
}
|
}
|
||||||
|
|
||||||
_send_BM1397((TYPE_JOB | GROUP_SINGLE | CMD_WRITE), (uint8_t*) &job, sizeof(job_packet), BM1397_DEBUG_WORK);
|
_send_BM1397((TYPE_JOB | GROUP_SINGLE | CMD_WRITE), (uint8_t*) &job, sizeof(job_packet), BM1397_DEBUG_WORK);
|
||||||
|
|
||||||
return id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
asic_result *BM1397_receive_work(uint16_t timeout)
|
asic_result *BM1397_receive_work(uint16_t timeout)
|
||||||
@ -394,7 +390,7 @@ asic_result *BM1397_receive_work(uint16_t timeout)
|
|||||||
return (asic_result *)asic_response_buffer;
|
return (asic_result *)asic_response_buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
task_result *BM1397_proccess_work(bm_job_t *job, uint16_t timeout)
|
task_result *BM1397_proccess_work(uint32_t version, uint16_t timeout)
|
||||||
{
|
{
|
||||||
|
|
||||||
asic_result *asic_result = BM1397_receive_work(timeout);
|
asic_result *asic_result = BM1397_receive_work(timeout);
|
||||||
@ -408,10 +404,10 @@ task_result *BM1397_proccess_work(bm_job_t *job, uint16_t timeout)
|
|||||||
uint8_t nonce_found = 0;
|
uint8_t nonce_found = 0;
|
||||||
uint32_t first_nonce = 0;
|
uint32_t first_nonce = 0;
|
||||||
|
|
||||||
uint8_t rx_job_id = asic_result->job_id & 0xfc;
|
uint8_t rx_job_id = (asic_result->job_id & 0xfc) >> 2;
|
||||||
uint8_t rx_midstate_index = asic_result->job_id & 0x03;
|
uint8_t rx_midstate_index = asic_result->job_id & 0x03;
|
||||||
|
|
||||||
uint32_t rolled_version = job->version;
|
uint32_t rolled_version = version;
|
||||||
for (int i = 0; i < rx_midstate_index; i++)
|
for (int i = 0; i < rx_midstate_index; i++)
|
||||||
{
|
{
|
||||||
rolled_version = increment_bitmask(rolled_version, 0x1fffe000);
|
rolled_version = increment_bitmask(rolled_version, 0x1fffe000);
|
||||||
@ -446,3 +442,4 @@ task_result *BM1397_proccess_work(bm_job_t *job, uint16_t timeout)
|
|||||||
|
|
||||||
return &result;
|
return &result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,10 +46,10 @@ typedef struct __attribute__((__packed__))
|
|||||||
|
|
||||||
uint8_t BM1397_init(uint64_t frequency, uint16_t asic_count);
|
uint8_t BM1397_init(uint64_t frequency, uint16_t asic_count);
|
||||||
|
|
||||||
uint8_t BM1397_send_work(bm_job_t * next_bm_job);
|
void BM1397_send_work(bm_job_t * next_bm_job, uint8_t job_id);
|
||||||
void BM1397_set_job_difficulty_mask(int);
|
void BM1397_set_job_difficulty_mask(int);
|
||||||
int BM1397_set_max_baud(void);
|
int BM1397_set_max_baud(void);
|
||||||
int BM1397_set_default_baud(void);
|
int BM1397_set_default_baud(void);
|
||||||
void BM1397_send_hash_frequency(float frequency);
|
void BM1397_send_hash_frequency(float frequency);
|
||||||
task_result *BM1397_proccess_work(bm_job_t *job, uint16_t timeout);
|
task_result *BM1397_proccess_work(uint32_t version, uint16_t timeout);
|
||||||
|
|
||||||
|
@ -159,10 +159,17 @@ void asic_create_job(mining_subscribe *mWorker, mining_job *job, bm_job_t *next_
|
|||||||
//next_job->pool_diff = stratum_difficulty;
|
//next_job->pool_diff = stratum_difficulty;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t asic_send_work(bm_job_t *next_bm_job) {
|
void asic_send_work(bm_job_t *next_bm_job, uint8_t job_id) {
|
||||||
return BM1397_send_work(next_bm_job);
|
BM1397_send_work(next_bm_job, job_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
task_result *asic_proccess_work(bm_job_t *job, uint16_t timeout) {
|
task_result *asic_proccess_work(uint32_t version, uint16_t timeout) {
|
||||||
return BM1397_proccess_work(job, timeout);
|
return BM1397_proccess_work(version, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
void asic_free_bm_job(bm_job_t *job) {
|
||||||
|
free(job->jobid);
|
||||||
|
free(job->extranonce2);
|
||||||
|
// mark as free
|
||||||
|
job->ntime = 0;
|
||||||
}
|
}
|
@ -26,7 +26,8 @@ typedef struct
|
|||||||
} bm_job_t;
|
} bm_job_t;
|
||||||
|
|
||||||
|
|
||||||
uint8_t asic_send_work(bm_job_t *next_bm_job);
|
void asic_send_work(bm_job_t *next_bm_job, uint8_t job_id);
|
||||||
task_result *asic_proccess_work(bm_job_t *job, uint16_t timeout);
|
task_result *asic_proccess_work(uint32_t version, uint16_t timeout);
|
||||||
|
|
||||||
double asic_test_nonce_value(const bm_job_t *job, const uint32_t nonce, const uint32_t rolled_version);
|
double asic_test_nonce_value(const bm_job_t *job, const uint32_t nonce, const uint32_t rolled_version);
|
||||||
|
void asic_free_bm_job(bm_job_t *job);
|
@ -374,11 +374,13 @@ void runMiner(void * task_id) {
|
|||||||
|
|
||||||
void asic_create_job(mining_subscribe *mWorker, mining_job *job, bm_job_t *next_job, uint32_t extranonce_2);
|
void asic_create_job(mining_subscribe *mWorker, mining_job *job, bm_job_t *next_job, uint32_t extranonce_2);
|
||||||
|
|
||||||
|
// we can have 32 different job ids
|
||||||
|
bm_job_t asic_jobs[32];
|
||||||
|
|
||||||
void runASIC(void * task_id) {
|
void runASIC(void * task_id) {
|
||||||
Serial.printf("[MINER] Started runASIC Task!\n");
|
Serial.printf("[MINER] Started runASIC Task!\n");
|
||||||
|
|
||||||
uint32_t extranonce_2 = 0;
|
uint32_t extranonce_2 = 0;
|
||||||
bm_job_t asic_job;
|
|
||||||
while(1) {
|
while(1) {
|
||||||
// wait for new job
|
// wait for new job
|
||||||
while(1) {
|
while(1) {
|
||||||
@ -396,33 +398,49 @@ void runASIC(void * task_id) {
|
|||||||
Serial.println(">>> STARTING TO HASH NONCES");
|
Serial.println(">>> STARTING TO HASH NONCES");
|
||||||
uint32_t startT = micros();
|
uint32_t startT = micros();
|
||||||
|
|
||||||
|
memset(asic_jobs, 0, sizeof(asic_jobs));
|
||||||
|
|
||||||
|
// we are assuming the version doesn't change from job to job
|
||||||
|
uint32_t version = strtoul(mJob.version.c_str(), NULL, 16);
|
||||||
|
|
||||||
|
mMonitor.NerdStatus = NM_hashing;
|
||||||
|
|
||||||
while (mMiner.inRun) {
|
while (mMiner.inRun) {
|
||||||
mMonitor.NerdStatus = NM_hashing;
|
|
||||||
extranonce_2++;
|
extranonce_2++;
|
||||||
|
|
||||||
|
// use extranonce2 as job id
|
||||||
|
uint8_t asic_job_id = (uint8_t) (extranonce_2 % 32);
|
||||||
|
|
||||||
|
// if it was used before, we have to free the pointers
|
||||||
|
if (asic_jobs[asic_job_id].ntime) {
|
||||||
|
asic_free_bm_job(&asic_jobs[asic_job_id]);
|
||||||
|
}
|
||||||
|
|
||||||
// create the next asic job
|
// create the next asic job
|
||||||
asic_create_job(&mWorker, &mJob, &asic_job, extranonce_2);
|
asic_create_job(&mWorker, &mJob, &asic_jobs[asic_job_id], extranonce_2);
|
||||||
|
|
||||||
// send the job and
|
// send the job and
|
||||||
uint8_t asic_job_id = asic_send_work(&asic_job);
|
asic_send_work(&asic_jobs[asic_job_id], asic_job_id);
|
||||||
|
|
||||||
// wait 30ms for the response
|
// wait 30ms for the response
|
||||||
task_result *result = asic_proccess_work(&asic_job, 30);
|
// the pointer returned is the RS232 receive buffer :shushing-face:
|
||||||
|
// but we only have a single thread so it should be okay
|
||||||
|
task_result *result = asic_proccess_work(version, 30);
|
||||||
|
|
||||||
|
// if we haven't received anything in time, so send a new job
|
||||||
if (!result) {
|
if (!result) {
|
||||||
// we haven't received anything in time, so send a new job
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result->job_id != asic_job_id) {
|
// if we have received a job we don't know
|
||||||
// job id mismatch
|
if (!asic_jobs[result->job_id].ntime) {
|
||||||
Serial.printf("ID mismatch, expected %02x, got %02x\n", asic_job_id, result->job_id);
|
Serial.printf("No Job found for received ID %02x\n", result->job_id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check the nonce difficulty
|
// check the nonce difficulty
|
||||||
double diff_hash = asic_test_nonce_value(
|
double diff_hash = asic_test_nonce_value(
|
||||||
&asic_job,
|
&asic_jobs[result->job_id],
|
||||||
result->nonce,
|
result->nonce,
|
||||||
result->rolled_version);
|
result->rolled_version);
|
||||||
|
|
||||||
@ -435,7 +453,7 @@ void runASIC(void * task_id) {
|
|||||||
|
|
||||||
if(diff_hash > mMiner.poolDifficulty)
|
if(diff_hash > mMiner.poolDifficulty)
|
||||||
{
|
{
|
||||||
tx_mining_submit_with_version(client, mWorker, &asic_job, extranonce_2, result->nonce, result->rolled_version);
|
tx_mining_submit_asic(client, mWorker, &asic_jobs[result->job_id], result);
|
||||||
Serial.println("valid share!");
|
Serial.println("valid share!");
|
||||||
/*
|
/*
|
||||||
Serial.print(" - Current diff share: "); Serial.println(diff_hash,12);
|
Serial.print(" - Current diff share: "); Serial.println(diff_hash,12);
|
||||||
|
@ -230,7 +230,7 @@ bool tx_mining_submit(WiFiClient& client, mining_subscribe mWorker, mining_job m
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tx_mining_submit_with_version(WiFiClient& client, mining_subscribe mWorker, const bm_job_t* asic_job, uint32_t extranonce2, unsigned long nonce, uint32_t version)
|
bool tx_mining_submit_asic(WiFiClient& client, mining_subscribe mWorker, const bm_job_t* asic_job, task_result *result)
|
||||||
{
|
{
|
||||||
char payload[BUFFER] = {0};
|
char payload[BUFFER] = {0};
|
||||||
|
|
||||||
@ -242,8 +242,8 @@ bool tx_mining_submit_with_version(WiFiClient& client, mining_subscribe mWorker,
|
|||||||
asic_job->jobid,
|
asic_job->jobid,
|
||||||
asic_job->extranonce2,
|
asic_job->extranonce2,
|
||||||
asic_job->ntime,
|
asic_job->ntime,
|
||||||
nonce,
|
result->nonce,
|
||||||
version ^ asic_job->version
|
result->rolled_version ^ asic_job->version
|
||||||
);
|
);
|
||||||
Serial.print(" Sending : "); Serial.print(payload);
|
Serial.print(" Sending : "); Serial.print(payload);
|
||||||
client.print(payload);
|
client.print(payload);
|
||||||
|
@ -62,7 +62,7 @@ bool parse_mining_notify(String line, mining_job& mJob);
|
|||||||
|
|
||||||
//Method Mining.submit
|
//Method Mining.submit
|
||||||
bool tx_mining_submit(WiFiClient& client, mining_subscribe mWorker, mining_job mJob, unsigned long nonce);
|
bool tx_mining_submit(WiFiClient& client, mining_subscribe mWorker, mining_job mJob, unsigned long nonce);
|
||||||
bool tx_mining_submit_with_version(WiFiClient& client, mining_subscribe mWorker, const bm_job_t* asic_job, uint32_t extranonce2, unsigned long nonce, uint32_t version);
|
bool tx_mining_submit_asic(WiFiClient& client, mining_subscribe mWorker, const bm_job_t* asic_job, task_result *result);
|
||||||
|
|
||||||
//Difficulty Methods
|
//Difficulty Methods
|
||||||
bool tx_suggest_difficulty(WiFiClient& client, double difficulty);
|
bool tx_suggest_difficulty(WiFiClient& client, double difficulty);
|
||||||
|
Loading…
Reference in New Issue
Block a user