Skip to content

Commit 020a8fa

Browse files
authored
Merge pull request 2140-dev#311 from nyonson/break-up-core
2 parents ed6dc8c + 41a9ac6 commit 020a8fa

27 files changed

+171
-197
lines changed

README.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,6 @@ just integrate
135135

136136
If you do not have `bitcoind` installed, you may simply run `just integrate` and it will be installed for you in the `build` folder.
137137

138-
## Project Layout
139-
140-
`chain`: Contains all logic for syncing block headers, filter headers, filters, parsing blocks. Also contains preset checkpoints for Signet, Regtest, and Bitcoin networks. Notable files: `chain.rs`
141-
142-
`core`: Organizes the primary user-facing components of the API. This includes both the `Node` and the `Client` that all developers will interact with, as well as the `NodeBuilder`. Importantly includes `peer_map.rs`, which is the primary file that handles peer threads by sending messages, persisting new peers, banning peers, and managing peer task handles. `node.rs` is the main application loop, responsible for driving the node actions. Notable files: `node.rs`, `peer_map.rs`, `builder.rs`, `client.rs`
143-
144-
`db`: Defines how data must be persisted with `traits.rs`, and includes some opinionated defaults for database components.
145-
146-
`filters`: Additional structures for managing compact filter headers and filters, used by `chain.rs`
147-
148-
`network`: Opens and closes connections, handles encryption and decryption of messages, generates messages, parses messages, times message response times, performs DNS lookups. Notable files: `peer.rs`, `reader.rs`, `parsers.rs`, `outbound_messages.rs`
149-
150138
## Contributing
151139

152140
Please read [CONTRIBUTING.md](./CONTRIBUTING.md) to get started.

doc/DETAILS.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,23 @@ The wallet required 12 block downloads, and took 5 minutes.
8181

8282
This section details what behavior to expect when using Kyoto, and why such decisions were made.
8383

84-
### Peer Selection
84+
## Peer Selection
8585

8686
Kyoto will first connect to all of the configured peers to maintain the connection requirement, and will use peers gleaned from the peer-to-peer gossip thereafter. If no peers are configured when building the node, and no peers are in the database, Kyoto will resort to DNS. Kyoto will not select a peer of the same netgroup (`/16`) as a previously connected peer. When selecting a new peer from the database, a random preference will be selected between a "new" peer and a peer that has been "tried." Rational is derived from [this research](https://www.ethanheilman.com/p/eclipse/index.html)
8787

88-
### Block Headers and Storage
88+
## Block Headers and Storage
8989

9090
Kyoto expects users to adopt some form of persistence between sessions when it comes to block header data. Reason being, Kyoto emits block headers that have been reorganized back to the client in such an event. To do so, in a rare but potential circumstance where the client has shut down on a stale tip, one that is reorganized in the future, Kyoto may use the header persistence to load the older chain into memory. Further, this allows the memory footprint of storing headers in a chain structure to remain small. Kyoto has a soft limit of 20,000 headers in memory at any given time, and if the chain representation exceeds that, Kyoto has a reliable backend to move the excess of block headers. To compensate for this, Kyoto only expects some generic datastore, and does not care about how persistence is implemented.
9191

92-
### Filters
92+
## Filters
9393

9494
Block filters for a full block may be 300-400 bytes, and may be needless overhead if scripts are revealed "into the future" for the underlying wallet. Full filters are checked for matches as they are downloaded, but are discarded thereafter. As a result, if the user adds scripts that are believe to be included in blocks _in the past_, Kyoto will have to redownload the filters. But if the wallet has up to date information, a revealing a new script is guaranteed to have not been used. This memory tradeoff was deemed worthwhile, as it is expected rescanning will only occur for recovery scenarios.
9595

96-
### Structure
96+
## Structure
97+
98+
* `chain`: Contains all logic for syncing block headers, filter headers, filters, parsing blocks. Also contains preset checkpoints for Signet, Regtest, and Bitcoin networks. Notable files: `chain.rs`
99+
* `db`: Defines how data must be persisted with `traits.rs`, and includes some opinionated defaults for database components.
100+
* `filters`: Additional structures for managing compact filter headers and filters, used by `chain.rs`
101+
* `network`: Opens and closes connections, handles encryption and decryption of messages, generates messages, parses messages, times message response times, performs DNS lookups. Notable files: `peer.rs`, `reader.rs`, `parsers.rs`, `outbound_messages.rs`
97102

98103
![Layout](https://github.com/user-attachments/assets/21280bb4-aa88-4e11-9223-aed35a885e99)

example/managed.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
//! many possible scripts to check. Enable the `filter-control` feature to check filters
33
//! manually in your program.
44
5-
use kyoto::core::messages::Event;
6-
use kyoto::{chain::checkpoints::HeaderCheckpoint, core::builder::NodeBuilder, Client};
5+
use kyoto::messages::Event;
6+
use kyoto::{builder::NodeBuilder, chain::checkpoints::HeaderCheckpoint, Client};
77
use kyoto::{AddrV2, Address, BlockHash, LogLevel, Network, ServiceFlags, TrustedPeer};
88
use std::collections::HashSet;
99
use std::{net::Ipv4Addr, str::FromStr};

example/rescan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! the filters for inclusions of these scripts and download the relevant
33
//! blocks.
44
5-
use kyoto::{chain::checkpoints::HeaderCheckpoint, core::builder::NodeBuilder};
5+
use kyoto::{builder::NodeBuilder, chain::checkpoints::HeaderCheckpoint};
66
use kyoto::{Address, Client, Event, Network};
77
use std::collections::HashSet;
88
use std::str::FromStr;

example/signet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Usual sync on Signet.
22
3-
use kyoto::{chain::checkpoints::HeaderCheckpoint, core::builder::NodeBuilder};
3+
use kyoto::{builder::NodeBuilder, chain::checkpoints::HeaderCheckpoint};
44
use kyoto::{AddrV2, Address, Client, Event, Log, Network, ServiceFlags, TrustedPeer};
55
use std::collections::HashSet;
66
use std::{

example/testnet4.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Usual sync on Testnet.
22
3-
use kyoto::{chain::checkpoints::HeaderCheckpoint, core::builder::NodeBuilder};
3+
use kyoto::{builder::NodeBuilder, chain::checkpoints::HeaderCheckpoint};
44
use kyoto::{Address, Client, Event, Log, Network, PeerStoreSizeConfig, TrustedPeer};
55
use std::collections::HashSet;
66
use std::{net::Ipv4Addr, str::FromStr};
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use bitcoin::Network;
55
#[cfg(not(feature = "filter-control"))]
66
use bitcoin::ScriptBuf;
77

8-
use super::{client::Client, config::NodeConfig, node::Node, FilterSyncPolicy};
8+
use super::{client::Client, config::NodeConfig, node::Node};
99
#[cfg(feature = "database")]
1010
use crate::db::error::SqlInitializationError;
1111
#[cfg(feature = "database")]
@@ -15,7 +15,7 @@ use crate::{
1515
chain::checkpoints::HeaderCheckpoint,
1616
db::traits::{HeaderStore, PeerStore},
1717
};
18-
use crate::{ConnectionType, LogLevel, PeerStoreSizeConfig, TrustedPeer};
18+
use crate::{ConnectionType, FilterSyncPolicy, LogLevel, PeerStoreSizeConfig, TrustedPeer};
1919

2020
#[cfg(feature = "database")]
2121
/// The default node returned from the [`NodeBuilder`](crate::core).

src/chain/block_queue.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use bitcoin::BlockHash;
44
use tokio::time::Instant;
55

66
#[cfg(feature = "filter-control")]
7-
use crate::core::messages::BlockRequest;
8-
use crate::core::messages::BlockSender;
7+
use crate::messages::BlockRequest;
8+
use crate::messages::BlockSender;
99

1010
const SPAM_LIMIT: u64 = 5;
1111

src/chain/chain.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,13 @@ use super::{
2020
HeightMonitor,
2121
};
2222
#[cfg(feature = "filter-control")]
23-
use crate::core::error::FetchBlockError;
23+
use crate::error::FetchBlockError;
2424
#[cfg(feature = "filter-control")]
25-
use crate::core::messages::BlockRequest;
25+
use crate::messages::BlockRequest;
2626
#[cfg(feature = "filter-control")]
2727
use crate::IndexedFilter;
2828
use crate::{
2929
chain::header_batch::HeadersBatch,
30-
core::{
31-
dialog::Dialog,
32-
error::HeaderPersistenceError,
33-
messages::{Event, Warning},
34-
},
3530
db::traits::HeaderStore,
3631
filters::{
3732
cfheader_batch::CFHeaderBatch,
@@ -41,6 +36,11 @@ use crate::{
4136
Filter, CF_HEADER_BATCH_SIZE, FILTER_BATCH_SIZE,
4237
},
4338
IndexedBlock,
39+
{
40+
dialog::Dialog,
41+
error::HeaderPersistenceError,
42+
messages::{Event, Warning},
43+
},
4444
};
4545

4646
const MAX_REORG_DEPTH: u32 = 5_000;
@@ -902,11 +902,11 @@ mod tests {
902902
checkpoints::{HeaderCheckpoint, HeaderCheckpoints},
903903
error::HeaderSyncError,
904904
},
905-
core::{
905+
filters::cfheader_chain::AppendAttempt,
906+
{
906907
dialog::Dialog,
907908
messages::{Event, Log, Warning},
908909
},
909-
filters::cfheader_chain::AppendAttempt,
910910
};
911911

912912
use super::{Chain, HeightMonitor};

0 commit comments

Comments
 (0)