Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor rpc server implementation #4199

Merged
merged 50 commits into from
Apr 29, 2020

Conversation

cbeams
Copy link
Contributor

@cbeams cbeams commented Apr 27, 2020

This PR implements a number of refactorings and a couple minor substantive changes that I've been meaning to get to since @chimp1984's original PoC in #3888.

The substantive changes include:

  • Removing the stopServer method (until a clear use case for it emerges)
  • Adding an --apiPort configuration option to avoid hardcoding the 9998 port

Otherwise these are pure refactorings that make the implementation of GrpcServer more idiomatic and hopefully easier to contribute to going forward, e.g. in the PR that will come together as part of #4198.

Note that this PR builds atop the commits in the as-yet unmerged PR #4189. The commits specific to this PR begin with 01580ae ("Remove StopServer rpc method"). In any case, PR #4189 should be merged before this one.

ghubstan and others added 30 commits April 22, 2020 18:16
 * Renamed CliCommand to RpcCommand, differentiating it from cmd
   string token(s)

 * Added new CliConfig, based on :common Config

 * Injected Config into CoreApi to make bisq.properties and cmd line
   args available to server

 * Added cleartext username:password BisqCallCredentials to :cli, and
   an AuthenticationInterceptor to :core (server)

 * Moved :daemon resources folder to expected location under src/main

 * Duplicated CompositeOptionSet, ConfigException and BisqException
   in :cli because they are not visible from :common.  (TODO refactor?)
   CompositeOptionSet will be used to let command line parameters
   override params set in config file.

 * Removed outdated references to :cli in a couple of comments in
   :common Config

 * gRPC parameters & command names are lowercase to mimic bitcoind/rpc

TBD

 * Decide what rpc auth param names to use, to differentiate them from
   bitcoind rpc user/passord param names
There is no need or benefit to injecting Config into CoreApi for the
purpose of accessing it indirectly through BisqGrpcServer.
Final fields should be favored wherever possible to advertise and
enforce immutability. Also as a matter of style, favor declaring fields
one per line instead of multiple on the same line. This style guideline
is not consistent throughout the codebase, but is favored because it
makes diffs / patches cleaner and is the more widely accepted style
througout most modern Java codebases.
There is actually no use case for both username and password forming the
authentication token. This change simplifies the arrangement such that a
single token is passed.

--rpcUser and --rpcPassword are no longer used and are replaced by
--apiToken on both cli and daemon sides.
When e.g. a given option is not recognized, print a clean error message
and exit 1 as opposed to printing a stack trace.
Fail fast if the specified command is unknown
To increase simplicity and make the implementation more
intention-revealing.
Strip double quotes from :cli --password arg before it is passed
to server.  Otherwise, a correct "password" will fail authentication.
The client was displaying
	Error: UNAUTHENTICATED: incorrect 'password' rpc header value
from the StatusRuntimeException message.

Strip "UNAUTHENTICATED: " from the exception message string before
printing it.
No need to strip quotes from password.  The problem was a bug
in my expect/tcl script's quote escape syntax.
Versus needing to manage calling custom shutdown method in all the right
places.
No StatusRuntimeException can be thrown from this code, so it is not
necessary to include in the try block.
cbeams and others added 20 commits April 26, 2020 20:30
 - Ensure script runs from root directory regardless of where it is
   invoked from

 - Touch up documentation and whitespace
Don't instruct the user to create a fresh data directory every time, as
this takes quite a bit longer to initialize the wallet than running
against the same data directory repeatedly. Just be clear that the
requirement is an unencrypted wallet with 0 BTC balance.
Stop attempting to align Option and Method description columns with one
another. It's a moving target as we add options and method names, and
this help output format will probably change in the future anyway.
This is a partial reversion of the earlier commit. Marking the password
option as required at the parser level made it impossible to run
./bisq-cli without options or arguments and get the help text. This is a
useful thing to do, and not worth creating a bad user experience to get
the free required option error handling and error messaging.
There is no actual requirement for this method, so removing it. It also
helps improve the implementation by removing the need for the static
'instance' field.
So they can easily access the enclosing BisqGrpcServer#coreApi field.
@cbeams
Copy link
Contributor Author

cbeams commented Apr 27, 2020

@ghubstan, please review the commits unique to this PR, thanks.

@cbeams cbeams requested a review from ghubstan April 27, 2020 18:08
@cbeams cbeams self-assigned this Apr 27, 2020
@ghubstan
Copy link
Contributor

uACK

I'll test this branch with a bats script after I port the expect script.

Copy link
Contributor

@ghubstan ghubstan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK

@cbeams cbeams merged commit 4277e62 into bisq-network:master Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants