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

feat: new grpc call for subscribing alerts and low balance alert (#864) #2023

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

rsercano
Copy link
Collaborator

@rsercano rsercano commented Dec 5, 2020

Resolves #864

This adds a new middleware between alerts that are being thrown during xud flows and grpc level as we discussed @sangaman But I haven't created two separate PRs, it doesn't make sense since we add a single alert instead of two as in the previous PR (#1984)

  • Created a new middleware Alerts class.
  • I added time to alert message let me know if want me to remove it or put it to json output.
  • Minimum balance alert threshold to re-throw is 10 seconds, let me know if you want to change.
  • I added a TODO to Alerts class, it's because we need a clear mechanism there for the map.

This requires a full re-test sorry @raladev

@rsercano rsercano requested review from a user, sangaman and raladev December 5, 2020 08:54
@rsercano rsercano self-assigned this Dec 5, 2020
@rsercano rsercano force-pushed the feat/subscribealerts-rework branch 2 times, most recently from a9fbc51 to 368167f Compare December 5, 2020 10:34
@ghost
Copy link

ghost commented Dec 7, 2020

Thanks for the PR.

Created a new middleware Alerts class.

Why do we need a a new class Alerts? Currently, the class has no public methods and it's just a wrapper event emitter for swap client. Would it make sense to move this to SwapClientManager? Thoughts @sangaman @rsercano?

@rsercano
Copy link
Collaborator Author

rsercano commented Dec 7, 2020

Thanks for the PR.

Created a new middleware Alerts class.

Why do we need a a new class Alerts? Currently, the class has no public methods and it's just a wrapper event emitter for swap client. Would it make sense to move this to SwapClientManager? Thoughts @sangaman @rsercano?

Since alerts are not specific to swaps/swapclients actually it was @sangaman's idea to create a new class, which I think makes more sense because in a further time we can add more alerts to xud flow's different places.

@raladev
Copy link
Contributor

raladev commented Dec 7, 2020

@rsercano can u please rebase it ? (need to get connext changes for vector from master).

…at/subscribealerts-rework

� Conflicts:
�	test/simulation/xudrpc/xudrpc.pb.go
@rsercano
Copy link
Collaborator Author

rsercano commented Dec 7, 2020

@rsercano can u please rebase it ? (need to get connext changes for vector from master).

rebased @raladev

Copy link
Contributor

@raladev raladev left a comment

Choose a reason for hiding this comment

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

  • u dont need to throw alert for remote balance of connext currencies because this value is not user controllable, and depends on collateralization
    (Tue Dec 08 2020 11:20:58 GMT+0000) LowTradingBalance: Remote trading balance (0 ETH) is lower than 10% of trading capacity (15 ETH)

  • we need to decide how it will look for connext or we just should support this alert only for lnd (looks correct for me) @rsercano @sangaman @kilrau

  • text message contains time, but json does not contain timestamp, would be good to add.

(Tue Dec 08 2020 11:21:22 GMT+0000) LowTradingBalance: Remote trading balance (0 ETH) is lower than 10% of trading capacity (15 ETH)
^Csimnet > streamalerts -j
Successfully connected, streaming
{
  "type": "LowTradingBalance",
  "payload": {
    "totalBalance": 1500000000,
    "side": "Remote",
    "sideBalance": 0,
    "bound": 10,
    "currency": "ETH"
  }
}

@kilrau
Copy link
Contributor

kilrau commented Dec 10, 2020

* we need to decide how it will look for connext or we just should support this alert only for lnd (looks correct for me) @rsercano @sangaman @kilrau

The user will be able to influence this. At the moment the requestCollateral is hidden from the user, but once users need to pay for collateral we will have to show it to the user. We can keep this alert imo.

@rsercano
Copy link
Collaborator Author

@raladev added date to json output as Unix time and formatted in formatted output :)

@kilrau
Copy link
Contributor

kilrau commented Dec 14, 2020

Let's give this another round of review @sangaman @raladev

@rsercano rsercano requested review from sangaman, raladev and a user December 19, 2020 07:31
raladev
raladev previously approved these changes Dec 21, 2020
@sangaman
Copy link
Collaborator

I pushed a commit to do some refactoring and to preserve type checking. As a general rule I really think we ought to preserve types whenever possible, which are lost with declaring emit: Function.

My last concern is in regards to the proto file field naming & comments/description for purposes of API documentation. See my comments on the unresolved issues above.

@kilrau
Copy link
Contributor

kilrau commented Dec 22, 2020

also keep an eye on the failing builds

@sangaman
Copy link
Collaborator

also keep an eye on the failing builds

Thanks, just a linting issue. Fixed.

@rsercano
Copy link
Collaborator Author

I guess @sangaman already pushed a commit for this review: #2023 (comment) Is there anything to do for me here? @raladev @sangaman

@raladev
Copy link
Contributor

raladev commented Dec 29, 2020

I guess @sangaman already pushed a commit for this review: #2023 (comment) Is there anything to do for me here? @raladev @sangaman

  • Resolve conflicts
  • Check tests, they contain JS errors

…at/subscribealerts-rework

� Conflicts:
�	lib/swaps/SwapClient.ts
�	test/simulation/xudrpc/xudrpc.pb.go
@rsercano rsercano requested a review from raladev January 3, 2021 05:59
raladev
raladev previously approved these changes Jan 4, 2021
Copy link
Collaborator

@sangaman sangaman left a comment

Choose a reason for hiding this comment

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

The proto file still needs work unfortunately. The bound field is not in the proto definition currently, but it's being used in the xud code. I also still have some open questions for the naming and commenting of the balance alert fields in the proto file, we need to make sure they are clear.

Once that's done we can squash and merge everything. I'm taking care of the merge conflicts, but we need another commit to address the proto file concerns. See if my questions make sense to you @kilrau, I can also take care of the final changes once it's clear to me which exactly which fields we want on the balance alert message.

// The bound of the low balance in percentage.
uint32 bound = 3 [json_name = "bound"];
// The current side balance.
uint64 side_balance = 4 [json_name = "side_balance"];
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we still need an answer here and I'm not sure what it is.

if (serviceAlert.type === AlertType.LowTradingBalance) {
const balanceServiceAlert = serviceAlert as Alert;
const balanceAlert = new xudrpc.BalanceAlert();
balanceAlert.setBound(balanceServiceAlert.bound);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Bound is not in the xudrpc.proto definition currently. Regenerating the protos results in compile errors currently. Do we want this field?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Side side = 2 [json_name = "side"];
// The bound of the low balance in percentage.
uint32 bound = 3 [json_name = "bound"];
// The current side balance.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you change this or would you like me to?

@rsercano
Copy link
Collaborator Author

rsercano commented Jan 8, 2021

@kilrau
Copy link
Contributor

kilrau commented Jan 8, 2021

I synced with @michael1011 about this and we will not use this information for a channel rebalancer any time soon, the UI will rather use it to display a notification about a general imbalance on a certain asset (not even a specific channel). I think the fields in this PR deliver this, so if if passed your review with that in mind, we can merge as is @sangaman

@sangaman sangaman removed their request for review October 5, 2022 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
grpc gRPC API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SubscribeAlerts
4 participants