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

Parse opreturn before other outputs #175

Closed
wants to merge 7 commits into from

Conversation

sqrrm
Copy link
Member

@sqrrm sqrrm commented Sep 3, 2018

Since the effects of opreturn act on the BSQ outputs it makes more sense
to parse the opreturn before parsing the remaining outputs.

Put the lock time in the LOCKUP txOutput. It makes more logical sense to
keep it there.

Since the effects of opreturn act on the BSQ outputs it makes more sense
to parse the opreturn before parsing the remaining outputs.

Put the lock time in the LOCKUP txOutput. It makes more logical sense to
keep it there.
* OpReturn output might contain the lockTime in case of a LockTx. It has to be the last output.
* We store technically the lockTime there as is is stored in the OpReturn data but conceptually we want to provide
* it from the transaction.
* The locktime is stored in the LOCKUP txOutput, which is the first txOutput.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... I am not sure if the first output is a good place here. Technically its the opReturn output, conceptually its the tx (thats why we use a delegate there).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I moved it to the LOCKUP txoutput is that elsewhere it's expected to reside there. It's also a logical place since that's the txoutput that has a restriction on it.

@@ -154,6 +158,9 @@ public TxParser(PeriodService periodService,
DevEnv.logErrorAndThrowIfDevMode(msg);
}
} else {
// TODO(SQ): The transaction has already been parsed here and the individual txouputs are considered
// spendable or otherwise correct. Perhaps this check should be done earlier.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are correct. Should be probably done earlier

txOutputParser.processOpReturnCandidate(outputs.get(lastIndex));
int lastNonOpReturnIndex = lastIndex;
if (txOutputParser.processOpReturnCandidate(outputs.get(lastIndex))) {
txOutputParser.processTxOutput(true, outputs.get(lastIndex), lastIndex);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not 100% if that can cause problems. We can discuss tomorrow.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I see there is only the lockup opreturn processing that really does anything here, and that was the one I wanted to fix. Would be good with more eyes to verify that of course.

@@ -81,8 +82,9 @@ public void processGenesisTxOutput(TempTx genesisTx) {
}
}

void processOpReturnCandidate(TempTxOutput txOutput) {
boolean processOpReturnCandidate(TempTxOutput txOutput) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we return a boolean we should rename to make that more clear (e.g. isOpReturnCandidate)

@@ -164,6 +166,7 @@ private void handleBsqOutput(TempTxOutput txOutput, int index, long txOutputValu
optionalVoteRevealUnlockStakeOutput = Optional.of(txOutput);
} else if (isFirstOutput && opReturnTypeCandidate == OpReturnType.LOCKUP) {
bsqOutput = TxOutputType.LOCKUP;
txOutput.setLockTime(lockTime);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why put it in first output? Technically its in opReturn, conceptually in Tx.

@sqrrm
Copy link
Member Author

sqrrm commented Sep 5, 2018

I did some more refactoring, the main thing being that the txOutputs are only commited after the tx type is determined. That way we avoid inconsistency of adding some outputs to bsq stateservice and later finding out the tx is invalid.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants