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

Fix multiple REST issues, allow only one macaroon to be used for lnd connection #210

Merged
merged 10 commits into from
Feb 2, 2021

Conversation

guggero
Copy link
Member

@guggero guggero commented Jan 26, 2021

Fixes #208.
Fixes #209.
Fixes #196.
Fixes #204.

Contains a number of smaller fixes that should help developers and users alike.

@guggero guggero requested review from a team, Roasbeef and halseth and removed request for a team January 26, 2021 10:02
server.go Outdated
s.cfg.Network,
s.cfg.Lnd.Host, s.cfg.Lnd.TLSPath,
path.Dir(s.cfg.Lnd.MacaroonPath), s.cfg.Network,
lndclient.MacFilename(defaultLndMacaroon),
Copy link
Contributor

Choose a reason for hiding this comment

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

does this work if admin macaroon is not used?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! It would indeed not have worked. Fixed it by using path.Base() instead.

@halseth
Copy link
Contributor

halseth commented Jan 27, 2021

Great PR and additions :)

]
}
},
"/v1/pool/batch/snapshots/{start_batch_id}": {

Choose a reason for hiding this comment

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

Does this work with /v1/pool/batch/snapshots/ as well, without start_batch_id? It states the parameter is required (line 473), but with or without trailing slash should work the same IMO.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that's what line 409 is for. There are three URL patterns now:

/v1/pool/batch/snapshots
/v1/pool/batch/snapshots/{start_batch_id}
/v1/pool/batch/snapshots/{start_batch_id}/{num_batches_back}

And you can use the GET parameters too:

/v1/pool/batch/snapshots?num_batches_back=10
/v1/pool/batch/snapshots/{start_batch_id}?num_batches_back=10

Choose a reason for hiding this comment

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

My comment was on /v1/pool/batch/snapshots/, with a trailing slash and without start_batch_id query param. It looks like that's not included in the pattern. But it's a minor thing.

@mutatrum
Copy link

Nice additions!

Two more things for getinfo, but these might be out of scope for this:

  • poold version
  • auctioneer connection state

@guggero guggero force-pushed the rest-fixes branch 2 times, most recently from 949d472 to add330c Compare January 28, 2021 09:21
@guggero
Copy link
Member Author

guggero commented Jan 28, 2021

Thanks for the review, @mutatrum!

Two more things for getinfo, but these might be out of scope for this:

Great ideas, added both of them.

Copy link
Contributor

@halseth halseth left a comment

Choose a reason for hiding this comment

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

Two comments about potential race conditions, otherwise LGTM 👍

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

Solid set of changes! Quite a few issue will be closed by this PR which is great, ofc.

One smol question re ensuring proper mutex usage, but we should be good after that's cleared up.

LGTM 🍄

c.streamMutex.Lock()
defer c.streamMutex.Unlock()
needToConnect := c.serverStream == nil
c.streamMutex.Unlock()
Copy link
Member

Choose a reason for hiding this comment

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

Don't we also need the lock for subscribedAccts below?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, added an extra mutex.

Fixes lightninglabs#208 by always rendering the default values in a JSON response,
even if they are "falsey" in the RPC message.
The order manager already stores the local lnd node's identity public
key. We return it in an exported method so the RPC server can access it
as well without needing to query it again.
To make sure we only allow querying it after the manager is started, we
add an atomic flag for the startup state.
The IsSubscribed() method informs about the subscription connection
status to the auctioneer server.
This commit fixes a missing mutex lock in the SendAuctionMessage. To
make it possible to hold it there, we need to remove the deferred unlock
in connectAndAuthenticate into connectServerStream. Otherwise we'd run
into deadlocks.
Because the subscribedAccts map is potentially also accessed by multiple
goroutines at the same time, we add a mutex for it as well.
To give developers and users more information about the current state of
the trader daemon, we add a new GetInfo RPC that shows a summary of all
accounts and orders known to the system.
And because there currently is no other way than to <ctrl>+c or kill the
daemon, we add a StopDaemon RPC as well for proper shutdown.
This commit adds the required macaroon permissions for the two new RPC
methods added in the previous commit.
We don't want to introduce a new permission that didn't exist before
because that would mean all users would need to re-create their macaroon
to use the commands. Therefore we use the account:write permission for
the shutdown command as that is probably the most sensitive permission
anyway as it gives access to on-chain funds.
Fixes lightninglabs#204 by allowing multiple REST URI patterns for the batch
snapshots call.
Fixes lightninglabs#196 by allowing only one macaroon to be specified in the
--lnd.macaroonpath config option.
@guggero guggero merged commit 41d958e into lightninglabs:master Feb 2, 2021
@guggero guggero deleted the rest-fixes branch February 2, 2021 09:09
@halseth halseth mentioned this pull request Feb 16, 2021
positiveblue pushed a commit to positiveblue/pool that referenced this pull request Oct 11, 2022
venue: ignore all messages from traders not part of the batch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants