Commit Graph

97 Commits

Author SHA1 Message Date
ghubstan
9b62a005df
Refactor takeoffer reply proto & ErrorMessageHandler
- Add description msg TakeOfferReply proto, and fromProto method
  to core.offer.enum AvailabilityResult.  The description field
  maps a client usable error message to the enum.

- Adjust GrpcErrorMessageHandler to add AvailabilityResult.description()
  to takeoffer reply.

- Refactor (split up) GrpcClient's takeOffer.  Add getTakeOfferReply()
  to give clients a chance to make choices based on the reply's
  AvailabilityResult when the takeoffer command did not result in a
  trade. (Some errors are fatal, some not.)
2021-03-19 19:38:03 +01:00
ghubstan
c58366090f
Derive AvailabilityResult from Task errorMessage 2021-03-19 19:37:41 +01:00
ghubstan
14215a1fbd
Adjust grpc & core services to new takeoffer error handling
- GrpcErrorMessageHandler  A new ErrorMessageHandler implementation
  to get around the api specific problem of having to use Task
  ErrorMessageHandlers that build task error messages for the UI.

- GrpcExceptionHandler  A new method for working with the
  ErrorMessageHandler interface.

- GrpcTradesService, CoreApi, CoreTradesService:  Ajdusted takeoffer
  error handling to give a failure reason provided by the new
  GrpcErrorMessageHandler.
2021-03-19 19:37:10 +01:00
ghubstan
3f84246f59
Improve interceptor's rate metering key definition and lookup
This change replaces the hard coded strings used as keys in
interceptor rate-metering lookup maps.

Now, the fullMethodName defined in each bisq.proto.grpc.* class'
io.grpc.MethodDescriptor is used, not a hard coded String.

For example, the rate metering lookup key for 'GetBalances',
in 'GrpcWalletsService', is the

   fullMethodName = SERVICE_NAME + '/' + "GetBalances",

   where SERVICE_NAME = "io.bisq.protobuffer.Wallets".

Also adjusted affected tests, and tidy'd up interceptor logging.
2021-02-28 17:10:51 -03:00
ghubstan
6b2c386a7c
Fix call rate metering interceptor bug
The gRPC interceptor was not using the correct method/ratemeter
map key, and failing to find a rate meter for the server call.

- Fix the rate meter key lookup bug.

- Disable most strict, default call rate meters in tests.
  Made an adjustment to the test harness' scaffold setup so an interceptor
  testing or disabling config file is always picked up by bob and alice
  daemons.

- Set arbitration daemon's registerDisputeAgent rate @ 10/second, so
  it does not interfere with the test harness.  (There is no pre-existing
  arb node appDataDir before that daemon starts.)

Note:  The test harness cannot install the custom rate metering file in
an arb daemon's appDataDir before it starts because there is no dao-setup
file for that node type.

TODO:  Adjust api simulation scripts to interceptor bug fix.
2021-02-27 21:47:52 -03:00
ghubstan
f90d2cee57
Fix test bug 2021-02-27 18:24:57 -03:00
ghubstan
320e63c0a1
Log 'trade not found' a warning instead of full stack trace 2021-02-27 17:25:49 -03:00
ghubstan
e5a0a3998d
Permit some gRPC excptions to be logged only as warning
A new handleExceptionAsWarning method logs warn(ex.msg) instead of
the full stack trace.
2021-02-27 17:14:22 -03:00
ghubstan
e5291e9f45
Use the logger of the gRPC service throwing an exception 2021-02-27 17:09:54 -03:00
ghubstan
1154085632
Add api method 'stop'
This change gives CLI users a 'stop' command to shutdown a daemon.

- Server side gRPC boilerpate was added to :proto and :daemon.

- When the new GrpcShutdownService accepts a 'stop' request from the CLI,
  it calls UserThread.runAfter(BisqHeadlessApp.getShutDownHandler(), 500, MILLISECONDS);

- Method help file 'stop-help.txt' was added to :core.

