Bitcoin Forum
June 24, 2025, 12:36:04 AM *
News: Pizza day contest voting
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: bitaxe -> full node. | Sending a job to bm1368  (Read 206 times)
cnk1220 (OP)
Newbie
*
Offline Offline

Activity: 35
Merit: 0


View Profile
April 04, 2025, 08:35:15 PM
Last edit: April 04, 2025, 09:25:21 PM by cnk1220
 #1

*** I post it at https://github.com/skot/bitaxe/discussions yesterday and it was answered  ( no sucess by 404 panda user)  but right now, I' reanswered him but all section "discussion" was gone from skot/bitaxe.. ***

Hi, good night.

I need a help with something.

I have a Bitaxe Supra. I have a full node too, and for learning I make a python script that takes block data with "bitcoin-cli getblocktemplate", mount the block and try to mine this block.

So I trying to do samething with my Bitaxe, but, trying/testing how to process the block I get trouble and stuck.

I don't know if I mounting the merkle root in wrong order or what, but the nonce returned is never right.

For tests I get the block 850253:

// Cabeçalho do bloco:

// Versão: 0x20a00000

// Hash do bloco anterior: 0000000000000000000121c6c2fb091c8f23192b23ccb978313a121e673ee94e

// Hash da árvore de Merkle: fab947d4de52402c7b71d64c24ebf9e8912742358b4f841b3edcdf1a62ce5a62

// Timestamp: 0x6682d0fa

// Bits de dificuldade: 0x17035d25

// Nonce: 0x4325613f

// Hash do bloco: 000000000000000000018e6395574b2c177aa0033fb4736bb5a3b6d38a040f41

// Hash do midstate: c6aafbd036459eeb9267395191bed72439bd1724bbf5898355c65a0489f6f01

With dumping the block data I get that prev block hash is in diferent order:

FROM THIS: 00 00 00 00 00 00 00 00 00 01 21 C6 C2 FB 09 1C 8F 23 19 2B 23 CC B9 78 31 3A 12 1E 67 3E E9 4E

TO THIS: 00 00 00 00 00 00 00 00 C6 21 01 00 1C 09 FB C2 2B 19 23 8F 78 B9 CC 23 1E 12 3A 31 4E E9 3E 67

Nonce, bits, timestamp and version I think is ok, but the merkle root I don't know how to calculate from stratum data, so I don't able to compare o dump like i did with prev block hash.

I was thinking about the asic diff or asic mask, but if someone get um hash above current difficult he in fact find the block so I realize that was not the problem, although I don't realy understand how it works (bitmask, verison mask, etc.)

Before someone try me to install a local stratum, I'm not interesting, that will be easy, I just want make it work.

Thankful for your help!

My code:

Code:
void test_case(){

uint8_t prev_block_hash_raw[32] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x21, 0xc6, 0xc2, 0xfb, 0x09, 0x1c, 0x8f, 0x23, 0x19, 0x2b, 0x23, 0xcc, 0xb9, 0x78, 0x31, 0x3a, 0x12, 0x1e, 0x67, 0x3e, 0xe9, 0x4e};

uint8_t merkle_root_raw[32] = {0xfa, 0xb9, 0x47, 0xd4, 0xde, 0x52, 0x40, 0x2c, 0x7b, 0x71, 0xd6, 0x4c, 0x24, 0xeb, 0xf9, 0xe8, 0x91, 0x27, 0x42, 0x35, 0x8b, 0x4f, 0x84, 0x1b, 0x3e, 0xdc, 0xdf, 0x1a, 0x62, 0xce, 0x5a, 0x62};

BM1368_job test_job = {

.job_id = 0x10,

.num_midstates = 0x01, // Exemplo, ajuste conforme necessário

// .starting_nonce = {0x3F, 0x61, 0x25, 0x43}, // 0x4325613F → Little-endian

.starting_nonce = {0x01, 0x00, 0x00, 0x00}, // 0x00000001 → Little-endian

.nbits = {0x25, 0x5D, 0x03, 0x17}, // 0x17035D25 → Little-endian

.ntime = {0xFA, 0xD0, 0x82, 0x66}, // 0x6682D0FA → Little-endian

.version = {0x00, 0x00, 0xA0, 0x20}, // 0x20a00000

};

// reverse_bytes(test_job.merkle_root, 32);

