-
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
Lock used utxos #913
Lock used utxos #913
Conversation
38a9baf
to
5e9f3da
Compare
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. I've left some comments to clean this up a bit, but I think it's good.
pub trait EstimateFeeRate { | ||
fn estimate(&self, target: ConfirmationTarget) -> FeeRate; | ||
async fn update(&self) -> Result<()>; | ||
} |
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 should be defined next to the component that requires this contract i.e. the wallet.
I would keep the get
method and just call it when implementing the foreign trait method estimate
.
#[async_trait] | ||
pub trait EstimateFeeRate { | ||
fn estimate(&self, target: ConfirmationTarget) -> FeeRate; | ||
async fn update(&self) -> Result<()>; |
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 update
needs to be part of this trait. The wallet only cares about getting the estimate, not how it is internally updated.
} | ||
|
||
#[autometrics] | ||
pub(crate) async fn update(&self) -> Result<()> { |
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 shouldn't be async anymore. I'll fix that separately.
@@ -25,32 +25,32 @@ use std::sync::Arc; | |||
use std::time::Instant; | |||
use tokio::sync::RwLock; | |||
|
|||
pub struct Wallet<D> | |||
pub struct Wallet<D, B, F> |
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.
🙃 Since we only need the generics for testing, I would isolate the rest of the modules from them by providing a pub type
which is Wallet<sled::Tree, EsploraBlockchain, FeeRateEstimator>
.
I can do this afterwards though.
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.
Thank you, I'l leave it for now then.
let mut locked_out_points = self.locked_outpoints.lock(); | ||
for out_point in locked_out_points.iter() { | ||
tx_builder.add_unspendable(*out_point); | ||
} |
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.
🙃 Let's use outpoint
instead of out_point
consistently.
.map(|input| input.previous_output) | ||
.collect::<Vec<_>>(); | ||
|
||
locked_out_points.extend(prev_outpoints); |
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 might be a good idea to take this lock twice rather than holding it for an extended period of time. What do you think, @klochowicz?
} | ||
|
||
#[tokio::test] | ||
async fn wallet_with_two_utxo_should_be_able_to_fund_twice_but_not_three_times() { |
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.
🙃 Let's move the test to the top of the module, please.
async fn update(&self) -> Result<()> { | ||
unimplemented!() | ||
} |
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, I think this confirms that we don't need it in the trait.
581ec3f
to
ae8d138
Compare
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 👍
@@ -90,6 +93,8 @@ where | |||
"Finished on-chain sync", | |||
); | |||
|
|||
self.locked_outpoints.lock().clear(); |
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 it safe to clear the utxos here? or do we even have to wait for the locked utxo to get a confirmation, before we can safely remove it from the locked_outputs
?
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 believe it is because during sync with on-chain we should catch-up with all transactions which are in the mempool
by extracting traits we can easier test the wallet and pass in dummies.
to prevent accidentally reusing utxos for different funding transactions we lock a used utxo. On next wallet sync we clear the locked utxos because the wallet should pick up said utxos from the mempool
This fixes a weird situation where bitcoind decides to go for an absurdly high fee of 10,000 sats/vbyte which confuses the fee estimator.
We don't want this to run forever. Timing this out if no balance can be found after some time helps us to get better errors in the tests.
We are blocking utxos after we used them. Because of this the coordinator needs to start with more utxos.
After repeated running tests, the coordinator might run out of utxos/money. Hence, we ensure that he has an available utxo before the test runs
ae8d138
to
46f3be2
Compare
f82ed66
to
dc97aae
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. |
fixes #873