Commit Graph

17394 Commits

Author SHA1 Message Date
Steven Barclay
ade339349c
Clean up BurningManAccountingService: deduplicate code
Factor out duplicated logic in the 'Stream.map' lambdas to compute the
BSQ value of the BTC of each streamed ReceivedBtcBalanceEntry, returned
as an 'Optional<Long>'. Also simplify the logic slightly and return an
OptionalLong instead for greater efficiency.

(Also replace a statement lambda with an expression lambda.)
2023-05-10 19:41:26 +01:00
Steven Barclay
e287177e49
Speed up burn target calculations in burning man view
Optimise 'BurningManPresentationService.getCandidateBurnTarget' to avoid
the repeated computation of the total accumulated decayed burned amount
for every listed burning man. To this end, cache the total in a nullable
Long field, along with the method 'getAccumulatedDecayedBurnedAmount()'
to lazily initialise it. (This eliminates a minor hotspot in the burning
man view revealed by JProfiler.)
2023-05-10 19:41:25 +01:00
Steven Barclay
9ce9ffc694
Use TemporalAdjusterModel cache to speed up BSQ supply view
Use the previously added 'ChartDataModel.toCachedTimeIntervalFn' to
additionally speed up some of the charts in the BSQ supply view, in
particular the trade fees & total burned BSQ, via the DaoChartDataModel
methods 'getBsqTradeFeeByInterval' & 'getTotalBurnedByInterval'. (The
other changes in the BSQ supply, such as proofs of burn or issuance, are
too infrequent to benefit from the LocalDate caching.)

For this to work, the filtered BSQ txs must be streamed in chronological
order, so provide local methods 'get[Burnt|Trade]FeeTxStream()', to use
in place of the DaoStateService methods 'get[Burnt|Trade]FeeTxs()',
which return unordered HashSets.
2023-05-10 19:41:25 +01:00
Steven Barclay
f3fd555ced
Add caches to TemporalAdjusterModel to speed up BSQ dashboard view
Now that the trade statistics are retrieved in chronological order,
optimise the per-interval BSQ & USD price and volume calculations in
PriceChartDataModel & VolumeChartDataModel, by adding caches to avoid
relatively expensive timezone calculations in TemporalAdjusterModel,
similarly to the cache added for 'ChartCalculations.roundToTick' (as
profiling shows 'TemporalAdjusterModel.toTimeInteval' is a hotspot).

Add a cache to speed up Instant -> LocalDate mappings by storing the
unix time (Instant) range of the last seen day (LocalDate) in a tuple,
then just returning that day if the next Instant falls in range. Also
add a cache of the last temporal adjustment (start of month, week, etc.)
of that day. In this way, successive calls to 'toTimeInteval(Instant)'
with input times on the same day are sped up.

Since TemporalAdjusterModel is used by multiple threads simultaneously,
store the caches in instance fields and add a 'withCache' method which
clones the model and enables the caching, since otherwise the separate
threads keep invalidating one another's caches, making it slower than it
would be without them. (We could use ThreadLocals, but profiling
suggests they are too heavyweight to be very useful here, so instead use
unsynchronised caching with nonfinal fields and benign data races.)

Provide the method 'ChartDataModel.toCachedTimeIntervalFn' which returns
a method reference to a cloned & cache-enabled TemporalAdjustedModel, to
use in place of the delegate method 'ChartDataModel.toTimeInterval' when
the caching is beneficial.
2023-05-10 19:41:25 +01:00
Steven Barclay
964321a1e1
Use parallelStream to speed up fillTradeCurrencies
As profiling shows a hotspot mapping the set of trade statistics to a
list of currencies to pass to 'CurrencyList.updateWithCurrencies',
attempt to speed this up with a parallel stream. For this to work
correctly, take care to use the backing set (with unmodifiable wrapper)
in place of 'tradeStatisticsManager.getObservableTradeStatisticsSet()',
as ObservableSetWrapper doesn't delegate calls to its spliterator.
2023-05-10 19:41:24 +01:00
Steven Barclay
6e330e4a14
Speed up SortedList creation in TradesChartsView.fillList
Reduce a hotspot sorting the trade statistics table, triggered by the
'sortedList.bind(comparatorProperty)' call upon completion of the
'fillList' future. Profiling shows that repeated invocation of the cell
value factory over the entries of the sorted column is a bottleneck, so
speed this up by caching the returned cell value (given by calling
'new ReadOnlyObjectWrapper<>(listItem)') as an instance field of
TradeStatistics3ListItem.

As a further significant optimisation, stream the trade statistics in
reverse chronological order, when collecting into a list wrapped by
SortedList, as this matches the default display order, reducing the
number of comparisons done by SortedList's internal mergesort to O(n).
2023-05-10 19:41:24 +01:00
Steven Barclay
a489697a54
Speed up candle data creation in getUpdateChartResult
Optimise (further) the ChartCalculations methods 'getItemsPerInterval' &
'getCandleData' by replacing HashSets in the former with sorted sets,
which avoids relatively expensive calls to 'TradeStatistics3.hashCode'
and needless subsequent re-sorting by date in 'getCandleData'. (Forming
the trade statistics into an ImmutableSortedSet, OTOH, is cheap since
they are already encountered in chronological order.)

Further optimise the latter by using a primitive array sort of the trade
prices to calculate their median, instead of needlessly boxing them and
using 'Collections.sort'.
2023-05-10 19:41:23 +01:00
Steven Barclay
0f52b65daa
Further speedups to getUsdAveragePriceMapsPerTickUnit
Avoid calculating average prices for ticks that won't ever be part of a
visible chart candle, as only the last 90 ticks can fit on the chart. To
this end, stream the trade statistics in reverse chronological order
(which requires passing them as a NavigableSet), so that once more than
MAX_TICKS ticks have been encountered for a given tick unit, the
relevant map (and all lower granularity maps) can stop being filled up.

Also add a 'PriceAccumulator' static class to save time and memory when
filling up the intermediate maps, by avoiding the addition of each trade
statistics object to (multiple) temporary lists prior to average price
calculation.
2023-05-10 19:41:23 +01:00
Steven Barclay
372f92d7aa
Add cache to speed up ChartCalculations.roundToTick
Now that the trade statistics are encountered in chronological order,
speed up 'roundToTick(LocalDateTime, TickUnit)' by caching the last
calculated LocalDateTime -> Date mapping from the tick start (with one
cache entry per tick unit), as multiple successive trades will tend to
have the same tick start.

This avoids a relatively expensive '.atZone(..).toInstant()' call, which
was slowing down 'ChartCalculations.getUsdAveragePriceMapsPerTickUnit',
as it uses 'roundToTick' in a tight loop (#trades * #tick-units calls).

Also unqualify 'TradesChartsViewModel.TickUnit' references for brevity.
2023-05-10 19:41:22 +01:00
Steven Barclay
914d75682c
Cache enum.values() in ChartCalculations & TradeStatistics3
Cache enum arrays 'TickUnit.values()' & 'PaymentMethodWrapper.values()'
as the JVM makes defensive copies of them every time they are returned,
and they are both being used in tight loops. In particular, profiling
suggests this will make 'TradeStatistics3.isValid' about twice as fast.
2023-05-10 19:41:22 +01:00
Steven Barclay
835593f2c9
Fix broken test in TradesChartsViewModelTest that passed accidentally
The test was erroneously passing a candle tick start time (as a long) to
'ChartCalculations.getCandleData', which expects a tick index from 0 to
MAX_TICKS + 1 (91) inclusive. Since this is out of range, the method
skipped an 'itemsPerInterval' map lookup which would have thrown an NPE
prior to the last commit. Fix the test by making 'itemsPerInterval'
nonempty and passing 0 as the tick index. Also check the now correctly
populated 'date' field in the returned candle data.

Additionally, tidy up the class a little and avoid an unnecessary temp
directory creation.
2023-05-10 19:41:22 +01:00
Steven Barclay
47776b3836
Speed up ChartCalculations.getItemsPerInterval & return as List
Avoid scanning all the ticks backwards from 90 to 1 repeatedly, to find
the one with the correct date interval for each item in the
'tradeStatisticsByCurrency' list. Instead, for each item, remember the
last found tick index and move forwards if necessary, then scan
backwards from that point to find the correct tick. As the trade
statistics are now in chronological order, this is much faster (though
it will still work correctly regardless of the order of the list items).

Also, hold 'itemsPerInterval' as a 'List<Pair<..>>' instead of a
'Map<Long, Pair<..>>', since the keys are just tick indices from 0 to 91
inclusive, so it is cleaner and more efficient to use an array than a
hash table.
2023-05-10 19:41:21 +01:00
Steven Barclay
5846095b6b
Minor cleanup of ChartCalculations & TradesChartsView
1) Change statement lambdas to expression lambdas;
2) Replace 'Map.putIfAbsent' then 'Map.get' with 'Map.computeIfAbsent';
3) Add missing @VisibleForTesting annotation or make private.
2023-05-10 19:41:21 +01:00
Steven Barclay
0ba2e491ca
Fix quadratic time bug in AveragePriceUtil.getUSDAverage
Now that the trade statistics are retrieved as a sorted set, it can be
assumed that the USD & BSQ trade lists passed to 'getUSDAverage' are
already sorted. Use this to avoid repeatedly scanning the USD trade list
for the first trade dated after each given BSQ trade, by moving two
cursors in a single pass across the respective lists simultaneously.
2023-05-10 19:41:20 +01:00
Steven Barclay
b417e36a28
Make TradeStatistics3 comparable & hold in a TreeSet
Make TradeStatistics3 implement the previously added ComparableExt
interface and make TradeStatisticsManager hold them as a TreeSet instead
of a HashSet, to support fast retrieval of statistics in any given date
range. (Even though red-black trees are generally slower than hash
tables, this should not matter here since the set is only being iterated
over and infrequently appended, and does not benefit from O(1) lookups/
additions/removals.)

