Skip to content

Conversation

NicolasDorier
Copy link
Contributor

Alternative of #8259 as advised by @sipa.
Mid hashes are calculated lazily instead of aggressively.

@NicolasDorier NicolasDorier mentioned this pull request Jul 29, 2016
@NicolasDorier
Copy link
Contributor Author

test_big_witness_transaction add significant test duration because of the creation of many signature, I don't feel like removing it as it may still be useful though.

@NicolasDorier
Copy link
Contributor Author

travis fail probably unrelated to this PR

addCachedHashesToMap &= !cachedHashes.IsFull();
bool result = VerifyScript(scriptSig, scriptPubKey, witness, nFlags, CachingTransactionSignatureChecker(ptxTo, nIn, amount, cacheStore, cachedHashes), &error);
// do not update the cache if cachedHashes is still empty, it can happen if the evaluation ends before any segwit CheckSig operation could run
addCachedHashesToMap &= !cachedHashes.IsEmpty();
Copy link
Member

Choose a reason for hiding this comment

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

Might make sense to check if any "progress" was made instead to avoid grabbing locks for setting any time the retrieved cachedHashes isn't empty already.

@NicolasDorier
Copy link
Contributor Author

@instagibbs I've just updated the PR following your suggestion.

@sipa
Copy link
Member

sipa commented Jul 29, 2016

You're making script/interpreter depend on sync, which causes a compile failure as libconsensus (which uses script/interpreter) does not link in Boost.

One way would be to make CachedHashesMap a virtual class, with only a naive implementation (which does not cache anything). Then elsewhere you can create a derived class which adds the map and the lock.

EDIT: oh no, I think you just need to stop including cachedhashesmap.h from interpreter.h.
EDIT2: verified, this is what causes the build failure.

@sipa
Copy link
Member

sipa commented Jul 29, 2016

Can you also follow the coding style? Spaces after if, and { on the same line (except for classes or function bodies).

@NicolasDorier
Copy link
Contributor Author

@sipa yes, it was a mistake just removed it and fixed coding style.

I am suprised, that https://travis-ci.org/bitcoin/bitcoin/builds/148371080 and when I compiled myself I did not experienced any build fails because of this mistake.

@sipa
Copy link
Member

sipa commented Jul 29, 2016

Did you run make check ?

@NicolasDorier
Copy link
Contributor Author

nop, only make -j4. What does the check do ? I thought it was only running tests.

// if the scriptPubKey is not witness program, no need for cachedHashes, so do not read the map (it would acquire the lock needlessly)
bool addCachedHashesToMap = cachedHashesMap != NULL &&
scriptPubKey.IsWitnessProgram(version, program);
if(addCachedHashesToMap) {
Copy link
Member

Choose a reason for hiding this comment

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

Space after if.

@NicolasDorier
Copy link
Contributor Author

@sipa nits fix

@sipa
Copy link
Member

sipa commented Jul 30, 2016

utACK 5547521c0ae38583e9f0504b3302bba928f5477d
Will test.

@sipa
Copy link
Member

sipa commented Aug 1, 2016

Needs rebase.

@NicolasDorier NicolasDorier force-pushed the cachedhashes2 branch 3 times, most recently from 522b23d to 7dbd2e7 Compare August 1, 2016 15:09
@NicolasDorier
Copy link
Contributor Author

NicolasDorier commented Aug 1, 2016

Rebased, it made the diff smaller as this commit removed a code path where CachedHashesMap was previously needed. (but not used)

@sipa
Copy link
Member

sipa commented Aug 2, 2016

Noting that this requires backport to 0.13 before segwit is activated.

#define SRC_CACHEDHASHESMAP_H


#include "script/interpreter.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

You can move this include to the cpp or save the class CachedHashes; below.

@jtimon
Copy link
Contributor

jtimon commented Aug 4, 2016

utACK 7dbd2e7

@@ -0,0 +1,21 @@
// Copyright (c) 2009-2015 The Bitcoin Core developers
Copy link
Contributor

Choose a reason for hiding this comment

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

s/2015/2016/

@btcdrak
Copy link
Contributor

btcdrak commented Aug 5, 2016

utACK 7dbd2e7

@NicolasDorier
Copy link
Contributor Author

@btcdrak updated the file header.

@sipa
Copy link
Member

sipa commented Aug 15, 2016

Tested ACK 910e7bb: I timed the verification in the added test_big_witness_transaction test, and backported it to master (without sighash cache); this PR made it 7.5 times faster.

@sipa sipa added this to the 0.13.1 milestone Aug 15, 2016
@sipa
Copy link
Member

sipa commented Aug 16, 2016

Merely listing this for exposure, as I am perfectly fine with merging this PR here as it is:

I made an altered implementation in https://github.com/sipa/bitcoin/commits/noprecomputecachedhashes that simply precomputes the 3 hashes for each transaction. In the listed benchmark, it is around 1% faster than the PR here. It may be preferable if we want to avoid contention on the sighash cache like in #8464.

@NicolasDorier
Copy link
Contributor Author

NicolasDorier commented Aug 16, 2016

@sipa actually I did that before (#8259)

EDIT: ah no, it is actually different

@sipa sipa mentioned this pull request Aug 16, 2016
@NicolasDorier
Copy link
Contributor Author

supersede by #8524

@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants