Skip to content

PrivateSend: dont waste keys from keypool on failure in CreateDenominated#1473

Merged
UdjinM6 merged 4 commits into
dashpay:v0.12.2.xfrom
krychlicki:track_19
May 28, 2017
Merged

PrivateSend: dont waste keys from keypool on failure in CreateDenominated#1473
UdjinM6 merged 4 commits into
dashpay:v0.12.2.xfrom
krychlicki:track_19

Conversation

@krychlicki
Copy link
Copy Markdown

@krychlicki krychlicki commented May 21, 2017

Changes:

  • store keys for denominations in vector
  • on success run keep on all keys
  • on failure run return of all keys
  • log current number of created outputs
  • can be up to 11 outputs per denomination not 10
  • add lock at the start of CPrivateSendClient::CreateDenominated() so no one can spend outputs used for denominations

connected with track#19.

Copy link
Copy Markdown

@UdjinM6 UdjinM6 left a comment

Choose a reason for hiding this comment

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

Thanks!

int nOutputs = 0;

// add each output up to 10 times until it can't be added again
// add each output up to 11 times until it can't be added again
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ha! I'm pretty sure nOutputs were meant to be limited by 10 originally so you can fix either part, but 11 should work just as well as 10 would :)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

ok! let's leave it as 11 then!

Comment thread src/privatesend-client.cpp Outdated
nOutputs++;
nValueLeft -= nDenomValue;
LogPrintf("CreateDenominated1: nOutputsTotal: %d, nOutputs: %d, nValueLeft: %f\n", nOutputsTotal, nOutputs, (float)nValueLeft/COIN);
LogPrintf("CreateDenominated1: nOutputsTotal: %d, nOutputs: %d, nValueLeft: %f\n", nOutputsTotal + nOutputs, nOutputs, (float)nValueLeft/COIN);
Copy link
Copy Markdown

@UdjinM6 UdjinM6 May 22, 2017

Choose a reason for hiding this comment

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

why? the log output seems incorrect now...

Copy link
Copy Markdown
Author

@krychlicki krychlicki May 22, 2017

Choose a reason for hiding this comment

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

the idea here was to show the actual number of total outputs created.
now logs look like this:

2017-05-19 16:50:04 CreateDenominated1: nOutputsTotal: 0, nOutputs: 1, nValueLeft: 999.984985
2017-05-19 16:50:04 CreateDenominated1: nOutputsTotal: 0, nOutputs: 2, nValueLeft: 999.974976
2017-05-19 16:50:04 CreateDenominated1: nOutputsTotal: 0, nOutputs: 3, nValueLeft: 999.965027
2017-05-19 16:50:04 CreateDenominated1: nOutputsTotal: 0, nOutputs: 4, nValueLeft: 999.955017
2017-05-19 16:50:04 CreateDenominated1: nOutputsTotal: 0, nOutputs: 5, nValueLeft: 999.945007
2017-05-19 16:50:04 CreateDenominated1: nOutputsTotal: 0, nOutputs: 6, nValueLeft: 999.934998
2017-05-19 16:50:04 CreateDenominated1: nOutputsTotal: 0, nOutputs: 7, nValueLeft: 999.924988
2017-05-19 16:50:05 CreateDenominated1: nOutputsTotal: 0, nOutputs: 8, nValueLeft: 999.914978
2017-05-19 16:50:05 CreateDenominated1: nOutputsTotal: 0, nOutputs: 9, nValueLeft: 999.905029
2017-05-19 16:50:05 CreateDenominated1: nOutputsTotal: 0, nOutputs: 10, nValueLeft: 999.895020
2017-05-19 16:50:05 CreateDenominated1: nOutputsTotal: 0, nOutputs: 11, nValueLeft: 999.885010
2017-05-19 16:50:05 CreateDenominated1: nOutputsTotal: 11, nOutputs: 1, nValueLeft: 999.784973

you are right that with my change log is incorrect - variable nOutputsTotal has diffrent value than printed.
So maybe something like in may next commit?

@UdjinM6 UdjinM6 added this to the 12.2 milestone May 22, 2017
LogPrintf("CPrivateSendClient::CreateDenominated -- %d keys keeped\n", reservekeyDenomVec.size() + 1);

if(!pwalletMain->CommitTransaction(wtx, reservekeyChange)) {
LogPrintf("CPrivateSendClient::CreateDenominated -- CommitTransaction failed!\n");
Copy link
Copy Markdown

@tgflynn tgflynn May 23, 2017

Choose a reason for hiding this comment

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

What if failure occurs here (ie. in CommitTransaction) ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

CommitTransaction can only be unsuccessful when transaction fails validation on adding to memory pull.
As we constructed this transaction by ourselves it can only fail when outputs that we want to anonymize are already spent.
If this happens our wallet is already in invalid state (must be repaired?) so losing couple of keys will have probably no meaning.

Besides that, in other places in the source code keys are released (keeped) after CreateTransaction not CommitTransaction, so to be consistent I think is better to keep it as it is right now.

Copy link
Copy Markdown

@UdjinM6 UdjinM6 May 26, 2017

Choose a reason for hiding this comment

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

The thing that was failing here was always CreateTransaction in practice. CommitTransaction can only fail if it's not accepted to mempool - must not fail. The transaction has already been signed and recorded.. However, to make sure we still actually have inputs we are trying to spend, I guess we have to LOCK2(cs_main, pwalletMain->cs_wallet); at the start of CPrivateSendClient::CreateDenominated(). Other places with Create/Commit have the same issue I guess, but they should be fixed in separate PR.

Copy link
Copy Markdown

@UdjinM6 UdjinM6 left a comment

Choose a reason for hiding this comment

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

slightly tested (mixing as usual, not trying to force any conflicts) - works as expected

ACK

@UdjinM6 UdjinM6 merged commit 68e858f into dashpay:v0.12.2.x May 28, 2017
@UdjinM6 UdjinM6 mentioned this pull request May 28, 2017
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.

3 participants