-
Notifications
You must be signed in to change notification settings - Fork 669
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
base: master
Are you sure you want to change the base?
Conversation
And, in multithreading, what needs to be compared with the |
818e4b5
to
0baa9d6
Compare
0baa9d6
to
ad035e9
Compare
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 But actually, just only one of the threads minted the |
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.
|
I retire my words. with the logging is clear how it behaves. Great job though :-) |
如果挖到min difficulty就停所有线程,就会降低挖到高难度的概率。 |
No, the min difficulty comparison only occurs when the remaining time is exceeded. At this time, pursuing high difficulty is irrational behavior. |
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. |
According to https://github.com/regolith-labs/ore/blob/b4bae9c823444db86fbc7f08aa624690a9d33e6b/program/src/mine.rs#L93 , the difficulty minted can equal to min difficulty.