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

[events API 1/2]: Add new send and receive streaming RPCs #836

Merged
merged 19 commits into from
Apr 1, 2024
Merged

Conversation

guggero
Copy link
Member

@guggero guggero commented Mar 14, 2024

Replaces #773.

Fixes #781.
Fixes #806.
Fixes #739.

This PR adds new RPCs for being notified about inbound and outbound asset transfers.
The existing SubscribeSendAssetEventNtfns and SubscribeReceiveAssetEventNtfns were mostly built for asserting the internal state during integration tests and weren't super helpful for app builders. That's why these old RPCs were moved to the tapdevrpc package and are now only used in the integration tests.

The new RPCs notify on all send and receive states instead of only a few of them. The events also contain way more information that's useful to map them to the user action. And both RPCs allow the events to be filtered (either by address for receive events and by script key for send events).

This is part 1 of the "events API" saga. The follow-up PRs will base on this one and address:

Copy link
Contributor

@ffranr ffranr left a comment

Choose a reason for hiding this comment

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

BTW, CI failed on RPC and lint check.

@guggero
Copy link
Member Author

guggero commented Mar 19, 2024

BTW, CI failed on RPC and lint check.

Fixed!

Copy link
Contributor

@jharveyb jharveyb left a comment

Choose a reason for hiding this comment

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

Looks great! Seems to expose all the relevant info. Just had a few notes + nits.

cmd/tapcli/events.go Show resolved Hide resolved
itest/assertions.go Show resolved Hide resolved
itest/send_test.go Outdated Show resolved Hide resolved
itest/send_test.go Outdated Show resolved Hide resolved
rpcserver.go Show resolved Hide resolved
tapdb/addrs.go Show resolved Hide resolved
WHERE addrs.taproot_output_key = $1
)
SELECT
addr_events.id, creation_time, status, asset_proof_id, asset_id,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why expose addr_events.id here? I didn't spot a use of it later on (may be in some follow-on PR?)

Copy link
Member Author

Choose a reason for hiding this comment

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

It's part of the address.Event struct. It looks like it's currently only used in unit tests... Didn't want to also refactor them, as the PR was already growing quite a bit. But it looks like we could probably un-export the address.Event.ID field.

tapgarden/custodian.go Outdated Show resolved Hide resolved
rpcserver.go Show resolved Hide resolved
Copy link
Contributor

@jharveyb jharveyb left a comment

Choose a reason for hiding this comment

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

Re-reviewed, LGTM! Rebase looks correct, I think it needs another.

@guggero guggero changed the title [events API 1/?]: Add new send and receive streaming RPCs [events API 1/2]: Add new send and receive streaming RPCs Mar 22, 2024
config.go Show resolved Hide resolved
rpcserver.go Show resolved Hide resolved
tapgarden/custodian.go Show resolved Hide resolved
tapgarden/custodian.go Show resolved Hide resolved
tapfreighter/chain_porter.go Show resolved Hide resolved
taprpc/taprootassets.proto Show resolved Hide resolved
taprpc/taprootassets.proto Show resolved Hide resolved
rpcserver.go Show resolved Hide resolved
guggero added 15 commits March 26, 2024 20:08
To avoid pending streams attempting to remove the same subscribers on
stopping the daemon, we hold the corresponding mutex during the whole
time and not just for each iteration.
This commit ensures that we only notify subscribers after we've actually
updated the database to complete an event.
With this commit we skip inspecting on-chain addresses for inbound
asset transfers that have already fully completed.
Previously, if there was an incomplete inbound transfer for a certain
block height, we would go through all transactions in blocks after that
height and notify for all inbound transfers found, even if they already
were fully complete.
With this commit we change the AssetReceiveCompleteEvent into a more
generic AddressReceive event and publish more granular events.
To not change the behavior of the developer RPC, we filter the events
and only forward the completed event.
All other events will be notified on the new RPC that is going to be
added a couple of commits later.
With this commit we create "deep" copy methods for items we will send
out as events. We need these to make sure the objects we notify about
aren't changed by the main thread while we're serializing them to the
RPC notification interface.
Because the loop that sends out the notifications for each send
state terminates before reaching the SendStateComplete state, we
manually need to send out that event once we've sent out all proofs to
the receivers.
We also want to unify how and when we send out notifications, so we move
the event creation to _after_ executing an event.
With this commit we add a new RPC that allows users to subscribe to
address receive events in general or filtered by a specific address.
This RPC notifies more granularly about the different states an inbound
asset goes through, but hides some of the implementation details the
previous (now development only) RPC showed (namely the proof courier
backoff events).
In this commit we slightly refactor the event stream subscription
handling in the send integration test to make sure we correctly time out
in case we don't receive the required events.
We want to make sure the new receive and send events RPC notifies on the correct
events during the send process.
We don't need to assert every single case, so we just add the new
assertion to our main send test cases.
@jharveyb
Copy link
Contributor

Re-reviewed after rebases, still 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.

LGTM 🦊

@Roasbeef Roasbeef added this pull request to the merge queue Apr 1, 2024
Merged via the queue into main with commit 1f37bdf Apr 1, 2024
14 checks passed
@guggero guggero deleted the events-api branch April 2, 2024 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
5 participants