-
Notifications
You must be signed in to change notification settings - Fork 23
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/matching fee tracking #946
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👍
ebb2c68
to
ea61df8
Compare
I'm not merging this yet, I think it would be good if @bonomat and @luckysori can have a look :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is well done!
I suggested a couple of things that are not so important and I left a few questions that other teammates might want to address.
coordinator/src/metrics.rs
Outdated
@@ -243,3 +257,48 @@ fn node_metrics(cx: &Context, inner_node: Arc<ln_dlc_node::node::Node<NodeStorag | |||
} | |||
} | |||
} | |||
|
|||
pub fn collect_metrics_based_on_node_events( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓We had a conversation about this yesterday, but I would still like to hear from others on why we think collecting metrics like this is necessary if they are already stored in the database. Cc @bonomat.
I don't see much benefit and this code needs to be maintained.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Context: @luckysori and me discussed if we should actually report this to prometheus at all. If we plan to use it for reporting we will created a report based on the database - what's the motivation to report it to prometheus?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see these two different types of reports:
- business metrics to track KPIs: these are in the DB and are collected manually once every X (e.g. 1/week)
- liveness metrics: these are reported via prometheus to grafana so that we get a glimpse of what is happening.
We can combine these: for that I would not send events around but rather have a recurring thread that polls from the db and collects the data and prepares it for prometheus/grafana.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I completely agree with the DB based reports. That makes sense.
I am not totally convinced about reporting this particular metric to prometheus. Are we able to query the Postgres database from the Grafana board instead of reporting this via prometheus?
If we want to keep reporting this metric to prometheus I think it's better reporting it based on the event rather than a periodic task. If we have a periodic task that loads and reports fees it can happen that we miss reporting one (when we e.g. shut down the coordinator) unless we track what was already reported. This might create scenarios where we get confused because e.g. what is reported on prometheus does not match the report we got from the database. I am not convinced it's worth creating logic to track what we already reported; that's why I opted for reporting to prometheus based on the event.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed offline just now: We won't report fees
as metrics to Grafana (through Prometheus) because there is nothing to act on here. Reporting to Prometheus will be removed from this PR.
// Upon collab closing an expired position we cannot charge a fee using an | ||
// invoice. This dummy hash exists in the database to | ||
// represent zero-amount invoices. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓Is this what we want to do, @bonomat? I'm not totally sure after reading this comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually wanted to try charging the user in this scenario as well, but this would require a more elaborate process in terms of messages. The coordinator currently triggers the close on the DLC subchannel level. We could change this so the coordinator proposes the close by sending an event over to the app. The app then triggers the close automatically - that way we would tap into the existing process and would charge the fee. I don't see this as part of this PR though.
My understanding is, that eventually we want to calculate the fee into the payout (and not charge it with a separate invoice); if we do this at some point this problem will go away.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, both ways are better then what we have at the moment 😅
It would be nicer if the app would try to collab close an expired position when it detects it cc @holzeis
-- Your SQL goes here | ||
-- insert a payment with amount zero that is a dummy default payment that corresponds to this actual zero-amount invoice: | ||
-- lnbcrt0m1pj26wczdq50fjhymeqd9h8vmmfvdjsnp4qtwk40kf07d8fzlhdt2s9vqyeczarvk37safua4a0kz7wellkq3vjpp5d7dce9wzhfa3s4a3n7t4xu3ss9slah6sl6mc5ffzqqf45sv82ggqsp54cmyvxklz48ap60guqsln4wuh2ranlap3grg2djt5ykz7005fc6s9qyysgqcqpcxq8z7ps9nqepcz2l2s4qrp6qeks68qry55ylcz542c8a6m6fffmhlmhtn9nnf458ngv83pk0473xfecdk7m7maumqk4jvaymdg7fpgn9tujcehxpqqte97xd | ||
-- We insert this dummy payment so we are able to sum up fees on already existing trades and make the fee payment hash a mandatory field. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙃 It's also for closing expired positions, at least at the moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that was not planned initially - I can adapt the comment or even opt for having another dummy value in the db for that.
I thought about changing the model make the fee optional (removing the NOT NULL
) constraint instead, but I feel eventually there should be a fee for every trade. Or not...? CC @bonomat :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I fully understand the question: are you asking if there should be a fee for every trade? Imho the answer to this question is yes, if it is a trade, i.e. it remove liquidity from the orderbook, then there should be a fee involved.
// represent zero-amount invoices. | ||
let zero_amount_payment_hash_dummy = PaymentHash( | ||
<[u8; 32]>::from_hex( | ||
"6f9b8c95c2ba7b1857b19f975372308161fedf50feb78a252200135a41875210", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔧 I think it would help if this is private to the db
module. We could have a close_expired_position
method without the fee_payment_hash
. And maybe a NewTrade::close_expired
encapsulating this stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we agree that the trade fee should always be set (but it is not for this particular case at the moment because it's not implemented) then I would keep this in the business logic. The database expects the payment hash to be set and should not "default" it (initial migration excepted, but that's a different case).
- Add different structs for insert / query - Don't expose the db model to the business logic - Make `position_id` mandatory field in the db (we cannot have a trade without a position)
c70f478
to
404dfa1
Compare
404dfa1
to
044e726
Compare
bors r+ |
Build succeeded! The publicly hosted instance of bors-ng is deprecated and will go away soon. If you want to self-host your own instance, instructions are here. If you want to switch to GitHub's built-in merge queue, visit their help page. |
949: Save routing fees in database r=da-kami a=da-kami fixes https://github.com/get10101/meta/issues/177 Notes: - I have not added the prometheus counter yet because I am waiting for the result of discussion here: #946 (comment) - Opted for a separate table in the databse instead of adding a table that abstracts over multiple "fees". I think it's better to created views / reports on top Co-authored-by: Daniel Karzel <[email protected]>
Track matching fees in database and report on prometheus as counter.