mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-20 10:22:18 +01:00
Wait to commit BSQ txOutputs to bsqStateService until after parsing
If a transaction is considered invalid it should consider all the txOutputs to be invalid. To avoid counting a txOutput as valid it's better to commit to stateservice only after checking the validity of the transaction.
This commit is contained in:
parent
5dffe7159e
commit
3f87460b57
@ -28,6 +28,8 @@ import bisq.core.dao.state.blockchain.TxType;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import lombok.Getter;
|
||||
@ -49,6 +51,7 @@ public class TxOutputParser {
|
||||
@Setter
|
||||
private long availableInputValue = 0;
|
||||
private int lockTime;
|
||||
private List<TempTxOutput> bsqOutputs = new ArrayList<>();
|
||||
@Setter
|
||||
private int unlockBlockHeight;
|
||||
@Setter
|
||||
@ -74,11 +77,28 @@ public class TxOutputParser {
|
||||
this.bsqStateService = bsqStateService;
|
||||
}
|
||||
|
||||
public void commitTxOutputs() {
|
||||
bsqOutputs.forEach(bsqOutput -> {
|
||||
bsqStateService.addUnspentTxOutput(TxOutput.fromTempOutput(bsqOutput));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* This sets all outputs to BTC_OUTPUT and doesn't add any txOutputs to the bsqStateService
|
||||
*/
|
||||
public void commitTxOutputsForInvalidTx() {
|
||||
bsqOutputs.forEach(bsqOutput -> {
|
||||
bsqOutput.setTxOutputType(TxOutputType.BTC_OUTPUT);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void processGenesisTxOutput(TempTx genesisTx) {
|
||||
for (int i = 0; i < genesisTx.getTempTxOutputs().size(); ++i) {
|
||||
TempTxOutput tempTxOutput = genesisTx.getTempTxOutputs().get(i);
|
||||
bsqStateService.addUnspentTxOutput(TxOutput.fromTempOutput(tempTxOutput));
|
||||
bsqOutputs.add(tempTxOutput);
|
||||
}
|
||||
commitTxOutputs();
|
||||
}
|
||||
|
||||
boolean isOpReturnOutput(TempTxOutput txOutput) {
|
||||
@ -144,7 +164,7 @@ public class TxOutputParser {
|
||||
availableInputValue -= optionalSpentLockupTxOutput.get().getValue();
|
||||
|
||||
txOutput.setTxOutputType(TxOutputType.UNLOCK);
|
||||
bsqStateService.addUnspentTxOutput(TxOutput.fromTempOutput(txOutput));
|
||||
bsqOutputs.add(txOutput);
|
||||
|
||||
//TODO move up to TxParser
|
||||
// We should add unlockBlockHeight to TempTxOutput and remove unlockBlockHeight from tempTx
|
||||
@ -178,7 +198,7 @@ public class TxOutputParser {
|
||||
bsqOutput = TxOutputType.BSQ_OUTPUT;
|
||||
}
|
||||
txOutput.setTxOutputType(bsqOutput);
|
||||
bsqStateService.addUnspentTxOutput(TxOutput.fromTempOutput(txOutput));
|
||||
bsqOutputs.add(txOutput);
|
||||
|
||||
bsqOutputFound = true;
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ public class TxParser {
|
||||
}
|
||||
|
||||
// Apply state changes to tx, inputs and outputs
|
||||
// return true if any input contained BSQ
|
||||
// return Tx if any input contained BSQ
|
||||
// Any tx with BSQ input is a BSQ tx (except genesis tx but that is not handled in
|
||||
// that class).
|
||||
// There might be txs without any valid BSQ txOutput but we still keep track of it,
|
||||
@ -143,7 +143,6 @@ public class TxParser {
|
||||
|
||||
remainingInputValue = txOutputParser.getAvailableInputValue();
|
||||
|
||||
// TODO(SQ): If the tx is set to INVALID in this check the txOutputs stay valid
|
||||
processOpReturnType(blockHeight, tempTx);
|
||||
|
||||
// TODO(SQ): Should the destroyed BSQ from an INVALID tx be considered as burnt fee?
|
||||
@ -170,6 +169,12 @@ public class TxParser {
|
||||
DevEnv.logErrorAndThrowIfDevMode(msg);
|
||||
}
|
||||
}
|
||||
|
||||
if (tempTx.getTxType() != TxType.INVALID){
|
||||
txOutputParser.commitTxOutputs();
|
||||
} else {
|
||||
txOutputParser.commitTxOutputsForInvalidTx();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO || parsingModel.getBurntBondValue() > 0; should not be necessary
|
||||
|
Loading…
Reference in New Issue
Block a user