Page MenuHomePhabricator

[avalanche] Improve the conflicting proof selection algorithm
ClosedPublic

Authored by Fabien on Nov 5 2021, 11:49.

Details

Reviewers
deadalnix
Group Reviewers
Restricted Project
Maniphest Tasks
Restricted Maniphest Task
Commits
rABC7df196b92feb: [avalanche] Improve the conflicting proof selection algorithm
Summary

The current algorithm special cases conflicting proofs using the same master key, so that it is possible to update a proof with a lower amount by increasing the sequence number.

But this comparator is incomplete: if 2 conflicting proofs with the same sequence number are submitted, the last arrived one is rejected. This comparaison exhibit a weird behavior: it is possible to get isConflictingProofPreferred(a, b) == isConflictingProofPreferred(b, a). For example, this prevents from using this algo for sorting.

This diff changes the behavior so that identical sequence are compared by the other parameters, i.e. amount, then stake count, then id. This fixes the above issue, while maintaining the possibility for a user to update a proof with a lower stake amount as long as he owns the master key.

As a consequence the unit test can be simplified in a single case to avoid duplication.

Ref T1854.

Test Plan
ninja all check-all

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Fabien requested review of this revision.Nov 5 2021, 11:49

Tail of the build log:

wallet_encryption.py --descriptors      | ✓ Passed  | 5 s
wallet_hd.py                            | ✓ Passed  | 8 s
wallet_hd.py --descriptors              | ✓ Passed  | 6 s
wallet_import_rescan.py                 | ✓ Passed  | 10 s
wallet_import_with_label.py             | ✓ Passed  | 1 s
wallet_importdescriptors.py             | ✓ Passed  | 7 s
wallet_importmulti.py                   | ✓ Passed  | 6 s
wallet_importprunedfunds.py             | ✓ Passed  | 2 s
wallet_keypool.py                       | ✓ Passed  | 3 s
wallet_keypool_topup.py                 | ✓ Passed  | 4 s
wallet_keypool_topup.py --descriptors   | ✓ Passed  | 4 s
wallet_labels.py                        | ✓ Passed  | 2 s
wallet_labels.py --descriptors          | ✓ Passed  | 2 s
wallet_listreceivedby.py                | ✓ Passed  | 14 s
wallet_listsinceblock.py                | ✓ Passed  | 6 s
wallet_listtransactions.py              | ✓ Passed  | 11 s
wallet_multiwallet.py --usecli          | ✓ Passed  | 17 s
wallet_reorgsrestore.py                 | ✓ Passed  | 4 s
wallet_resendwallettransactions.py      | ✓ Passed  | 3 s
wallet_send.py                          | ✓ Passed  | 8 s
wallet_startup.py                       | ✓ Passed  | 3 s
wallet_txn_clone.py                     | ✓ Passed  | 3 s
wallet_txn_clone.py --mineblock         | ✓ Passed  | 4 s
wallet_txn_doublespend.py               | ✓ Passed  | 3 s
wallet_txn_doublespend.py --mineblock   | ✓ Passed  | 4 s
wallet_watchonly.py                     | ✓ Passed  | 1 s
wallet_watchonly.py --usecli            | ✓ Passed  | 2 s

ALL                                     | ✓ Passed  | 1275 s (accumulated) 
Runtime: 256 s

----------------------------------------------------------------------
Ran 10 tests in 0.162s

OK

[197/456] Running avalanche test suite
PASSED: avalanche test suite
[198/456] Running seeder test suite
PASSED: seeder test suite
[199/456] Test Bitcoin RPC authentication...
...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK
[200/456] cd /work/contrib/devtools/chainparams && /usr/bin/python3.7 ./test_make_chainparams.py
.....
----------------------------------------------------------------------
Ran 5 tests in 0.001s

OK
[426/456] Running pow test suite
PASSED: pow test suite
[449/456] Running bitcoin-qt test suite
PASSED: bitcoin-qt test suite
[454/456] Running bitcoin test suite
PASSED: bitcoin test suite
ninja: build stopped: cannot make progress due to previous errors.
Build build-debug failed with exit code 1

Unrelated failure, restarting the build

This revision is now accepted and ready to land.Nov 17 2021, 17:38