Skip to content
This repository has been archived by the owner on Aug 23, 2020. It is now read-only.

Commit

Permalink
removed double spend training wheels
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul D Handy committed Sep 23, 2017
1 parent fca143a commit 9fb9198
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 74 deletions.
49 changes: 0 additions & 49 deletions src/main/java/com/iota/iri/controllers/TransactionViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,55 +411,6 @@ public void updateHeights(final Tangle tangle) throws Exception {
}
}

public static Set<String> dsHashes = new HashSet<>();
static {
dsHashes.add(Iota.MAINNET_COORDINATOR_ADDRESS);
dsHashes.add(Iota.TESTNET_COORDINATOR_ADDRESS);
dsHashes.add(Hash.NULL_HASH.toString());
}


private static final int firstBundlesSeenAllowed = 2;

public boolean isDoubleSpend(Tangle tangle) throws Exception {
{
String addy = getAddressHash().toString();
if (dsHashes.contains(addy)) {
return false;
}
}
Set<Hash> hashes;
{
AddressViewModel addressViewModel = this.getAddress(tangle);
hashes = addressViewModel.getHashes();
}
if(hashes.size() < 2) {
return false;
}
Set<Hash> bundleViewModels = new HashSet<>();
Set<Hash> firstBundlesSeen = new HashSet<>(firstBundlesSeenAllowed);
for(Hash txHash: hashes) {
TransactionViewModel transactionViewModel = TransactionViewModel.fromHash(tangle, txHash);
if(transactionViewModel.value() < 0) {
Hash bundleHash = transactionViewModel.getBundleHash();
bundleViewModels.add(bundleHash);

if( firstBundlesSeen.size() < firstBundlesSeenAllowed){
firstBundlesSeen.add(bundleHash);
}
if(firstBundlesSeen.contains(this.getBundleHash())) {
//allow re-attachment of first seen bundles.
return false;
}
}

if(bundleViewModels.size() > firstBundlesSeenAllowed) {
return true;
}
}
return false;
}

public void updateSender(String sender) throws Exception {
transaction.sender = sender;
}
Expand Down
25 changes: 0 additions & 25 deletions src/main/java/com/iota/iri/service/TipsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,6 @@ Hash randomWalk(final Hash start, final Hash extraTip, final Map<Hash, Long> rat
log.info("Reason to stop: transactionViewModel==extraTip");
messageQ.publish("rtsd %s", transactionViewModel.getHash());
break;
} else if (isBundleReusingKey(transactionViewModel)) {
log.info("Reason to stop: key reuse");
messageQ.publish("rtsk %s", transactionViewModel.getHash());
break;
}
// set the tail here!
tail = tip;
Expand Down Expand Up @@ -262,27 +258,6 @@ Hash randomWalk(final Hash start, final Hash extraTip, final Map<Hash, Long> rat
return tail;
}

private boolean isBundleReusingKey(TransactionViewModel tailTransaction) throws Exception {
//skip milestones and NULL_HASH
if (TransactionViewModel.dsHashes.contains(tailTransaction.getAddressHash().toString())) {
return false;
}
if (tailTransaction.lastIndex() == 0){
//single transaction bundle, doesn't spend.
return false;
}

for(
TransactionViewModel transactionViewModel = tailTransaction;
transactionViewModel.getCurrentIndex() != transactionViewModel.lastIndex();
transactionViewModel = transactionViewModel.getTrunkTransaction(tangle)) {
if(transactionViewModel.value() < 0 && transactionViewModel.isDoubleSpend(tangle)) {
return true;
}
}
return false;
}

static long capSum(long a, long b, long max) {
if(a + b < 0 || a + b > max) {
return max;
Expand Down

0 comments on commit 9fb9198

Please sign in to comment.