Commit Graph

15955 Commits

Author SHA1 Message Date
chimp1984
d74bffb595
In case the BSQ blocks directory does not exist in resources (as in case of REG_TEST)
we do not want to log an error stacktrace but just an info message.

Use `File.separator` instead of "/"
2021-12-09 11:04:55 -05:00
Christoph Atteneder
eb074ac0e2
Merge pull request #5908 from ripcurlx/update-data-stores-for-v1.8.0-again
Update data stores for v1.8.0 (again, again)
2021-12-09 16:03:39 +01:00
Christoph Atteneder
f3d2cc38dc
Merge pull request #5907 from alvasw/offer_book_action_button_text_cutoff
OfferBook: Show Complete Text Of Action Button If Enough Space Available
2021-12-09 10:19:30 +01:00
chimp1984
444d045c4f
At shutdown the executor can throw a RejectedExecutionException which
is expected as we shut down the executor immediately.
If not thrown at shutdown or exception is not a RejectedExecutionException
we log a warning and re-throw the exception (to avoid change of behaviour
of current version). The exception is likely not handled by callers and goes up to
the uncaught exception handler.
2021-12-09 10:10:06 +01:00
Bisq GitHub Admin
be4cbcdcec
Merge pull request #5901 from chimp1984/handle-RejectedExecutionException-in-RpcService
Add Exception handling at RpcService
2021-12-09 10:09:24 +01:00
Steven Barclay
34409638f7
Avoid enumerating every jar entry in FileUtil::listResourceDirectory
Use 'java.nio.file.FileSystem' in place of 'java.util.jar.JarFile' to
list all the resources under a given classpath (on Windows & Linux), as
that is a bit neater and potentially more efficient than scanning the
entire ZIP directory structure.
2021-12-09 09:52:30 +01:00
Steven Barclay
e07c7b5d4b
Fix BSQ blocks resync from resources on Windows & Linux
Prevent a "URI is not hierarchical" IllegalArgumentException from the
expression, 'new File(dirUrl.toURI())', which occurs on Linux & Windows
when listing the resource directory of BSQ blocks. Adapt a solution from
StackOverflow which uses two separate code paths depending on the
environment, into the new method 'FileUtil::listResourceDirectory'.

The issue is caused by the resource URL taking one of the two forms:

  file:/Users/[USER]/Java/bisq/bisq/p2p/out/production/resources/BsqBlocks_BTC_MAINNET
  jar:file:...p2p.jar!/BsqBlocks_BTC_MAINNET

depending on whether the system is OSX or not.
2021-12-09 09:52:30 +01:00
Christoph Atteneder
601163eeb3
Merge pull request #5900 from stejbac/fix-resync-blocks-from-resources
Fix resync BSQ blocks from resources
2021-12-09 09:51:51 +01:00
Christoph Atteneder
7d66264453
Update data stores for v1.8.0 (again, again) 2021-12-08 21:13:21 +01:00
chimp1984
81d112bdf3
Add null checks
Return early at connection if stopped
Cleanup logs
2021-12-08 19:39:37 +01:00
chimp1984
ee1371276f
Reduce timeouts
Add logs when shutdown starts
2021-12-08 19:39:37 +01:00
chimp1984
d5d60b59cc
Extract duplicated code at shutdown
Move timeout before shutdown sequence starts and use a Timer thread instead of
UserThread to avoid that in case the UserThread gets blocked that the timeout
would not get triggered.
Reduce timeout from 20 sec. to 10 sec.
2021-12-08 19:39:37 +01:00
chimp1984
c58d9a9edd
Do not shut down networkNode and Tor in parallel as network node
requires still tor when sending close messages.
Reduce timeout from 5 sec to 2 sec.
Reduce timeout for executor shutdown from 500 ms to 100 ms
2021-12-08 19:39:36 +01:00
Christoph Atteneder
ff3809713b
Merge pull request #5905 from chimp1984/improve_shutdown_process
Improve shutdown process
2021-12-08 19:39:22 +01:00
chimp1984
32cd812744
Increase trade protocol timeout from 60 sec to 120 sec 2021-12-08 19:37:41 +01:00
Christoph Atteneder
226a81e7d1
Merge pull request #5904 from chimp1984/increase_trade_timeout
Increase trade protocol timeout from 60 sec to 120 sec
2021-12-08 19:37:12 +01:00
Alva Swanson
f32f1d488a
OfferBook: Show Complete Text Of Action Button If Enough Space Available
Even if the app is maximized it does not show the full text of the
action button if the text is long. Switching Bisq to German and
maximizing the window reveals the problem.

Fixes #5862
2021-12-08 13:09:03 +01:00
chimp1984
3d40b3bf29
Add null checks
Return early at connection if stopped
Cleanup logs
2021-12-07 21:07:40 -05:00
chimp1984
2474e0daf9
Reduce timeouts
Add logs when shutdown starts
2021-12-07 20:45:02 -05:00
chimp1984
4eb14fb226
Extract duplicated code at shutdown
Move timeout before shutdown sequence starts and use a Timer thread instead of
UserThread to avoid that in case the UserThread gets blocked that the timeout
would not get triggered.
Reduce timeout from 20 sec. to 10 sec.
2021-12-07 20:42:53 -05:00
chimp1984
a7c8f2d966
Do not shut down networkNode and Tor in parallel as network node
requires still tor when sending close messages.
Reduce timeout from 5 sec to 2 sec.
Reduce timeout for executor shutdown from 500 ms to 100 ms
2021-12-07 20:35:20 -05:00
chimp1984
b5b7e86323
Increase trade protocol timeout from 60 sec to 120 sec 2021-12-07 19:39:22 -05:00
chimp1984
e85e46cb13
At shutdown the executor can throw a RejectedExecutionException which
is expected as we shut down the executor immediately.
If not thrown at shutdown or exception is not a RejectedExecutionException
we log a warning and re-throw the exception (to avoid change of behaviour
of current version). The exception is likely not handled by callers and goes up to
the uncaught exception handler.
2021-12-07 09:58:11 -05:00
Steven Barclay
746061ef85
Avoid enumerating every jar entry in FileUtil::listResourceDirectory
Use 'java.nio.file.FileSystem' in place of 'java.util.jar.JarFile' to
list all the resources under a given classpath (on Windows & Linux), as
that is a bit neater and potentially more efficient than scanning the
entire ZIP directory structure.
2021-12-07 14:53:28 +00:00
Steven Barclay
ec58b26657
Fix BSQ blocks resync from resources on Windows & Linux
Prevent a "URI is not hierarchical" IllegalArgumentException from the
expression, 'new File(dirUrl.toURI())', which occurs on Linux & Windows
when listing the resource directory of BSQ blocks. Adapt a solution from
StackOverflow which uses two separate code paths depending on the
environment, into the new method 'FileUtil::listResourceDirectory'.

The issue is caused by the resource URL taking one of the two forms:

  file:/Users/[USER]/Java/bisq/bisq/p2p/out/production/resources/BsqBlocks_BTC_MAINNET
  jar:file:...p2p.jar!/BsqBlocks_BTC_MAINNET

depending on whether the system is OSX or not.
2021-12-07 11:48:07 +00:00
Christoph Atteneder
75ca2faeb2
Update translations for v1.8.0 (again) 2021-12-07 11:12:29 +01:00
Christoph Atteneder
9cdd4ae623
Merge pull request #5899 from ripcurlx/fix-master
Fix issue caused by auto merge
2021-12-07 10:06:39 +01:00
Christoph Atteneder
ed1dac715b
Add missing import 2021-12-07 10:01:24 +01:00
Christoph Atteneder
ce541f6401
Add missing import 2021-12-07 09:51:54 +01:00
Christoph Atteneder
f1799a5206
Make Codacy happy 2021-12-07 09:41:41 +01:00
Christoph Atteneder
d39820bbcd
Apply suggestions and fix edge case when BSQ legacy payment account offer is duplicated 2021-12-07 09:41:41 +01:00
Christoph Atteneder
f41203858c
Add visual icon for duplicate offer functionality 2021-12-07 09:41:41 +01:00
Christoph Atteneder
7d7a9ecfc8
Add support to duplicate bsq swap offers also in History view 2021-12-07 09:41:40 +01:00
Christoph Atteneder
4d1ee3fc9b
Add support to duplicate bsq swap offers 2021-12-07 09:41:40 +01:00
Bisq GitHub Admin
5041dc57ef
Merge pull request #5886 from ripcurlx/add-bsq-swap-duplicate-offer-support
Add support to duplicate BSQ swap offers
2021-12-07 09:41:10 +01:00
Steven Barclay
d5839bc6b2
Add separate ProofOfWork.solution proto field for Equihash
Avoid repurposing the 'ProofOfWork.payload' field for Equihash puzzle
solutions, as that may be of later use in interactive PoW schemes such
as P2P network DoS protection (where the challenge may be a random nonce
instead of derived from the offer ID). Instead, make the payload the
UTF-8 bytes of the offer ID, just as with Hashcash.

Also, make the puzzle seed the SHA-256 hash of the payload concatenated
with the challenge, instead of just the 256-bit challenge on its own, so
that the PoW is tied to a particular payload and cannot be reused for
other payloads in the case of future randomly chosen challenges.
2021-12-07 09:35:46 +01:00
Steven Barclay
ceb9b9acbd
Code cleanup: proto fields, duplicated expr & null char separator
1. Reorder the PoW fields in the 'Filter' proto by field index, instead
 of contextually.
2. Deduplicate expression for 'pow' & replace if-block with boolean op
 to simplify 'FilterManager::isProofOfWorkValid'.
3. Avoid slightly confusing use of null char as a separator to prevent
 hashing collisions in 'EquihashProofOfWorkService::getChallenge'. Use
 comma separator and escape the 'itemId' & 'ownerId' arguments instead.

(based on PR #5858 review comments)
2021-12-07 09:35:45 +01:00
Steven Barclay
c9c2be6dcd
Fix bug in Equihash.IntListMultimap & adjust constants
Fix a trivial bug in the iterator returned by 'IntListMultimap::get',
caused by mistaken use of the iterator index in place of the key when
doing lookups into the overspill map. This was causing puzzle solutions
to be invalid about 3% of the time, as well as substantially reducing
the average number of solutions found per nonce.

As the fix increases the mean solution count per nonce to the correct
value of 2.0 predicted by the paper (regardless of puzzle params k & n),
inline the affected constants to simplify 'Equihash::adjustDifficulty'.
2021-12-07 09:35:45 +01:00
Steven Barclay
92209c3ed7
Inline predicates to simplify HashCashService & FilterManager
Remove all the 'challengeValidation', 'difficultyValidation' and
'testDifficulty' BiPredicate method params from 'HashCashService' &
'ProofOfWorkService', to simplify the API. These were originally
included to aid testing, but turned out to be unnecessary.

Patches committed on behalf of @chimp1984.
2021-12-07 09:35:45 +01:00
Steven Barclay
772cd74ab2
Store difficulty as floating point in Filter & PoW
Change the type of the 'difficulty' field in the Filter & ProofOfWork
proto objects from int32/bytes to double and make it use a linear scale,
in place of the original logarithmic scale which counts the (effective)
number of required zeros.

This allows fine-grained difficulty control for Equihash, though for
Hashcash it simply rounds up to the nearest power of 2 internally.

NOTE: This is a breaking change to PoW & filter serialisation (unlike
the earlier PR commits), as the proto field version nums aren't updated.
2021-12-07 09:35:44 +01:00
Steven Barclay
266a7ccea4
Add+enable service to mint/verify Equihash proofs of work
Add an abstract base class, 'ProofOfWorkService', for the existing PoW
implementation 'HashCashService' and a new 'EquihashProofOfWorkService'
PoW implementation based on Equihash-90-5 (which has 72 byte solutions &
5-10 MB peak memory usage). Since the current 'ProofOfWork' protobuf
object only provides a 64-bit counter field to hold the puzzle solution
(as that is all Hashcash requires), repurpose the 'payload' field to
hold the Equihash puzzle solution bytes, with the 'challenge' field
equal to the puzzle seed: the SHA256 hash of the offerId & makerAddress.

Use a difficulty scale factor of 3e-5 (derived from benchmarking) to try
to make the average Hashcash & Equihash puzzle solution times roughly
equal for any given log-difficulty/numLeadingZeros integer chosen in the
filter.

NOTE: An empty enabled-version-list in the filter defaults to Hashcash
(= version 0) only. The new Equihash-90-5 PoW scheme is version 1.
2021-12-07 09:35:44 +01:00
Steven Barclay
23252caa3b
Fix method name typo: redoProofOfWorkAndRepublish 2021-12-07 09:35:44 +01:00
Steven Barclay
eb435a9513
Add difficulty adjustment & benchmarking to Equihash(Test)
Provide a utility method, 'Equihash::adjustDifficulty', to linearise and
normalise the expected time taken to solve a puzzle, as a function of
the provided difficulty, by taking into account the fact that there
could be 0, 1, 2 or more puzzle solutions for any given nonce. (Wagner's
algorithm is supposed to give 2 solutions on average, but the observed
number is fewer, possibly due to duplicate removal.) For tractability,
assume that the solution count has a Poisson distribution, which seems
to have good agreement with the tests.

Also add some (disabled) benchmarks to EquihashTest. These reveal an
Equihash-90-5 solution time of ~146ms per puzzle per unit difficulty on
a Core i3 laptop, with a verification time of ~50 microseconds.
2021-12-07 09:35:43 +01:00
Steven Barclay
c3e5dfd19e
Add PoW version(-list) fields to ProofOfWork & Filter
Add a numeric version field to the 'ProofOfWork' protobuf object, along
with a list of allowed version numbers, 'enabled_pow_versions', to the
filter. The versions are taken to be in order of preference from most to
least preferred when creating a PoW, with an empty list signifying use
of the default algorithm only (that is, version 0: Hashcash).

An explicit list is used instead of an upper & lower version bound, in
case a new PoW algorithm (or changed algorithm params) turns out to
provide worse resistance than an earlier version.

(The fields are unused for now, to be enabled in a later commit.)
2021-12-07 09:35:43 +01:00
Steven Barclay
998a0e0aaf
Further Equihash optimisation: partial parallelisation
Run the initial XorTable fillup in 'Equihash::computeAllHashes' in
parallel, using a parallel stream, to get an easy speed up. (The solver
spends about half its time computing BLAKE2b hashes before iteratively
building tables of partial collisions using 'Equihash::findCollisions'.)

As part of this, replace the use of 'java.nio.ByteBuffer' array wrapping
in 'Utilities::(bytesToIntsBE|intsToBytesBE)' with manual for-loops, as
profiling reveals an unexpected bottleneck in the former when used in a
multithreaded setting. (Lock contention somewhere in unsafe code?)
2021-12-07 09:35:43 +01:00
Steven Barclay
0a603167f1
Further Equihash optimisation: avoid lambda+stream in tight loop
Manually iterate over colliding table rows using a while- loop and a
custom 'PrimitiveIterator.OfInt' implementation, instead of a foreach
lambda called on an IntStream, in 'Equihash::findCollisions'. Profiling
shows that this results in a slight speedup.
2021-12-07 09:35:42 +01:00
Steven Barclay
3130d9329c
Add Equihash.IntListMultimap (private) class for speedup
Provide a (vastly cut down) drop-in replacement for the Guava multimap
instance 'indexMultimap', of type 'ListMultimap<Integer, Integer>', used
to map table row indices to block values, to detect collisions at a
given block position (that is, in a given table column).

The replacement stores (multi-)mappings from ints to ints in a flat int-
array, only spilling over to a ListMultimap if there are more than 4
values added for a given key. This vastly reduces the amount of boxing
and memory usage when running 'Equihash::findCollisions' to build up the
next table as part of Wagner's algorithm.
2021-12-07 09:35:42 +01:00
Steven Barclay
95637e0fa0
Add Equihash implementation for use in ASIC-resistant PoW
Implement the Equihash (https://eprint.iacr.org/2015/946.pdf) algorithm
for solving/verifying memory-hard client-puzzles/proof-of-work problems
for ASIC-resistant DoS attack protection. The scheme is asymmetric, so
that even though solving a puzzle is slow and memory-intensive, needing
100's of kB to MB's of memory, the solution verification is instant.

Instead of a single 64-bit counter/nonce, as in the case of Hashcash,
Equihash solutions are larger objects ranging from 10's of bytes to a
few kB, depending on the puzzle parameters used. These need to be
stored in entirety, in the proof-of-work field of each offer payload.

Include logic for fine-grained difficulty control in Equihash with a
double-precision floating point number. This is based on lexicographic
comparison with a target hash, like in Bitcoin, instead of just
counting the number of leading zeros of a hash.

The code is unused at present. Also add some simple unit tests.
2021-12-07 09:35:42 +01:00
Steven Barclay
484afbc522
Code cleanup: replace (Bi)Function<..,Boolean> with (Bi)Predicate<..>
Replace 'BiFunction<T, U, Boolean>' with the primitive specialisation
'BiPredicate<T, U>' in HashCashService & FilterManager.

As part of this, replace similar predicate constructs found elsewhere.
NOTE: This touches the DAO packages (trivially @ VoteResultService).
2021-12-07 09:35:41 +01:00
Steven Barclay
b3f7cb5c76
Code cleanup: remove unused PoW class & test
Remove (possible draft) 'ProofOfWorkService(Test)', which is a near
duplicate of the class 'HashCashService' but is currently unused.
2021-12-07 09:35:41 +01:00