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

fix: min difficulty #98

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

Conversation

GoudanWoo
Copy link

@GoudanWoo
Copy link
Author

And, in multithreading, what needs to be compared with the min_difficulty is the global_best_difficulty, not the best_difficulty of the current thread, otherwise all threads will have to mint the min_difficulty.

@HardhatChad
Copy link
Collaborator

This is not necessary. Each thread returns their best hash and then we reduce at the end for the global best.

@HardhatChad
Copy link
Collaborator

#100

@GoudanWoo
Copy link
Author

GoudanWoo commented Aug 6, 2024

This is not necessary. Each thread returns their best hash and then we reduce at the end for the global best.

No, it is necessary. For example, if min_difficulty = 10, so it means that all threads need to mint the difficulty >= 10 before my fix.

But actually, just only one of the threads minted the difficulty >= 10, and we can stop all threads.

@StaRkeSolanaValidator
Copy link

This is not necessary. Each thread returns their best hash and then we reduce at the end for the global best.

No, it is necessary. For example, if min_difficulty = 10, so it means that all threads need to mint the difficulty >= 10 before my fix.

But actually, just only one of the threads minted the difficulty >= 10, and we can stop all threads.

I was testing your fix and I still see that behaviour. Meaning if I set to 10, all the threads need to mint at least 10 and right after the last one is achieved, it choose the best one to send the transaction.

@GoudanWoo
Copy link
Author

I was testing your fix and I still see that behaviour. Meaning if I set to 10, all the threads need to mint at least 10 and right after the last one is achieved, it choose the best one to send the transaction.

How did you test it?

You can log the result of each thread:

        // Join handles and return best nonce
        let mut best_nonce = 0;
        let mut best_difficulty = 0;
        let mut best_hash = Hash::default();
        for (i, h) in handles.into_iter().enumerate() {
            if let Ok((nonce, difficulty, hash)) = h.join() {
                println!("thread {} find {} difficulty, hash: {}", i, difficulty, bs58::encode(hash.h).into_string());
                if difficulty > best_difficulty {
                    best_difficulty = difficulty;
                    best_nonce = nonce;
                    best_hash = hash;
                }
            }
        }

Then you will got logs like it (I set the min difficulty to 12):

thread 0 find 13 difficulty, hash: 15BQbKmazLhodbPAR61y5EdTDvEE8pUeV5kpQe1GxK7
thread 1 find 7 difficulty, hash: 6taHHV66KZbaPJRYuQcW13tgLBSLwdMomcKzJENGm9J
thread 2 find 9 difficulty, hash: 12RmHtg2wuetMn98mR2zFyi6iuJgTWgWPNwFJspddeq5
thread 3 find 10 difficulty, hash: 1ve5jhgCDYwhJY29R46kqDPpeYgS1uHy3SUSA2twq5D
thread 4 find 11 difficulty, hash: 1UodHxpLupQj6wCQGogxushtadADPQnZsF7HDoAASRj
thread 5 find 10 difficulty, hash: 1qsiobfwr7Nd4mBEyPsq3kD3EkTGHh9iUrbMVMC6eVk
thread 6 find 8 difficulty, hash: 14JkJuq3jEFXjk2DEFuvyin1YDJmxwfHRAiW3F1cTG9W
thread 7 find 10 difficulty, hash: 1qw9Npw17UCqCtCBuFmX4dANFe7FL225t8rLWKPkbfy
thread 8 find 10 difficulty, hash: 1awLx1jCUMFuYnjzFPfEFYHAsnkhNpMgApktF4iWtox
thread 9 find 10 difficulty, hash: 1agVydratjs7LRSwMv2JJL7KDcmMXTgJpWTCwEXefrM
thread 10 find 8 difficulty, hash: 139xCN7Hf9RKCs4HjYZwTEzdSE97guC9ffVMqSMjs7mk
thread 11 find 10 difficulty, hash: 1y28a2oiuD4iZqQKUNMyVp7hjmAyxAyrctxKbEzyhVf
  Best hash: 15BQbKmazLhodbPAR61y5EdTDvEE8pUeV5kpQe1GxK7 (difficulty: 13) 