memcpy(test_job.prev_block_hash, prev_block_hash_raw, 32);

printf("\nPREV HASH:\t");

hexdump_my(&test_job.prev_block_hash, sizeof(test_job.prev_block_hash));

// reverse_bytes(test_job.prev_block_hash, 32);

printf("\nPREV HASH BE:\t");

hexdump_my(&test_job.prev_block_hash, sizeof(test_job.prev_block_hash));

convert_hash_my(prev_block_hash_raw);

// convert_hash_my(merkle_root_raw);

memcpy(test_job.prev_block_hash, prev_block_hash_raw, 32);

memcpy(test_job.merkle_root, merkle_root_raw, 32);

printf("\nPREV HASH V:\t");

hexdump_my(&test_job.prev_block_hash, sizeof(test_job.prev_block_hash));

// uint8_t job_id;

// uint8_t num_midstates;

// uint8_t starting_nonce[4];

// uint8_t nbits[4];

// uint8_t ntime[4];

// uint8_t merkle_root[32];

// uint8_t prev_block_hash[32];

// uint8_t version[4];

// Cabeçalho do bloco:

// Versão: 0x20a00000

// Hash do bloco anterior: 0000000000000000000121c6c2fb091c8f23192b23ccb978313a121e673ee94e

// Hash da árvore de Merkle: fab947d4de52402c7b71d64c24ebf9e8912742358b4f841b3edcdf1a62ce5a62

// Timestamp: 0x6682d0fa

// Bits de dificuldade: 0x17035d25

// Nonce: 0x4325613f

// Hash do bloco: 000000000000000000018e6395574b2c177aa0033fb4736bb5a3b6d38a040f41

// Hash do midstate: c6aafbd036459eeb9267395191bed72439bd1724bbf5898355c65a0489f6f01

// 44fe0174 that response is get by increasing the 'BM1368_ASIC_DIFFICULTY' parameter.

// AA 55 74 01 FE 44 04 29 80 D9 92

printf("\nIH: 1368 JOB CONSTRUIDO\n");

hexdump_my(&test_job, sizeof(test_job));

uint8_t buf[1024];

memset(buf, 0, 1024);

// BM1397_send_work_my(&test_job);

_send_BM1368((TYPE_JOB | GROUP_SINGLE | CMD_WRITE), (uint8_t *)&test_job, sizeof(BM1368_job), BM1368_DEBUG_WORK);

// free_bm_job(test_job.job_id);

// sleep(2);

// wait for a response

int received = SERIAL_rx(buf, 11, BM1368_TIMEOUT_MS);

printf("\nIH: 1368 HEX BUF 1\n");

hexdump_my(&buf, 24);

asic_result nonce;

memcpy((void *)&nonce, buf, sizeof(asic_result));

printf("\nIH: NONCE RECUPERADO\n");

hexdump_my(&nonce, sizeof(nonce));

printf("\nIH: RESULT NONCE: %lx", nonce.nonce);

// Response:

// uint8_t preamble[2];

// uint32_t nonce;

// uint8_t midstate_num;

// uint8_t job_id;

// uint16_t version;

// uint8_t crc;

uint8_t job_id = (nonce.job_id & 0xf0) >> 1;

uint8_t core_id = (uint8_t)((reverse_uint32(nonce.nonce) >> 25) & 0x7f);

uint8_t small_core_id = nonce.job_id & 0x0f;

uint32_t version_bits = (reverse_uint16(nonce.version) << 13);

printf("\nJob ID: %02X, Nonce: %lx, Core: %d/%d, Ver: %08" PRIX32, job_id, nonce.nonce, core_id, small_core_id, version_bits);

vTaskDelete(NULL);

}
NotFuzzyWarm
Legendary
*
Online Online

Activity: 4032
Merit: 3139


Evil beware: We have waffles!


View Profile
April 04, 2025, 09:17:52 PM
 #2

PLEASE edit that text wall to use the code tag # to change those walls of code into much easier to view scrollable windows...

- For bitcoin to succeed the community must police itself -    My info useful? Donations welcome!  3NtFuzyWREGoDHWeMczeJzxFZpiLAFJXYr
 -Sole remaining active Primary developer of cgminer, Kano's repo is here  Discord support invite at https://kano.is/
-Support Sidehacks miner development. Donations to:   1BURGERAXHH6Yi6LRybRJK7ybEm5m5HwTr
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!