HomePhabricator

[avalanche] Improve the conflicting proof selection algorithm

Description

[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

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Maniphest Tasks: T1854

Differential Revision: https://reviews.bitcoinabc.org/D10435

Details

Provenance
FabienAuthored on Nov 5 2021, 11:41
FabienPushed on Nov 18 2021, 08:23
Reviewer
Restricted Project
Differential Revision
D10435: [avalanche] Improve the conflicting proof selection algorithm
Parents
rABC800f21378651: [avalanche] Remove getPeerId
Branches
Unknown
Tags
Unknown
Tasks
Restricted Maniphest Task