Skip to content

Commit

Permalink
fix(genesis): make genesis starts working with the new spend struct
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi committed Jul 7, 2024
1 parent a370dd4 commit b601380
Show file tree
Hide file tree
Showing 14 changed files with 275 additions and 157 deletions.
32 changes: 31 additions & 1 deletion .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -855,13 +855,43 @@ jobs:
- name: Create and fund a wallet first time
run: |
~/faucet --log-output-dest=data-dir send 100000000 $(~/safe --log-output-dest=data-dir wallet address | tail -n 1) | tail -n 1 1>first.txt
address=$(~/safe --log-output-dest=data-dir wallet address | tail -n 1)
echo "-----------------------------------"
~/faucet --log-output-dest=data-dir send 100000000 $address > first_faucet.txt
echo "-----------------------------------"
cat first_faucet.txt
echo "==================================="
cat first_faucet.txt | tail -n 1 1>first.txt
echo "----------"
cat first.txt
env:
SN_LOG: "all"
timeout-minutes: 5

- name: Move faucet log to the working folder
run: |
echo "SAFE_DATA_PATH has: "
ls -l $SAFE_DATA_PATH
echo "test_faucet foder has: "
ls -l $SAFE_DATA_PATH/test_faucet
echo "logs folder has: "
ls -l $SAFE_DATA_PATH/test_faucet/logs
mv $SAFE_DATA_PATH/test_faucet/logs/faucet.log ./faucet_log.log
env:
SN_LOG: "all"
SAFE_DATA_PATH: /home/runner/.local/share/safe
continue-on-error: true
if: always()
timeout-minutes: 1

- name: Upload faucet log
uses: actions/upload-artifact@main
with:
name: faucet_test_first_faucet_log
path: faucet_log.log
continue-on-error: true
if: always()

- name: Create and fund a wallet second time
run: |
ls -l /home/runner/.local/share
Expand Down
33 changes: 20 additions & 13 deletions sn_client/src/audit/spend_dag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,36 +625,36 @@ impl SpendDag {
/// Verify the DAG and return faults detected in the DAG
/// If the DAG itself is invalid, return an error immediately
pub fn verify(&self, source: &SpendAddress) -> Result<BTreeSet<SpendFault>, DagError> {
info!("Verifying DAG starting off: {source:?}");
println!("Verifying DAG starting off: {source:?}");
let mut recorded_faults = BTreeSet::new();

// verify the DAG is acyclic
if petgraph::algo::is_cyclic_directed(&self.dag) {
warn!("DAG is cyclic");
println!("DAG is cyclic");
return Err(DagError::DagContainsCycle(*source));
}

// verify DAG source exists in the DAG (Genesis in case of a complete DAG)
debug!("Verifying DAG source: {source:?}");
println!("Verifying DAG source: {source:?}");
match self.spends.get(source) {
None => {
debug!("DAG does not contain its source: {source:?}");
println!("DAG does not contain its source: {source:?}");
return Err(DagError::MissingSource(*source));
}
Some(DagEntry::DoubleSpend(_)) => {
debug!("DAG source is a double spend: {source:?}");
println!("DAG source is a double spend: {source:?}");
recorded_faults.insert(SpendFault::DoubleSpend(*source));
}
_ => (),
}

// identify orphans (spends that don't come from the source)
debug!("Looking for orphans of {source:?}");
println!("Looking for orphans of {source:?}");
recorded_faults.extend(self.find_orphans(source)?);

// check all transactions
for (addr, _) in self.spends.iter() {
debug!("Verifying transaction at: {addr:?}");
println!("Verifying transaction at: {addr:?}");
// get the spend at this address
let spends = self
.spends
Expand All @@ -664,22 +664,22 @@ impl SpendDag {

// record double spends
if spends.len() > 1 {
debug!("Found a double spend entry in DAG at {addr:?}");
println!("Found a double spend entry in DAG at {addr:?}");
recorded_faults.insert(SpendFault::DoubleSpend(*addr));
let direct_descendants: BTreeSet<SpendAddress> = spends
.iter()
.flat_map(|s| s.spend.descendants.keys())
.map(SpendAddress::from_unique_pubkey)
.collect();
debug!("Making the direct descendants of the double spend at {addr:?} as faulty: {direct_descendants:?}");
println!("Making the direct descendants of the double spend at {addr:?} as faulty: {direct_descendants:?}");
for a in direct_descendants.iter() {
recorded_faults.insert(SpendFault::DoubleSpentAncestor {
addr: *a,
ancestor: *addr,
});
}
if self.double_spend_has_forking_descendant_branches(&spends) {
debug!("Double spend at {addr:?} has multiple living descendant branches, poisoning them...");
println!("Double spend at {addr:?} has multiple living descendant branches, poisoning them...");
let poison = format!(
"spend is on one of multiple branches of a double spent ancestor: {addr:?}"
);
Expand All @@ -697,7 +697,7 @@ impl SpendDag {

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

Expand All @@ -707,7 +707,7 @@ impl SpendDag {
}
}

info!(
println!(
"Found {} faults: {recorded_faults:#?}",
recorded_faults.len()
);
Expand Down Expand Up @@ -744,8 +744,15 @@ impl SpendDag {
};
recorded_faults.extend(faults);

let mut parents_collector = BTreeSet::new();
for ancestor in ancestor_spends {
let mut collector = BTreeSet::new();
let _ = collector.insert(ancestor);
let _ = parents_collector.insert(collector);
}

// verify the tx
if let Err(e) = spend.verify_parent_spends(&ancestor_spends) {
if let Err(e) = spend.verify_parent_spends(parents_collector.iter()) {
warn!("Parent Tx verfication failed for spend at: {addr:?}: {e}");
recorded_faults.insert(SpendFault::InvalidTransaction(addr, format!("{e}")));
let poison = format!("ancestor transaction was poisoned at: {addr:?}: {e}");
Expand Down
Loading

0 comments on commit b601380

Please sign in to comment.