-
Notifications
You must be signed in to change notification settings - Fork 224
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: make dyn bitcoin rpc available in ServerModuleInitArgs #6456
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
use std::fmt::Debug; | ||
use std::sync::Arc; | ||
|
||
use anyhow::Result; | ||
use bitcoin::{BlockHash, ScriptBuf, Transaction, Txid}; | ||
use macro_rules_attribute::apply; | ||
|
||
use crate::envs::BitcoinRpcConfig; | ||
use crate::txoproof::TxOutProof; | ||
use crate::{async_trait_maybe_send, dyn_newtype_define, Feerate}; | ||
|
||
/// Trait that allows interacting with the Bitcoin blockchain | ||
/// | ||
/// Functions may panic if the bitcoind node is not reachable. | ||
#[apply(async_trait_maybe_send!)] | ||
pub trait IBitcoindRpc: Debug { | ||
/// Returns the Bitcoin network the node is connected to | ||
async fn get_network(&self) -> Result<bitcoin::Network>; | ||
|
||
/// Returns the current block count | ||
async fn get_block_count(&self) -> Result<u64>; | ||
|
||
/// Returns the block hash at a given height | ||
/// | ||
/// # Panics | ||
/// If the node does not know a block for that height. Make sure to only | ||
/// query blocks of a height less to the one returned by | ||
/// `Self::get_block_count`. | ||
/// | ||
/// While there is a corner case that the blockchain shrinks between these | ||
/// two calls (through on average heavier blocks on a fork) this is | ||
/// prevented by only querying hashes for blocks tailing the chain tip | ||
/// by a certain number of blocks. | ||
async fn get_block_hash(&self, height: u64) -> Result<BlockHash>; | ||
|
||
/// Estimates the fee rate for a given confirmation target. Make sure that | ||
/// all federation members use the same algorithm to avoid widely | ||
/// diverging results. If the node is not ready yet to return a fee rate | ||
/// estimation this function returns `None`. | ||
async fn get_fee_rate(&self, confirmation_target: u16) -> Result<Option<Feerate>>; | ||
|
||
/// Submits a transaction to the Bitcoin network | ||
/// | ||
/// This operation does not return anything as it never OK to consider its | ||
/// success as final anyway. The caller should be retrying | ||
/// broadcast periodically until it confirms the transaction was actually | ||
/// via other means or decides that is no longer relevant. | ||
/// | ||
/// Also - most backends considers brodcasting a tx that is already included | ||
/// in the blockchain as an error, which breaks idempotency and requires | ||
/// brittle workarounds just to reliably ignore... just to retry on the | ||
/// higher level anyway. | ||
/// | ||
/// Implementations of this error should log errors for debugging purposes | ||
/// when it makes sense. | ||
async fn submit_transaction(&self, transaction: Transaction); | ||
|
||
/// If a transaction is included in a block, returns the block height. | ||
/// Note: calling this method with bitcoind as a backend must first call | ||
/// `watch_script_history` or run bitcoind with txindex enabled. | ||
async fn get_tx_block_height(&self, txid: &Txid) -> Result<Option<u64>>; | ||
|
||
/// Check if a transaction is included in a block | ||
async fn is_tx_in_block( | ||
&self, | ||
txid: &Txid, | ||
block_hash: &BlockHash, | ||
block_height: u64, | ||
) -> Result<bool>; | ||
|
||
/// Watches for a script and returns any transactions associated with it | ||
/// | ||
/// Should be called at least prior to transactions being submitted or | ||
/// watching may not occur on backends that need it | ||
/// TODO: bitcoind backend is broken | ||
/// `<https://github.com/fedimint/fedimint/issues/5329>` | ||
async fn watch_script_history(&self, script: &ScriptBuf) -> Result<()>; | ||
|
||
/// Get script transaction history | ||
/// | ||
/// Note: should call `watch_script_history` at least once, before calling | ||
/// this. | ||
async fn get_script_history(&self, script: &ScriptBuf) -> Result<Vec<Transaction>>; | ||
|
||
/// Returns a proof that a tx is included in the bitcoin blockchain | ||
async fn get_txout_proof(&self, txid: Txid) -> Result<TxOutProof>; | ||
|
||
/// Returns the Bitcoin RPC config | ||
fn get_bitcoin_rpc_config(&self) -> BitcoinRpcConfig; | ||
} | ||
|
||
dyn_newtype_define! { | ||
#[derive(Clone)] | ||
pub DynBitcoindRpc(Arc<IBitcoindRpc>) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Are we moving
IBitcoindRpc
tofedimint-core
to avoid a circular dependency betweenfedimint-bitcoind
andfedimint-core
? Or is there another reason? It's strange to separateIBitcoindRpc
fromIBitcoindRpcFactory
, but it sounds like we might be removingIBitcoindRpcFactory
anyway.If we can't keep
IBitcoindRpc
infedimint-bitcoind
, it might make sense to just merge all offedimint-bitcoind
intofedimint-core
. We can see how further refactors play out.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.
Actually I had to move the IBitcoinRpc trait into fedimint core into fedimint core so I can use it in the ServerModuleInitArgs.
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 would like to turn this into a bigger refactor where at the end we can remove the factory.