Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tx_type in Coin and Snapshot instead of fIsCoinbase #856

Merged
merged 4 commits into from
Apr 2, 2019

Conversation

frolosofsky
Copy link
Member

@frolosofsky frolosofsky commented Mar 27, 2019

Context
Currently, node cannot operate after fast-sync because it cannot validate finalizer commit inputs as these checks perform GetTransaction that leads to reading block from the disk; but node doesn't have such a block when running in fast-sync mode. Finally, node rejects finalizer commits and ban its peers. On the other hand, snapshot transfers UTXO set which has all needed transactions but there is a lack of transaction type in UTXO representation that prevents from using it.

This PR fixes that by:

  • adding transaction type to the UTXO set (via Coin and snapshot classes).
  • performing UTXO lookup prior to GetTransaction() in esperanza::ContextualCheck*;

Fixes #547.

@frolosofsky frolosofsky force-pushed the tx-type-in-the-coin branch 2 times, most recently from f23c526 to 8d4583f Compare March 28, 2019 13:13
@frolosofsky frolosofsky self-assigned this Mar 28, 2019
@frolosofsky frolosofsky added this to the 0.1 milestone Mar 28, 2019
@frolosofsky frolosofsky marked this pull request as ready for review March 28, 2019 13:39
@frolosofsky
Copy link
Member Author

Rebased with master, fixed compilation errors when ENABLE_USBDEVICE is on.

Signed-off-by: Stanislav Frolov <stanislav@thirdhash.com>
src/esperanza/checks.cpp Outdated Show resolved Hide resolved
src/esperanza/checks.cpp Outdated Show resolved Hide resolved
src/rpc/blockchain.cpp Outdated Show resolved Hide resolved
src/rpc/blockchain.cpp Outdated Show resolved Hide resolved
src/miner.cpp Outdated Show resolved Hide resolved
src/rpc/blockchain.cpp Outdated Show resolved Hide resolved
Copy link
Member

@kostyantyn kostyantyn left a comment

Choose a reason for hiding this comment

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

ConceptACK 5e7351f

@scravy scravy changed the title Use tx_type in the Coin and Snapshot instead of fIsCoinbase Use tx_type in Coin and Snapshot instead of fIsCoinbase Mar 29, 2019
src/test/coins_tests.cpp Outdated Show resolved Hide resolved
src/txdb.cpp Show resolved Hide resolved
Signed-off-by: Stanislav Frolov <stanislav@thirdhash.com>
Signed-off-by: Stanislav Frolov <stanislav@thirdhash.com>
@frolosofsky
Copy link
Member Author

@kostyantyn @Nizametdinov @Gnappuraz @scravy I've reacted on your comments and adjusted the code. Please take another look.

src/test/coins_tests.cpp Outdated Show resolved Hide resolved
src/esperanza/checks.h Outdated Show resolved Hide resolved
Signed-off-by: Stanislav Frolov <stanislav@thirdhash.com>
Copy link
Member

@Nizametdinov Nizametdinov left a comment

Choose a reason for hiding this comment

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

utACK 93d3ca7

Copy link
Member

@scravy scravy left a comment

Choose a reason for hiding this comment

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

utACK 93d3ca7

Copy link
Member

@kostyantyn kostyantyn left a comment

Choose a reason for hiding this comment

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

utACK 93d3ca7

There is a comment about the withdraw check which is not resolved #856 (comment) But since it's not related to this change and I noticed few other checks that are questionable, I think it's good to work on them separately and don't block this PR. I am currently reviewing esperanza protocol and will take care of such finalizer commit checks.

@@ -175,23 +206,20 @@ bool ContextualCheckLogoutTx(const CTransaction &tx, CValidationState &err_state
// check (potentially goes to disk) and there is a good chance that if the
// vote is not valid (i.e. outdated) then the function will return before
// reaching this point.
CTransactionRef prev_tx;
uint256 block_hash;
TxType prev_tx_type = TxType::REGULAR;
Copy link
Member

@Gnappuraz Gnappuraz Apr 2, 2019

Choose a reason for hiding this comment

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

This might result quite confusing. Since we are passing a pointer as an out parameter I would init as nullptr and then also change the FindPrevOutData signature to make it more evident (prev_tx_type_out). I would rather init this to TxType::REGULAR inside FindPrevOutData.

Copy link
Member Author

Choose a reason for hiding this comment

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

bool FindPrevOutData(const COutPoint &prevout,
                     const CCoinsView &view,
                     TxType *tx_type_out,
                     CScript *script_out) {

tx_type_out refers exactly to prevout outpoint. I think appending prev_ prefix would make it much more ambiguous.

Regarding nullptr initialization, pointers doesn't work in this way. I cannot initialize TxType with nullptr as it is not a pointer. I cannot pass nullptr to the FindPrevOutData because otherwise I cannot assign its value. We can pass pointer-to-pointer to the function (TxType **prev_tx_type) but then we will face with a problem of returning pointer to temporary (stack) variable — the Coin.

I suppose I could not understand your suggestion, feel free to elaborate a bit, then I will fix them in follow-up PR.

Copy link
Member

@Gnappuraz Gnappuraz Apr 2, 2019

Choose a reason for hiding this comment

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

I would have created a TxType* and initialized to nullptr and passed it to the function.

Copy link
Member Author

Choose a reason for hiding this comment

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

Then it would not work unfortunately. We cannot write to the pointer, like *tx_type = TxType::REGULAR when tx_type is nullptr. We could use pointer-to-pointer (or reference-to-pointer), but I described why we can't.

@frolosofsky frolosofsky merged commit 204239d into dtr-org:master Apr 2, 2019
@frolosofsky frolosofsky deleted the tx-type-in-the-coin branch April 2, 2019 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ContextualCheckFinalizationTx may ban nodes if in pruning mode
5 participants