But if you test it without my fix, you will got:

thread 0 find 13 difficulty, hash: 15BQbKmazLhodbPAR61y5EdTDvEE8pUeV5kpQe1GxK7                                                                                      thread 1 find 13 difficulty, hash: 16mRUnNnenMQ61GyCEQisRAypQP3Pb1LpSUzKZc2yVv
thread 2 find 13 difficulty, hash: 17mei2zh3me6pRmeGhDu4vf4HErAbNQxk1HV4pZeGrK
thread 3 find 14 difficulty, hash: 132fdbL51xUdn9M53HCZkZQQRujRz2JgCnYwCBTfRYx
thread 4 find 14 difficulty, hash: 13GKTuGBi9V2T9esy5smumHah2wACveL2qGf1aLhWC5
thread 5 find 13 difficulty, hash: 16WmpAxosrkpxFuiVZk1TGWFP4Ee8V7yL9SZg19Map4
thread 6 find 14 difficulty, hash: 12qtgR4UD9KCT2b2dwSU2oGPsLx6hH2Etm7234j9Krg
thread 7 find 14 difficulty, hash: 13BazxXrRxQrY1PjLtQsQXdXGXJrST3UDHqrrHAMYNs
thread 8 find 13 difficulty, hash: 15hKC81i28QQt299wQvRhjfoZyqVZtjVmMPZUakQEMW
thread 9 find 13 difficulty, hash: 17kTkWKGQkFhi64qZaVzRZoiybcabNZrTWZnLNaPWXY
thread 10 find 20 difficulty, hash: 113goYrn5Q7ioD34U8vcHFwAnmoW4CkAQkTbVnPtLT3
thread 11 find 14 difficulty, hash: 13N9EzCrGKkDpS7baJgCBkW9yc4AnzjSjRGJvRLmano
  Best hash: 113goYrn5Q7ioD34U8vcHFwAnmoW4CkAQkTbVnPtLT3 (difficulty: 20) 

So I believe my fix is useful.

If you test it, but no difference was found, you may be need to increase min difficulty. Because you computer is too fast to find low difficulty.

@StaRkeSolanaValidator
Copy link

I was testing your fix and I still see that behaviour. Meaning if I set to 10, all the threads need to mint at least 10 and right after the last one is achieved, it choose the best one to send the transaction.

How did you test it?

You can log the result of each thread:

        // Join handles and return best nonce
        let mut best_nonce = 0;
        let mut best_difficulty = 0;
        let mut best_hash = Hash::default();
        for (i, h) in handles.into_iter().enumerate() {
            if let Ok((nonce, difficulty, hash)) = h.join() {
                println!("thread {} find {} difficulty, hash: {}", i, difficulty, bs58::encode(hash.h).into_string());
                if difficulty > best_difficulty {
                    best_difficulty = difficulty;
                    best_nonce = nonce;
                    best_hash = hash;
                }
            }
        }

Then you will got logs like it (I set the min difficulty to 12):

thread 0 find 13 difficulty, hash: 15BQbKmazLhodbPAR61y5EdTDvEE8pUeV5kpQe1GxK7
thread 1 find 7 difficulty, hash: 6taHHV66KZbaPJRYuQcW13tgLBSLwdMomcKzJENGm9J
thread 2 find 9 difficulty, hash: 12RmHtg2wuetMn98mR2zFyi6iuJgTWgWPNwFJspddeq5
thread 3 find 10 difficulty, hash: 1ve5jhgCDYwhJY29R46kqDPpeYgS1uHy3SUSA2twq5D
thread 4 find 11 difficulty, hash: 1UodHxpLupQj6wCQGogxushtadADPQnZsF7HDoAASRj
thread 5 find 10 difficulty, hash: 1qsiobfwr7Nd4mBEyPsq3kD3EkTGHh9iUrbMVMC6eVk
thread 6 find 8 difficulty, hash: 14JkJuq3jEFXjk2DEFuvyin1YDJmxwfHRAiW3F1cTG9W
thread 7 find 10 difficulty, hash: 1qw9Npw17UCqCtCBuFmX4dANFe7FL225t8rLWKPkbfy
thread 8 find 10 difficulty, hash: 1awLx1jCUMFuYnjzFPfEFYHAsnkhNpMgApktF4iWtox
thread 9 find 10 difficulty, hash: 1agVydratjs7LRSwMv2JJL7KDcmMXTgJpWTCwEXefrM
thread 10 find 8 difficulty, hash: 139xCN7Hf9RKCs4HjYZwTEzdSE97guC9ffVMqSMjs7mk
thread 11 find 10 difficulty, hash: 1y28a2oiuD4iZqQKUNMyVp7hjmAyxAyrctxKbEzyhVf
  Best hash: 15BQbKmazLhodbPAR61y5EdTDvEE8pUeV5kpQe1GxK7 (difficulty: 13) 

But if you test it without my fix, you will got:

thread 0 find 13 difficulty, hash: 15BQbKmazLhodbPAR61y5EdTDvEE8pUeV5kpQe1GxK7                                                                                      thread 1 find 13 difficulty, hash: 16mRUnNnenMQ61GyCEQisRAypQP3Pb1LpSUzKZc2yVv
thread 2 find 13 difficulty, hash: 17mei2zh3me6pRmeGhDu4vf4HErAbNQxk1HV4pZeGrK
thread 3 find 14 difficulty, hash: 132fdbL51xUdn9M53HCZkZQQRujRz2JgCnYwCBTfRYx
thread 4 find 14 difficulty, hash: 13GKTuGBi9V2T9esy5smumHah2wACveL2qGf1aLhWC5
thread 5 find 13 difficulty, hash: 16WmpAxosrkpxFuiVZk1TGWFP4Ee8V7yL9SZg19Map4
thread 6 find 14 difficulty, hash: 12qtgR4UD9KCT2b2dwSU2oGPsLx6hH2Etm7234j9Krg
thread 7 find 14 difficulty, hash: 13BazxXrRxQrY1PjLtQsQXdXGXJrST3UDHqrrHAMYNs
thread 8 find 13 difficulty, hash: 15hKC81i28QQt299wQvRhjfoZyqVZtjVmMPZUakQEMW
thread 9 find 13 difficulty, hash: 17kTkWKGQkFhi64qZaVzRZoiybcabNZrTWZnLNaPWXY
thread 10 find 20 difficulty, hash: 113goYrn5Q7ioD34U8vcHFwAnmoW4CkAQkTbVnPtLT3
thread 11 find 14 difficulty, hash: 13N9EzCrGKkDpS7baJgCBkW9yc4AnzjSjRGJvRLmano
  Best hash: 113goYrn5Q7ioD34U8vcHFwAnmoW4CkAQkTbVnPtLT3 (difficulty: 20) 

So I believe my fix is useful.

If you test it, but no difference was found, you may be need to increase min difficulty. Because you computer is too fast to find low difficulty.

I retire my words. with the logging is clear how it behaves. Great job though :-)

@kabaBZ
Copy link

kabaBZ commented Aug 8, 2024

如果挖到min difficulty就停所有线程,就会降低挖到高难度的概率。

@GoudanWoo
Copy link
Author

如果挖到min difficulty就停所有线程,就会降低挖到高难度的概率。

No, the min difficulty comparison only occurs when the remaining time is exceeded. At this time, pursuing high difficulty is irrational behavior.

@liangxiwei
Copy link

min difficult is easy to reach. stop all thread or wait all thread reach the min difficult is no different.

@WankkoRee
Copy link

min difficult is easy to reach. stop all thread or wait all thread reach the min difficult is no different.

But you can't assume that the min difficulty will still be so easy to reach in the future. You must to know, the min difficulty is dynamic. It is not necessarily constant 1. It may go up to 10 or even 20 in the future.

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.

6 participants