Commit Graph

328 Commits

Author SHA1 Message Date
TomZ 2f7f7cec4c Nicely initialize the variable every loop 2020-04-24 10:41:55 +02:00
TomZ 3f08053db3 Fix compile
In case the BENCHMARK feature is enabled (by removing the comment in the
private header) this would fail to compile due to a refactor some time
ago.
2020-04-13 15:57:42 +02:00
TomZ 2aa462f8bb Replace SigOps with SigChecks
This is part of the protocol upgrade for 2020-05-15, and in general it
seems to go the direction of "we did this before, lets do this again".

The spec is clear enough, but there is still a lack of questioning and
testing. The problem this attempts to fix has been neutered for years[1].

The spec states:
> The essential idea of SigChecks is to perform counting solely in the
> spending transaction, and count actual executed signature check
> operations.

This, however nobel and logical, ignores that the
check-for-being-too-costly just pulled in a UTXO lookup and the loading
of the output script from the historical chain.
The goal that we protect against CPU over-use may be reached, but the
price is a total system slowdown. You can have multiple CPUs, but the
bus to permanent storage has one, max 2 parallel pipes.

To ensure theHub stays the number one scalable node, I didn't blindly
follow the spec, while making sure that the Hub is correctly going to
follow/reject consensus violations of newly mined blocks.

As a result the implementation in Flowee the Hub:

* does not check sigcheck-counts on historical blocks (more than 1000
  blocks in the past).

  This may increase the risk of chain-splits ever so slightly, but the cost
  of disk-IO would be too high.

* No longer stores the value in the mempool, nor uses it for the
  CPU-miner.

* Ties the sigcheck-limits to the user-set block-size-accept-limit.

  This is contrary to the spec which mistakenly thinks that BCH has a
  max block-size in the consensus rules. The effect is the same, though.

* The per-intput standardness suggestion is not implemented because
  standardness checks don't currently fetch the previous outputs and
  that would be too expensive to add.

* Standardness rules for the whole transaction are moved to the
  mempool-acceptance logic instead. The cost would be too great
  otherwise, similar to the previous point.
  Again, the effect is the same as likely intented.

---
1) since the intro of the CachingTransactionSignatureChecker
2020-04-13 15:57:42 +02:00
TomZ 0386f38cc1 Inline CScriptCheck
It was only called twice, and in very close proximity. The class didn't
add anything.
This improves readability and with the new state its easier to write
too.
2020-04-13 13:44:18 +02:00
TomZ 916cb9b5d7 Start sigCheck implementation; actually count them.
Update Script::State to add a sigCheckCount counter.
2020-04-12 18:08:51 +02:00
TomZ e101591f1a Refactor ScriptEval/ScriptVerify calls
Feeling cute, may update this API later.

namespace Script {
struct State {
    State() = default;
    State(uint32_t flags) : flags(flags) {}
    uint32_t flags = SCRIPT_VERIFY_NONE; // validation flags
    ScriptError error = SCRIPT_ERR_OK;

    const char* errorString() const;
};

bool eval(std::vector<std::vector<unsigned char> > &stack, const CScript
    &script, const BaseSignatureChecker checker, Script::State &state);
bool verify(const CScript& scriptSig, const CScript& scriptPubKey, const
    BaseSignatureChecker& checker, Script::State &state);
bool checkTransactionSignatureEncoding(const std::vector<unsigned char>
    &vchSig, State &state);
}

More of the same.
2020-04-12 18:08:09 +02:00
TomZ 1882bed839 remove dead code 2020-04-11 17:05:39 +02:00
TomZ 9195ad96e1 Add May Protocol Upgrade activation code 2020-04-10 17:28:02 +02:00
TomZ 414bee9e9f Implementation of OP_REVERSEBYTES
Previously named OP_REVERSE, then OP_BSWAP, then OP_ENDIAN_REVERSE.
2020-04-10 15:17:18 +02:00
TomZ 4733554817 Make bloom class more modern
This follows the coding style (method naming) better and it adds
an insert method which uses a Streaming::ConstBuffer argument.
2020-04-10 12:21:49 +02:00
TomZ fcdb52d5aa Make leveldb build with cmake
As this now means we completely use cmake, remove some legacy
stuff as well.
2020-04-08 22:48:29 +02:00
TomZ e8028035a1 make univalue build using cmake 2020-04-08 22:48:29 +02:00
TomZ 1144f013a4 Build secp256k1 with cmake 2020-04-08 22:48:29 +02:00
TomZ ba76c35a7d Move merkle to flowee_utils libs
Merkle-block and merkle-tree classes and methods are pretty much stand-
alone and can be moved with no efforts.

Also move the relevent unit test to qtestlib.
2020-04-01 22:53:07 +02:00
TomZ 9276a45faf Move bloom filters to flowee_utils lib
Also move its unit test from the boost to qtestlib
2020-04-01 22:24:26 +02:00
TomZ 655d9fecb9 Port a log-line. 2020-04-01 20:24:08 +02:00
TomZ 40cad6112c Pass by reference 2020-04-01 20:22:55 +02:00
TomZ 0c15e877a2 Move arith_uint256 from server to utils lib 2020-04-01 20:22:55 +02:00
TomZ 22e2f3ca7c Make p2p version message mandatory
This was always the intention, but the satoshi code was stupid and buggy.
First, the 'version has been seen' flag was set even if there was a parsing
error in it.
Second, ignoring messages (up to 100) until a version message was seen
makes no sense. Just disconnect instantly.
2020-03-29 12:55:12 +02:00
TomZ 7b1b742036 Remove workaround for old boost version
The API changes in boost between 1.66 and later was the need
for the boost_compat.h header file.
Its been a long time since Flowee started demanding 1.67 minimum
for boost, making this compat obsolete.
2020-03-29 12:55:12 +02:00
TomZ 997e861e93 Add fetch method on mempool for DSPs
Allow the retrieval of a double spend proof based on the transaction-id
it is paired with inside the mempool.
2020-03-19 22:05:11 +01:00
TomZ 6ad8374794 Update testnet seeders 2020-03-19 15:04:28 +01:00
TomZ e9ef907c1f Sync checkpoint save and index-db saveCaches
When the UTXO saved checkpoints this change makes sure we also store the
index-db changes.

Since we stopped saving simple state changes fromt the index-db, the
only real data we save is the 'undo-block-index', as such this will be
relatively cheap to save.
Without an undo block position we will currently fail to verify those
blocks and as such it is useful to save all at the same time to actually
have a state we can start from.
2020-03-05 23:29:53 +01:00
TomZ 043f496c73 Make scope of variable smaller. 2020-03-05 23:29:53 +01:00
TomZ 579dc67bc2 Remove dead code 2020-03-05 23:29:52 +01:00
TomZ c79be8860a Use VerifyDB as well when finding a functional UTXO state
Allow VerifyDB to disquality a utxo-state so we can find an older one, if
available, and try harder to start without reindex.
2020-03-05 23:29:52 +01:00
TomZ 01ff5ff1db Make writing to blk file not follow symlinks
To share the downloaded blocks between instances on Linux it is common
to sym-link the blk files from read-only storage.
The Hub would fail to write to the last file due to the file being on
read-only storage and the Hub would shut down.
This change makes sure we instead create a new file instead of trying to
write to a symlinked one.
2020-03-05 23:29:52 +01:00
TomZ a790b26133 Just warn about failing to write to a legacy blk
Boost throws an exception when the resize fails, which would cause
a total shutdown of the client. So make sure we catch it in the
scheduled task to avoid this problem.
2020-03-01 18:27:28 +01:00
TomZ 0e6231e636 Add a check to only write when not loaded
In some unit tests I noticed that we write a block that was just loaded
from disk, this check avoids this overhead.
Not sure how relevant this is for normal operations.
2020-02-28 12:55:16 +01:00
TomZ 7e7f42e8ec Make de-orphaning code no longer recursive.
The recovering of orphans was recursive and that meant there was a max
length of headers we could process with a gap in the chain due to normal
stack-depth for recursivity (approx 50k).
As headers are being provided to us from external peers this could be a
DOS vector.

