Skip to content
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

Massive Spend Refactor #1989

Merged
merged 28 commits into from
Aug 28, 2024
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
abc3df2
chore!: refactor spend struct
maqi Jun 29, 2024
75afa35
fix(spend): support multiple inputs with different keys
maqi Jul 9, 2024
b66d5a9
chore(kad): not enough close peers no longer result in error out
maqi Jul 10, 2024
cbde3dc
chore(spend_simulation): disable non-cashnote UTXO spend error out
maqi Jul 10, 2024
9942c03
chore(spend_simulation): disable failing query attempt assertion
maqi Jul 10, 2024
b187c8f
feat: add support for multi parents in CNR
grumbach Jul 11, 2024
8bb3a29
feat: remove middle spend from offline transfers
grumbach Jul 12, 2024
56a56cf
chore: rename token to amount
grumbach Jul 18, 2024
2c1ca64
refactor: entire transacting flow from CashNote to SignedSpend
grumbach Jul 19, 2024
9a54e12
fix: move tx verification to wallet sign
grumbach Jul 19, 2024
17d95d2
fix: re enable reissue bench
grumbach Jul 22, 2024
178b01c
fix: doctests
grumbach Jul 22, 2024
cabb759
fix: bench
grumbach Jul 22, 2024
e48af65
feat: improve network royalties identification for spends
grumbach Jul 22, 2024
dd91c1c
fix: spends fixes and security verifications
grumbach Jul 23, 2024
386d1c7
chore: improve code quality
grumbach Jul 23, 2024
9bd610a
fix: dag double spend test
grumbach Jul 23, 2024
d3c9e39
fix: serious error in spend dag double spend branching
grumbach Jul 23, 2024
fb33e07
fix: dag crawling invalid source check
grumbach Jul 23, 2024
fbc6613
fix: re comment uncommented block
grumbach Jul 23, 2024
dbe8822
chore: update docs for CashNote and spends
grumbach Jul 24, 2024
0f92260
feat: fixes and tests for unsigned tx
grumbach Jul 25, 2024
f574fb5
chore: disable flawed tests sending out invalid 0 tx
grumbach Jul 25, 2024
c2b3bb1
fix: allow time for double spend to spread in spend test
grumbach Jul 29, 2024
9fe6f44
chore: adapt after rebase
grumbach Jul 29, 2024
8bcab6d
test: bump sleep time to 20s
grumbach Jul 29, 2024
bab2054
fix: test issue
grumbach Jul 29, 2024
4643330
feat: remove output purpose
grumbach Aug 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: dag double spend test
grumbach committed Jul 29, 2024
commit 9bd610a6eca043150caba909c2fbd590e15307a0
4 changes: 2 additions & 2 deletions sn_client/src/audit/spend_dag.rs
Original file line number Diff line number Diff line change
@@ -719,9 +719,9 @@ impl SpendDag {
continue;
}

// skip parent Tx verification for source as we don't know its ancestors
// skip parent verification for source as we don't know its ancestors
if addr == source {
debug!("Skip transaction verification for source at: {addr:?}");
debug!("Skip parent verification for source at: {addr:?}");
continue;
}

28 changes: 11 additions & 17 deletions sn_client/src/audit/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ fn test_spend_dag_verify_valid_simple() -> Result<()> {
for spend in net.spends {
dag.insert(spend.address(), spend.clone());
}
assert!(dag.record_faults(&genesis).is_ok());
assert_eq!(dag.record_faults(&genesis), Ok(()));
// dag.dump_to_file("/tmp/test_spend_dag_verify_valid_simple")?;

assert_eq!(dag.verify(&genesis), Ok(BTreeSet::new()));
@@ -84,8 +84,8 @@ fn test_spend_dag_double_spend_poisonning() -> Result<()> {
for spend in net.spends {
dag.insert(spend.address(), spend.clone());
}
assert!(dag.record_faults(&genesis).is_ok());
// dag.dump_to_file("/tmp/test_spend_dag_double_spend_poisonning")?;
assert_eq!(dag.record_faults(&genesis), Ok(()));

// make sure double spend is detected
assert_eq!(spend1, spend2, "both spends should be at the same address");
@@ -112,15 +112,19 @@ fn test_spend_dag_double_spend_poisonning() -> Result<()> {
assert_eq!(got, expected, "UTXO of double spend should be unspendable");
let s3 = spend_ko3.first().expect("spend_ko3 to have an element");
let got = dag.get_spend_faults(s3);
let expected = BTreeSet::from_iter([SpendFault::DoubleSpend(*double_spent)]);
let expected = BTreeSet::from_iter([SpendFault::DoubleSpentAncestor {
addr: *s3,
ancestor: *double_spent,
}]);
assert_eq!(got, expected, "spend_ko3 should be unspendable");

// make sure this didn't poison the rest of the DAG
let s4 = spend_ok4.first().expect("spend_ok4 to be unique");
let s5 = spend_ok5.first().expect("spend_ok5 to be unique");
let unaffected = BTreeSet::new();

assert_eq!(dag.get_spend_faults(s4), expected);
assert_eq!(dag.get_spend_faults(s5), expected);
assert_eq!(dag.get_spend_faults(s4), unaffected);
assert_eq!(dag.get_spend_faults(s5), unaffected);
Ok(())
}

@@ -178,29 +182,19 @@ fn test_spend_dag_double_spend_branches() -> Result<()> {
let expected = BTreeSet::from_iter([SpendFault::DoubleSpend(*double_spent)]);
assert_eq!(got, expected, "DAG should have detected double spend");

// make sure the double spend's direct descendants are marked as bad
// make sure the double spend's direct descendants are marked as double spent
let s3 = spend3.first().expect("spend3 to have an element");
let got = dag.get_spend_faults(s3);
let expected = BTreeSet::from_iter([SpendFault::DoubleSpentAncestor {
addr: *s3,
ancestor: *double_spent,
}]);
// let expected = BTreeSet::from_iter([
// SpendFault::MissingAncestry {
// addr: *s3,
// ancestor: *double_spent,
// },
// SpendFault::DoubleSpentAncestor {
// addr: *s3,
// ancestor: *double_spent,
// },
// ]); TODO check this
assert_eq!(got, expected, "spend3 should be unspendable");
let s3a = spend3a.first().expect("spend3a to have an element");
let got = dag.get_spend_faults(s3a);
assert_eq!(got, expected, "spend3a should be unspendable");

// make sure all the descendants further down the branch are marked as bad as well
// make sure all the descendants further down the branch are poisoned due to a double spent ancestor
let utxo_of_5a = SpendAddress::from_unique_pubkey(
&net.wallets
.get(&owner5a)