Commit Graph

5542 Commits

Author SHA1 Message Date
Steven Barclay
1abf4c5d96
Exclude segwit pubkeys by block height instead of a blacklist
Since extraction of segwit pubkeys technically represents a hard fork,
activate it by block height in the same way as the fork defined in
TxOutputParser, instead of relying on the absence of premature segwit
BSQ inputs outside of a blacklist. This also means we no longer need to
exclude all but the first tx input from segwit pubkey extraction to
maintain backwards compatibility, which is a little safer and consistent
with the original behaviour of extracting every available P2PKH pubkey.

Provisionally activate this (2nd) DAO hard fork at block height 672646,
which should be 6 weeks from now, just under 5 weeks from the planned
1.5.5 release on 2021/01/27. (Block 1906689 for testnet - 2 weeks from
now assuming an average block time of 10 minutes, but it's erratic.)
2021-01-21 10:10:31 +00:00
Steven Barclay
4b0711bfcc
Add Bitcoin Core version & health check to RpcService
Make a 'getnetworkinfo' RPC call to bitcoind immediately upon startup,
to check that the node is up (and throw a ConnectException to ensure
that the user is presented with an appropriate warning popup otherwise).
Log a warning if the node version is outside the 0.18.0 - 0.20.1 range.

Additionally, call 'getbestblockhash' to check that the chain tip is not
stale (> 6 hours old). As part of this, make sure the 'getblock' RPC
call works correctly with verbosity < 2, by fixing JSON deserialisation
of the response when the block or txs are in summary (hex string) form.

(These version & health checks are almost identical to the ones done by
the original btcd-cli4j library during RPC client startup.)
2021-01-21 10:10:31 +00:00
Steven Barclay
d595cac477
Add getNetworkInfo & getBestBlockHash RPC client methods
Provide a 'NetworkInfo' DTO class (with associated nested DTO classes),
returned by the 'getnetworkinfo' RPC method call to bitcoind. This will
be used during startup of RpcService to determine if Bitcoin Core is
available and which version it is using. Add a unit test to round-trip a
sample NetworkInfo JSON response.

Also add the missing 'getbestblockhash' RPC method, which will be needed
by RpcService to determine the Bitcoin Core node health.
2021-01-21 10:10:31 +00:00
Steven Barclay
a850adadb6
Make special case for irregular tx with segwit BSQ inputs
Selectively disable pubkey extraction from segwit inputs of a particular
tx at block height 660384 (2020-12-07), which spends spuriously created
segwit BSQ (later burned), to prevent a change in the DAO state hashes
from that point.

(Since a tx with a given ID can only appear on one chain, a fixed global
exclusion list of IDs should not cause any issues on testnet/regtest
versus mainnet. This is simpler than conditioning by block height.)
2021-01-21 10:10:30 +00:00
Steven Barclay
796097abbc
Fix data race in BitcoindDaemonTest
Prevent intermittent test failures, caused by a race between checking
whether the mock socket is closed upon accepting a new connection and
setting 'socketClosed' to true during shutdown. Waiting to accept and
then checking the flag needs to be done in a synchronized block.
2021-01-21 10:10:30 +00:00
Steven Barclay
93b46e3a40
Fix Codacy issues & deduplicate code in RpcService
Factor out shared construction logic to a new 'getBlockFromRawDtoBlock'
method in RpcService. Also add some 'NOPMD' comments in an attempt to
suppress unfixable Codacy warnings about qualified imports.
2021-01-21 10:10:29 +00:00
Steven Barclay
6ca42c0cd1
Enable extraction of segwit pubkeys from raw tx inputs
Factor out a new RpcService.extractPubKeyAsHex method, to take public
keys from the inputs of the raw transactions returned by the RPC client,
when building TxInput objects to incorporate into the DAO state. Enhance
the method to additionally support segwit (P2WPKH & P2SH-P2WPKH) inputs
(but only the first input for backwards compatibility - see code
comment). Also fix a bug when handling non-SIGHASH_ALL input signatures.

This will allow segwit BSQ to be used in proof-of-burn and issuance txs,
which need a public key associated with the tx to establish ownership of
it, when signing messages with a proof-of-burn or staking merit awarded
from a compensation issuance, respectively.

Also add unit tests for the factored-out method and add a missing RawTx
toString() method, to aid debugging the TxInput fields within the
processed block returned by RpcService.
2021-01-21 10:10:29 +00:00
Steven Barclay
8104301b52
Use new Bitcoind(Client|Daemon) & remove btcd-cli4j
Migrate RpcService over to the new block notification daemon and RPC
client based on jsonrpc4j. Drop in own DTO classes in place of the ones
defined by btcd-cli4j and rename requestBtcBlock & addNewBtcBlockHandler
to requestDtoBlock & addNewDtoBlockHandler respectively.

Also remove now redundant filtering from the logback config and update
grade-witness.
2021-01-21 10:10:28 +00:00
Steven Barclay
ac78639656
Improve exception handling in BitcoindDaemon
Wrap any exception that occurs during socket IO or within the supplied
BlockListener with a new 'BlockNotificationException'. This brings the
exception handling more in line with that of the old BtcdDaemonImpl and
makes it easier to match them downstream in FullNode.handleError.
2021-01-21 10:08:24 +00:00
Steven Barclay
4470af8edb
Add missing copyright headers to new files 2021-01-21 10:08:23 +00:00
Steven Barclay
f34231abb6
Factor out failure callback logic into new Utilities method 2021-01-21 10:08:23 +00:00
Steven Barclay
863392bc74
Factor out executor shutdown logic into new Utilities method 2021-01-21 10:08:22 +00:00
Steven Barclay
b7c7eaf1f2
Add replacement bitcoind block notification daemon
Provide a new 'BitcoindDaemon' block notification socket server, to
replace 'com.neemre.btcdcli4j.daemon.BtcdDaemonImpl'. This starts a
single service thread to listen for raw block hashes on localhost port
512*, sent by the specified 'blocknotify' shell/batch script, delegating
to a pool of worker threads to run the supplied BlockListener handler.
Unlike the original BtcdDaemonImpl class, a call to the 'getblock' RPC
method is not made automatically to supply a complete block to the
handler, instead requiring a separate, manual BitcoindClient.getBlock
invocation from within RpcService.

Also provide unit tests using a mock ServerSocket + Socket.

TODO: Use the new Bitcoind(Client|Daemon) implementations in RpcService,
 in place of btcdcli4j Btcd(Client|Daemon)Impl & remove the old library.
2021-01-21 10:08:22 +00:00
Steven Barclay
dbe4953f63
Add replacement bitcoind RPC client using jsonrpc4j
Create a new 'BitcoindClient' interface and a corresponding builder, to
replace the old 'com.neemre.btcdcli4j.core.client.BtcdClientImpl' class
from the btcdcli4j library. This is instantiated by jsonrpc4j using a
dynamic proxy. It provides only a cut down version of the bitcoind RPC
API, exposing the methods 'getblock', 'getblockcount' & 'getblockhash',
as they are the only ones currently being used by RpcService.

Add corresponding Jackson-annotated DTO classes to model the JSON
structures returned by bitcoind, very similar to the classes provided by
btcdcli4j. Note that we use Double instead of BigDecimal to represent
fractional fields (difficulties + coin amounts in BTC), as they have
more consistent Jackson (de)serialisation and appear to be able to
faithfully round-trip numeric fields produced by bitcoind. Also note
that doubles can faithfully represent any valid decimal BTC amount (that
is, with 8 d.p. of precision) up to 21 million.

For now, keep the old BtcdClientImpl instance used by RpcService in
place, as the btcdcli4j block notification daemon is dependent upon it
and would also need to be replaced.

Also add unit tests for BitcoindClient which test against sample regtest
responses, using a mock HttpURLConnection.
2021-01-21 10:08:22 +00:00
Steven Barclay
5990fcf9e7
Bring ScryptType enum up to date with latest bitcoind
Add 'witness_v1_taproot' script type to the enum and proto.pb, so that
it doesn't cause any problems when Taproot is activated and the new
script type starts showing up in RPC getBlock(..) responses (including
possibly BSQ transactions).

Also change the Java enum order (which shouldn't cause any problems as
the ordinal isn't used directly in hashCode calculations) and add the
missing 'witness_unknown' enum value to pb.proto to bring it in sync.
2021-01-21 10:08:15 +00:00
sqrrm
d3971ef7dd
Merge pull request #5072 from chimp1984/persist-and-republish-mailbox-messages
Persist and republish mailbox messages
2021-01-16 20:24:13 +01:00
ghubstan
1ad7b351b6
Remove uneeded method 2021-01-15 16:33:52 -03:00
ghubstan
ec9f783eb5
Remove switch(hardcoded enum.name)
There is no need for a switch here, the doc exists or it does not.
2021-01-15 16:25:39 -03:00
ghubstan
a067ba1228
Add new CoreHelpService and method help docs
Adds all the gRPC server boilerplate, and a simple help service
that serves method help in man page format.  Help text is maintained
in text files located in core/src/main/resources/help.

Only some of the method help text files are defined in this
change, more to be added.
2021-01-14 10:19:39 -03:00
sqrrm
f838b1a475
Merge pull request #5076 from ghubstan/03-support-trigger-price
Stub out support for OpenOffer's triggerPrice in api
2021-01-14 10:34:29 +01:00
Christoph Atteneder
01bfbe7ca0
Merge pull request #5071 from jmacxx/fix_issue_5067
Show a confirmation of successfully sending BTC or BSQ from wallet
2021-01-14 09:37:20 +01:00
chimp1984
541f367e81
Dont log filter content if a filter got updated 2021-01-13 20:39:26 -05:00
sqrrm
685d79749b
Merge pull request #5065 from ghubstan/offer-protection-tools-api-integration
Integrate new protection tools into api's offer & trade services
2021-01-14 00:26:10 +01:00
ghubstan
a8d15d0161
Merge branch 'offer-protection-tools-api-integration' into 03-support-trigger-price 2021-01-13 20:03:03 -03:00
ghubstan
0e779a4bf6
Inject CoreContext into server, then set isApiUser=true
Do not set isApiUser=true based on hardcoded thread name ;-(

For requested change
https://github.com/bisq-network/bisq/pull/5065#pullrequestreview-567708569
2021-01-13 19:55:49 -03:00
chimp1984
d434cb3022
Sort persisted mail box messages by age and limit total number.
Add size limit.
Add log for number of persisted mailbox msg per day
2021-01-12 22:59:44 -05:00
chimp1984
c12e239fa5
Refactor: rename method 2021-01-12 17:44:04 -05:00
chimp1984
36657f5532
Use TradeMailboxMessage as type for getMessage in SendMailboxMessageTask 2021-01-12 17:43:27 -05:00
chimp1984
2b05ed54fc
Let MailboxMessage extend ExpirablePayload:
For all MailboxMessage we want to be sure they have an expire date.
Add getTTL methods and TTL value.
We use 7 days for ChatMessages and 30 days for PrivateNotificationMessages.
All others use default 15 days.
We prefer to keep them explicit and not use a default method in
ExpirablePayload or MailboxMessage.
The value in PrefixedSealedAndSignedMessage will not be used as the
sender use the TTL of the payload and pass that to the MailboxStoragePayload
where we store it in the extraMap. That way we can use different TTL even the
payload message is encrypted and we would not be able to look it up.
2021-01-12 16:14:13 -05:00
chimp1984
470230c35c
Add TradeMailboxMessage and use a TTL of 15 days
Extend TradeMailboxMessage where we had `extends TradeMessage implements MailboxMessage`
2021-01-12 16:06:13 -05:00
chimp1984
008fb3b6dc
Inline isMyMessage methods 2021-01-12 14:43:25 -05:00
chimp1984
c229c3f014
Refactor handling of DecryptedMessageWithPubKey 2021-01-12 14:36:13 -05:00
chimp1984
d353140e7a
Refactor: rename getMyDecryptedMessages method to make it more explicit
that its only used for MailboxMsg
2021-01-12 13:54:54 -05:00
chimp1984
5cdae8620b
Refactor: rename method to make it more explicit that its only used for MailboxMsg 2021-01-12 13:54:25 -05:00
chimp1984
575196c16d
Refactor handleDecryptedMessageWithPubKey to use MailboxMessage
instead of decryptedMessageWithPubKey.
Here we change a bit the behaviour as now we check also if the
TradeMessage is a MailboxMessage. As that method is only called
from MailboxMessageService domain we never get a non MailboxMessage
here anyway and it would have been a bug.

Remove removeMailboxMsg(DecryptedMessageWithPubKey decryptedMessageWithPubKey) as not used anymore
2021-01-12 13:53:20 -05:00
chimp1984
2235c4fbdc
Use removeMailboxMsg method with MailboxMessage as param type 2021-01-12 13:36:46 -05:00
chimp1984
456ce70d22
Refactor: rename dispatchMessage to onSupportMessage (no functionality change) 2021-01-12 13:32:03 -05:00
chimp1984
f536aba841
Refactor handling of removeMailboxMsg 2021-01-12 13:31:03 -05:00
chimp1984
bffe2b82a7
Store PrivateNotificationMessage instead of DecryptedMessageWithPubKey 2021-01-12 13:25:19 -05:00
chimp1984
0f087946fc
Remove unneeded wrapping of tradeMessage into DecryptedMessageWithPubKey 2021-01-12 13:25:04 -05:00
chimp1984
32aeda7468
Add null check 2021-01-12 12:47:57 -05:00
chimp1984
d39a697611
Fix wrong delay, increase timeout 2021-01-12 10:48:29 -05:00
chimp1984
320e5f1aef
Refactor: Rename method 2021-01-12 10:48:28 -05:00
chimp1984
35ef3b842f
Add support for TTL defined by payload message so we can use
different TTL for lower prio mailbox messages like AckMessages.

As we cannot add a field without breaking signatures we
need to use the extraMap in MailboxStoragePayload
2021-01-12 10:48:28 -05:00
chimp1984
a3b2aad3b0
Refactor: move class to new utils package 2021-01-12 10:48:27 -05:00
chimp1984
41a92eae7f
Refactor: Rename class 2021-01-12 10:48:27 -05:00
chimp1984
75e547fda5
Refactor: move classes to persistence package 2021-01-12 10:48:27 -05:00
chimp1984
32f887478b
Persist map for removed mailbox messages (AddOncePayload more generally)
We add the date when we add the hash so that we can remove expired data.
2021-01-12 10:48:26 -05:00
chimp1984
504fb2e6a1
Refactor: Rename 2021-01-12 10:48:26 -05:00
chimp1984
4fc35a7b39
Cleanups 2021-01-12 10:48:25 -05:00