Commit Graph

15582 Commits

Author SHA1 Message Date
Steven Barclay
e383edc38a
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-11-27 05:59:41 +00:00
Steven Barclay
e0595aa284
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-11-26 04:08:15 +00:00
Steven Barclay
0c94e232f8
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-11-25 17:17:45 +00:00
Steven Barclay
647fc862d4
Fix method name typo: redoProofOfWorkAndRepublish 2021-11-25 11:45:23 +00:00
Steven Barclay
cb7481d21f
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-11-25 11:10:02 +00:00
Steven Barclay
d8d8ec3f97
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-11-24 15:07:42 +00:00
Steven Barclay
52f4981f15
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-11-23 08:54:55 +00:00
Steven Barclay
6bb0f27807
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-11-23 07:57:07 +00:00
Steven Barclay
a5f5a55775
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-11-23 07:34:52 +00:00
Steven Barclay
c2b3a078ff
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-11-23 06:27:33 +00:00
Steven Barclay
5da8df266a
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-11-21 17:46:15 +00:00
Steven Barclay
53220499e7
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-11-21 17:10:40 +00:00
Christoph Atteneder
e50cd42478
Merge pull request #5849 from chimp1984/add-limit-to-tradestats
Add checks for trade statistics
2021-11-21 17:39:30 +01:00
Christoph Atteneder
bc124b3064
Merge pull request #5851 from cbeams/fix-guava
Fix guava dependency issue
2021-11-21 17:37:09 +01:00
Chris Beams
42b00b3a3e
Fix guava dependency issue
Problem: a

    NoSuchMethodError: 'java.util.stream.Collector
    com.google.common.collect.ImmutableMultiset.toImmutableMultiset()'

exception was being thrown when testing the previously-merged upgrade to
Gradle 7.3, as described at keybase://chat/bisq#testing/2466.

Solution: This problem is similar to the issue reported at
jeremylong/DependencyCheck#3221. The source of the problem was multiple
conflicting guava jars on the runtime classpath. This commit upgrades to
guava 30.1.1-jre which ensures a single jar on the classpath.
2021-11-21 17:06:10 +01:00
chimp1984
71e40ce1b7
Add check for trade statistic for max amount and if currency exists in CurrencyUtil 2021-11-20 23:04:25 +01:00
Christoph Atteneder
b5a43c7f95
Merge pull request #5840 from chimp1984/add-i2p-to-btc-core-networktypes
Add I2P as enum entry
2021-11-18 18:34:17 +01:00
chimp1984
e442283db4
Add I2P as enum entry 2021-11-18 18:00:06 +01:00
Christoph Atteneder
ef7ce109ac
Merge pull request #5834 from jmacxx/dispute_ui_add_penalty
Add penalty calculation to dispute agent UI
2021-11-18 17:57:54 +01:00
Bisq GitHub Admin
e52a821f34
Merge pull request #5838 from ripcurlx/fix-broken-test
Fix broken test for new build
2021-11-18 17:55:51 +01:00
Christoph Atteneder
c64e6f3298
Fix broken test for new build 2021-11-18 17:11:17 +01:00
jmacxx
5c00e1974e
Add penalty calc to dispute UI 2021-11-18 08:43:06 -06:00
Christoph Atteneder
4b6b1cdf11
Merge pull request #5839 from cbeams/add-jackson-pom-checksum
Add missing metadata for jackson-base pom 2.12.1
2021-11-18 15:03:47 +01:00
Chris Beams
ea629de1a1
Add missing metadata for jackson-base pom 2.12.1
Problem: When merging #5824, the absence of this entry caused a build
failure at dependency verification time against JDK11 and JDK15 on
Ubuntu-latest [1]. It may also cause failures on other JDK/OS
combinations, but the GitHub workflow was aborted before those failures
couldhave occurred. In any case, this omission did not create build
failures on any of the local development machines that tested the
aforementioned PR. Reasons for this discrepancy are unknown.

Solution: manually fetch the pom from [2], run `sha256sum` on it locally
and commit the result to the verification metadata file.

[1]: https://github.com/bisq-network/bisq/runs/4249640611?check_suite_focus=true#step:6:33
[2]: https://repo1.maven.org/maven2/com/fasterxml/jackson/jackson-base/2.11.1/jackson-base-2.11.1.pom
2021-11-18 12:38:01 +01:00
Christoph Atteneder
c05e7a09c0
Merge pull request #5824 from cbeams/gradle-7.3
Upgrade to Gradle 7.3
2021-11-18 09:32:04 +01:00
Christoph Atteneder
a27ac4313b
Merge pull request #5826 from chimp1984/improve-fee-handling
Improve fee handling
2021-11-18 09:23:15 +01:00
Christoph Atteneder
90ea4fc14a
Merge pull request #5813 from jmacxx/fix_locked_funds_display
Fix calculation & display of Locked Funds
2021-11-16 09:35:06 +01:00
Christoph Atteneder
7faaa9d5ba
Merge pull request #5831 from jmacxx/fix_display_failed_trade_tab
Fix display of missing Failed Trade tab
2021-11-16 09:31:10 +01:00
jmacxx
daee63490e
Fix display of missing failed trade tab 2021-11-15 11:10:16 -06:00
Chris Beams
cb7b0e8da4
Set pricenode mainClassName explicitly
Problem: after the upgrade from 6.6.1 to 7.3, the usual invocation of,
e.g. `./bisq-pricenode 2 2` started failing as reported by @emzy at [1].

    bisq@ubuntu-4gb-fsn1-1:~$ /bisq/bisq/bisq-pricenode 2
    Error: Could not find or load main class 2
    Caused by: java.lang.ClassNotFoundException: 2

Solution: for unknown reasons, the bisq-pricenode script worked as
expected under 6.6.1, i.e. contained the fq main class name in its
scripted invocation of `java -jar ...`, but under 7.3, this main class
name was missing. Through trial and error, it turns out that setting
`mainClassName` explicitly in the :pricenode subproject configuration
solves this problem and makes the start script work as expected.
Presumably, this problem arose in conjunction with the major version
upgrade of the spring boot Gradle plugin that was necessary when
upgrading to Gradle 7.3, but this has not been verified.

[1]: https://github.com/bisq-network/bisq/pull/5824#issuecomment-968276686
2021-11-15 13:44:44 +01:00
Christoph Atteneder
0ea056c6d2
Add Windows artifact hashes 2021-11-15 13:26:05 +01:00
chimp1984
f17c2e1234
Rename method 2021-11-15 13:05:40 +01:00
Chris Beams
280c2aaa8e
Adapt Gradle startScript customization logic
Problem: ClassNotFoundError was getting thrown when attempting to run,
e.g. the `./bisq-desktop` or `./bisq-pricenode` start scripts.

Solution: Gradle's posix start scripts were changed significantly
between 6.6.1 and 7.3, including a change to the way the current
directory is determined. This change updates the way we customize start
script generation to allow running them from the root of the repo. This
change only affects the unix / posix variants. The Windows .bat files do
not need to be adapted similarly.
2021-11-15 13:03:49 +01:00
Christoph Atteneder
83c9355931
Merge pull request #5825 from chimp1984/improve-offer-validation
Improve offer validation
2021-11-15 12:03:29 +01:00
chimp1984
b00d317e88
Rename getFeeHistorical to calculateFee 2021-11-14 15:07:34 +01:00
chimp1984
5928b44843
Use genesis height in maybeTestFeeFromFilter instead of 0 2021-11-14 15:07:34 +01:00
chimp1984
2e137459dc
Add check for fee from filter
That check is done if:
- If we are after activation time
- If filter is available
- If value in filter is > 0

The check compares the paid fee and the fee value from filter
and requires that paid fee is > 70% of filter value.
See comments in code for more background.
2021-11-14 15:07:34 +01:00
chimp1984
1027b9d7fe
Extract vars
Cleanups
2021-11-14 15:07:33 +01:00
chimp1984
c88addef16
Break up if else clauses (helps for improvements
in later commits)
2021-11-14 15:07:33 +01:00
chimp1984
b427795e4c
Extract minFeeParam
Cleanup
2021-11-14 15:07:33 +01:00
chimp1984
e57c682001
Add blockHeightAtOfferCreation to TxValidator
Used in case of maker fee validation
2021-11-14 15:07:33 +01:00
chimp1984
65285e2c69
Add filterManager to filterManager (will
be used in follow-up commits)
2021-11-14 15:07:33 +01:00
chimp1984
a082fd4a84
Add fee fields to filter 2021-11-14 15:07:32 +01:00
chimp1984
478b7568ee
Add return
Add more info in case it fails
2021-11-14 11:28:25 +01:00
chimp1984
f054c8ae95
Rename 2021-11-14 02:00:54 +01:00
chimp1984
65d3ef4ff5
Add check for isUseMarketBasedPrice 2021-11-14 02:00:00 +01:00
Chris Beams
d964ded2af
Add missing verification metadata
These entries showed up as missing when @jmacxx ran this PR branch on
his local Linux machine under JDK 11. It is not clear why these
dependencies were required there and not elsewhere, e.g. under CI or on
my own Mac.
2021-11-13 15:28:43 +01:00
Chris Beams
5e93cfea47
Add missing dependency verification entries
This fixes the CI build failure at
https://github.com/bisq-network/bisq/runs/4198811212?check_suite_focus=true#step:6:306
by adding missing entries for findbugs, jsr305 and various netty
artifacts. It is not clear why these artifacts were required under linux
and not under MacOS.
2021-11-13 14:56:49 +01:00
Chris Beams
1460914757
Organize dependency entries
As mentioned in a prior commit, the upgrade to Gradle 7.x results in
many more dependency declarations in the file, many of which are
effectively duplicates. This change does not attempt to eliminate those
duplications in any clever way, but rather just tidies up and organizes
all dependency declarations by sorting them alphabetically.
2021-11-13 14:45:14 +01:00
Chris Beams
d7129a2d19
Disable verification for javadoc and source jars
Prior to this commit, IDEA would fail to build the project because it
downloads javadoc and source jars that do not have entries in the
verification file. These artifacts are now trusted by default as
documented at https://docs.gradle.org/current/userguide/dependency_verification.html#sec:skipping-javadocs
2021-11-13 14:43:03 +01:00