Commit Graph

64 Commits

Author SHA1 Message Date
tomFlowee defd3950f0 Remove CAmount typedef
The CAmount name is not helpful as its just an int64_t and not a
class, like the name implies. There were a handful of places where
it was passed in as const-ref, as a good example of this actually
creating sub-par code.
2021-01-20 19:59:35 +01:00
tomFlowee 6195f84068 Print IP since peer-ID is useless before handshake 2020-12-07 17:35:10 +01:00
TomZ 251cc76966 Avoid banning a whitelisted peer on bad headers. 2020-11-18 22:40:46 +01:00
TomZ 6d330622f2 Handle whitelisted nodes different for DSProof punishment. 2020-10-27 16:33:08 +01:00
TomZ 67cf8955b0 Drop usage of old log-style. 2020-10-27 16:33:08 +01:00
TomZ fdaa6e4a81 Import some improvements from Calin.
* API docs
* Fix possible race condition in addOrphan()
* Reject proofs that violate simple constraints
* clear up possible confusing API (first/double spender getters).
2020-09-29 17:33:20 +02:00
TomZ 84ebae427e Import ASERT DAA
This includes renaming some methods which makes the import look larger
than it really is.
2020-08-12 21:42:54 +02:00
TomZ 297a22dfa8 Move and fix partitionCheck()
Small refactor; move the partition check away from main and the obsolete
global variables we used to use, instead now just add it to the DB which
owns the data it works on.

This fixes the bug that in various cases we'd incorrectly get a warning
about no blocks being found in the last N hours.
2020-08-10 10:13:02 +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 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 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 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 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 99a78eb60a remove dead code 2020-02-27 13:51:21 +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 7a360f5a3d slight logging updates 2019-12-09 15:15:52 +01:00
TomZ c094c8d523 Merge branch '2019.09' 2019-11-22 19:24:13 +01:00
TomZ 79437d227e Avoid forwarding transactions twice.
An INV in some cases could lead us to reply with two transactions
instead of one.
2019-11-22 19:14:32 +01:00
TomZ 69ea2ddfcd Make whitelisted peers not get punished for bad transactions. 2019-11-22 18:58:58 +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 a645f963dc Make node ignore tx-invs during IBD/catch-up
This now also works when using '-connect' or other ways to whitelist a
node.
2019-11-06 23:43:13 +01:00
TomZ d24b4450ea A little cleanup of main.cpp 2019-10-15 19:23:57 +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 37b359cdac Implement network awareness of double-spend-proof 2019-09-02 23:57:46 +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 60195ba472 Change defaults, stop enabling xthin by default. 2019-08-12 11:08:48 +02:00
TomZ 055934b473 Be smarter about which INVs to send and respond to
This still drops the amount of INVs used during the catch-up phase,
while still being a good netizen.
2019-08-06 23:00:36 +02:00
TomZ b035ee5777 Waste less bandwidth during catch-up. 2019-08-05 11:55:59 +02:00
TomZ 1aacb3ae52 Vastly simplify mempool-acceptance
This removes the attempt at magic (predicting future) component
called the fee-estimator.
The direct effect is that all transactions have as a mempool acceptance
the same minimum fee. Regardless of how full the mempool or blocks were.

This mempool-acceptance minimum fee is 0 sat/byte. (aka free)

Notice the node-wide free-tx accept-limiter is going to avoid us getting
overloaded.
2019-06-28 14:02:11 +02:00
TomZ 75b394e94b Various little fixes
* user selected nodes (using -connect=) are whitelisted, which allows
them to get your headers even if you are still in initial download.
* Avoid crash in a starting node in isInInitialDownload when
pIndexBestHeader was still null.
2019-06-17 22:07:17 +02:00
TomZ f868a8274e Make all protocol upgrades equal.
The "UAHF" one used to be "more equal", mostly just because it happened
to be the first.
This makes them all equally equal.

Specifically this removes the special casing and the enum for the 201708
HF (aka BCH fork-point).
We select the right branch now purely based on the historical check-
points.
2019-06-02 13:57:47 +02:00
TomZ 01459ec961 Refactor; move lastCommonAncestor to Blocks::Index ns
Out of the main.cpp and usable for a bigger audience.
2019-05-27 09:27:08 +02:00
TomZ e1388b8ce7 Disconnect nodes that follow a different chain
Nodes that follow a different chain (and thus send us headers that we
already invalidated) now get an immediate disconnect whereas before
we could keep them around for an hour.
2019-05-08 10:51:46 +02:00
TomZ a7f9b9fed5 Remove obsolete code.
Remove txIndex option, its move to Flowee Indexer

Also remove the GUI option for setting the amount
of "script validator threads". :D

Remove DBCash command line option too, equally obsolete.
2019-04-22 21:16:10 +02:00
TomZ d20dd6d70a Cleanup; block-pruning
This has been commented out code for some time and its probably best to
remove dead code so as to avoid it rotting.
2019-04-22 20:33:49 +02:00
TomZ 890ebf2650 Remove obsolete method GetTransaction
It was a bad attempt of correctness and with Indexer it is ready to be
retired.

The RPC methods now just look in the mempool.
2019-04-10 16:16:05 +02:00
TomZ bcc454f1c6 Add some useful log output 2019-03-23 19:31:31 +01:00
TomZ 776c9d019b Don't crash when dir already locked
Should you have a hub already running then starting a second aborts
at startup.
Since the shutdown sequence is run it tries to save everything.
This fix avoids a nullptr dereference in this specific event.
2019-03-10 11:34:04 +01:00
TomZ 7b185570e5 Various cleanups and fixes 2019-02-25 21:35:05 +01:00
TomZ 135bbb9a5f Cleanup BOOST_FOREACH -> for(:) 2018-12-30 15:33:11 +01:00
TomZ 898cb1fc5f Remove dead code
As the miners have started using the block-version bits for their
own purposes this means that BIP9 checks are rather irrelevant.
Signalling using version bits is rather silly anyway.

In Flowee there will no longer be warnings generated based on
these now outdated assumptions.
And this means less code :)
2018-12-30 13:51:25 +01:00
TomZ 4623a07968 Remove some usages of the multi-chain feature
During the BCH fork-off time we allowed the client to be started
as either BCH or BTC and as such there are several code-paths
that behave different based on this user setting.
We remove those as we no longer allow starting as BTC client.

This also removes the check for the min-block-size (rollback protection)
as this is accomplished by the checkpoints on the BCH chain.
2018-12-30 13:33:25 +01:00
TomZ 3e3f8843f3 Remove the optional replay protection feature
Its sundown has passed, so the code is now effectively dead.
2018-11-29 23:13:48 +01:00
TomZ b256676044 Rename debug.log -> hub.log 2018-11-21 12:18:32 +01:00
TomZ 7bfabca6fc Mark log-levels 2018-11-21 11:31:54 +01:00