-
Notifications
You must be signed in to change notification settings - Fork 7
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: get last bitcoin fees from sweep tables (#809) #810
base: main
Are you sure you want to change the base?
feat: get last bitcoin fees from sweep tables (#809) #810
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.
This looks okay, but I don't think the query does what we want (or we need to change our usage).
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 there is only one issue with the last_fee
part in the coordinator. Looks good otherwise.
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.
Looks good ✅ 🚢. We should check if the integration tests in the transaction_coordinator
run in CI.
/// This test asserts that the `get_btc_state` function returns the correct | ||
/// `SignerBtcState` when there are no sweep transactions available, i.e. | ||
/// the `last_fees` field should be `None`. | ||
#[cfg_attr(not(feature = "integration-tests"), ignore)] |
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.
Does this test run in CI? I would think that it doesn't, but I'm not sure. If not, then I think there are others that we need to move. And I've made this mistaken in some tests as well 😞.
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.
@djordon hmm, I'm not sure of the best approach. Here we're testing get_btc_state()
which is private, so it needs to be here, but otoh it also needs postgres, so it needs to be run as an integration-test. Should I just make it public and move the test, or do you have a better suggestion?
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.
Moved the tests in 2b22025 and verified they run in CI
I decided to go and check myself and I didn't find those tests in the CI output logs. Also, we should have CI explicitly output which tests were ignored. |
Yeah I'd make it public. |
let total: u64 = self | ||
.iter() | ||
.map(|tx| tx.fee) | ||
.try_fold(0u64, |acc, fee| acc.checked_add(fee)) | ||
.ok_or(Error::ArithmeticOverflow)?; |
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.
Hmmm, these fees cannot add up to anything more than u64::MAX
, even if we added up all bitcoins (measured in sats).
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.
Nope, but the code otherwise is technically not panic-safe, which is what we've been striving for.
Same argument could be made for the vsize
-- we should realistically never have transactions larger than a handful of vKb, and it would take a crazy number (u32::MAX+1
) of transactions holding u32::MAX
, but the code can still panic.
if total_size == 0 { | ||
return Err(Error::DivideByZero); | ||
} |
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.
This can only happen if the vector is empty, so we could just return zero.
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 don't think zero is what we want -- compute_transaction_fee()
matches on an Option<>
and None
would not be the same as Fees::ZERO
.
But I changed the signature and added a check and return Ok(None)
if it's empty as I could describe that mode in the trait description and it matches its use (basis for calculation is missing). We did this check manually before in the coordinator, so it's essentially just moved here.
The DivideByZero
remains because you could still have a bug elsewhere i.e. when pulling these out of the database which defaults vsize
to zero (i.e. the code still has a panic-able path otherwise).
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.
LGTM, but I think you should revert the changes in generated code (make lint
should do the trick).
@matteojug yeah, crap, those generated files snuck in on me. |
Description
Closes: #809
Changes
Removes the
BitcoinInteract::get_last_fees()
method (described in #541) and replaces it with logic to retrieve theFees
from the latest sweep transaction package (described in #809).Testing Information
RBF tests updated to use the
sweep_transactions
method.Checklist: