fix and consolidate tx ordering logic
This commit is contained in:
parent
d16d961cb2
commit
078bc1d914
@ -55,11 +55,14 @@ pub fn partial_cmp_uid_score(a: (u32, u32, f64), b: (u32, u32, f64)) -> Option<O
|
|||||||
// If either score is NaN, this is false,
|
// If either score is NaN, this is false,
|
||||||
// and partial_cmp will return None
|
// and partial_cmp will return None
|
||||||
if a.2 != b.2 {
|
if a.2 != b.2 {
|
||||||
|
// compare by score (sorts by ascending score)
|
||||||
a.2.partial_cmp(&b.2)
|
a.2.partial_cmp(&b.2)
|
||||||
} else if a.1 != b.1 {
|
} else if a.1 != b.1 {
|
||||||
|
// tie-break by comparing partial txids (sorts by descending txid)
|
||||||
Some(b.1.cmp(&a.1))
|
Some(b.1.cmp(&a.1))
|
||||||
} else {
|
} else {
|
||||||
Some(a.0.cmp(&b.0))
|
// tie-break partial txid collisions by comparing uids (sorts by descending uid)
|
||||||
|
Some(b.0.cmp(&a.0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +70,7 @@ impl PartialOrd for AuditTransaction {
|
|||||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||||
partial_cmp_uid_score(
|
partial_cmp_uid_score(
|
||||||
(self.uid, self.order, self.score),
|
(self.uid, self.order, self.score),
|
||||||
(other.uid, self.order, other.score),
|
(other.uid, other.order, other.score),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,13 +36,10 @@ impl PartialEq for TxPriority {
|
|||||||
impl Eq for TxPriority {}
|
impl Eq for TxPriority {}
|
||||||
impl PartialOrd for TxPriority {
|
impl PartialOrd for TxPriority {
|
||||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||||
if self.score != other.score {
|
partial_cmp_uid_score(
|
||||||
self.score.partial_cmp(&other.score)
|
(self.uid, self.order, self.score),
|
||||||
} else if self.order != other.order {
|
(other.uid, other.order, other.score),
|
||||||
Some(other.order.cmp(&self.order))
|
)
|
||||||
} else {
|
|
||||||
Some(self.uid.cmp(&other.uid))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Ord for TxPriority {
|
impl Ord for TxPriority {
|
||||||
@ -153,26 +150,31 @@ pub fn gbt(mempool: &mut ThreadTransactionsMap) -> GbtResult {
|
|||||||
overflow.push(next_tx.uid);
|
overflow.push(next_tx.uid);
|
||||||
failures += 1;
|
failures += 1;
|
||||||
} else {
|
} else {
|
||||||
let mut package: Vec<(u32, usize)> = Vec::new();
|
let mut package: Vec<(u32, u32, usize)> = Vec::new();
|
||||||
let mut cluster: Vec<u32> = Vec::new();
|
let mut cluster: Vec<u32> = Vec::new();
|
||||||
let is_cluster: bool = !next_tx.ancestors.is_empty();
|
let is_cluster: bool = !next_tx.ancestors.is_empty();
|
||||||
for ancestor_id in &next_tx.ancestors {
|
for ancestor_id in &next_tx.ancestors {
|
||||||
if let Some(ancestor) = audit_pool.get(ancestor_id) {
|
if let Some(ancestor) = audit_pool.get(ancestor_id) {
|
||||||
package.push((*ancestor_id, ancestor.ancestors.len()));
|
package.push((*ancestor_id, ancestor.order(), ancestor.ancestors.len()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
package.sort_unstable_by(|a, b| -> Ordering {
|
package.sort_unstable_by(|a, b| -> Ordering {
|
||||||
if a.1 == b.1 {
|
if a.2 != b.2 {
|
||||||
b.0.cmp(&a.0)
|
// order by ascending ancestor count
|
||||||
} else {
|
a.2.cmp(&b.2)
|
||||||
|
} else if a.1 != b.1 {
|
||||||
|
// tie-break by ascending partial txid
|
||||||
a.1.cmp(&b.1)
|
a.1.cmp(&b.1)
|
||||||
|
} else {
|
||||||
|
// tie-break partial txid collisions by ascending uid
|
||||||
|
a.0.cmp(&b.0)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
package.push((next_tx.uid, next_tx.ancestors.len()));
|
package.push((next_tx.uid, next_tx.order(), next_tx.ancestors.len()));
|
||||||
|
|
||||||
let cluster_rate = next_tx.cluster_rate();
|
let cluster_rate = next_tx.cluster_rate();
|
||||||
|
|
||||||
for (txid, _) in &package {
|
for (txid, _, _) in &package {
|
||||||
cluster.push(*txid);
|
cluster.push(*txid);
|
||||||
if let Some(tx) = audit_pool.get_mut(txid) {
|
if let Some(tx) = audit_pool.get_mut(txid) {
|
||||||
tx.used = true;
|
tx.used = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user