-
Notifications
You must be signed in to change notification settings - Fork 54
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
Allow perpetual dft mining to correctly accept the next bitwork #110
Conversation
ae99739
to
84608d9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is good overall. Thanks for the patch which significantly helps users to save their mints!
To prove the next
difficulty can be equal to the current
, we might make tests to iterate the combination of inc
and start
to find out if we can avoid anti-patterns as much as possible.
@@ -459,3 +460,116 @@ def test_calculate_expected_bitwork_base(): | |||
assert(calculate_expected_bitwork('abcdefe', 33000, 1000, 1, 127) == 'abcdefe000') | |||
assert(calculate_expected_bitwork('abcdefe', 33000, 1000, 3, 127) == 'abcdefe0000000.2') | |||
|
|||
def test_calculate_expected_bitwork_rollover(): | |||
|
|||
assert(calculate_expected_bitwork('888888888888', 49995, 3333, 1, 64) == '8888.15') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding cases to guard increments other than 1
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please also consider adding cases for more general cases like: 8888.2, 8888.3, 8888.8, 8888.9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, added a variety and using an array-loop
electrumx/lib/util_atomicals.py
Outdated
@@ -1664,6 +1663,21 @@ def get_subname_request_candidate_status(current_height, atomical_info, status, | |||
'pending_candidate_atomical_id': candidate_id_compact | |||
} | |||
|
|||
# Whether txid is valid for the current and next bitwork | |||
def is_txid_valid_for_bitwork(txid, bitwork_vec, actual_mints, max_mints, target_increment, starting_target, allow_next): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For readability: rename to is_txid_valid_for_perpetual_bitwork
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
electrumx/server/block_processor.py
Outdated
return None | ||
|
||
mint_bitworkr_start = mint_info_for_ticker.get('$mint_bitworkr_start') | ||
if height >= self.coin.ATOMICALS_ACTIVATION_HEIGHT_BITWORKEXT: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get error AttributeError: type object 'BitcoinTestnet' has no attribute 'ATOMICALS_ACTIVATION_HEIGHT_BITWORKEXT'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Please don't just fix the problem for the cli mining mode, we need to make the txid that already meets the longer bv prefix valid under any shorter bitwork requirements with ext. |
electrumx/server/block_processor.py
Outdated
return None | ||
|
||
mint_bitworkr_start = mint_info_for_ticker.get('$mint_bitworkr_start') | ||
if height >= self.coin.ATOMICALS_ACTIVATION_HEIGHT_BITWORKEXT: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit
: this is essentially
if height >= self.coin.ATOMICALS_ACTIVATION_HEIGHT_BITWORKEXT: | |
if self.is_dft_bitwork_rollover_activated(height): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Fully test, it work, here is my test log
The only failed tx's bitwork is |
Please review again as there have been some changes and additional tests to accept the next full complete bitwork string. ie: 88888 should be valid for 8888.10 |
electrumx/lib/util_atomicals.py
Outdated
base_bitwork_padded = bitwork_vec.ljust(32, '0') | ||
b = base_bitwork_padded[:current_prefix_len] | ||
p = base_bitwork_padded[:current_prefix_len + 1] | ||
print(f'next_full_bitwork_prefix b={b} p={p} ') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need print, logger.debug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done and removed
electrumx/server/block_processor.py
Outdated
mint_bitworkr_start = mint_info_for_ticker.get('$mint_bitworkr_start') | ||
if height >= self.coin.ATOMICALS_ACTIVATION_HEIGHT_BITWORKEXT: | ||
if not is_txid_valid_for_perpetual_bitwork(atomicals_operations_found_at_inputs['commit_txid'], mint_bitwork_vec, decentralized_mints, max_mints, mint_bitworkr_inc, mint_bitworkr_start, True): | ||
self.logger.warning(f'create_or_delete_decentralized_mint_output: mint_bitworkc_inc not is_mint_pow_valid {hash_to_hex_str(tx_hash)}, atomicals_operations_found_at_inputs={atomicals_operations_found_at_inputs}...') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.logger.warning(f'create_or_delete_decentralized_mint_output: mint_bitworkc_inc not is_mint_pow_valid {hash_to_hex_str(tx_hash)}, atomicals_operations_found_at_inputs={atomicals_operations_found_at_inputs}...') | |
self.logger.warning(f'create_or_delete_decentralized_mint_output: mint_bitworkr_inc not is_mint_pow_valid {hash_to_hex_str(tx_hash)}, atomicals_operations_found_at_inputs={atomicals_operations_found_at_inputs}...') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
electrumx/server/block_processor.py
Outdated
return None | ||
else: | ||
if not is_txid_valid_for_perpetual_bitwork(atomicals_operations_found_at_inputs['reveal_location_txid'], mint_bitwork_vec, decentralized_mints, max_mints, mint_bitworkr_inc, mint_bitworkr_start, False): | ||
self.logger.warning(f'create_or_delete_decentralized_mint_output: mint_bitworkc_inc not is_mint_pow_valid {hash_to_hex_str(tx_hash)}, atomicals_operations_found_at_inputs={atomicals_operations_found_at_inputs}...') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.logger.warning(f'create_or_delete_decentralized_mint_output: mint_bitworkc_inc not is_mint_pow_valid {hash_to_hex_str(tx_hash)}, atomicals_operations_found_at_inputs={atomicals_operations_found_at_inputs}...') | |
self.logger.warning(f'create_or_delete_decentralized_mint_output: mint_bitworkr_inc not is_mint_pow_valid {hash_to_hex_str(tx_hash)}, atomicals_operations_found_at_inputs={atomicals_operations_found_at_inputs}...') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
electrumx/server/block_processor.py
Outdated
|
||
mint_bitworkr_start = mint_info_for_ticker.get('$mint_bitworkr_start') | ||
if height >= self.coin.ATOMICALS_ACTIVATION_HEIGHT_BITWORKEXT: | ||
if not is_txid_valid_for_perpetual_bitwork(atomicals_operations_found_at_inputs['commit_txid'], mint_bitwork_vec, decentralized_mints, max_mints, mint_bitworkr_inc, mint_bitworkr_start, True): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be reveal_location_txid
?
if not is_txid_valid_for_perpetual_bitwork(atomicals_operations_found_at_inputs['commit_txid'], mint_bitwork_vec, decentralized_mints, max_mints, mint_bitworkr_inc, mint_bitworkr_start, True): | |
if not is_txid_valid_for_perpetual_bitwork(atomicals_operations_found_at_inputs['reveal_location_txid'], mint_bitwork_vec, decentralized_mints, max_mints, mint_bitworkr_inc, mint_bitworkr_start, True): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ATOMICALS_ACTIVATION_HEIGHT_BITWORKEXT not define, need fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
a73ec52
to
077d276
Compare
bfc74e2
to
b3c5a5e
Compare
FYI to everyone: the activation height is atomicals-electrumx/electrumx/lib/coins.py Line 669 in 2372c56
|
Problem
Users who mine the next bitwork difficulty instead of the current will not be awarded the dft mint. This problem is magnified due to the atomicals-js CLI as of the previous version choosing to mine the next bitwork difficulty for an infinitely mineable token.
The user impact is that the users who attempted to mine the next difficulty after a certain threshold will not get their token mint because the indexer does not recognize bitwork difficulties higher than the currently acceptable one.
For example, if the current bitwork is
7777.15
and the next bitwork is77777
then anyone who mined77777
will not be accepted because according to the current rules (before this fix) only7777f
is valid (due to the presence of15
).The solution below focuses on also allowing the
77777
to be mined along with the7777f
since they are both technically the same difficulty.Solution
The solution presented here is to allow the indexer flexibility to also accept the next difficulty gracefully and award the user their dft mint.
The solution is activated (param
ATOMICALS_ACTIVATION_HEIGHT_BITWORKEXT
) on livenet as of height828500
and testnet as of height2576412
.When the new configuration becomes active, a Bitwork will be accepted from the next increment roll over.
Unit tests:
Note: Care must be taken for roll overs with increments that are not necessarily evenly divided by 16.
Run tests with:
pytest ./tests/lib/test_atomicals_utils.py
https://github.com/atomicals/atomicals-electrumx/blob/accept-next-bitwork/tests/lib/test_atomicals_utils.py#L463