- Client side gRPC boiler plate and 'stop' implementation was added to :cli.
2021-02-18 11:54:10 -03:00
ghubstan
c99624015b
Factor out repeated 'new CallRateMeteringInterceptor' calls
Move this into a static CallRateMeteringInterceptor.valueOf(Map) method.
2021-01-25 14:38:53 -03:00
ghubstan
4eed44d350
Define gRPC api call rate constraints
The general rule is limit calls that change p2p data to 1/minute,
others to 1/second.  An exception is made to set/remove wallet password
methods (1/5s), due to the latency of writing wallet changes to disk.

This change may affect api testing in the future.  If that happens,
further changes to the call rate metering interceptor may be made to loosen
the constraints when running in regtest/dev mode.
2021-01-22 13:45:12 -03:00
ghubstan
d18b2d5a10
Run an async price feed request when CLI needs market price
The CLI was receiving stale, cached market prices from the feed service.
2021-01-20 17:46:35 -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
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
ghubstan
0c6005ed2d
Stub out support for OpenOffer's triggerPrice in api
This is a feature that will not be included in api v1, but partial
support is added in this change to the server.  CLI will pass a
default triggerPrice of 0 (unused) with the createoffer command.

When fully implemented, an optional trigger-price param will be
added to the CLI's createoffer method, and the value will only be
visible to offer owners.  New enableoffer and disableoffer
methods will also need to be added.
2021-01-11 14:36:51 -03:00
ghubstan
18de222d38
Add new api methods 'getmyoffers' and 'getmyoffer'
Similar to 'getoffers' and 'getoffer', but filters out offers not
created by the user.  The new methods are so similar some offer list
filtering and sorting was refactored in CoreOffersService.

Also fixed some createoffer apitest cases in anticipation of a new OfferFilter,
which will filter out offers not matching any user payment account.
2021-01-04 21:43:34 -03:00
ghubstan
10727fc083
Fix GrpcCallRateMeter method and variable name
- Change method isAllowed() -> checkAndIncrement().

- Change variable allowedCallsPerTimeUnit -> allowedCallsPerTimeWindow.
2020-12-23 11:30:16 -03:00
ghubstan
63564760a8
Support more fine grained rate metering
We need to be able to define call rate meters for time spans not limited
to TimeUnit intervals of 1 SECOND, 1 HOUR, or 1 DAY.  This change allows
more flexibility, e.g., 10 per 5 seconds, 10 per 5 hrs, 100 per 7 days.
2020-12-22 21:11:04 -03:00
ghubstan
c8ef4141e3
Fix comment 2020-12-22 18:33:18 -03:00
ghubstan
0d4ed952e7
Remove redundant callCount field
The size of the timestamp queue is the call count
2020-12-22 17:00:01 -03:00
ghubstan
d61521276f
Remove unused local var 2020-12-22 16:30:37 -03:00
ghubstan
01546ad11d
Use a simpler, time windowing call rate meter
Rewrote the GrpcCallRateMeter class and adjusted afected classes.

These changes were requested in PR review
https://github.com/bisq-network/bisq/pull/4966#pullrequestreview-557040093
2020-12-22 16:14:49 -03:00
ghubstan
87f75ee10c
Configure GrpcVersionService's rate metering interceptor
This change demonstrates how a method call rate metering interceptor
is configured for a gRPC service.  GrpcVersionService uses a custom
rate metering interceptor, or none.  A commented out, 'default'
interceptor is defined as a usage example.
2020-12-19 16:41:26 -03:00
ghubstan
ea97a801e5
Don't cancel gRPC call if an interceptor does not meter all methods 2020-12-19 16:31:41 -03:00
ghubstan
9f679deb08
Add license note and toString method 2020-12-19 15:47:20 -03:00
ghubstan
830a5f009a
Add license note 2020-12-19 15:43:44 -03:00
ghubstan
455ed67f9b
Add GrpcServiceRateMeteringConfigTest 2020-12-19 15:41:55 -03:00
ghubstan
b307593c82
Make CallRateMeteringInterceptor configurable via json
This adds a GrpcServiceRateMeteringConfig class that can read and
write rate metering interceptor config files, and configure
a gRPC rate metering service interceptor at startup.

