Skip to content

Conversation

NicolasDorier
Copy link

I am using a shared map<txid,cachedhashes> protected by a lock.
A hash may be calculated several time because there is no lock at the transaction level.

@NicolasDorier NicolasDorier force-pushed the cachedhashes branch 3 times, most recently from 10fefe4 to 28153df Compare April 3, 2016 20:30
@sipa sipa force-pushed the segwit branch 2 times, most recently from c700b59 to 85b6ae6 Compare April 4, 2016 14:52
@NicolasDorier NicolasDorier force-pushed the cachedhashes branch 2 times, most recently from 3dcead2 to 4d2809e Compare April 5, 2016 12:31
This removes the following executables from the binary gitian release:

- test_bitcoin-qt[.exe]
- bench_bitcoin[.exe]

@jonasschnelli and me discussed this on IRC a few days ago - unlike the
normal `bitcoin_tests` which is useful to see if it is safe to run
bitcoin on a certain OS/environment combination, there is no good reason
to include these. Better to leave them out to reduce the download
size.

Sizes from the 0.12 release:
```
2.4M bitcoin-0.12.0/bin/bench_bitcoin.exe
 22M bitcoin-0.12.0/bin/test_bitcoin-qt.exe
```

Github-Pull: bitcoin#7776
Rebased-From: f063863
@NicolasDorier NicolasDorier force-pushed the cachedhashes branch 2 times, most recently from 07e0bfd to 2d7ffaa Compare April 5, 2016 14:00
New languages:

- `af` Afrikaans
- `es_AR` Spanish (Argentina)
- `es_CO` Spanish (Colombia)
- `ro` Romanian
- `ta` Tamil
- `uz@Latn` Uzbek in Latin script
@theuni
Copy link

theuni commented Apr 5, 2016

A few issues:

  • libbitcoinconsensus needs to be boost/lock free. Is it necessary to have caching there?
  • Looks like there's an out-of-bounds access of vtxinwit in the tx_valid test. I don't see how you would've caused that, though.

@NicolasDorier
Copy link
Author

@theuni this is not out of bound as https://github.com/sipa/bitcoin/blob/segwit/src/primitives/transaction.h#L298 resize the witscript to the length of inputs.

I'll think today about a way to remove the lock out of the consensus path. There may be a way.

@theuni
Copy link

theuni commented Apr 6, 2016

@NicolasDorier There's an out-of-bounds somewhere: https://travis-ci.org/sipa/bitcoin/jobs/120930116#L5390

Maybe it's caused by a new test?

@NicolasDorier
Copy link
Author

Wow very strange the tests passed on my machine. I will add a check just to be sure.

Is there any compile debug flag which would have make me catch such error ?

@NicolasDorier NicolasDorier force-pushed the cachedhashes branch 2 times, most recently from 0c78964 to 06bda69 Compare April 6, 2016 05:10
@NicolasDorier
Copy link
Author

@theuni I addressed both of your concern. Can you check if it is ok for you now ?
I'm also wondering why I did not have the out of bound error on my local dev machine. I could not check with Travis, because travis crash on a non determistic test fixed by bitcoin@fa3fafc . (not merged to segwit for now)

For people wanting to benchmark the time difference with and without cache, you can check with the following code in big witnesss test:

int64_t before = GetTimeMicros();
for(uint32_t i = 0; i < mtx.vin.size(); i++) {
    std::vector<CScriptCheck> vChecks;
    CScriptCheck check(coins, tx, i, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS, false, &cachedHashesMap);
    vChecks.push_back(CScriptCheck());
    check.swap(vChecks.back());
    control.Add(vChecks);
}

bool controlCheck = control.Wait();
assert(controlCheck);

int64_t after = GetTimeMicros();
BOOST_CHECK_MESSAGE(false, (after - before) * 0.000001);

before = GetTimeMicros();

for(uint32_t i = 0; i < mtx.vin.size(); i++) {
    std::vector<CScriptCheck> vChecks;
    CScriptCheck check(coins, tx, i, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS, false, NULL);
    vChecks.push_back(CScriptCheck());
    check.swap(vChecks.back());
    control.Add(vChecks);
}

 controlCheck = control.Wait();
assert(controlCheck);

after = GetTimeMicros();

BOOST_CHECK_MESSAGE(false, (after - before) * 0.000001);

@sipa
Copy link
Owner

sipa commented Apr 6, 2016 via email

@NicolasDorier
Copy link
Author

I am thinking about adding an overload to VerifyScript of libconsensus to provide a way to the user to specify CachedHashes so libconsensus user can protect themselves against the O(n²) problem. What do you think ? should I do it ? if yes, in this PR ?

laanwj and others added 4 commits April 7, 2016 13:00
Two-line patch to make it possible to shut down bitcoind cleanly during
the initial ActivateBestChain.

Fixes bitcoin#6459 (among other complaints).

To reproduce:

- shutdown bitcoind
- copy chainstate
- start bitcoind
- let the chain sync a bit
- shutdown bitcoind
- copy back old chainstate
- start bitcoind
- bitcoind will catch up with all blocks during Init()

(the `boost::this_thread::interruption_point` / `ShutdownRequested()`
dance is ugly, this should be refactored all over bitcoind at some point
when moving from boost::threads to c++11 threads, but it works...)

Github-Pull: bitcoin#7821
Rebased-From: 07398e8
Currently, we're keeping a timeout for each requested block, starting
from when it is requested, with a correction factor for the number of
blocks in the queue.

That's unnecessarily complicated and inaccurate.

As peers process block requests in order, we can make the timeout for each
block start counting only when all previous ones have been received, and
have a correction based on the number of peers, rather than the total number
of blocks.

Conflicts:
	src/main.cpp
	src/main.h

Self check after the last peer is removed

Github-Pull: bitcoin#7804
Rebased-From: 2d1d658 0e24bbf
Now that bitcoin#7804 fixed the timeout handling, reduce the block timeout from
20 minutes to 10 minutes. 20 minutes is overkill.

Conflicts:
	src/main.h

Github-Pull: bitcoin#7832
Rebased-From: 62b9a55
@NicolasDorier
Copy link
Author

I gave up changing libconsensus for now I did this: a807f42 which can be useful for later. (after first release of segwit)
The problem with such commit was that it exposed internal plumbing to the API. I explored solutions, but it would have meant that the "cache object" would not be thread safe, making a burden to the caller.

5:28 PM <sipa> honestly i think we should revamp the consensus api after c++11, and have it expose contexts for block, transaction, and script validation
5:28 PM <sipa> which maintain the caches
5:28 PM <sipa> and have locks internally

sdaftuar and others added 2 commits April 8, 2016 14:22
Before activation, such transactions might not be mined, so don't
allow into the mempool.

- Tests: move get_bip9_status to util.py

- Test relay of version 2 transactions

Github-Pull: bitcoin#7835
Rebased-From: e4ba9f6 5cb1d8a da5fdbb
CodeShark and others added 26 commits April 11, 2016 12:38
Includes a fix by Suhas Daftuar
Includes simplifications by Eric Lombrozo.
Includes RPC field name changes by Luke-jr.
Includes changes by Suhas Daftuar and Luke-jr.
…en verify_script receives VERIFY_WITNESS flag

script_tests: always test bitcoinconsensus_verify_script_with_amount if VERIFY_WITNESS isn't set

Rename internal method + make it static

trim bitcoinconsensus_ prefix

Add SERIALIZE_TRANSACTION_WITNESS flag
Witness blocks can be greater than 2MiB, but cannot be validly greater
than 4MB.
Includes support for pushkeyhash wit v0 by Alex Morcos.
Amended by Pieter Wuille to use multisig 1-of-1 for P2WSH tests, and BIP9
based switchover logic.
...with the four types of segwit payment, as well as all sighash combinaisons.
@NicolasDorier
Copy link
Author

rebased on segwit4 #70

@instagibbs instagibbs mentioned this pull request Apr 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants