Commit Graph

174 Commits

Author SHA1 Message Date
TomZ 69a7db91ec Introduce TransactionMonitorService
This supplies a push notification on txid becoming known to the Hub.

Additionally this changes its close relative the AddressMonitorService
to use a different tag for the transaction data and the
double-spend-proof data so as to make it obvious which one is being
sent.
2020-05-19 20:57:51 +02:00
TomZ a5e6bea027 Merge branch '2020.03' 2020-05-18 22:52:19 +02:00
TomZ e9a2437c2d Add unit tests for UTXO and fixes
This fixes that the .info file is sometimes not written when nothing
changed in the db file.

This fixes that the info file with .1.info extension is reused again
and again, effectively reducing the usefulness of the snapshots.
This only really affects the indexer as pruning avoids this most
of the time.

Closes issue flowee-issues#6
2020-05-18 22:51:41 +02:00
TomZ d49b1ae5e2 Make NetworkManager connections leaner
The NetworkManager usage was mostly for low connection counts and this
made defaults selection easy.
With more usages it is important to allow the NWM-connection to be more
configurable about memory usage and leaner in general.

This changes the headers-buffers (used to create envelopes) to not be per
connection anymore but per thread using the tread_local keyword.

This changes the ring-buffers to become configurable using
NetworkConnections::setMessageQueueSizes().

Also removing some include statements where they were not really needed
in the P2PNet lib.
2020-05-09 20:23:05 +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 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 337598a8bb Remove unused files 2020-04-11 17:04:14 +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 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 899a6e0f18 Make the API test a bit more stable.
The case where multiple hubs were started which cross-connected works
better if we have a small wait in-between the starts.
2020-03-19 18:53:35 +01:00
TomZ 09b4e5050e Make link under strictness rules
This re-adds the flowee_utils lib which was implied and should have
been auto-added by cmake, but it failed to link for AUR strictness
settings.
2020-03-19 16:08:56 +01:00
TomZ ac030e328c Fail fast. 2020-03-19 14:59:31 +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 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 f7f4ea0093 make testing/streaming not link to flowee_server
Also split the testlib into two static libraries and avoid
recompile of the base test file in each test that used it.
2019-12-30 17:55:48 +01:00
TomZ 3315aec93f Add ConstBuffer::operator==() 2019-12-30 17:37:23 +01:00
TomZ f2191ad380 Make UTXO lookup report also the outindex
We have that info, it should be send.
2019-11-30 18:56:25 +01:00
TomZ d86c5a837f Make orphancache follow coding style-guide.
member methods start with a lowercase character.
2019-11-21 20:03:26 +01:00
TomZ 175096b2bd Refactor: move files
Move some files back to the server "library".
Merge the 'console' lib with server, as it doesn't really make sense with
just one file and nobody exclusively linking to it.

The server "libary" is not really a library, its the place we put all
the files shared by hub-qt hub-cli and hub.
We no longer depend on these files from other places (mostly due to
moving to the new logging framework) and as such we can move the files
back.
2019-11-13 19:09:24 +01:00
TomZ d573e307c3 Refactor; move SplitHostPort to utilstrencodings 2019-11-12 15:35:54 +01:00
TomZ 8e9808edaf Test: Follow changes in the API 2019-10-21 14:18:19 +02:00
TomZ 79e4974d19 Port API getblock::filter to use script-hash
The API call for GetBlock has a filter-on-address functionality which is
now ported to no longer use ripe160 addresses but instead uses output-
script hashes.
This avoids problems for transactions not using p2pkh and generally is a
cleaner solution.

This also adds a unit test to test this feature.
2019-10-20 22:12:09 +02:00
TomZ f1d0a68579 Port address monitor service to use address-hash
Remove addresses of type ripe160 to be used in the API of AddresMonitor
API service. Instead use a sha256 hash of the entire output script.

This is mostly internal changes not affecting the operations much.
2019-10-20 20:17:17 +02:00
TomZ 00814e24f9 API: Use hash of outscript instead of address
The usage of a ripe160 for bitcoin addresses in the API and in the
Indexer loses some info, specifically what kind of script it is.
Additionally not all types of scripts fit this mold. At best that means
its not future-proof.

This adds a method to the API in order to select from a Tx the hashed
outscript (thats singlehashed sha256) and refactor the address indexer
to use that instead of the ripe160 address.

