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

development of unit test to verify bm1366 is able to find a solution for a known block #167

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

MoellerDi
Copy link
Contributor

@MoellerDi MoellerDi commented Apr 21, 2024

The intention of this PR is to share my findings with the dev-team and to get a possible bug addressed.

I'm was working on a unit test to proof my Bitaxe is actual able to find correct nonce and version for any given stratum notification. As I didn't have time to wait for years ;-) I took data from an already resolved block (merkle_root, ntime) and mixed it with the related stratum notification from public-pool.io targeting the same block. Block #839900 was selected for my unit test but any given block where stratum notification as well as correct and valid merkle_root and ntime is known should do.

During the unit test implementation, I noticed that the bm1366 chip is actually not hashing the whole nonce space but only a small part of it. It turns out the chip is (IMHO) using its chip address to divide the nonce space into smaller portions (this was also highlighted at: https://youtu.be/6o92HhvOc1I?t=5710). It seems it is also doing so even if a single chip is not in a chain with others, as my unit test shows.

Anyway, in order to proof the Bitaxe is able to find a solution of any given stratum notification, the unit test is changing the chip address of a single bm1366 on-the-fly during the test to emulate kind of a bigger chain and to jump into all the different nonce spaces. This was working fine and it took just a couple of minutes to hash thru the whole nonce space for the already confirmed working merkle_root. Sadly no success, the expected nonce/version combination did not show up.

I was wondering why the bm1366 still was not able to find the correct nonce (and version), so I double checked the code referenced by the unit test and found a possible bug in construct_bm_job (to be confirmed by one of the core devs). I used a script (also included in this PR) to verify hash values and found the merkle_root only needs endian words swapped and should not be in reversed order. Anyway, a suggestion for a fix is included in this PR and applied to my code, my unit test was finally able to find the correct nonce and version and my goal was achieved. If I find time I might try to develop a kind of chip address switching feature to actually cover the whole nonce space on my Bitaxe.

Below some selected output from my unit test, a longer version of the log is included in this PR.
Update, as I reverted my changes to construct_bm_job, this unit test is not yet fully functional and I need to rework this stuff
Update2, it seems the merkle_root copied from blockchain.info needs to be in reversed order. It's not yet fully clear to me why. However, unit test is working again and is verifying the nonce and version again ;-)

<cut>
I (1654) test_bm1366: Changing chip address and sending job; new chip address: 0xc0
I (1664) test_bm1366: Waiting for result ... (might take a while due to 60s timeout)
I (2114) test_bm1366: Result[1]: Nonce 3818226259 Nonce difficulty 8452.86377870396427169907838106155396. rolled-version 0x24148000
I (3974) test_bm1366: Result[2]: Nonce 504135883 Nonce difficulty 816.88959549147682537295622751116753. rolled-version 0x349cc000
I (5704) test_bm1366: Result[3]: Nonce 3818226259 Nonce difficulty 8452.86377870396427169907838106155396. rolled-version 0x24148000
I (7554) test_bm1366: Result[4]: Nonce 504135883 Nonce difficulty 816.88959549147682537295622751116753. rolled-version 0x349cc000
I (9294) test_bm1366: Result[5]: Nonce 3818226259 Nonce difficulty 8452.86377870396427169907838106155396. rolled-version 0x24148000
I (11144) test_bm1366: Result[6]: Nonce 504135883 Nonce difficulty 816.88959549147682537295622751116753. rolled-version 0x349cc000
I (12874) test_bm1366: Result[7]: Nonce 3818226259 Nonce difficulty 8452.86377870396427169907838106155396. rolled-version 0x24148000
I (14724) test_bm1366: Result[8]: Nonce 504135883 Nonce difficulty 816.88959549147682537295622751116753. rolled-version 0x349cc000
I (16464) test_bm1366: Result[9]: Nonce 3818226259 Nonce difficulty 8452.86377870396427169907838106155396. rolled-version 0x24148000
I (18314) test_bm1366: Result[10]: Nonce 504135883 Nonce difficulty 816.88959549147682537295622751116753. rolled-version 0x349cc000
I (20044) test_bm1366: Changing chip address and sending job; new chip address: 0xc2
I (20044) test_bm1366: Waiting for result ... (might take a while due to 60s timeout)
I (21064) test_bm1366: Result[1]: Nonce 3118696143 Nonce difficulty 1007.71313585765790321602253243327141. rolled-version 0x2915a000
I (21234) test_bm1366: Result[2]: Nonce 3529540887 Nonce difficulty 125538251293054.07812500000000000000000000000000. rolled-version 0x2a966000
I (21234) test_bm1366: Expected nonce and version match. Solution found!
<cut>

Nonce 3529540887 and version 0x2a966000 are according to blockchain.info the correct solution for block #839900 and was found by a pool called "Poolin" two days ago.

Possible follow-up / next steps (IMHO):

  • IMHO it would make sense to develop kind of chip address switching feature to emulate a bigger chip chain to cover the whole nonce space on single-chip as well as on multi-chip hardware. It should further increase the chance to find a block.
  • the code used to calculate midstate hashes for bm1397 based hardware should be re-checked and verified as I noticed my "fix" is causing the bm1397 related unit test "validate bm job construction" to FAIL. Sadly I do not have any bm1397 based hardware available to test/verify this on my own.
  • This unit test might need further optimization and could be adapted for bm1397 and bm1368 based hardware.

Disclaimer: This PR was developed and tested on my Bitaxe Ultra 205 only and needs further testing on other supported hardware.

… valid block. Include script for block validation.
…root_be needs to be reversed. confirmed by validation script as well as unit test running on real hardware (bitaxe 205 ultra, bm1366)
….merkle_root_be needs to be reversed. confirmed by validation script as well as unit test running on real hardware (bitaxe 205 ultra, bm1366)"

This reverts commit b922e3e.
@MoellerDi
Copy link
Contributor Author

After further testing it seems there is no bug in construct_bm_job and the current code is correct. This means something else is wrong with my unit test. I need to further investigate.

@MoellerDi MoellerDi changed the title possible bug in construct_bm_job and new unit test to verify bm1366 is able to find a solution for a known block development of unit test to verify bm1366 is able to find a solution for a known block Apr 21, 2024
@MoellerDi
Copy link
Contributor Author

ok, it seems the merkle_root copied from blockchain.info needs to be in reversed order. It's not yet fully clear to me why. However, unit test is working again and is verifying the nonce and version again ;-)

@skot
Copy link
Owner

skot commented Apr 22, 2024

The way the nonce range is split up across the chain using the bits in the chip address doesn't really make sense to me. It almost seems as if we can't set a single chip to hash the entire 32 bit nonce range?

While I don't think it affects mining currently, it would be nice to understand this more.

@MoellerDi
Copy link
Contributor Author

MoellerDi commented Apr 22, 2024

As known already, the chip is somehow using its chip address to calculate the nonce range to hash.
If the entire 32 bit nonce range needs to be hashed by just one single chip, it seems we need to change the chip address like I do in my unit test:

    for (uint8_t i = 0; i < 128; i++) {

        uint8_t chip_address = i * 2;
        
        ESP_LOGI(TAG, "Changing chip address and sending job; new chip address: 0x%02x", chip_address);

        BM1366_set_chip_address(chip_address);

        (*GLOBAL_STATE.ASIC_functions.send_work_fn)(&GLOBAL_STATE, &job);

        ESP_LOGI(TAG, "Waiting for result ... (might take a while due to 60s timeout)");
        asic_result = (*GLOBAL_STATE.ASIC_functions.receive_result_fn)(&GLOBAL_STATE);

        int counter = 1;
        while (asic_result != NULL && counter <= 10) { // I just consider the first 10 results

            double nonce_diff = test_nonce_value(&job, asic_result->nonce, asic_result->rolled_version);
            ESP_LOGI(TAG, "Result[%d]: Nonce %lu Nonce difficulty %.32f. rolled-version 0x%08lx", counter, asic_result->nonce, nonce_diff, asic_result->rolled_version);

            asic_result = (*GLOBAL_STATE.ASIC_functions.receive_result_fn)(&GLOBAL_STATE); // wait for next result
            counter++;
        }
    }

I see overlapping nonce ranges (results) if I just incrementally increasing the chip address bit by bit. So IMHO a single chip is just hashing 1/128 of the entire 32 bit nonce range as it's using the chip address to calculate that range (as kind of suffix/prefix?). That makes kind of sense as the chip is designed to be in a chain, One design goal would be to avoid overlapping nonce ranges. A simple way is to use the unique chip address for the same. I wonder if there is a register to configure this somehow.

I (19064) test_bm1366: Changing chip address and sending job; new chip address: 0xc0
I (19064) test_bm1366: Waiting for result ... (might take a while due to 60s timeout)
I (19454) test_bm1366: Result[1]: Nonce 1943830683 Nonce difficulty 161.99540018004628905146091710776091. rolled-version 0x2375c000
I (19484) test_bm1366: Result[2]: Nonce 1268285461 Nonce difficulty 74.95286973802697616520163137465715. rolled-version 0x23c8a000
I (19524) test_bm1366: Result[3]: Nonce 3818226259 Nonce difficulty 8452.86377870396427169907838106155396. rolled-version 0x24148000
I (20744) test_bm1366: Result[4]: Nonce 938574417 Nonce difficulty 213.24548440398311299759370740503073. rolled-version 0x2f006000
I (20874) test_bm1366: Result[5]: Nonce 140869725 Nonce difficulty 416.32579788853871605169842950999737. rolled-version 0x30298000
I (21224) test_bm1366: Result[6]: Nonce 1927381515 Nonce difficulty 100.25435878207206030765519244596362. rolled-version 0x334e0000
I (21374) test_bm1366: Result[7]: Nonce 504135883 Nonce difficulty 816.88959549147682537295622751116753. rolled-version 0x349cc000
I (23034) test_bm1366: Result[8]: Nonce 1943830683 Nonce difficulty 161.99540018004628905146091710776091. rolled-version 0x2375c000
I (23074) test_bm1366: Result[9]: Nonce 1268285461 Nonce difficulty 74.95286973802697616520163137465715. rolled-version 0x23c8a000
I (23104) test_bm1366: Result[10]: Nonce 3818226259 Nonce difficulty 8452.86377870396427169907838106155396. rolled-version 0x24148000

I (24334) test_bm1366: Changing chip address and sending job; new chip address: 0xc1
I (24334) test_bm1366: Waiting for result ... (might take a while due to 60s timeout)
I (24344) test_bm1366: Result[1]: Nonce 2752546077 Nonce difficulty 173.72130802885851608152734115719795. rolled-version 0x20122000
I (24794) test_bm1366: Result[2]: Nonce 3818226259 Nonce difficulty 8452.86377870396427169907838106155396. rolled-version 0x24148000
I (25004) test_bm1366: Result[3]: Nonce 2017625141 Nonce difficulty 124.54376260897227268742426531389356. rolled-version 0x25fea000
I (25514) test_bm1366: Result[4]: Nonce 3529540887 Nonce difficulty 125538251293054.07812500000000000000000000000000. rolled-version 0x2a966000
I (25854) test_bm1366: Result[5]: Nonce 3998909521 Nonce difficulty 101.11314490559792034218844491988420. rolled-version 0x2d8f4000
I (26014) test_bm1366: Result[6]: Nonce 938574417 Nonce difficulty 213.24548440398311299759370740503073. rolled-version 0x2f006000
I (26494) test_bm1366: Result[7]: Nonce 1927381515 Nonce difficulty 100.25435878207206030765519244596362. rolled-version 0x334e0000
I (27924) test_bm1366: Result[8]: Nonce 2752546077 Nonce difficulty 173.72130802885851608152734115719795. rolled-version 0x20122000
I (28374) test_bm1366: Result[9]: Nonce 3818226259 Nonce difficulty 8452.86377870396427169907838106155396. rolled-version 0x24148000
I (28594) test_bm1366: Result[10]: Nonce 2017625141 Nonce difficulty 124.54376260897227268742426531389356. rolled-version 0x25fea000

I (29104) test_bm1366: Changing chip address and sending job; new chip address: 0xc2
I (29104) test_bm1366: Waiting for result ... (might take a while due to 60s timeout)
I (29114) test_bm1366: Result[1]: Nonce 2752546077 Nonce difficulty 173.72130802885851608152734115719795. rolled-version 0x20122000
I (29704) test_bm1366: Result[2]: Nonce 197166559 Nonce difficulty 121.87992365732269206546334316954017. rolled-version 0x25528000
I (29774) test_bm1366: Result[3]: Nonce 2017625141 Nonce difficulty 124.54376260897227268742426531389356. rolled-version 0x25fea000
I (29824) test_bm1366: Result[4]: Nonce 2833483103 Nonce difficulty 337.08302260535907635130570270121098. rolled-version 0x26692000
I (30124) test_bm1366: Result[5]: Nonce 3118696143 Nonce difficulty 1007.71313585765790321602253243327141. rolled-version 0x2915a000
I (30294) test_bm1366: Result[6]: Nonce 3529540887 Nonce difficulty 125538251293054.07812500000000000000000000000000. rolled-version 0x2a966000
I (30464) test_bm1366: Result[7]: Nonce 523077293 Nonce difficulty 100.04363388498167353191092843189836. rolled-version 0x2c22e000
I (30624) test_bm1366: Result[8]: Nonce 3998909521 Nonce difficulty 101.11314490559792034218844491988420. rolled-version 0x2d8f4000
I (31834) test_bm1366: Result[9]: Nonce 1815316077 Nonce difficulty 349.17412221386513238030602224171162. rolled-version 0x3860c000
I (32164) test_bm1366: Result[10]: Nonce 1970177947 Nonce difficulty 84.09917491794885791023261845111847. rolled-version 0x3b414000

I (32704) test_bm1366: Changing chip address and sending job; new chip address: 0xc3
I (32704) test_bm1366: Waiting for result ... (might take a while due to 60s timeout)
I (33724) test_bm1366: Result[1]: Nonce 3118696143 Nonce difficulty 1007.71313585765790321602253243327141. rolled-version 0x2915a000
I (33784) test_bm1366: Result[2]: Nonce 886605891 Nonce difficulty 1194.31917192739751953922677785158157. rolled-version 0x29afa000
I (34064) test_bm1366: Result[3]: Nonce 523077293 Nonce difficulty 100.04363388498167353191092843189836. rolled-version 0x2c22e000
I (35434) test_bm1366: Result[4]: Nonce 1815316077 Nonce difficulty 349.17412221386513238030602224171162. rolled-version 0x3860c000
I (35734) test_bm1366: Result[5]: Nonce 2781186099 Nonce difficulty 491.49066131527769130116212181746960. rolled-version 0x3b0d4000
I (35754) test_bm1366: Result[6]: Nonce 1970177947 Nonce difficulty 84.09917491794885791023261845111847. rolled-version 0x3b414000
I (37304) test_bm1366: Result[7]: Nonce 3118696143 Nonce difficulty 1007.71313585765790321602253243327141. rolled-version 0x2915a000
I (37374) test_bm1366: Result[8]: Nonce 886605891 Nonce difficulty 1194.31917192739751953922677785158157. rolled-version 0x29afa000
I (37644) test_bm1366: Result[9]: Nonce 523077293 Nonce difficulty 100.04363388498167353191092843189836. rolled-version 0x2c22e000
I (39014) test_bm1366: Result[10]: Nonce 1815316077 Nonce difficulty 349.17412221386513238030602224171162. rolled-version 0x3860c000

@skot
Copy link
Owner

skot commented Apr 22, 2024

Are you sure it's fixed to 1/128th of the 32bit nonce range? What about hashboards that have chains with less chips? The S19k Pro only has 77 BM1366 chips in the chain.

@MoellerDi
Copy link
Contributor Author

The S19k Pro only has 77 BM1366 chips in the chain.

Is there anywhere a hashboard dump/log of the init sequence of the S19k Pro available?
I would love to read it. Especially to check if it also init the A8 register with 55 AA 41 09 00 A8 00 07 01 F0 15

Are you sure it's fixed to 1/128th of the 32bit nonce range?

No it is (hopefully) not fixed. IMHO there should be a way to configure it, perhaps a config register or something.

See my previous posts, on my Bitaxe I see a complete different nonce range when I change the chip address from 0xC0 to 0xC2 but I'm getting an overlapping nonce range when I change the chip address from 0xC0 to 0xC1.

As you can see below, both nonce ranges for chip address 0xC0 and 0xC2 are overlapping with the nonce range of chip address 0xC1. But the nonce range of chip address 0xC0 and 0xC2 are not overlapping at all.

That's why I assume the chip is configured to split up the entire 32 bit nonce range into smaller unique chunks, one chunk per chip address (0x00 ... 0xFE), as outlined in your session with NebulaMiner

I (1702) test_bm1366: Changing chip address and sending job; new chip address: 0xc0
I (1712) test_bm1366: Waiting for result ... (might take a while due to 60s timeout)
I (2092) test_bm1366: Result[1]: Nonce 1943830683 Nonce difficulty 161.99540018004628905146091710776091. rolled-version 0x2375c000
I (2132) test_bm1366: Result[2]: Nonce 1268285461 Nonce difficulty 74.95286973802697616520163137465715. rolled-version 0x23c8a000
I (2162) test_bm1366: Result[3]: Nonce 3818226259 Nonce difficulty 8452.86377870396427169907838106155396. rolled-version 0x24148000
I (3392) test_bm1366: Result[4]: Nonce 938574417 Nonce difficulty 213.24548440398311299759370740503073. rolled-version 0x2f006000
I (3522) test_bm1366: Result[5]: Nonce 140869725 Nonce difficulty 416.32579788853871605169842950999737. rolled-version 0x30298000
I (3872) test_bm1366: Result[6]: Nonce 1927381515 Nonce difficulty 100.25435878207206030765519244596362. rolled-version 0x334e0000
I (4022) test_bm1366: Result[7]: Nonce 504135883 Nonce difficulty 816.88959549147682537295622751116753. rolled-version 0x349cc000
I (5682) test_bm1366: Result[8]: Nonce 1943830683 Nonce difficulty 161.99540018004628905146091710776091. rolled-version 0x2375c000
I (5722) test_bm1366: Result[9]: Nonce 1268285461 Nonce difficulty 74.95286973802697616520163137465715. rolled-version 0x23c8a000
I (5752) test_bm1366: Result[10]: Nonce 3818226259 Nonce difficulty 8452.86377870396427169907838106155396. rolled-version 0x24148000

I (6972) test_bm1366: Changing chip address and sending job; new chip address: 0xc2
I (6972) test_bm1366: Waiting for result ... (might take a while due to 60s timeout)
I (6982) test_bm1366: Result[1]: Nonce 2752546077 Nonce difficulty 173.72130802885851608152734115719795. rolled-version 0x20122000
I (7572) test_bm1366: Result[2]: Nonce 197166559 Nonce difficulty 121.87992365732269206546334316954017. rolled-version 0x25528000
I (7652) test_bm1366: Result[3]: Nonce 2017625141 Nonce difficulty 124.54376260897227268742426531389356. rolled-version 0x25fea000
I (7692) test_bm1366: Result[4]: Nonce 2833483103 Nonce difficulty 337.08302260535907635130570270121098. rolled-version 0x26692000
I (7992) test_bm1366: Result[5]: Nonce 3118696143 Nonce difficulty 1007.71313585765790321602253243327141. rolled-version 0x2915a000
I (8162) test_bm1366: Result[6]: Nonce 3529540887 Nonce difficulty 125538251293054.07812500000000000000000000000000. rolled-version 0x2a966000
I (8342) test_bm1366: Result[7]: Nonce 523077293 Nonce difficulty 100.04363388498167353191092843189836. rolled-version 0x2c22e000
I (8492) test_bm1366: Result[8]: Nonce 3998909521 Nonce difficulty 101.11314490559792034218844491988420. rolled-version 0x2d8f4000
I (9712) test_bm1366: Result[9]: Nonce 1815316077 Nonce difficulty 349.17412221386513238030602224171162. rolled-version 0x3860c000
I (10032) test_bm1366: Result[10]: Nonce 1970177947 Nonce difficulty 84.09917491794885791023261845111847. rolled-version 0x3b414000
I (19064) test_bm1366: Changing chip address and sending job; new chip address: 0xc0
I (19064) test_bm1366: Waiting for result ... (might take a while due to 60s timeout)
I (19454) test_bm1366: Result[1]: Nonce 1943830683 Nonce difficulty 161.99540018004628905146091710776091. rolled-version 0x2375c000
I (19484) test_bm1366: Result[2]: Nonce 1268285461 Nonce difficulty 74.95286973802697616520163137465715. rolled-version 0x23c8a000
I (19524) test_bm1366: Result[3]: Nonce 3818226259 Nonce difficulty 8452.86377870396427169907838106155396. rolled-version 0x24148000
I (20744) test_bm1366: Result[4]: Nonce 938574417 Nonce difficulty 213.24548440398311299759370740503073. rolled-version 0x2f006000
I (20874) test_bm1366: Result[5]: Nonce 140869725 Nonce difficulty 416.32579788853871605169842950999737. rolled-version 0x30298000
I (21224) test_bm1366: Result[6]: Nonce 1927381515 Nonce difficulty 100.25435878207206030765519244596362. rolled-version 0x334e0000
I (21374) test_bm1366: Result[7]: Nonce 504135883 Nonce difficulty 816.88959549147682537295622751116753. rolled-version 0x349cc000
I (23034) test_bm1366: Result[8]: Nonce 1943830683 Nonce difficulty 161.99540018004628905146091710776091. rolled-version 0x2375c000
I (23074) test_bm1366: Result[9]: Nonce 1268285461 Nonce difficulty 74.95286973802697616520163137465715. rolled-version 0x23c8a000
I (23104) test_bm1366: Result[10]: Nonce 3818226259 Nonce difficulty 8452.86377870396427169907838106155396. rolled-version 0x24148000

I (24334) test_bm1366: Changing chip address and sending job; new chip address: 0xc1
I (24334) test_bm1366: Waiting for result ... (might take a while due to 60s timeout)
I (24344) test_bm1366: Result[1]: Nonce 2752546077 Nonce difficulty 173.72130802885851608152734115719795. rolled-version 0x20122000
I (24794) test_bm1366: Result[2]: Nonce 3818226259 Nonce difficulty 8452.86377870396427169907838106155396. rolled-version 0x24148000
I (25004) test_bm1366: Result[3]: Nonce 2017625141 Nonce difficulty 124.54376260897227268742426531389356. rolled-version 0x25fea000
I (25514) test_bm1366: Result[4]: Nonce 3529540887 Nonce difficulty 125538251293054.07812500000000000000000000000000. rolled-version 0x2a966000
I (25854) test_bm1366: Result[5]: Nonce 3998909521 Nonce difficulty 101.11314490559792034218844491988420. rolled-version 0x2d8f4000
I (26014) test_bm1366: Result[6]: Nonce 938574417 Nonce difficulty 213.24548440398311299759370740503073. rolled-version 0x2f006000
I (26494) test_bm1366: Result[7]: Nonce 1927381515 Nonce difficulty 100.25435878207206030765519244596362. rolled-version 0x334e0000
I (27924) test_bm1366: Result[8]: Nonce 2752546077 Nonce difficulty 173.72130802885851608152734115719795. rolled-version 0x20122000
I (28374) test_bm1366: Result[9]: Nonce 3818226259 Nonce difficulty 8452.86377870396427169907838106155396. rolled-version 0x24148000
I (28594) test_bm1366: Result[10]: Nonce 2017625141 Nonce difficulty 124.54376260897227268742426531389356. rolled-version 0x25fea000

Nonce 2752546077 -> is in nonce range of chip address C1 and C2
Nonce 3818226259 -> is in nonce range of chip address C1 and C0
Nonce 2017625141 -> is in nonce range of chip address C1 and C2
Nonce 3529540887 -> is in nonce range of chip address C1 and C2
Nonce 3998909521 -> is in nonce range of chip address C1 and C2
Nonce 938574417 -> is in nonce range of chip address C1 and C0
Nonce 1927381515 -> is in nonce range of chip address C1 and C0
Nonce 2752546077 -> is in nonce range of chip address C1 and C2 (actual duplicated due to nonce rollover)
Nonce 3818226259 -> is in nonce range of chip address C1 and C0 (actual duplicated due to nonce rollover)
Nonce 2017625141 -> is in nonce range of chip address C1 and C2 (actual duplicated due to nonce rollover)

@skot
Copy link
Owner

skot commented Apr 22, 2024

Is there anywhere a hashboard dump/log of the init sequence of the S19k Pro available? I would love to read it. Especially to check if it also init the A8 register with 55 AA 41 09 00 A8 00 07 01 F0 15

I don't have one yet, but it's definitely on my todo list. Maybe I can get that this week 🤞

Are you sure it's fixed to 1/128th of the 32bit nonce range?

No it is (hopefully) not fixed. IMHO there should be a way to configure it, perhaps a config register or something.

that would make sense.. I really hope such a thing exists.

See my previous posts, on my Bitaxe I see a complete different nonce range when I change the chip address from 0xC0 to 0xC2 but I'm getting an overlapping nonce range when I change the chip address from 0xC0 to 0xC1.

As you can see below, both nonce ranges for chip address 0xC0 and 0xC2 are overlapping with the nonce range of chip address 0xC1. But the nonce range of chip address 0xC0 and 0xC2 are not overlapping at all.

That's why I assume the chip is configured to split up the entire 32 bit nonce range into smaller unique chunks, one chunk per chip address (0x00 ... 0xFE), as outlined in your session with NebulaMiner

Yes, that's what Nebula was going over in the session; the nonce range is split up with even addresses. 0xC1 is odd and so it would be in the middle of the range of 0xC0. The question is how do these ranges get setup to be 2? Can we change that to be a much bigger range? Ideally all 32 bits since we only have one chip on the Bitaxe. Maybe it's hardcoded and they just don't hash a big part of the range on the kPro?

Back on the S17, each chip would hash the entire 32bit range (and then loop around), starting with the address. It was up to the miner to send new work in time so as not to do redundant hashing. I had hoped that was how it worked on the XP, but it doesn't appear to be the case. I suspect this change is because now version is being incremented internally.

@skot
Copy link
Owner

skot commented Apr 23, 2024

Here is the kPro parsed hexdump and the Saleae Logic file
kPro_hexdump.txt
kProDump.sal.zip

@skot
Copy link
Owner

skot commented Apr 23, 2024

Sure enough, it sends 127 setaddress commands, incrementing by two. Even though you can clearly see in the previous sequence only 77 chips respond.

@MoellerDi
Copy link
Contributor Author

MoellerDi commented Apr 23, 2024

Thanks Skot for sharing the hexdump. It was very helpful and I assume I got something working.

I compared the s19k-pro (77 chips) hexdump with another hexdump of a s19xp-luxos (110 chips). Both init sequences are very similar. Well the s19xp is doing some magic autotune stuff while the s19k-pro was loading some preloaded/predefined PLL0 parameters.

All in all, same well known procedure .... almost all parameters the same. Beside different Io driver strength configuration, I noticed a register write to register "10", as per the documentation in your bm1397 repo, register 10 is called "Hash Counting Number"....

Well interesting, why would something write to a counter register......, I would expect the control board to read it.
Anyway, comparing both hashlogs side-by-side (s19xp-luxos and s19k-pro) it turns out the control board is writing different values to register 10 (known as "Hash Counting Number").

S19k-pro:
55 AA 51 09 00 10 00 00 11 5A 04 / s19kPro (77 chips) 0x115a = 4442
{0x00, 0x10, 0b00000000, 0b00000000, 0b00010001, 0b01011010} -> 6 bits high

S19xp-luxos:
55 AA 51 09 00 10 00 00 14 46 04 / s19xp_luxos (110 chips) 0x1446 = 5190
{0x00, 0x10, 0b00000000, 0b00000000, 0b00010100, 0b01000110} -> 5 bits high

After playing with it, it seems to be some kind of 20bit mask [0..20].
Setting register '10' like {0x00, 0x10, 0b00000000, 0b00001111, 0b11111111, 0b11111111}
After even more playing, it seems to be some kind of 16bit mask [4..20].
Setting register '10' like {0x00, 0x10, 0b00000000, 0b00001111, 0b11111111, 0b11110000}
After even more playing, it seems to be some kind of 4bit mask [16..19]. (still testing)
Setting register '10' like {0x00, 0x10, 0b00000000, 0b00001111, 0b00000000, 0b00000000}
makes my Bitaxe Ultra to hash the entire 32 bit nonce range including version rolling for any given chip address. It seems all chip addresses are hashing the same range. At least I'm getting the same results, doesn't matter what chip address is configured.

Setting any of the bits 21..31 to high makes the hashing very sloooow. It seems it prevent the chip internal parallel processing somehow. Setting not all 20bits to high, gives me a different nonce range pattern per chip address. It's not yet fully clear to me what pattern is used. Considering the fact that S19k-Pro with 77 chip is using a 6bit mask and S19xp-luxos with 110 chips a 5 bit mask, seems to confirm that the S19k-Pro is hashing a bigger nonce range per chip address as S19xp-luxos.
This might need further investigation.....

Anyway, the duration for a full 2^32 nonces and 2^16 version rolling on my Bitaxe took (689521-2281/1000) 687,24 sec
If my math is correct, this gives me: 4.294.967.296 * 65.536 = 281.474.976.710.656 hashes / 687,24 sec = 409.573.041.020,1036028171 hashes/sec = 409 Gh/s. That sounds reasonable to me (considering running a unit test w/o optimization). Bonus, my unit test still found the nonce/version to resolve block #839900 ;-)

Below, the serial log of my session. It's somewhat pretty to see how the Bitaxe is hashing thru the entire 32bit nonce range from lowest to highest version until rollover ;-)

Next stop would be to get it implemented into ESP-Miner ;-)

Running Testing single BM1366 chip against a known valid block...
I (401) test_bm1366: ASIC: BM1366
I (401) test_bm1366: I2C initialized successfully
I (401) DS4432U.c: Set ASIC voltage = 1.250V [0xB9]
I (411) DS4432U.c: Writing 0xB9
I (411) serial: Initializing serial
I (411) bm1366Module: Initializing BM1366
I (1621) bm1366Module: 1 chip(s) detected on the chain
I (1651) bm1366Module: Setting Frequency to 550.00MHz (0.01)
I (1651) bm1366Module: Setting max baud of 1000000 
I (1661) serial: Changing UART baud to 1000000
I (1661) test_bm1366: BM1366 is ready and waiting for work
I (1671) test_bm1366: Preparing job
I (1671) bm1366Module: Setting job ASIC mask to 1023 (3ff)

I (1681) test_bm1366: Changing chip address and sending job; new chip address: 0x00
I (1691) test_bm1366: Waiting for result ... (might take a while)
I (2281) test_bm1366: Result[1]: Nonce 3356630138 Nonce difficulty 1026.29000767828665630077011883258820. rolled-version 0x2007c000
I (6401) test_bm1366: Result[2]: Nonce 4098331810 Nonce difficulty 1064.96651917922304164676461368799210. rolled-version 0x20386000
I (18171) test_bm1366: Result[3]: Nonce 730428121 Nonce difficulty 12925.98079703762959979940205812454224. rolled-version 0x20c40000
I (25471) test_bm1366: Result[4]: Nonce 2054183361 Nonce difficulty 1083.48521959102208711556158959865570. rolled-version 0x211b6000
I (32101) test_bm1366: Result[5]: Nonce 4220411461 Nonce difficulty 1352.93364926346794163691811263561249. rolled-version 0x216aa000
I (33841) test_bm1366: Result[6]: Nonce 1738592294 Nonce difficulty 3253.28003757193982892204076051712036. rolled-version 0x217f8000
I (44821) test_bm1366: Result[7]: Nonce 3296296050 Nonce difficulty 1453.17780613829404501302633434534073. rolled-version 0x2202c000
I (57001) test_bm1366: Result[8]: Nonce 2916474458 Nonce difficulty 2900.01401468868380106869153678417206. rolled-version 0x22932000
I (65581) test_bm1366: Result[9]: Nonce 728484779 Nonce difficulty 73303.47024935472290962934494018554688. rolled-version 0x22f9e000
I (72761) test_bm1366: Result[10]: Nonce 3543509168 Nonce difficulty 2768.57575025543292213114909827709198. rolled-version 0x234f4000
I (74531) test_bm1366: Result[11]: Nonce 3733637076 Nonce difficulty 5323.27495962955345021327957510948181. rolled-version 0x23640000
I (77281) test_bm1366: Result[12]: Nonce 3314032302 Nonce difficulty 6208.96365635305573960067704319953918. rolled-version 0x2385a000
I (85471) test_bm1366: Result[13]: Nonce 624424727 Nonce difficulty 1174.62942058242470011464320123195648. rolled-version 0x23e66000
I (89321) test_bm1366: Result[14]: Nonce 3818226259 Nonce difficulty 8452.86377870396427169907838106155396. rolled-version 0x24148000
I (107401) test_bm1366: Result[15]: Nonce 1379217352 Nonce difficulty 1947.37949368304271047236397862434387. rolled-version 0x24ece000
I (122361) test_bm1366: Result[16]: Nonce 435963153 Nonce difficulty 3911.03653636329499931889586150646210. rolled-version 0x259ec000
I (176881) test_bm1366: Result[17]: Nonce 3021266242 Nonce difficulty 2761.89034417103221130673773586750031. rolled-version 0x2828c000
I (185631) test_bm1366: Result[18]: Nonce 3850541471 Nonce difficulty 14370.11093116940901381894946098327637. rolled-version 0x28902000
I (209701) test_bm1366: Result[19]: Nonce 886605891 Nonce difficulty 1194.31917192739751953922677785158157. rolled-version 0x29afa000
I (215751) test_bm1366: Result[20]: Nonce 2161230739 Nonce difficulty 1958.41612947111821085854899138212204. rolled-version 0x29f72000
I (215911) test_bm1366: Result[21]: Nonce 2896796331 Nonce difficulty 6206.93857926386044709943234920501709. rolled-version 0x29f98000
I (223941) test_bm1366: Result[22]: Nonce 3310734796 Nonce difficulty 22439.06738404306452139280736446380615. rolled-version 0x2a59e000
I (229081) test_bm1366: Result[23]: Nonce 3529540887 Nonce difficulty 125538251293054.07812500000000000000000000000000. rolled-version 0x2a966000
I (254881) test_bm1366: Result[24]: Nonce 3979369686 Nonce difficulty 1065.74329468743121651641558855772018. rolled-version 0x2bca0000
I (270031) test_bm1366: Result[25]: Nonce 2367093861 Nonce difficulty 1053.33980769035611047002021223306656. rolled-version 0x2c7e0000
I (279641) test_bm1366: Result[26]: Nonce 1466870368 Nonce difficulty 1202.53008809878724605368915945291519. rolled-version 0x2cf18000
I (280841) test_bm1366: Result[27]: Nonce 3095815785 Nonce difficulty 1113.14920939102808006282430142164230. rolled-version 0x2cff6000
I (290151) test_bm1366: Result[28]: Nonce 3515377569 Nonce difficulty 3075.84001209167627166607417166233063. rolled-version 0x2d6e8000
I (293151) test_bm1366: Result[29]: Nonce 753393608 Nonce difficulty 4753.95315653250781906535848975181580. rolled-version 0x2d920000
I (293941) test_bm1366: Result[30]: Nonce 2554068531 Nonce difficulty 18653.14885606238385662436485290527344. rolled-version 0x2d9ba000
I (312051) test_bm1366: Result[31]: Nonce 4214192723 Nonce difficulty 1077.07178599741473590256646275520325. rolled-version 0x2e73e000
I (316051) test_bm1366: Result[32]: Nonce 4260924074 Nonce difficulty 1171.41560793723556344048120081424713. rolled-version 0x2ea3a000
I (318831) test_bm1366: Result[33]: Nonce 1412305839 Nonce difficulty 1199.63505616408269816020037978887558. rolled-version 0x2ec44000
I (335921) test_bm1366: Result[34]: Nonce 2446869902 Nonce difficulty 5151.08160455553479550871998071670532. rolled-version 0x2f900000
I (347421) test_bm1366: Result[35]: Nonce 3996152402 Nonce difficulty 1711.36246177649127275799401104450226. rolled-version 0x30194000
I (361861) test_bm1366: Result[36]: Nonce 1403708462 Nonce difficulty 1686.77668423937393527012318372726440. rolled-version 0x30c52000
I (371931) test_bm1366: Result[37]: Nonce 4292405564 Nonce difficulty 4826.03334644024380395421758294105530. rolled-version 0x313da000
I (374251) test_bm1366: Result[38]: Nonce 4113567568 Nonce difficulty 9897.91747666776609548833221197128296. rolled-version 0x31592000
I (391531) test_bm1366: Result[39]: Nonce 1276381192 Nonce difficulty 1256.61434292565650139295030385255814. rolled-version 0x3227a000
I (398331) test_bm1366: Result[40]: Nonce 3030061972 Nonce difficulty 1909.77368000968203887168783694505692. rolled-version 0x3278c000
I (404641) test_bm1366: Result[41]: Nonce 532194200 Nonce difficulty 1766.84642728682615597790572792291641. rolled-version 0x32c3a000
I (416871) test_bm1366: Result[42]: Nonce 2856921458 Nonce difficulty 4395.74669893087684613419696688652039. rolled-version 0x3355e000
I (417171) test_bm1366: Result[43]: Nonce 2625422405 Nonce difficulty 3364.87174582585703319637104868888855. rolled-version 0x33586000
I (421321) test_bm1366: Result[44]: Nonce 1340820186 Nonce difficulty 1561.98338810546511012944392859935760. rolled-version 0x338ac000
I (434581) test_bm1366: Result[45]: Nonce 3925501370 Nonce difficulty 2798.92112900040274325874634087085724. rolled-version 0x34286000
I (442251) test_bm1366: Result[46]: Nonce 2612621415 Nonce difficulty 41195.99239840431255288422107696533203. rolled-version 0x3483e000
I (460701) test_bm1366: Result[47]: Nonce 3490792207 Nonce difficulty 1454.04923850163299903215374797582626. rolled-version 0x355f4000
I (469731) test_bm1366: Result[48]: Nonce 3804451920 Nonce difficulty 5845.79301263196884974604472517967224. rolled-version 0x35cbe000
I (522091) test_bm1366: Result[49]: Nonce 2276386072 Nonce difficulty 1804.72462226439961341384332627058029. rolled-version 0x383bc000
I (564551) test_bm1366: Result[50]: Nonce 2129142167 Nonce difficulty 2050.76354358329308524844236671924591. rolled-version 0x3a35a000
I (588381) test_bm1366: Result[51]: Nonce 3792324699 Nonce difficulty 1050.60596683861763267486821860074997. rolled-version 0x3b51e000
I (589701) test_bm1366: Result[52]: Nonce 3616117198 Nonce difficulty 1780.86896359463571570813655853271484. rolled-version 0x3b61a000
I (595321) test_bm1366: Result[53]: Nonce 2318185730 Nonce difficulty 1411.90923138176458451198413968086243. rolled-version 0x3ba4c000
I (637431) test_bm1366: Result[54]: Nonce 779646338 Nonce difficulty 1309.10155970781420364801306277513504. rolled-version 0x3d9a0000
I (648341) test_bm1366: Result[55]: Nonce 106727592 Nonce difficulty 1900.49249539394349994836375117301941. rolled-version 0x3e1c4000
I (670081) test_bm1366: Result[56]: Nonce 3485472715 Nonce difficulty 1212.32286936800187504559289664030075. rolled-version 0x3f1f0000
I (677381) test_bm1366: Result[57]: Nonce 1397762629 Nonce difficulty 1877.09231490095703520637471228837967. rolled-version 0x3f764000
I (689521) test_bm1366: Result[58]: Nonce 3356630138 Nonce difficulty 1026.29000767828665630077011883258820. rolled-version 0x2007c000 (version rollover)
I (693641) test_bm1366: Result[59]: Nonce 4098331810 Nonce difficulty 1064.96651917922304164676461368799210. rolled-version 0x20386000 (version rollover)
I (705411) test_bm1366: Result[60]: Nonce 730428121 Nonce difficulty 12925.98079703762959979940205812454224. rolled-version 0x20c40000 (version rollover)