Add a 'TradeStatisticsManager.getNavigableTradeStatisticsSet' accessor,
which returns the backing TreeSet of the current ObservableSet field, so
that callers can access its NavigableSet interface where needed (as
there is no ObservableSortedSet or similar in JavaFX). Use this to
optimise 'AveragePriceUtil.getAveragePriceTuple',
'DisputeAgentSelection.getLeastUsedDisputeAgent' and
'MutableOfferDataModel.getSuggestedSecurityDeposit', to obtain a narrow
date range of trade statistics without streaming over the entire set.

Additionally optimise & simplify the price collation in
'TradeStatisticsManager.onAllServicesInitialised', by exploiting the
fact that the statistics are now sorted in order of date (which is the
presently defined natural order).
2023-05-10 19:41:20 +01:00
Steven Barclay
1f8538f6c1
Add utilities for SortedSet ranging with mapped keys & predicates
Provide a 'RangeUtils' class for computing subsets of a navigable set
with natural element order, with each bound defined by a mathematical
filter (that is, a predicate specifying whether an element is 'big' -
true, or 'small' - false), instead of a specific element. This allows
the subset of all elements which map into a given range to be computed,
provided the mapping function is (strictly or non-strictly) increasing.
Provide a fluent interface for this in RangeUtils (with unit tests).

To support this, provide a Comparable sub-interface, 'ComparableExt', of
elements which may be compared with marks/delimiters instead of just
elements of the same type, to work round the limitation that sorted (&
navigable) Sets/Maps in Java do not support general binary searching
with a filter (predicate) on the keys instead of just a specific key.

This will make it possible to efficiently take subsets of objects within
a given date range, say, without having to scan the entire set, provided
it is sorted (w.r.t. a suitable natural order).
2023-05-10 19:41:19 +01:00
Steven Barclay
e231c64cc2
Use primitive arrays & streams to optimise InlierUtil
Use a DoubleStream when streaming over 'List<Double>' method arguments
in InlierUtil, as well as a primitive array sort in 'InlierUtil.trim'
(followed by taking a sublist view), instead of calling 'Stream.sorted'.

To this end, use Guava 'Doubles.asList' to pass lists of Doubles to/from
the InlierUtil methods without incurring any boxing or unboxing costs,
since their spliterators can be simply downcast to Spliterator.OfDouble
(opportunistically), instead of needing to use 'mapToDouble' to unbox.

This was a minor hotspot when called from AveragePriceUtil (used by the
burning man and BSQ dashboard views).
2023-05-10 19:41:19 +01:00
Steven Barclay
069b20ae5f
Use correct bounds in AveragePriceUtil.removeOutliers
Use nonstrict bounds when filtering outliers from the provided trade
statistics list, since otherwise it will always remove the outermost two
inliers from the list. This is because the dependent call to
'InlierUtil.findInlierRange' returns the min & max inlier values.
2023-05-10 19:41:19 +01:00
Steven Barclay
277b170e3c
Further speedups of TradeStatistics3.isValid
Use a Map to speed up 'PaymentMethod.getPaymentMethod', called from
'isValid', instead of scanning the payment method list every invocation.
Make the list immutable to ensure the map never goes stale, which is OK
since no code modified it outside PaymentMethod's static initialisation.