This seems excessive, but we need to be able to test and tune
method rate metering without having to change hard coded, default
interceptor rate meters.
2020-12-19 15:32:40 -03:00
ghubstan
a5ed17e43f
Add license comment, stop & toString methods, and make isRunning transient 2020-12-19 13:14:06 -03:00
ghubstan
89e2187878
Change long to int, tidy up error msg 2020-12-17 14:12:04 -03:00
ghubstan
2148a4d958
Prevent excessive api calls
This change provides a gRPC CallRateMeteringInterceptor to help protect
the server and network against being overloaded by CLI scripting mistakes.

An interceptor instance can be configured on a gRPC service to set
individual method call rate limits on one or more of the the service's
methods. For example, the GrpcOffersService could be configured with
this interceptor to set the createoffer rate limit to 5/hour, and
the takeoffer call rate limit could be set to 20/day.  Whenever a
call rate limit is exceeded, the gRPC call is aborted and the client
recieves a "rate limit exceeded" error.

Below is a simple example showing how to set rate limits for one method
in GrpcVersionService.

    final ServerInterceptor[] interceptors() {
        return new ServerInterceptor[]{
                new CallRateMeteringInterceptor(new HashMap<>() {{
                    put("getVersion", new GrpcCallRateMeter(2, SECONDS));
                }})
        };
    }

It specifies a CLI can execute getversion 2 times / second.

This is not a throttling mechansim, there is no blocking nor locking
to slow call rates.  When call rates are exceeded, calls are
simply aborted.
2020-12-17 12:33:45 -03:00
ghubstan
fa9ffa1fb2
Put arguments on separate lines 2020-12-16 15:35:12 -03:00
ghubstan
2572e8641d
Create grpc interceptor pkg, move auth interceptor into it 2020-12-16 15:30:40 -03:00
ghubstan
f7c1103848
Rename gRPC exception handler class 2020-12-16 14:42:23 -03:00
ghubstan
c60605f75c
Fix class level comment 2020-12-16 14:26:12 -03:00
ghubstan
e6c6d3b8d3
Add new CoreApiExceptionHandler to gRPC services
This change reduces gRPC service error handling duplication by moving
it into a @Singleton encapsulating everything needed to wrap
an expected or unexpected core api exception into a gRPC
StatusRuntimeException before sending it to the client.  It also
fixes some boilerpate classes were gRPC error handling was missing.
2020-12-16 13:34:21 -03:00
ghubstan
5522d0c53e
Add new api method gettransaction
This change was prompted by the recent changes in the main branch to
allow a tx memo field to be set from the UI and API.

This and the prior PR address the API's need to be able to fetch a
tx (with a memo).  The API can now get a completed trade's withdrawal
txid and pass it as a gettransaction parameter.

See previous PR "Append nullable withdrawalTxId field to Trade".

	https://github.com/bisq-network/bisq/pull/4937

A summary of changes by file:

grpc.proto

- Added withdrawalTxId field to existing TradeInfo proto & wrapper.
- Reordered fields in TradeInfo proto.
- Added new fields to be displayed by TxInfo proto in CLI.
- Fixed typo: unsetTxFeeRatePreference -> UnsetTxFeeRatePreference.
- Added new GetTransaction rpc.

GrpcWalletsService - Added new getTransaction gRPC boilerplate.

CoreWalletsService - Added new getTransaction implementation.

TxInfo - Added the new fields for displaying a tx summary from CLI.
This is not intended to be more than a brief summary;  a block explorer
or bitcoin-core client should be used to see the complete definition.

TradeInfo - Added the new withdrawalTxId field defined in grpc.proto.

CliMain - Added new 'case gettransaction'.

TransactionFormat - Formats a TxInfo sent from the server to CLI.

ColumnHeaderConstants - Added console headers used by TransactionFormat.