@skot
Copy link
Owner

skot commented Apr 23, 2024

Ooo! this sounds promising. I'm going to have to take a closer look at your writeup tonight. In the meantime here is a XP dump. pretty sure this is from stock firmware.
XP_hexdump.txt

@MoellerDi
Copy link
Contributor Author

Thanks Skot for sharing the dump. I'll read it tomorrow. Now I need to take some rest It's already after midnight in my timezone ;-)

@WantClue WantClue added enhancement New feature or request help wanted Extra attention is needed labels Apr 24, 2024
@MoellerDi
Copy link
Contributor Author

ok, thanks once again for sharing the XP hexdump.

As I can see, the XP is using 55 AA 51 09 00 10 00 00 15 1C 02 to init register 10. That's the same as being used in Bitaxe firmware as of today. It seems the XP hexdump was used to develop the chip init Bitaxe is using (it follows the same structure/pattern).

To recap what we have so far:

  • S19k-Pro (77 chips):
    55 AA 51 09 00 10 00 00 11 5A 04
    {0x00, 0x10, 0b00000000, 0b00000000, 0b00010001, 0b01011010} -> 6 bit high

  • S19xp-luxos (110 chips):
    55 AA 51 09 00 10 00 00 14 46 04
    {0x00, 0x10, 0b00000000, 0b00000000, 0b00010100, 0b01000110} -> 5 bit high

  • S19xp-stock (110 chips):
    55 AA 51 09 00 10 00 00 15 1C 02
    {0x00, 0x10, 0b00000000, 0b00000000, 0b00010101, 0b00011100} -> 6 bit high

It's interesting that XP stock firmware and luxos using different pattern to init reg. 10 on the XP (for the same amount of chips). So it seems it's not just the amount of high bits what matters. Needs further testing and more hexdumps with different amount of chips (if available).

@WantClue WantClue removed enhancement New feature or request help wanted Extra attention is needed labels Apr 24, 2024
@MoellerDi
Copy link
Contributor Author

Ok, it seems I was wrong yesterday (maybe I was too tired last night). I updated my post above to avoid confusion.

After more testing today, it turns out that bitmask seems to only 4bits:
{0x00, 0x10, 0b00000000, 0b00001111, 0b00000000, 0b00000000}
seems to get me the entire 32 bit nonce range doesn't matter what chip address is used (details below).
Next on my list is to understand how to equally distribute the entire 32 bit nonce range to 2 chips, 4 chips, 8 chips, etc.

I (1724) test_bm1366: Changing chip address and sending job; new chip address: 0x00
I (1734) test_bm1366: Waiting for result ... (might take a while)
I (2284) test_bm1366: Result[1]: Nonce 3356630138 (0xc8121c7a) Nonce difficulty 1026.29000767828665630077011883258820. rolled-version 0x2007c000
I (6154) test_bm1366: Result[2]: Nonce 4098331810 (0xf44794a2) Nonce difficulty 1064.96651917922304164676461368799210. rolled-version 0x20386000
I (17194) test_bm1366: Result[3]: Nonce 730428121 (0x2b8972d9) Nonce difficulty 12925.98079703762959979940205812454224. rolled-version 0x20c40000
I (24034) test_bm1366: Result[4]: Nonce 2054183361 (0x7a7059c1) Nonce difficulty 1083.48521959102208711556158959865570. rolled-version 0x211b6000
I (30244) test_bm1366: Result[5]: Nonce 4220411461 (0xfb8e5e45) Nonce difficulty 1352.93364926346794163691811263561249. rolled-version 0x216aa000
I (31874) test_bm1366: Result[6]: Nonce 1738592294 (0x67a0d026) Nonce difficulty 3253.28003757193982892204076051712036. rolled-version 0x217f8000
I (42174) test_bm1366: Result[7]: Nonce 3296296050 (0xc4797c72) Nonce difficulty 1453.17780613829404501302633434534073. rolled-version 0x2202c000
I (53584) test_bm1366: Result[8]: Nonce 2916474458 (0xadd5de5a) Nonce difficulty 2900.01401468868380106869153678417206. rolled-version 0x22932000
I (61634) test_bm1366: Result[9]: Nonce 728484779 (0x2b6bcbab) Nonce difficulty 73303.47024935472290962934494018554688. rolled-version 0x22f9e000
I (68364) test_bm1366: Result[10]: Nonce 3543509168 (0xd335a8b0) Nonce difficulty 2768.57575025543292213114909827709198. rolled-version 0x234f4000
I (70024) test_bm1366: Result[11]: Nonce 3733637076 (0xde8ac7d4) Nonce difficulty 5323.27495962955345021327957510948181. rolled-version 0x23640000
I (72594) test_bm1366: Result[12]: Nonce 3314032302 (0xc5881eae) Nonce difficulty 6208.96365635305573960067704319953918. rolled-version 0x2385a000
I (80284) test_bm1366: Result[13]: Nonce 624424727 (0x2537f717) Nonce difficulty 1174.62942058242470011464320123195648. rolled-version 0x23e66000
I (83884) test_bm1366: Result[14]: Nonce 3818226259 (0xe3958253) Nonce difficulty 8452.86377870396427169907838106155396. rolled-version 0x24148000
I (100834) test_bm1366: Result[15]: Nonce 1379217352 (0x52352fc8) Nonce difficulty 1947.37949368304271047236397862434387. rolled-version 0x24ece000
I (114864) test_bm1366: Result[16]: Nonce 435963153 (0x19fc4511) Nonce difficulty 3911.03653636329499931889586150646210. rolled-version 0x259ec000
I (165974) test_bm1366: Result[17]: Nonce 3021266242 (0xb414dd42) Nonce difficulty 2761.89034417103221130673773586750031. rolled-version 0x2828c000
I (174174) test_bm1366: Result[18]: Nonce 3850541471 (0xe582999f) Nonce difficulty 14370.11093116940901381894946098327637. rolled-version 0x28902000
I (196744) test_bm1366: Result[19]: Nonce 886605891 (0x34d88843) Nonce difficulty 1194.31917192739751953922677785158157. rolled-version 0x29afa000
I (202414) test_bm1366: Result[20]: Nonce 2161230739 (0x80d1c393) Nonce difficulty 1958.41612947111821085854899138212204. rolled-version 0x29f72000
I (202574) test_bm1366: Result[21]: Nonce 2896796331 (0xaca99aab) Nonce difficulty 6206.93857926386044709943234920501709. rolled-version 0x29f98000
I (210094) test_bm1366: Result[22]: Nonce 3310734796 (0xc555cdcc) Nonce difficulty 22439.06738404306452139280736446380615. rolled-version 0x2a59e000
I (214914) test_bm1366: Result[23]: Nonce 3529540887 (0xd2608517) Nonce difficulty 125538251293054.07812500000000000000000000000000. rolled-version 0x2a966000
I (239104) test_bm1366: Result[24]: Nonce 3979369686 (0xed305cd6) Nonce difficulty 1065.74329468743121651641558855772018. rolled-version 0x2bca0000
I (253314) test_bm1366: Result[25]: Nonce 2367093861 (0x8d16fc65) Nonce difficulty 1053.33980769035611047002021223306656. rolled-version 0x2c7e0000
I (262314) test_bm1366: Result[26]: Nonce 1466870368 (0x576eaa60) Nonce difficulty 1202.53008809878724605368915945291519. rolled-version 0x2cf18000
I (263434) test_bm1366: Result[27]: Nonce 3095815785 (0xb8866669) Nonce difficulty 1113.14920939102808006282430142164230. rolled-version 0x2cff6000
I (272164) test_bm1366: Result[28]: Nonce 3515377569 (0xd18867a1) Nonce difficulty 3075.84001209167627166607417166233063. rolled-version 0x2d6e8000
I (274984) test_bm1366: Result[29]: Nonce 753393608 (0x2ce7dfc8) Nonce difficulty 4753.95315653250781906535848975181580. rolled-version 0x2d920000
I (275724) test_bm1366: Result[30]: Nonce 2554068531 (0x983bfe33) Nonce difficulty 18653.14885606238385662436485290527344. rolled-version 0x2d9ba000
I (292694) test_bm1366: Result[31]: Nonce 4214192723 (0xfb2f7a53) Nonce difficulty 1077.07178599741473590256646275520325. rolled-version 0x2e73e000
I (296444) test_bm1366: Result[32]: Nonce 4260924074 (0xfdf88aaa) Nonce difficulty 1171.41560793723556344048120081424713. rolled-version 0x2ea3a000
I (299054) test_bm1366: Result[33]: Nonce 1412305839 (0x542e13af) Nonce difficulty 1199.63505616408269816020037978887558. rolled-version 0x2ec44000
I (315074) test_bm1366: Result[34]: Nonce 2446869902 (0x91d8458e) Nonce difficulty 5151.08160455553479550871998071670532. rolled-version 0x2f900000
I (325854) test_bm1366: Result[35]: Nonce 3996152402 (0xee307252) Nonce difficulty 1711.36246177649127275799401104450226. rolled-version 0x30194000
I (339394) test_bm1366: Result[36]: Nonce 1403708462 (0x53aae42e) Nonce difficulty 1686.77668423937393527012318372726440. rolled-version 0x30c52000
I (348834) test_bm1366: Result[37]: Nonce 4292405564 (0xffd8e93c) Nonce difficulty 4826.03334644024380395421758294105530. rolled-version 0x313da000
I (351014) test_bm1366: Result[38]: Nonce 4113567568 (0xf5300f50) Nonce difficulty 9897.91747666776609548833221197128296. rolled-version 0x31592000
I (367214) test_bm1366: Result[39]: Nonce 1276381192 (0x4c140808) Nonce difficulty 1256.61434292565650139295030385255814. rolled-version 0x3227a000
I (373584) test_bm1366: Result[40]: Nonce 3030061972 (0xb49b1394) Nonce difficulty 1909.77368000968203887168783694505692. rolled-version 0x3278c000
I (379504) test_bm1366: Result[41]: Nonce 532194200 (0x1fb8a398) Nonce difficulty 1766.84642728682615597790572792291641. rolled-version 0x32c3a000
I (390964) test_bm1366: Result[42]: Nonce 2856921458 (0xaa492972) Nonce difficulty 4395.74669893087684613419696688652039. rolled-version 0x3355e000
I (391254) test_bm1366: Result[43]: Nonce 2625422405 (0x9c7cc445) Nonce difficulty 3364.87174582585703319637104868888855. rolled-version 0x33586000
I (395144) test_bm1366: Result[44]: Nonce 1340820186 (0x4feb4ada) Nonce difficulty 1561.98338810546511012944392859935760. rolled-version 0x338ac000
I (407574) test_bm1366: Result[45]: Nonce 3925501370 (0xe9fa65ba) Nonce difficulty 2798.92112900040274325874634087085724. rolled-version 0x34286000
I (414764) test_bm1366: Result[46]: Nonce 2612621415 (0x9bb97067) Nonce difficulty 41195.99239840431255288422107696533203. rolled-version 0x3483e000
I (432054) test_bm1366: Result[47]: Nonce 3490792207 (0xd011430f) Nonce difficulty 1454.04923850163299903215374797582626. rolled-version 0x355f4000
I (440524) test_bm1366: Result[48]: Nonce 3804451920 (0xe2c35450) Nonce difficulty 5845.79301263196884974604472517967224. rolled-version 0x35cbe000
I (489614) test_bm1366: Result[49]: Nonce 2276386072 (0x87aee518) Nonce difficulty 1804.72462226439961341384332627058029. rolled-version 0x383bc000
I (529424) test_bm1366: Result[50]: Nonce 2129142167 (0x7ee82197) Nonce difficulty 2050.76354358329308524844236671924591. rolled-version 0x3a35a000
I (551764) test_bm1366: Result[51]: Nonce 3792324699 (0xe20a485b) Nonce difficulty 1050.60596683861763267486821860074997. rolled-version 0x3b51e000
I (552994) test_bm1366: Result[52]: Nonce 3616117198 (0xd78991ce) Nonce difficulty 1780.86896359463571570813655853271484. rolled-version 0x3b61a000
I (558274) test_bm1366: Result[53]: Nonce 2318185730 (0x8a2cb502) Nonce difficulty 1411.90923138176458451198413968086243. rolled-version 0x3ba4c000
I (597744) test_bm1366: Result[54]: Nonce 779646338 (0x2e787582) Nonce difficulty 1309.10155970781420364801306277513504. rolled-version 0x3d9a0000
I (607974) test_bm1366: Result[55]: Nonce 106727592 (0x065c88a8) Nonce difficulty 1900.49249539394349994836375117301941. rolled-version 0x3e1c4000
I (628354) test_bm1366: Result[56]: Nonce 3485472715 (0xcfc017cb) Nonce difficulty 1212.32286936800187504559289664030075. rolled-version 0x3f1f0000
I (635204) test_bm1366: Result[57]: Nonce 1397762629 (0x53502a45) Nonce difficulty 1877.09231490095703520637471228837967. rolled-version 0x3f764000
I (646574) test_bm1366: Result[58]: Nonce 3356630138 (0xc8121c7a) Nonce difficulty 1026.29000767828665630077011883258820. rolled-version 0x2007c000 (version rollover)
I (650444) test_bm1366: Result[59]: Nonce 4098331810 (0xf44794a2) Nonce difficulty 1064.96651917922304164676461368799210. rolled-version 0x20386000 (version rollover)
I (661484) test_bm1366: Result[60]: Nonce 730428121 (0x2b8972d9) Nonce difficulty 12925.98079703762959979940205812454224. rolled-version 0x20c40000 (version rollover)
I (668324) test_bm1366: Changing chip address and sending job; new chip address: 0x01
I (668324) test_bm1366: Waiting for result ... (might take a while)
I (668874) test_bm1366: Result[1]: Nonce 3356630138 (0xc8121c7a) Nonce difficulty 1026.29000767828665630077011883258820. rolled-version 0x2007c000
I (672744) test_bm1366: Result[2]: Nonce 4098331810 (0xf44794a2) Nonce difficulty 1064.96651917922304164676461368799210. rolled-version 0x20386000
I (683784) test_bm1366: Result[3]: Nonce 730428121 (0x2b8972d9) Nonce difficulty 12925.98079703762959979940205812454224. rolled-version 0x20c40000
I (690624) test_bm1366: Result[4]: Nonce 2054183361 (0x7a7059c1) Nonce difficulty 1083.48521959102208711556158959865570. rolled-version 0x211b6000
I (696834) test_bm1366: Result[5]: Nonce 4220411461 (0xfb8e5e45) Nonce difficulty 1352.93364926346794163691811263561249. rolled-version 0x216aa000
I (698464) test_bm1366: Result[6]: Nonce 1738592294 (0x67a0d026) Nonce difficulty 3253.28003757193982892204076051712036. rolled-version 0x217f8000
I (708764) test_bm1366: Result[7]: Nonce 3296296050 (0xc4797c72) Nonce difficulty 1453.17780613829404501302633434534073. rolled-version 0x2202c000
I (720174) test_bm1366: Result[8]: Nonce 2916474458 (0xadd5de5a) Nonce difficulty 2900.01401468868380106869153678417206. rolled-version 0x22932000
I (728224) test_bm1366: Result[9]: Nonce 728484779 (0x2b6bcbab) Nonce difficulty 73303.47024935472290962934494018554688. rolled-version 0x22f9e000
I (734954) test_bm1366: Result[10]: Nonce 3543509168 (0xd335a8b0) Nonce difficulty 2768.57575025543292213114909827709198. rolled-version 0x234f4000
I (736614) test_bm1366: Result[11]: Nonce 3733637076 (0xde8ac7d4) Nonce difficulty 5323.27495962955345021327957510948181. rolled-version 0x23640000
I (739184) test_bm1366: Result[12]: Nonce 3314032302 (0xc5881eae) Nonce difficulty 6208.96365635305573960067704319953918. rolled-version 0x2385a000
I (746874) test_bm1366: Result[13]: Nonce 624424727 (0x2537f717) Nonce difficulty 1174.62942058242470011464320123195648. rolled-version 0x23e66000
I (750474) test_bm1366: Result[14]: Nonce 3818226259 (0xe3958253) Nonce difficulty 8452.86377870396427169907838106155396. rolled-version 0x24148000
I (767424) test_bm1366: Result[15]: Nonce 1379217352 (0x52352fc8) Nonce difficulty 1947.37949368304271047236397862434387. rolled-version 0x24ece000
I (781454) test_bm1366: Result[16]: Nonce 435963153 (0x19fc4511) Nonce difficulty 3911.03653636329499931889586150646210. rolled-version 0x259ec000
I (832564) test_bm1366: Result[17]: Nonce 3021266242 (0xb414dd42) Nonce difficulty 2761.89034417103221130673773586750031. rolled-version 0x2828c000
I (840764) test_bm1366: Result[18]: Nonce 3850541471 (0xe582999f) Nonce difficulty 14370.11093116940901381894946098327637. rolled-version 0x28902000
I (863334) test_bm1366: Result[19]: Nonce 886605891 (0x34d88843) Nonce difficulty 1194.31917192739751953922677785158157. rolled-version 0x29afa000
I (869004) test_bm1366: Result[20]: Nonce 2161230739 (0x80d1c393) Nonce difficulty 1958.41612947111821085854899138212204. rolled-version 0x29f72000
I (869164) test_bm1366: Result[21]: Nonce 2896796331 (0xaca99aab) Nonce difficulty 6206.93857926386044709943234920501709. rolled-version 0x29f98000
I (876684) test_bm1366: Result[22]: Nonce 3310734796 (0xc555cdcc) Nonce difficulty 22439.06738404306452139280736446380615. rolled-version 0x2a59e000
I (881504) test_bm1366: Result[23]: Nonce 3529540887 (0xd2608517) Nonce difficulty 125538251293054.07812500000000000000000000000000. rolled-version 0x2a966000
I (905694) test_bm1366: Result[24]: Nonce 3979369686 (0xed305cd6) Nonce difficulty 1065.74329468743121651641558855772018. rolled-version 0x2bca0000
I (919904) test_bm1366: Result[25]: Nonce 2367093861 (0x8d16fc65) Nonce difficulty 1053.33980769035611047002021223306656. rolled-version 0x2c7e0000
I (928904) test_bm1366: Result[26]: Nonce 1466870368 (0x576eaa60) Nonce difficulty 1202.53008809878724605368915945291519. rolled-version 0x2cf18000
I (930024) test_bm1366: Result[27]: Nonce 3095815785 (0xb8866669) Nonce difficulty 1113.14920939102808006282430142164230. rolled-version 0x2cff6000
I (938754) test_bm1366: Result[28]: Nonce 3515377569 (0xd18867a1) Nonce difficulty 3075.84001209167627166607417166233063. rolled-version 0x2d6e8000
I (941574) test_bm1366: Result[29]: Nonce 753393608 (0x2ce7dfc8) Nonce difficulty 4753.95315653250781906535848975181580. rolled-version 0x2d920000
I (942314) test_bm1366: Result[30]: Nonce 2554068531 (0x983bfe33) Nonce difficulty 18653.14885606238385662436485290527344. rolled-version 0x2d9ba000
I (959284) test_bm1366: Result[31]: Nonce 4214192723 (0xfb2f7a53) Nonce difficulty 1077.07178599741473590256646275520325. rolled-version 0x2e73e000
I (963034) test_bm1366: Result[32]: Nonce 4260924074 (0xfdf88aaa) Nonce difficulty 1171.41560793723556344048120081424713. rolled-version 0x2ea3a000
I (965644) test_bm1366: Result[33]: Nonce 1412305839 (0x542e13af) Nonce difficulty 1199.63505616408269816020037978887558. rolled-version 0x2ec44000
I (981664) test_bm1366: Result[34]: Nonce 2446869902 (0x91d8458e) Nonce difficulty 5151.08160455553479550871998071670532. rolled-version 0x2f900000
I (992444) test_bm1366: Result[35]: Nonce 3996152402 (0xee307252) Nonce difficulty 1711.36246177649127275799401104450226. rolled-version 0x30194000
I (1005984) test_bm1366: Result[36]: Nonce 1403708462 (0x53aae42e) Nonce difficulty 1686.77668423937393527012318372726440. rolled-version 0x30c52000
I (1015424) test_bm1366: Result[37]: Nonce 4292405564 (0xffd8e93c) Nonce difficulty 4826.03334644024380395421758294105530. rolled-version 0x313da000
I (1017604) test_bm1366: Result[38]: Nonce 4113567568 (0xf5300f50) Nonce difficulty 9897.91747666776609548833221197128296. rolled-version 0x31592000
I (1033804) test_bm1366: Result[39]: Nonce 1276381192 (0x4c140808) Nonce difficulty 1256.61434292565650139295030385255814. rolled-version 0x3227a000
I (1040174) test_bm1366: Result[40]: Nonce 3030061972 (0xb49b1394) Nonce difficulty 1909.77368000968203887168783694505692. rolled-version 0x3278c000
I (1046094) test_bm1366: Result[41]: Nonce 532194200 (0x1fb8a398) Nonce difficulty 1766.84642728682615597790572792291641. rolled-version 0x32c3a000
I (1057554) test_bm1366: Result[42]: Nonce 2856921458 (0xaa492972) Nonce difficulty 4395.74669893087684613419696688652039. rolled-version 0x3355e000
I (1057844) test_bm1366: Result[43]: Nonce 2625422405 (0x9c7cc445) Nonce difficulty 3364.87174582585703319637104868888855. rolled-version 0x33586000
I (1061734) test_bm1366: Result[44]: Nonce 1340820186 (0x4feb4ada) Nonce difficulty 1561.98338810546511012944392859935760. rolled-version 0x338ac000
I (1074164) test_bm1366: Result[45]: Nonce 3925501370 (0xe9fa65ba) Nonce difficulty 2798.92112900040274325874634087085724. rolled-version 0x34286000
I (1081354) test_bm1366: Result[46]: Nonce 2612621415 (0x9bb97067) Nonce difficulty 41195.99239840431255288422107696533203. rolled-version 0x3483e000
I (1098644) test_bm1366: Result[47]: Nonce 3490792207 (0xd011430f) Nonce difficulty 1454.04923850163299903215374797582626. rolled-version 0x355f4000
I (1107114) test_bm1366: Result[48]: Nonce 3804451920 (0xe2c35450) Nonce difficulty 5845.79301263196884974604472517967224. rolled-version 0x35cbe000
I (1156204) test_bm1366: Result[49]: Nonce 2276386072 (0x87aee518) Nonce difficulty 1804.72462226439961341384332627058029. rolled-version 0x383bc000
I (1196014) test_bm1366: Result[50]: Nonce 2129142167 (0x7ee82197) Nonce difficulty 2050.76354358329308524844236671924591. rolled-version 0x3a35a000
I (1218354) test_bm1366: Result[51]: Nonce 3792324699 (0xe20a485b) Nonce difficulty 1050.60596683861763267486821860074997. rolled-version 0x3b51e000
I (1219584) test_bm1366: Result[52]: Nonce 3616117198 (0xd78991ce) Nonce difficulty 1780.86896359463571570813655853271484. rolled-version 0x3b61a000
I (1224864) test_bm1366: Result[53]: Nonce 2318185730 (0x8a2cb502) Nonce difficulty 1411.90923138176458451198413968086243. rolled-version 0x3ba4c000
I (1264334) test_bm1366: Result[54]: Nonce 779646338 (0x2e787582) Nonce difficulty 1309.10155970781420364801306277513504. rolled-version 0x3d9a0000
I (1274564) test_bm1366: Result[55]: Nonce 106727592 (0x065c88a8) Nonce difficulty 1900.49249539394349994836375117301941. rolled-version 0x3e1c4000
I (1294944) test_bm1366: Result[56]: Nonce 3485472715 (0xcfc017cb) Nonce difficulty 1212.32286936800187504559289664030075. rolled-version 0x3f1f0000
I (1301794) test_bm1366: Result[57]: Nonce 1397762629 (0x53502a45) Nonce difficulty 1877.09231490095703520637471228837967. rolled-version 0x3f764000
I (1313164) test_bm1366: Result[58]: Nonce 3356630138 (0xc8121c7a) Nonce difficulty 1026.29000767828665630077011883258820. rolled-version 0x2007c000 (version rollover)
I (1317034) test_bm1366: Result[59]: Nonce 4098331810 (0xf44794a2) Nonce difficulty 1064.96651917922304164676461368799210. rolled-version 0x20386000 (version rollover)
I (1328074) test_bm1366: Result[60]: Nonce 730428121 (0x2b8972d9) Nonce difficulty 12925.98079703762959979940205812454224. rolled-version 0x20c40000 (version rollover)

@MoellerDi
Copy link
Contributor Author

@skot IMHO this PR is completed and ready for your review.

While I was working on this PR I noticed some interesting stuff I would like to share as well.

  • BM1366 is using its chip/core address to compute the nonce range as explained by NebulaMiner. However the chip address is more like somewhat in the middle of the nonce and not at the MSB. It seems the core address is at the MSB.
  • The chip is testing its (filtered) nonce range from lowest to highest version (made rollover detection possible).
  • A chip with chip address < 0x80 calculate only nonces ending with 2,4,6,8,0. Chip with chip address of >= 0x80 calculate nonces ending with 1,3,5,7,9. Except register 0x10 is configured to combine the entire 32 bit nonce range into 1 single search range and assign it to chip address 0x00 (like in this unit test).

I hope my comments in the source code are sufficient to get you an understanding what I did or was aiming for. If not, just let me know and I will rework this PR.

Btw, I did not change bm1366_init to use BM1366_set_nonce_mask because it's messing up the job timing (BM1366_FULLSCAN_MS). It might be needed to rework the current job timing to adapt dynamically for different nonce range sizes instead of using a magic number.

@MoellerDi MoellerDi marked this pull request as ready for review May 2, 2024 19:29
@VikashLoomba
Copy link

@MoellerDi I just want to confirm that the implication of your findings is that right now BitAxes will never find the correct nonce, is that correct? Would you mind updating your forked repo with the .bin releases?

@DaCryptoRaccoon
Copy link

Can I ask how it would be possible to set this?

#A chip with chip address < 0x80 calculate only nonces ending with 2,4,6,8,0. Chip with chip address of >= 0x80 calculate nonces ending with 1,3,5,7,9. Except register 0x10 is configured to combine the entire 32 bit nonce range into 1 single search range and assign it to chip address 0x00 (like in this unit test).

I am interested in testing this I have a few devices and would like to set one to < 0x80 one with >= 0x80 and one with 0x10

I could not find where this would be possible any pointers?

Thanks.

@MoellerDi
Copy link
Contributor Author

I just want to confirm that the implication of your findings is that right now BitAxes will never find the correct nonce, is that correct?

No, that not correct. The goal of this PR (unit test) was actually to prove Bitaxe is able to find the correct nonce (and version). However, it seems it is not testing the full nonce space in a single chip configuration.

@MoellerDi
Copy link
Contributor Author

Can I ask how it would be possible to set this?

#A chip with chip address < 0x80 calculate only nonces ending with 2,4,6,8,0. Chip with chip address of >= 0x80 calculate nonces ending with 1,3,5,7,9. Except register 0x10 is configured to combine the entire 32 bit nonce range into 1 single search range and assign it to chip address 0x00 (like in this unit test).

There is no easy setting in the current firmware to change the chip address if that's what you are looking for. The chip address is assigned during the init phase of the chips/chain. If you want to change it, you would need to build a custom firmware for that. A good starting point would be the code used in this PR and/or the dev branch in my forked repo.

@benjamin-wilson
Copy link
Collaborator

IMHO it would make sense to develop kind of chip address switching feature to emulate a bigger chip chain to cover the whole nonce space on single-chip as well as on multi-chip hardware. It should further increase the chance to find a block.

I don't think there's any advantage to searching more of the (sub) space - it won't increase the chance of finding a block. Each hash has the same probability regardless where it is in the nonce space.

@DaCryptoRaccoon
Copy link

IMHO it would make sense to develop kind of chip address switching feature to emulate a bigger chip chain to cover the whole nonce space on single-chip as well as on multi-chip hardware. It should further increase the chance to find a block.

I don't think there's any advantage to searching more of the (sub) space - it won't increase the chance of finding a block. Each hash has the same probability regardless where it is in the nonce space.

Actually there is ranges that produce blocks more often than not. can be found here in the nonce pattern topic from a few years back. Bitmex research also did a good paper on this. I believe it may be a bitmain ASIC thing but interesting none the less.

https://www.reddit.com/r/Bitcoin/comments/adddja/the_weird_nonce_pattern/

There was most definetly a range of nonces that produced strange outcome. My questions is this.. If we are able to set the range and we have more than once device would it not be better to ensure each one is trying a various range. I can't speak for all miners but I know some larger operations and the do not start at 0 nonce.

image

@benjamin-wilson
Copy link
Collaborator

There cannot be nonce ranges that produce more blocks than others, otherwise mining would be inherently broken. That reddit article concluded that.

@skot
Copy link
Owner

skot commented May 25, 2024

This pattern is just a selection bias. They find more golden nonces in that pattern because that's all they are checking.

@Georges760
Copy link
Collaborator

hey guys, you should have pinged me on this Issue ;)

To clarify this "nonce space splitting" with Bitmain chip, here under is what I am almost (95%) sure of.

There are 3 different stages of splitting for a chain (a chain is equal to a Hashboard) :

  • split 1: between the ASIC of the chain
  • split 2: between the cores inside a single ASIC
  • split 3: between the small cores inside a single core

Split 1: this is done by the logical chip address given by the CB FW at the begining to every asic in the chain. It is a 8 bits space (256 values) that each ASIC will add (on the 8 msb of the 32 bits) as an offset on the first nonce value to begin hashing. So each ASIC in the chain will start at a different offset. It does not restrict the full nonce space hashing as if you let the chip run for enough time, it will hash the full nonce space (2^32 values). So in a single ASIC config (Bitaxe mono chip) we can use any Chip Address, as long aas we let enough time to hash. In a multi ASIC config (BitaxeHex, ...) we have to make sure to split evently by providing Chip Addresses with increment of round(256/num_asic) and let the Chain run for 1/increment the time of a single chip; waiting more time will make each asic hash header already hashed by the previous asic on the chain... It was the purpose of my "hex" branch from 9 month ago. I will rebase this work on the current "hex_v302" branch soon. When the number of ASIC on the chain is not a power or 2, there is always a "left over" at the end of the 32 bits nonce space that is never hashed by the chain, except if we let the chain hash for more time, the last ASIC in the chain will cover this "left over space" at the cost to have all other ASIC in the chain double hash space done by next-by ASIC... (I don't know if it ivery clear)

Split 2: each ASIC knows (by HW design) how many cores it has, so each cores start hashing at a different offset, this is all harcoded in the ASIC. But each ASIC has a formula to extract from the nonce value which cores founded it. For ASIC that does not have a power of 2 count of cores, the same effect as for "Split 1" appear for the "left over space"...

Split 3: each cores have a fixed number of "small cores" (by HW design). We have to make 2 cases for chip with (BM1366/68) or without (BM1397) version rolling :

  • without version rolling: the job command sent to the asic chain is composed by as much midstate as a single asic's core get "small cores", so each small cores hash a different midstate.
  • with version rolling: the job command sent to the asic chain is not composed by midstates, but get the full block header candidate, and each cores roll the version field for its different "small cores"

Copy link
Collaborator

@Georges760 Georges760 left a comment

Choose a reason for hiding this comment

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

this will conflict with the "hex_302" branch, so the merge in master should be done knowing that fact


unsigned char init7[7] = {0x55, 0xAA, 0x40, 0x05, 0x00, 0x00, 0x1C};
_send_simple(init7, 7);
//set chip address
Copy link
Collaborator

Choose a reason for hiding this comment

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

yes, this is exactly what I was talking about
it was the purpose of my "hex" branch from 9 month ago.
this have to be done also for other chip, not only BM1366. BM1397 and BM1368 may also be used in multi chip design in the furture

static int _calculate_chip_number(unsigned int actual_chip_count)
{
int i = 0;
if(actual_chip_count == 1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

the algo for this function may be written using interger algebra instead of this if else if else if structure.

I don't really understand the final usage of it, but as it is only for the added test (will not be used by actual mining), why not.

@skot
Copy link
Owner

skot commented May 29, 2024

It does not restrict the full nonce space hashing as if you let the chip run for enough time, it will hash the full nonce space (2^32 values). So in a single ASIC config (Bitaxe mono chip) we can use any Chip Address, as long aas we let enough time to hash.

This was my understanding too, based on what we have talked about. I have seen this to be the case on the BM1397.

I think what @MoellerDi is saying though is this isn't the case on the 1366.. it seems like those chips start hashing at the nonce offset provided by the address, but then do not continue to 2^32.. it sounds like they wrap around much before that.

Have you specifically seen version rolling chips hash nonces all the way from address offset to 2^32? This would be ideal in the single chip situation like the Bitaxe.

@Georges760
Copy link
Collaborator

Georges760 commented May 29, 2024

Have you specifically seen version rolling chips hash nonces all the way from address offset to 2^32? This would be ideal in the single chip situation like the Bitaxe.

No, never see it specifically, i can't confirm nor invalidate that...
I have very little experience with BM1366 compared to BM1397.
This is a very good point to be tested.

@MoellerDi
Copy link
Contributor Author

@skot @Georges760

It does not restrict the full nonce space hashing as if you let the chip run for enough time, it will hash the full nonce space (2^32 values). So in a single ASIC config (Bitaxe mono chip) we can use any Chip Address, as long aas we let enough time to hash.

based on the results of my testing (using this unit test) I cannot confirm this. I see the BM1366 is hashing/looping the same nonce space over and over again.

It is a 8 bits space (256 values) that each ASIC will add (on the 8 msb of the 32 bits) as an offset on the first nonce value to begin hashing. So each ASIC in the chain will start at a different offset.

yes, I noticed the logical chip address is somewhat used to filter the nonce space but I'm not sure if it's actually an offset on the 8 msb. I noticed that a chip with logical chip address 0x00 (like current bitaxe firmware) is producing nonces ending with, 0,2,4,6,8. If a logical chip address >= 0x80 is assigned, it's producing nonces ending with 1,3,5,7,9.
Would you kindly verify this in your bitaxe log? If I'm correct, you will see submitted nonces will end with 0,2,4,6,8 but no once ending with 1,3,5,7,9.

using chip address: 0x00:

I (1663) test_bm1366: Changing chip address and sending job; new chip address: 0x00
I (2673) test_bm1366: Waiting for result ... (might take a while)
I (2873) test_bm1366: Result[1]: Nonce 3356630138 (0xc8121c7a), Nonce difficulty 1026.29000767828665630077011883258820. rolled-version 0x2007c000 
I (4303) test_bm1366: Result[2]: Nonce 4098331810 (0xf44794a2), Nonce difficulty 1064.96651917922304164676461368799210. rolled-version 0x20386000 
I (5903) test_bm1366: Result[3]: Nonce 571883832 (0x22164138), Nonce difficulty 268.92169930113777809310704469680786. rolled-version 0x20706000 
I (7543) test_bm1366: Result[4]: Nonce 3684030306 (0xdb95d762), Nonce difficulty 273.29093164648435276831150986254215. rolled-version 0x20a84000 
I (9583) test_bm1366: Result[5]: Nonce 899195608 (0x3598a2d8), Nonce difficulty 428.04987293762587796663865447044373. rolled-version 0x20ef0000 
I (9663) test_bm1366: Result[6]: Nonce 3701308344 (0xdc9d7bb8), Nonce difficulty 348.14517558638596028686151839792728. rolled-version 0x20f28000 
I (10933) test_bm1366: Result[7]: Nonce 3734474184 (0xde978dc8), Nonce difficulty 490.89350913014163779735099524259567. rolled-version 0x211ea000 
I (12023) test_bm1366: Result[8]: Nonce 2470609446 (0x93428226), Nonce difficulty 472.43714049257033593676169402897358. rolled-version 0x2144a000 
I (13733) test_bm1366: Result[9]: Nonce 1738592294 (0x67a0d026), Nonce difficulty 3253.28003757193982892204076051712036. rolled-version 0x217f8000 
I (15843) test_bm1366: Result[10]: Nonce 1294996110 (0x4d30128e), Nonce difficulty 321.93918292484426046939915977418423. rolled-version 0x21c96000 
< cut >

using chip address: 0x80:

I (239063) test_bm1366: Changing chip address and sending job; new chip address: 0x80
I (240073) test_bm1366: Waiting for result ... (might take a while)
I (241493) test_bm1366: Result[1]: Nonce 1470390797 (0x57a4620d), Nonce difficulty 665.80246289296655959333293139934540. rolled-version 0x20318000 
I (243293) test_bm1366: Result[2]: Nonce 4226330125 (0xfbe8ae0d), Nonce difficulty 263.56319375457161413578432984650135. rolled-version 0x206f2000 
I (245733) test_bm1366: Result[3]: Nonce 730428121 (0x2b8972d9), Nonce difficulty 12925.98079703762959979940205812454224. rolled-version 0x20c40000 
I (248243) test_bm1366: Result[4]: Nonce 2054183361 (0x7a7059c1), Nonce difficulty 1083.48521959102208711556158959865570. rolled-version 0x211b6000 
I (250513) test_bm1366: Result[5]: Nonce 4220411461 (0xfb8e5e45), Nonce difficulty 1352.93364926346794163691811263561249. rolled-version 0x216aa000 
I (252403) test_bm1366: Result[6]: Nonce 1626525979 (0x60f2d11b), Nonce difficulty 287.72430257347406268308986909687519. rolled-version 0x21ab2000 
I (256953) test_bm1366: Result[7]: Nonce 792753113 (0x2f4073d9), Nonce difficulty 719.48733993563416788674658164381981. rolled-version 0x2249a000 
I (257633) test_bm1366: Result[8]: Nonce 2570145449 (0x99314ea9), Nonce difficulty 835.10603409449902301275869831442833. rolled-version 0x22618000 
I (262033) test_bm1366: Result[9]: Nonce 728484779 (0x2b6bcbab), Nonce difficulty 73303.47024935472290962934494018554688. rolled-version 0x22f9e000 
I (264653) test_bm1366: Result[10]: Nonce 257467217 (0x0f58a351), Nonce difficulty 874.22900469962451097671873867511749. rolled-version 0x23546000 
< cut >

Anyway, this PR/code needs - for sure - more development (I'm just a hobbyist, not a developer) but it's IMHO a good starting point. It shows reg 0x10 is somewhat changing the way how the chip is selecting/filtering the nonce range.

FYI, I made kind of proof-of-concept firmware in my repo (dev branch) if you like to test it out. It's functional firmware supporting full 32 bit nonce range hashing including dynamic job scheduling. It's running for 1-2 weeks on my bitaxe w/o issues.

@Georges760
Copy link
Collaborator

Georges760 commented May 30, 2024

I am always very cautious with these bit handling, there are so many way to get it wrong just by endianness error !

It shows reg 0x10 is somewhat changing the way how the chip is selecting/filtering the nonce range.

Register 0x10 is Hash Counting Number : https://github.com/skot/BM1397/blob/master/registers.md#hash-counting-number
It make sense that it is related to the maner the ASIC is incrementing the Nonce value at each iteration.

Can you elaborate about this effect of this register? maybe it is just the source of your nonce space problem.

@Georges760
Copy link
Collaborator

Georges760 commented May 30, 2024

Current BM1366 code is writing 0x0000151C in this HCN register : https://github.com/skot/ESP-Miner/blob/master/components/bm1397/bm1366.c#L511

Maybe we should write another value due to the fact we have a single chip in the Chain....

Can you try to write 0 and see if it solve your issue ?

To be noted that neither BM1397 (Max) nor BM1368 (Supra) change this HCN default value of 0x0000_0000...

@MoellerDi
Copy link
Contributor Author

Maybe we should write another value due to the fact we have a single chip in the Chain....

That's already done. The unit test in this PR is actually writing a value based on chip count. It try to select a none range as big as possible.

Can you try to write 0 and see if it solve your issue ?

Writing a zero to reg 0x10 will result in no hashing at all. What issue are you referring to? I do not have any issue, I just want to share what I got. The purpose of this unit test in this PR is to verify that the firmware/bm1366 chip is able to find the correct nonce/version combination as well as the correct hash for block #839900. It shows how I used reg. 0x10 to configure the bm1366 chip to use to full 32 bit nonce range.

Key part is "void BM1366_set_nonce_mask(int chip_count)".As you can see I'm using a magic number 0x15FF to calculate the offset like outlined below.

void BM1366_set_nonce_mask(int chip_count)
{
< cut >

    unsigned char command[9] = {0x00, 0x10, 0x00, 0x00, 0x00, 0x00};

    // This nonce_mask is used in combination with the chip address to calculate the nonce ranges for the chip.
    uint32_t offset = (0x15FF / 2); // found by try-and-error. 15FF seems to be max value. Any higher number result in duplicated nonces.
    uint32_t nonce_mask = offset * (0x100 / chip_count);

    // convert into char array and mix with command template
    for (int i = 0; i < 4; i++) {
        char value = (nonce_mask >> (8 * i)) & 0xFF;
        command[5 - i] = command[5 - i] | value;
    }

    ESP_LOGI(TAG, "Setting Nonce mask to %08lX", nonce_mask);
    _send_BM1366((TYPE_CMD | GROUP_ALL | CMD_WRITE), command, 6, false);
}

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.

7 participants