The API enums broke a little, so I used the opportunity to break it a
lot and clean up the enums in order to make them more future-proof.
But, yeah, software from before this commit is protocol incompatible
with software after this commit.
2019-10-16 22:57:50 +02:00
TomZ 09a251c1df Fix test stability. 2019-10-15 19:23:57 +02:00
TomZ 60390cc452 Promote multisig tests to the new test framework 2019-10-14 19:24:19 +02:00
TomZ 7593d06473 Use blockheight to enable historical features
We used various ways to enable new features over the last 10 years.
We can remove that legacy code and just set the blockheight.

This cleans up the code quite a bit.
2019-10-14 19:24:19 +02:00
TomZ 71f0dcf942 Fixlets
Add 'override' keyword on various places.
Make test output a more readable should it fail.
2019-10-10 19:20:04 +02:00
TomZ 2161d919fc Add test for SINGLE|ANYONECANPAY
Backport of Bitcoin Core PR12082
2019-10-10 17:33:31 +02:00
TomZ a69ab412f5 Add unit test to test the minimalPush consensus change. 2019-10-09 19:36:48 +02:00
TomZ 4e9f66a335 Remove unused CScript::isCommitment() method. 2019-10-09 19:16:52 +02:00
TomZ 80f27ee26d Make CheckMinimalPush exposed and unit test it. 2019-10-08 14:24:22 +02:00
TomZ 817682025d API make utxo also react to offsetinblock
Since all the APIs use blockheight/offsetinblock instead of TXID we
should be consistent and allow the UTXO fetch API to use this too.
2019-09-13 16:02:22 +02:00
TomZ 449081c476 Turns out, moving the connection is unwanted
Specifically when its returned from a method call.

Static code inspector concludes the std::move prohibits the compiler to
optimize this better.
2019-09-12 15:25:43 +02:00
TomZ 40f2e67db8 Fix removing of proof after tx removal
Including new unit test.
2019-09-04 14:12:38 +02:00
TomZ fc8360b507 Fix whitespace 2019-09-04 14:12:38 +02:00
TomZ 1dbb23224c Add unit tests for double spend proof 2019-09-02 23:59:52 +02:00
TomZ 9ca3a908fa move tipValidationFlags() to Validation::Engine 2019-09-02 23:24:28 +02:00
TomZ 0b152570ee Add ConstBuffer::startsWith()
and include unit test.
2019-08-26 20:48:12 +02:00
TomZ e7a7ada953 Cleanup dependencies a bit more.
This means that for apps like 'pos' no longer link against libSSL

The streams no longer zero-after-free, there are no secrets transported
in datastreams so this is useless and avoids linking in one OpenSSL
call.

The insecure_rand() method depended on the openssl code to seed it with
randomness. Now replaced with a proven current-time-milliseconds.
This is enough in those cases because it was always meant to be an
insecure random.
2019-08-24 22:25:10 +02:00
TomZ df7de2ecd2 Clean up the hairy ball of util.cpp
Move some globals and all stuff pulling in crypto to the
server/serverutil.cpp file

Remove dead code.

Move several items that were used in only one place to the respective
files using them.

Move the class WaitUntilFinishedHelper into its own file.

Made sure no header includes utils.h
remove a handfull of files including utils.h for nothing.
2019-08-24 22:25:09 +02:00
TomZ 2bb06afa9e Cleanup the link-lines 2019-08-24 22:25:09 +02:00
TomZ 67a27a617a Update testchain
This time remember the private keys...
2019-08-03 17:48:41 +02:00
TomZ 32adb9451d Summer cleanup
The block-box tests have long ago lost their usefullness
and have all been replaced by c++ ones.

The big-box testing was always frowned upon, but it kinda worked
for the original Core codebase which was practically speaking 100%
single-threaded.

Flowee the Hub breaks lots of questionable assumptions.
For instance the assumption that sending a transaction to a node
via the p2p layer and then immediately sending a request over RPC for
the mempool will find that tx there.
Flowee uses an async p2p layer, and therefore that old assumption no
longer holds.

Also, its python. Which is painful to read.
2019-08-03 13:53:17 +02:00
TomZ e07083dd85 Make uint256::Compare simpler and be unit-tested 2019-07-29 22:47:36 +02:00