This implementation avoids this problem by not being recursive.
2020-02-28 00:34:12 +01:00
TomZ 60d371afa7 Make loading find a functional UTXO state
When, on loading, the blockindex and the UTXO don't agree then try to find an older UTXO
state where they do agree.
The most typical state issue is where a block stored in the blocksdb is not available in
the index due to corruption or similar.
2020-02-28 00:34:08 +01:00
TomZ f0e93708e1 Minor cleanups 2020-02-28 00:33:11 +01:00
TomZ 30927fe0b2 Fix reindexing sometimes failing due to read-only blocks
When reindexing we now always first try to open a file read-write because
the algo to only open the last file in a sequence as RW failed in such
situations where we don't know the amount of files yet.
2020-02-28 00:33:11 +01:00
TomZ 489a9a4859 Move nStatus of blockindex into the UTXO
To allow the UTXO to actually use the power of checkpoints we need to
make sure that the block-validation state is not stored separately from
it.
The goal is that when we have some curruption we can just go back to an
earlier state of the UTXO and re-validate the blocks to get to the
current tip. The often seen problem is that corruption will instead
leave the block-index (leveldb) with an incorrect state so the replay
fails.

This change solves that by no longer reading the block-validation-state
and no longer writing it on a state change.
2020-02-28 00:33:04 +01:00
TomZ a1b4c0416d Avoid clearing an empty bloom filter 2020-02-27 23:26:20 +01:00
TomZ 99a78eb60a remove dead code 2020-02-27 13:51:21 +01:00
TomZ 4bea1f55c4 use QElapsedTimer 2020-01-30 15:29:03 +01:00
TomZ cb5d9d16f6 Fix usage of exceptions
Throwing an exception instead of returning false means we blacklist the
txid from being downloaded multiple times.
2020-01-15 17:11:27 +01:00
TomZ c672f80374 Catch exception from DSP::create() 2020-01-14 12:36:19 +01:00
TomZ c0ba4e49fb RPC getrawtransaction allow 'true' for bool
This allows fulcrum to work with this old API method.
2020-01-13 23:23:49 +01:00
TomZ 58299fcd70 Add 'initialblockdownload' bool to RPC getbclockchaininfo 2020-01-13 17:42:50 +01:00
TomZ 2e3f59716f Add claimOrphan() 2020-01-13 11:27:47 +01:00
TomZ 6e6f43a0d4 Remember peerID in DSP-orphanage
So when we adopt one proof, and it turns out to be faulty, we can
punish the peer.
2020-01-12 18:06:23 +01:00
TomZ 071629852a Treat DSP orphans with dignity
This improves the double spend proof orphans code.
Also add a DSProof log-category and lots of log lines to make
looking at a debug build much more fun.
2020-01-12 17:41:53 +01:00
TomZ d6a2488b5c Cleanup some DSP issues
remove the need for 'flags' as this code block doesn't use the
current flags at all.

Also validate proofs that were restored from orphan cache.
2020-01-12 17:10:29 +01:00
TomZ 2b68d149de Cleanups 2020-01-05 16:47:49 +01:00
TomZ 06535153b0 Remove unused argument. 2020-01-04 15:25:15 +01:00
TomZ a305edcafe Fix some compiler warnings. 2020-01-04 14:00:17 +01:00
TomZ 83b7243b70 Prepare for the 2020.01 release
From now on, make sure that the minor always has at least 2 digits
which allows us to use string compare of versions even if we have
more than 9 releases in a year.
2019-12-31 18:05:24 +01:00
TomZ 95646682b3 Use hex for the client minor number.
This makes string comparisons much easier (a > 9, while 10 < 9).
2019-12-12 17:34:14 +01:00