TradeFormat - Displays a completed trade's WithdrawalTxId if present.

Apitest - Adjusted affected tests: assert tx memo is persisted and
test gettransaction.
2020-12-14 15:01:03 -03:00
ghubstan
150e2f6851
Use Bisq's UserThread.executor in gRPC server 2020-12-11 18:33:19 -03:00
ghubstan
478c8f4eb2
Remove unused imports 2020-12-09 17:38:20 -03:00
ghubstan
bd66008062
Support tx memo field for btc withdrawals from api
- Added optional memo parameter to the api's sendbtc and
  withdrawfunds commands.

- Removed the @Nullable annotation was removed because protobuf
  does not support null.

- Visibility in two wallet check methods were changed from private
  to pkg protected so the CoreTradeService could use them.

- Adjusted affected tests.  (Asserting the memo field was set on a
  transaction cannot be checked from apitest yet.)
2020-12-09 16:51:56 -03:00
ghubstan
6c9f0c252d
Add new api method 'sendbtc' and test
Takes an address, amount, and optional txfeerate param,
returns a lightweight TxInfo proto.

Also overloaded two BtcWalletService methods to allow sendbtc
to pass in the tx fee rate -- overriding the fee service and
custom fee rate setting.
2020-12-08 21:12:02 -03:00
ghubstan
2842070afd
Merge branch 'master' into 03-add-txFeeRate-param 2020-12-08 19:04:27 -03:00
chimp1984
104b7edc99
Add memo field at withdraw to external wallet screen
Implements https://github.com/bisq-network/bisq/issues/4869
2020-12-07 12:32:56 -05:00
ghubstan
159d4cc6f5
Add optional txFeeRate parameter to api sendbsq
If present in the sendbsq command, the parameter will override the fee
service and custom fee rate setting for the BSQ transaction.

Also changed the sendbsq grpc return type to a lightweight TX proto wrapper.

Besides some small refactoring in the CLI, all the changes are
adjustments for this new sendbsq parameter and its new grpc return value.
2020-12-04 17:17:37 -03:00
ghubstan
987d89319e
Use ListenableFuture and callback when requesting tx fee
This change fixes the blocking problem in the fee rate request api.
Also redefined the TxFeeRateInfo.

- Redefined grpc.proto message TxFeeRateInfo, added
  lastFeeServiceRequestTs field. (CLI user may want to know
  TS of last fee request.)

- Adjusted TxFeeRateInfo proto wrapper.

- Adjusted CurrencyFormat and BtcTxFeeRateTest to new TxFeeRateInfo.

- Added @Getter annotation to FeeService.  (CLI user may want to know
  TS of last fee request).

- Pass resultHandler from GrpcWalletsService through CoreApi, to
  CoreWalletsService's tx fee rate api methods.
2020-12-01 21:10:47 -03:00
ghubstan
0b0f9f1120
Add gettxfeerate, settxfeerate, unsettxfeerate implementations 2020-11-26 18:36:15 -03:00
ghubstan
ff887eb339
Fix createpaymentacct validation problems
- Add missing boilerplate error handling to GrpcPaymentAccountsService.

- Edit some PaymentAccountForm & PaymentAccountTypeAdapter exception
  messages that would be passed to CLI;  they should be in the same
  style as existing CLI err msgs.
2020-11-19 13:38:34 -03:00
ghubstan
08228d07bc
Replace existing api method 'createpaymentacct' impl
In the CLI, this method now takes a single argument, the path to a json
file (a payment account form).  The json text is read from the file
and sent to the server, where it is serialized to a new PaymentAccount
instance, saved, and sent back to the CLI as a protobuf.PaymentAccount.

- Modified existing gRPC boilerplate in grpc.proto and GrpcPaymentAccountsService.

- Modified existing method signatures in CoreApi and CorePaymentAccountsService.

- Replaced existing method impl in CorePaymentAccountsService and
  removed dead code.

- Replaced the CLI's existing 'createpaymentacct' method impl.

- Modified existing tests.
2020-11-18 19:23:21 -03:00