Also speed up the global accessor 'TradeLimits.getMaxTradeLimit', by
caching the DAO param value in a volatile field, cleared upon each new
block arrival.

Furthermore, speed up 'TradeLimits.getFirstMonthRiskBasedTradeLimit' by
simplifying the rounding logic to avoid a pass through the (rather slow)
BigDecimal type.
2023-05-10 19:41:18 +01:00
Steven Barclay
4bc1d299e5
Avoid exception to speed up TradeStatistics3.isValid
Short circuit the exception control flow used in the method
'TradeStatistics3.getPaymentMethodId', which occurs whenever the payment
method code is stored directly in the 'paymentMethod' field instead of
first being converted into a numeric string. This occurs if the method
is unrecognised as it is not in listed into 'PaymentMethodWrapper' enum.

This fixes an unnecessary slowdown of 'TradeStatistics3.isValid', which
calls the above, when scanning the list of BSQ trade statistics in
AveragePriceUtil and elsewhere, due to the fact that the 'BSQ_SWAP'
payment method has been missed out of the above enum.

Also add a (presently disabled) unit test to prevent any future payment
methods from being missed out of the enum. (Should fix the missing BSQ
swaps issue in a separate PR to make sure that the seed nodes recognise
the new payment method code before anyone else.)
2023-05-10 19:40:19 +01:00
Alejandro García
b90776989b
Merge pull request #6619 from napoly/upgrade_junit4_to_junit5_jupiter
Replacing JUnit4 with JUnit5 Jupiter
2023-05-07 16:57:57 +00:00
napoly
e19ffe2308
Upgrade JUnit4 to JUnit5 Jupiter 2023-05-04 20:04:49 +02:00
Alejandro García
d17749110a
Merge pull request #6670 from jmacxx/trade_fee_leniency
Allow leniency of 50% when validating trade fees.
2023-05-04 05:59:13 +00:00
Alejandro García
0e22b1c6d7
Merge pull request #6674 from HenrikJannsen/fix-accounting-filter-for-large-fees
Increase fee limit for accounting data filter.
2023-05-03 14:24:56 +00:00
HenrikJannsen
35f69232fd
Increase fee limit for accounting data filter.
Signed-off-by: HenrikJannsen <boilingfrog@gmx.com>
2023-05-02 09:59:23 +07:00
jmacxx
8c05af1f0a
Allow leniency of 50% when validating trade fees. Issue #6669. 2023-04-30 14:04:03 -05:00
Christoph Atteneder
c8c256f958
Merge pull request #6666 from stejbac/fix-npe-from-burningmanview-comparators
Fix NPE from BurningManView column comparators
2023-04-24 11:01:56 +02:00
Steven Barclay
01de88b163
Slight code cleanup: BurningManView & BalanceEntryItem
1) Replace statement lambda with expression lambda;
2) Use '.iterator().next()' instead of 'new ArrayList<>(_).get(0)'.
2023-04-22 00:41:12 +01:00
Steven Barclay
c353a95cd9
Use primitive 'comparing*' comparators to avoid boxing
Replace uses of 'Comparator.comparing' with 'comparing[Double|Int|Long]'
in BurningManView, as appropriate, since it is slightly more efficient.
2023-04-22 00:29:13 +01:00
Steven Barclay
8e8d727231
Fix NPE from BurningManView column comparators
Make sure that none of the key extractor functions passed to
'Comparator.comparing(fn)' can return null, as this results in an NPE
when the corresponding column is sorted in the UI, but has blank entries
(such as the BTC received for a BSQ burn in the balance entries table).

(Make blanks appear smallest in magnitude using 'Comparator.nullsFirst'
or by defaulting to 0 instead of null, since the entries are initially
sorted biggest to smallest, pushing them to the bottom of the table.)

Also change the default sort type of the burned BSQ column, which should
be ASCENDING since the entries are negative.
2023-04-21 23:59:37 +01:00
Alejandro García
23dae954e7
Merge pull request #6662 from wiz/wiz/20230419-update-wiz-bitcoin-nodes
Update clearnet IPs for wiz's Bitcoin nodes
2023-04-21 10:24:58 +00:00
Alejandro García
1fe05c0fb9
Merge pull request #6656 from bisq-network/dependabot/github_actions/actions/checkout-3.5.2
Bump actions/checkout from 3.5.0 to 3.5.2
2023-04-21 10:22:40 +00:00
Alejandro García
6e65b2ba63
Merge pull request #6655 from bisq-network/dependabot/github_actions/gradle/gradle-build-action-2.4.2
Bump gradle/gradle-build-action from 2.4.0 to 2.4.2
2023-04-21 10:14:11 +00:00
wiz
4df4c4bc3a
Update clearnet IPs for wiz's Bitcoin nodes 2023-04-19 17:21:13 +09:00
dependabot[bot]
129944f59a
Bump actions/checkout from 3.5.0 to 3.5.2
Bumps [actions/checkout](https://github.com/actions/checkout) from 3.5.0 to 3.5.2.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3.5.0...v3.5.2)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-17 14:58:53 +00:00
dependabot[bot]
7d5d345367
Bump gradle/gradle-build-action from 2.4.0 to 2.4.2
Bumps [gradle/gradle-build-action](https://github.com/gradle/gradle-build-action) from 2.4.0 to 2.4.2.
- [Release notes](https://github.com/gradle/gradle-build-action/releases)
- [Commits](https://github.com/gradle/gradle-build-action/compare/v2.4.0...v2.4.2)

---
updated-dependencies:
- dependency-name: gradle/gradle-build-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-17 14:58:50 +00:00
Gabriel Bernard
caab3dbe55
Merge pull request #6649 from bisq-network/release/v1.9.10
Release/v1.9.10
2023-04-17 08:15:12 +00:00
Alejandro García
3f584e32fe
Merge pull request #6652 from alvasw/remove_broken_offer_util_test_test_get_random_offer_id
OfferUtilTest: Remove broken testGetRandomOfferId test
2023-04-17 07:30:18 +00:00
Alva Swanson
d969d497bb
OfferUtilTest: Remove broken testGetRandomOfferId test 2023-04-17 17:00:29 +10:00
Alejandro García
bfad06caae
Merge pull request #6647 from HenrikJannsen/show_total_distributed_btc_fees
Show total fees and total DPT
2023-04-15 02:32:21 +00:00
Alejandro García
e8a3d92d34
Merge pull request #6646 from helixx87/api-get-all
Support "all" attribute in getoffers API method
2023-04-15 02:31:02 +00:00
Alejandro García
28bb0a60fc
Merge pull request #6641 from helixx87/6629-fix-close-button-after-offer-creation
Fix close button behaviour on successful offer creation popup
2023-04-15 02:28:41 +00:00
Alejandro García
0391be64a5
Revert to SNAPSHOT version 2023-04-15 11:59:46 +10:00
HenrikJannsen
1416b946a8
Add fields for total BTC fees and total DPT amounts
Add more data to CSV export

Signed-off-by: HenrikJannsen <boilingfrog@gmx.com>
2023-04-12 16:17:44 +07:00
helixx87
458f50dec9
Support "all" attribute in getoffers API method 2023-04-11 12:50:00 +02:00
Alejandro García
e84dc6bb13
Merge pull request #6643 from alejandrogarcia83/update-data-stores-for-v1.9.10
Update data stores for v1.9.10
2023-04-11 02:12:19 +00:00
sqrrm
8b9619f4b7
Merge pull request #6644 from HenrikJannsen/make_processing_burningman_accounting_data_optional
Make processing burningman accounting data optional
2023-04-10 16:21:36 +02:00
HenrikJannsen
795964f06b
Add info if burningman accounting data processing is disabled or if it is in progress.
We use a postfix to the header title and not a busy animation, as the busy animation is quite CPU intense.

Signed-off-by: HenrikJannsen <boilingfrog@gmx.com>
2023-04-10 16:01:13 +07:00
HenrikJannsen
25fa962e5e
Enable processing of accounting data only if option in preferences is set.
Signed-off-by: HenrikJannsen <boilingfrog@gmx.com>
2023-04-10 14:52:45 +07:00
HenrikJannsen
cec05e13f9
Add toggle to PreferencesView
Add popup when selecting a burningman to ask for enabling processing

Signed-off-by: HenrikJannsen <boilingfrog@gmx.com>
2023-04-10 14:49:47 +07:00