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

Implements an internal txindex so we don't have to run bitcoind with txindex=1 #132

Merged
merged 3 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ You can get Bitcoin Core from [bitcoincore.org](https://bitcoincore.org/en/downl

Bitcoin needs to be running with the following options enabled:

- `txindex` to be able to look for non-wallet transactions
- `server` to run rpc commands

Here's an example of a `bitcoin.conf` you can use for mainnet. **DO NOT USE THE PROVIDED RPC USER AND PASSWORD.**
Expand All @@ -31,9 +30,6 @@ rpcuser=user
rpcpassword=passwd
rpcservertimeout=600

# [blockchain]
txindex=1

# [others]
daemon=1
debug=1
Expand Down
196 changes: 91 additions & 105 deletions teos/src/carrier.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions teos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub mod responder;
#[doc(hidden)]
mod rpc_errors;
pub mod tls;
mod tx_index;
pub mod watcher;

#[cfg(test)]
Expand Down
31 changes: 26 additions & 5 deletions teos/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use teos::responder::Responder;
use teos::tls::tls_init;
use teos::watcher::Watcher;

use teos_common::constants::IRREVOCABLY_RESOLVED;
use teos_common::cryptography::get_random_keypair;
use teos_common::TowerId;

Expand All @@ -44,7 +45,7 @@ where
B: DerefMut<Target = T> + Sized + Send + Sync,
T: BlockSource,
{
let mut last_n_blocks = Vec::new();
let mut last_n_blocks = Vec::with_capacity(n);
for _ in 0..n {
let block = poller.fetch_block(&last_known_block).await.unwrap();
last_known_block = poller
Expand Down Expand Up @@ -187,6 +188,20 @@ async fn main() {
} else {
validate_best_block_header(&mut derefed).await.unwrap()
};

// DISCUSS: This is not really required (and only triggered in regtest). This is only in place so the caches can be
// populated with enough blocks mainly because the size of the cache is based on the amount of blocks passed when initializing.
// However, we could add an additional parameter to specify the size of the cache, and initialize with however may blocks we
// could pull from the backend. Adding this functionality just for regtest seemed unnecessary though, hence the check.
if tip.height < IRREVOCABLY_RESOLVED {
log::error!(
"Not enough blocks to start teosd (required: {}). Mine at least {} more",
IRREVOCABLY_RESOLVED,
IRREVOCABLY_RESOLVED - tip.height
);
std::process::exit(1);
}

log::info!("Last known block: {}", tip.header.block_hash());

// This is how chain poller names bitcoin networks.
Expand All @@ -197,7 +212,7 @@ async fn main() {
};

let mut poller = ChainPoller::new(&mut derefed, Network::from_str(btc_network).unwrap());
let last_n_blocks = get_last_n_blocks(&mut poller, tip, 6).await;
let last_n_blocks = get_last_n_blocks(&mut poller, tip, IRREVOCABLY_RESOLVED as usize).await;

// Build components
let gatekeeper = Arc::new(Gatekeeper::new(
Expand All @@ -208,12 +223,18 @@ async fn main() {
dbm.clone(),
));

let carrier = Carrier::new(rpc, bitcoind_reachable.clone(), tip.deref().height);
let responder = Arc::new(Responder::new(carrier, gatekeeper.clone(), dbm.clone()));
let carrier = Carrier::new(rpc, bitcoind_reachable.clone(), tip.height);
let responder = Arc::new(Responder::new(
&last_n_blocks,
tip.height,
carrier,
gatekeeper.clone(),
dbm.clone(),
));
let watcher = Arc::new(Watcher::new(
gatekeeper.clone(),
responder.clone(),
last_n_blocks,
&last_n_blocks[0..6],
tip.height,
tower_sk,
TowerId(tower_pk),
Expand Down
Loading