Bitcoin Forum
December 07, 2025, 09:28:59 PM *
News: Latest Bitcoin Core release: 30.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: L7 9050 Miner. How to calculate the difficulty per share?  (Read 149 times)
v1rus96 (OP)
Newbie
*
Offline Offline

Activity: 4
Merit: 1


View Profile
December 16, 2024, 10:03:43 PM
Merited by nc50lc (1)
 #1

Hey guys. I have been trying to calculate difficulty for Litecoin shares sent by miner. I am using L7 9050 10Gh/s Miner. Shares have header value which I recieve from mining.submit. I tried to double hash it using sha256 and also tried with Scrypt hashing algo. But I am getting wrong values. For example pools sets the difficulty of 200k and values I am getting is around 14k 56k and etc. But it still accepted by the pool which means I am doing calculations. wrongly. Anybody can help?

Code:
import hashlib
from ltc_scrypt import getPoWHash

# LTC difficulty-1 target (original mainnet)
LTC_MAX_TARGET = 0x00000FFFF0000000000000000000000000000000000000000000000000000000

def hash_ltc_block_and_compute_diff(version_hex, prevhash_hex, merkle_root_hex_le,
                                    ntime_hex, nbits_hex, nonce_hex):
    """
    1) Builds an LTC block header (80 bytes) from the given hex fields.
    2) Hashes the header using LTC's Scrypt (ltc_scrypt.getPoWHash).
    3) Converts the result to an integer (big-endian).
    4) Divides LTC_MAX_TARGET by that integer to get the share difficulty.
    """

    # Convert each field from hex
    version_bin       = bytes.fromhex(version_hex)       # 4 bytes
    prevhash_bin      = bytes.fromhex(prevhash_hex)      # 32 bytes (LE in Stratum)
    merkle_root_le_bin= bytes.fromhex(merkle_root_hex_le)# 32 bytes (LE)
    ntime_bin         = bytes.fromhex(ntime_hex)         # 4 bytes
    nbits_bin         = bytes.fromhex(nbits_hex)         # 4 bytes
    nonce_bin         = bytes.fromhex(nonce_hex)         # 4 bytes

    # LTC block header is 80 bytes, with each 4-byte field in LE order
    block_header = (
        version_bin[::-1]         +  # version (4 bytes, LE)
        prevhash_bin              +  # previous block hash (32 bytes, LE)
        merkle_root_le_bin        +  # merkle root (32 bytes, LE)
        ntime_bin[::-1]           +  # ntime (4 bytes, LE)
        nbits_bin[::-1]           +  # nbits (4 bytes, LE)
        nonce_bin[::-1]           # nonce (4 bytes, LE)
    )

    # 1) Hash with LTC Scrypt
    pow_hash = getPoWHash(block_header)

    # 2) Convert final 32-byte hash to big-endian integer
    pow_int = int.from_bytes(pow_hash, byteorder='big')

    # 3) Difficulty = LTC_MAX_TARGET / pow_int
    found_diff = LTC_MAX_TARGET / pow_int

    return pow_hash.hex(), pow_int, found_diff


if name == "main":
    # Example hex fields (dummy placeholders)
    version_hex       = "20000000"  # e.g. 0x20000000
    prevhash_hex      = "86c16d2b8ae0c77491ae..." + "000000000000000000"  # 64 chars
    merkle_root_hex_le= "d9c56fd774..." + "000000000000000000"          # 64 chars
    ntime_hex         = "5f34eb28"
    nbits_hex         = "1e0fffff"
    nonce_hex         = "00000000"

    pow_hex, pow_int, found_diff = hash_ltc_block_and_compute_diff(
        version_hex, prevhash_hex, merkle_root_hex_le,
        ntime_hex, nbits_hex, nonce_hex
    )

    print(f"LTC Scrypt hash (hex): {pow_hex}")
    print(f"LTC Scrypt hash (int): {pow_int}")
    print(f"Share Difficulty: {found_diff:.6f}")
philipma1957
Legendary
*
Online Online

Activity: 4690
Merit: 10963


