Fixes #9759
If the -maxsigcachesize parameter is set to zero, setup a minimum sized sigcache (2 elements) rather than segfaulting.
If the -maxsigcachesize parameter is set to zero, setup a minimum sized
sigcache (2 elements) rather than segfaulting.
Hmm, I'd expect the sigcache to be bypassed entirely in this case. I suppose this is fine for 0.14, but I think it'd probably be useful to have a SignatureCheckerNoCache to benchmark cache overhead.
@theuni I'm ambivalent about that approach but I agree that it's likely a better approach (see my comment making the same point (sans solution) in the issue #9759). Ambivalence because more reliance on virtual methods, whereas it might be nice to get rid of the virtual-ness at some point. Running with cache size 0 under this patch means doing some likely unfruitful work every check though so clearly that's the better of 2 evils.
Slightly suboptimal performance with sigcachesize 0 (which is afaik not recommended anywhere) is perfectly acceptable for 0.14, I think - it's not even a regression. We can reconsider for 0.15.
I think this is a good pragmatic solution. What matters here is that it doesn't crash. A user shouldn't set the cache to 0 if the goal is performance.
utACK https://github.com/bitcoin/bitcoin/pull/9770/commits/d72fe44fc1989575ff5de98c882c0010d1de26e7 .
see below, need decision on what to do with negative values
BTW: what happens with a negative argument? Will it wrap around and still crash? :) edit: bad_alloc, apparently:
2017-02-16 09:35:27 Using at most 125 automatic connections (1024 file descriptors available)
2017-02-16 09:35:27
************************
EXCEPTION: St9bad_alloc
std::bad_alloc
bitcoin in AppInit()
************************
EXCEPTION: St9bad_alloc
std::bad_alloc
bitcoin in AppInit()
In #9759 I suggested setup_bytes(max(0, nMaxCacheSize)) for that reason, but I suppose that's not sufficient either: nMaxCacheSize should be made a signed int of some sort rather than size_t.
Yeah, ssize_t would do the job. Or apply the std::max() directly to the GetArg result.
Didn't intend to merge this one yet, sorry. Anyhow if we want to cope with the negative amounts, need to do that in a new PR.
Edit: needed to revert anyway - something went wrong with the tooling, the merge was not signed either.
Milestone
0.14.0