Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Commit

Permalink
Fix a race that could occur if somehow the P2P network got the depend…
Browse files Browse the repository at this point in the history
…ency tx to us before the lh server responded to the pledge upload request. Never seen this before but today it happened!
  • Loading branch information
mikehearn committed Dec 2, 2014
1 parent 5a6e18a commit 9adcb23
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions common/src/main/java/lighthouse/wallet/PledgingWallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,13 @@ public LHProtos.Pledge commit(boolean andBroadcastDependencies, LHProtos.Pledge
log.info("Committing pledge for stub: {}", stub);
committed = true;
if (dependency != null) {
commitTx(dependency);
if (andBroadcastDependencies) {
// It's possible that by the time we arrive here, the dependency is already committed, thus we use the
// maybe variant. The reason is, for a server-assisted project the server will broadcast the dependency
// for us to avoid races where the server thinks a pledge is invalid because it can't see the stub
// output. If the server responds to our HTTP upload request and we get here *slower* that the p2p
// network manages to propagate the transaction back to us, we might have already processed the
// dependency tx!
if (maybeCommitTx(dependency) && andBroadcastDependencies) {
log.info("Broadcasting dependency");
vTransactionBroadcaster.broadcastTransaction(dependency);
}
Expand Down

0 comments on commit 9adcb23

Please sign in to comment.