'The right to privacy matters'


View Profile WWW
December 16, 2024, 10:06:07 PM
 #2

first off don't post here in btc


post in

https://bitcointalk.org/index.php?board=160.0


alt coin mining


second off just point your l7 to


viabtc


do not bother setting difficulty

typical setting would be

url =          ltc.viabtc.com:3333
worker =     your name.L7
password = 1


I asked the mods to move this to the right part of the forum

▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
████████████████████████████████▀
██████████████████████████████▀██▄█
████████████████████████████▀██████
█████████████████████████▀█████████
██████████████████████▀████████████
█▄██▀▀█████████████▀███████▄▄▄█████
███▄████▀▀██████▀▀█████▄▄▀▀▀███████
█████▄▄█████▀▀█▀██████████▄████████
████████▀▀███▄███████████▄█████████
█████████▄██▀▀▀▀███▀▀██████████████
███████████▄▄█▀████▄███████████████
███████████████▄▄██████████████████

 AltairTech.io    Miners  Parts 🖰 Accessories 
_______Based in Missouri, USA._________________Your One-Stop Shop for Bitcoin Mining Solutions_____________________Mining Farm Consulting__________
.
.🛒SHOP NOW .
v1rus96 (OP)
Newbie
*
Offline Offline

Activity: 4
Merit: 1


View Profile
December 16, 2024, 10:31:18 PM
 #3

Thank you for clarification. I need the calculations for my side project. So I connected the miner to my own server, and I am receiving the shares. I need to calculate the difficulty per share.
JayDDee
Full Member
***
Offline Offline

Activity: 1453
Merit: 241


View Profile
December 17, 2024, 02:04:20 PM
 #4

Share difficulty doesn't matter, only that the share hash is below the target hash (share diff higher than target diff) set by stratum.
All submitted shares carry the same value for a given stratum diff. Your calculation only compares the share diff with the target diff
which is essentially what determines if the share may be submitted to the pool.


v1rus96 (OP)
Newbie
*
Offline Offline

Activity: 4
Merit: 1


View Profile
December 17, 2024, 03:33:36 PM
 #5

Share difficulty doesn't matter, only that the share hash is below the target hash (share diff higher than target diff) set by stratum.
All submitted shares carry the same value for a given stratum diff. Your calculation only compares the share diff with the target diff
which is essentially what determines if the share may be submitted to the pool.



Yes but how does the pool calculate and validates the difficulty of the shares? I would like to do the calculations myself. for example, pool sets difficulty 25k and then then share difficulty should be above that diffiulcty right? I want to know the correct formula how to get and validate myself?
JayDDee
Full Member
***
Offline Offline

Activity: 1453
Merit: 241


View Profile
December 17, 2024, 04:11:02 PM
Merited by nc50lc (2)
 #6

Share difficulty doesn't matter, only that the share hash is below the target hash (share diff higher than target diff) set by stratum.
All submitted shares carry the same value for a given stratum diff. Your calculation only compares the share diff with the target diff
which is essentially what determines if the share may be submitted to the pool.



Yes but how does the pool calculate and validates the difficulty of the shares? I would like to do the calculations myself. for example, pool sets difficulty 25k and then then share difficulty should be above that diffiulcty right? I want to know the correct formula how to get and validate myself?

Your overthinking, stratum diff is used to calculate the target, it isn't the target.
The miner already tests the hash to decide whether to submit the hash to the pool.
The formula is:  if (share_hash <= target_hash) submit share. Diff is just the reciprocal of the hash.
Inverted it's (share_diff > target_diff)

v1rus96 (OP)
Newbie
*
Offline Offline

Activity: 4
Merit: 1


View Profile
December 17, 2024, 08:33:08 PM
 #7

Share difficulty doesn't matter, only that the share hash is below the target hash (share diff higher than target diff) set by stratum.
All submitted shares carry the same value for a given stratum diff. Your calculation only compares the share diff with the target diff
which is essentially what determines if the share may be submitted to the pool.



