Commit Graph

93 Commits

Author SHA1 Message Date
TomZ 4a183dee98 Add needed include 2020-10-26 22:38:28 +01:00
TomZ b104025f12 Ensure memory leaks are impossible
unique_ptr all the way, baby.
2020-10-26 18:30:39 +01:00
TomZ ff58ae6a36 Implement the first ASync API command
This implements the sendTransaction command using the async framework,
allowing clients to benefit from multi-core systems to process
transactions in parallel when being submitted to the Hub.
2020-10-26 18:21:52 +01:00
TomZ cd6937a672 Set the proper default log section specific libs 2020-10-25 23:43:42 +01:00
TomZ 0293890e80 Add optional async job to Hub API
The current design of the API is that all questions are answered in-
order. This implies that handling of one connection will also just use
one thread.

If we want to improve performance of things like "sendTransaction" we
want an async option, which runs the action and generates the answer
when its done in a separate thread (a new one for each async-request).

This breaks the in-order reply sequence for clients and as such it
requires them to set a new header-option to enable this.
2020-09-29 17:34:06 +02:00
TomZ b033cd8ac4 [API] Add outindex field to mempool address search
When you request matching transactions from the mempool for certain
addreses, the API now returns the matched output-index as a separate
tag, which makes it easier to, for instance, use the 'amount' field in
the reply.
2020-09-18 20:40:11 +02:00
TomZ 8b2c928fae Fix comment confusion (add 'not') 2020-09-14 22:48:03 +02:00
TomZ fcc3b094ef [API] Improve featureset of MempoolSearch
The mempool search now shares its serialization code with the blockchain
transaction fetcher, allowing all the filtering and include flags to work
here too.
This also fixes several bugs and reverts the mempool API change.
Additionally I return the FirstSeenTime for each mempool entry.

There is a slight API breakage in the LiveTransactions service, which as
far as I know is still unused outside of Flowee.
These enum values changed:
Api::LiveTransactions::
  Transaction   20 =>  25
  UnspentState  23 => 26
  OutputScript  24 => 23

The reason for this change is to have the Blockchain namespace in
sync with the LiveTransactions namespace for similar features.
2020-09-14 15:27:15 +02:00
TomZ db9a80f8eb [API] Add support to query the mempool
This allows a search based on TxId or output-script-hash for
mempool transactions.
We include double spend proof info when available in the reply
2020-09-11 14:07:14 +02:00
TomZ 939bbbb2b6 Also in the error message; parrot headers back. 2020-09-02 13:54:41 +02:00
TomZ dc51b85c10 Fix usage-after-delete.
It is unsafe to de-reference an iterator after 'erasing' it.
2020-09-02 13:54:37 +02:00
TomZ 1355c03f63 Fix warnings
This fixes warnings from the compiler and the linter.
2020-09-02 13:47:07 +02:00
TomZ dda576b4bc Fix some warnings
Code cleanliness nitpicking.
2020-07-31 15:58:15 +02:00
TomZ 8e1eefaa81 Improve error message
when user specified wrong offset, send them an error.
2020-07-27 21:26:21 +02:00
TomZ dcff0532dc Improve error message
When missing argument, return to peer a specific message
2020-07-27 12:34:27 +02:00
TomZ e8f7698560 Remove stray log-lines. 2020-06-19 16:40:29 +02:00
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 82dfd082cd Initial support for a Transaction Monitor API 2020-05-19 08:29:31 +02:00
TomZ 5266529f13 Fix potential race condition
Add missing mutex
2020-03-19 22:05:05 +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 6e8c0b29f7 Also here, report minor ver as hex.
Also fix some compiler warnings
2019-12-12 17:48:48 +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 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 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 c2fe9629c1 Remove dead code. 2019-09-12 15:20:29 +02:00
TomZ 57220bb124 Handle doublespend proof message in AddressMonitor 2019-09-02 23:55:46 +02:00
TomZ dce04d2323 Add support for listen=0.0.0.0
This is not portable, so Linux only for now.
2019-08-12 23:48:46 +02:00
TomZ 6cb3e66421 Fix assert
We also return false when there are no listeners.
2019-08-12 11:08:52 +02:00
TomZ c2083fe5b0 Count missing bytes for the tag and length too 2019-08-04 21:19:56 +02:00
TomZ 0755acd1e6 [API] Add double-spend-proofs to addressMonitor
In the address monitor service this detects specifically if a double
spend detected by the Hub is applicable for our subscriber, and if it is
then a Message will be sent to the subscriber.

This introduces a new message type DoubleSpendFound
and changes the API for the TransactionFound message while dropping the
TransactionRejected message.
2019-07-24 18:41:16 +02:00
TomZ 98b3e7cece use new MessageBuilder::reply() 2019-06-26 22:19:28 +02:00
TomZ 3383d1e1dc Add method MessageBuilder::reply()
This is an overload of message() specifically meant to build
replies to incoming messages.
The behaviour changed here is that incoming messages with
headers other than "RequestId" now get copied to the outgoing
message by default.
2019-06-24 19:53:24 +02:00
TomZ ba213cfe9d Fix optimisation.
It incorrectly assumed all transactions were coinbases.
2019-06-19 22:45:44 +02:00
TomZ 9eb3814103 Stabilize new API 2019-06-17 20:50:17 +02:00
TomZ 4a4a61aeed Add unit test for GetTransaction
This also includes a little blockchain of 114 blocks (the first 100 just
coinbase to reach coin-maturity) with transactions generated by the
txVulcano. So lots of outputs.

I adjusted the BlackBoxTest to load this data into any hub with ease.
2019-06-16 23:04:14 +02:00
TomZ d5750426f4 Avoid sending too much 2019-06-15 19:57:35 +02:00
TomZ 1c27a291d0 Add a way for GetTransaction to only return certain outputs 2019-06-15 16:19:27 +02:00
TomZ 0bde548548 Improve allocation behavior in BufferPool
The old algorithm could end up doubling the size every time it
ran out, which eventually consumes all memory.
This way we reset to the user-default size when useful and increase
only based on need.

This means that the programmer needs to make a better estimation on
maximum size of messages, but it avoids behavior similar to memory
leaks.
2019-06-13 13:14:26 +02:00
TomZ 2eba51c5c6 Check message size in debug builds.
Double check our message-calculation is proper by checking the result.
Notice that asserts and logDebug both are turned off in release builds,
so this is just added to debug builds.
2019-06-13 12:30:20 +02:00
TomZ 4b96a30279 Use the chain, not the header for the API 2019-06-11 21:15:23 +02:00
TomZ 3fcd3536ed Clarify coinbase pos in block.
The first field after the header is the number of transactions. This
is a variable-width field of between 1 and 9 bytes.
Coinbase starts after that.
2019-06-11 17:38:30 +02:00
TomZ a310a529ce API cleanup; don't send prevtxhash for coinbases
The prevTxHash and prevOutIndex are irrelevant for coinbases as
the input isn't really an input.
2019-06-11 17:38:30 +02:00
TomZ 2822b4ed4a Make API handling more robust. 2019-06-10 21:02:15 +02:00
TomZ 0a916c21e9 Add UTXO support to APIs
Generically this looks like this;

IsUnspent
[
  { "txid": "0x111111", "output": 1 },
  { "txid": "0x111111", "output": 11 }
]
IsUnspentReply
[
  { "blockHeight": 1111, "offsetInBlock": 1111, "unspent": true },
  { "unspent": false }
]

GetUnspentOutput
[
  { "txid": "0x111111", "output": 1 },
  { "txid": "0x111111", "output": 0 }
]
GetUnspentOutputReply
[
  { "blockHeight": 1111, "offsetInBlock": 1111, "unspent": true,
    "amount": 1111, "outputscript": "bytearray" },
  { "unspent": false }
]

note: txids are naturally always sha256s.
2019-06-10 21:02:15 +02:00
TomZ 449f91f46d Move solver method to utils lib
The code that detects standard script-types is now available as a
library function, renamed to live in a namespace;
Script::solver()
2019-06-06 22:21:46 +02:00
TomZ a1dfd1cde9 Work on installable headers 2019-06-03 10:59:33 +02:00
TomZ 7203a058a3 Change API call SplitHostPort slightly
Instead of taking an int for the port, take a short.
This matches better with the networkmanager EndPoint struct.
2019-06-02 20:16:49 +02:00
TomZ 38b4e8b189 Allow hubs -apibind to use 'localhost' string
The command really only accepts IP addresses, but we use 'localhost' as
an exception to bind to loopback for ipv4 and ipv6 at the same time.

Also improve logging of errors and avoid failing to start the API
service if a bind address wasn't an IP.
2019-05-24 23:14:15 +02:00