Yes but how does the pool calculate and validates the difficulty of the shares? I would like to do the calculations myself. for example, pool sets difficulty 25k and then then share difficulty should be above that diffiulcty right? I want to know the correct formula how to get and validate myself?

Your overthinking, stratum diff is used to calculate the target, it isn't the target.
The miner already tests the hash to decide whether to submit the hash to the pool.
The formula is:  if (share_hash <= target_hash) submit share. Diff is just the reciprocal of the hash.
Inverted it's (share_diff > target_diff)

How can I calculate the exact difficulty of a share before submitting it to the pool? For example, if I have the share's hash and the current pool target, what is the correct formula to determine if the share qualifies as a 'high difficulty' or 'low difficulty' share relative to the current target difficulty?
JayDDee
Full Member
***
Offline Offline

Activity: 1453
Merit: 241


View Profile
December 17, 2024, 11:11:53 PM
Merited by philipma1957 (3)
 #8

When someone asks a question that was answered in the previous post, and the answer was
quoted, it's time to give up.

philipma1957
Legendary
*
Online Online

Activity: 4690
Merit: 10963


'The right to privacy matters'


View Profile WWW
December 23, 2024, 05:52:51 AM
 #9

When someone asks a question that was answered in the previous post, and the answer was
quoted, it's time to give up.

Well it is hard to say whats needed.

one thing we failed to mention that a pool can say we want only 500,000 setting per shares for diff

or we want 100,000 setting.

or we want 10,000 setting

since the pool knows its server capacity but does not know how many will try to mine at the server.

So you the miner could do what the pool wants since the pool will fuck you if you don’t set what we tell you.

now it is his server so he can limit the share to what he wants. since he won’t have a lot of traffic. just his one L7.

so set it at one see how it goes

since in his case as described it does not matter.

lots and lots of shares that are too low and a lot of traffic

or he can set it to 1,000,000 a few shares still too low and less traffic.



my road my highway.

my vehicle.

so a bus with two people
 

a bus with forty people .

eventually you move enough on the road to get a block

either way you need the correct amount to be reached for the block

but with forty on the bus overall less trips.


it matter more if you let other vehicles on the road.

you want 10,000 buses with 2 people moving 20,000 or

500 buses with 40 people moving 20,000.

only one bus is yours
only one miner is yours.


but look at all the other traffic on your server or road if you set 2 per bus vs 40.

at op you can set share difficulty from 1 to the coin difficulty for a block.

say 1 to 2 billion for ltc

it is the same principle as my bus/ miner example where I set the range at 2 to 40
and the goal or block is 20,000

So you could just look up the true difficulty number for ltc  and make sure you are a lot lower than that.

so block difficulty of 2,000,000,000 mean you could say a share must be

2,000,000 which is 1/1000 of the block difficulty call it high

and 20,000 which is 1/100,000 of the block difficulty call it low.

share difficulty is very arbitrary on the pool owner.

as long as the share difficulty is not higher than the actual block difficulty.

ie when block difficulty is 2,000,000,000 do not set you share to 2,000,000,010 since that is higher than some possible winning shares.

So i would say look at the actual block difficulty setting and do 1/1000 for the high share and 1/100,000 for the low share.

simple enough especially if it is your server and oyur miner is the only miner.


▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
████████████████████████████████▀
██████████████████████████████▀██▄█
████████████████████████████▀██████
█████████████████████████▀█████████
██████████████████████▀████████████
█▄██▀▀█████████████▀███████▄▄▄█████
███▄████▀▀██████▀▀█████▄▄▀▀▀███████
█████▄▄█████▀▀█▀██████████▄████████
████████▀▀███▄███████████▄█████████
█████████▄██▀▀▀▀███▀▀██████████████
███████████▄▄█▀████▄███████████████
███████████████▄▄██████████████████

 AltairTech.io    Miners  Parts 🖰 Accessories 
_______Based in Missouri, USA._________________Your One-Stop Shop for Bitcoin Mining Solutions_____________________Mining Farm Consulting__________
.
.🛒SHOP NOW .
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!