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

Download range of headers during syncing #1270

Merged
merged 50 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
fb481a0
Add requests for blocks to p2p service with test
MitchTurner Aug 1, 2023
2ce71ea
Create stream from singlee headers request rather than multiple requests
MitchTurner Aug 2, 2023
18cad5f
WIP fix tests
MitchTurner Aug 3, 2023
47b7347
Finish tests, remove unused functions
MitchTurner Aug 3, 2023
2df5a9b
Appease Clippy-sama
MitchTurner Aug 3, 2023
964e798
Get headers range test working
MitchTurner Aug 4, 2023
341e54b
Cleanup, make test more robust
MitchTurner Aug 4, 2023
7c25646
Rename tests
MitchTurner Aug 4, 2023
e677568
Fix back-pressure tests
MitchTurner Aug 4, 2023
fa39cd5
Fix new service test
MitchTurner Aug 4, 2023
3ab1ec1
Add impl for adapter
MitchTurner Aug 4, 2023
ce4c4b6
Fix data mapping
MitchTurner Aug 4, 2023
5abf18a
Appease Clippy-sama
MitchTurner Aug 4, 2023
318afda
Merge branch 'master' into download-block-range
xgreenx Aug 6, 2023
560ff4e
Remove not used variant
xgreenx Aug 6, 2023
b61b3b7
Merge remote-tracking branch 'origin/download-block-range' into downl…
xgreenx Aug 6, 2023
9ed60e4
Improve test, use range instead of start/end
MitchTurner Aug 7, 2023
a3854e8
Merge branch 'download-block-range' of github.com:FuelLabs/fuel-core …
MitchTurner Aug 7, 2023
432d49c
Improve the header filtering, rename helper, cleanup missed comments
MitchTurner Aug 7, 2023
53136b7
Appease clippy-sama
MitchTurner Aug 7, 2023
0aa691a
Merge remote-tracking branch 'origin/download-block-range' into downl…
xgreenx Aug 7, 2023
9b6d9ee
Fix off-by-one error, rename field
MitchTurner Aug 7, 2023
2523661
Merge branch 'download-block-range' of github.com:FuelLabs/fuel-core …
MitchTurner Aug 7, 2023
2733c5d
Merge remote-tracking branch 'origin/master' into download-block-range
MitchTurner Aug 10, 2023
b1e970f
Update Changelog
MitchTurner Aug 10, 2023
ee9efdd
Get headers in batches
MitchTurner Aug 11, 2023
efb7703
Cleanup commented code
MitchTurner Aug 11, 2023
66b7d7c
Merge remote-tracking branch 'origin/master' into download-block-range
MitchTurner Aug 11, 2023
0215ed1
Add new fields to sync config
MitchTurner Aug 11, 2023
1972302
Instrument
MitchTurner Aug 11, 2023
fabb2b3
Helm lint
MitchTurner Aug 11, 2023
2b75c60
Address most of the PR comments
MitchTurner Aug 14, 2023
b5df8d4
Merge branch 'master' into download-block-range
MitchTurner Aug 14, 2023
7ec0ac0
Fix compilation errors
MitchTurner Aug 14, 2023
1d4328a
Update crates/services/p2p/src/service.rs
MitchTurner Aug 15, 2023
3283587
Update crates/services/sync/src/ports.rs
MitchTurner Aug 15, 2023
d1f809a
Update crates/services/sync/src/import.rs
MitchTurner Aug 15, 2023
94fc48b
Update crates/services/sync/src/import.rs
MitchTurner Aug 15, 2023
c6a4b3d
Make PR requested changes
MitchTurner Aug 15, 2023
9c0412e
Add ignore for RustSec advisory
MitchTurner Aug 15, 2023
5d63451
Undo bump, remove unused imports
MitchTurner Aug 15, 2023
9a174b5
Add max requests check with config
MitchTurner Aug 16, 2023
98856e6
Remove sealed header (singular) path from p2p service
MitchTurner Aug 16, 2023
91d5253
Merge remote-tracking branch 'origin/master' into download-block-range
MitchTurner Aug 16, 2023
5332d01
Update crates/services/p2p/src/p2p_service.rs
MitchTurner Aug 16, 2023
f2d37b0
Manually format macro
MitchTurner Aug 16, 2023
978b488
Merge branch 'master' into download-block-range
MitchTurner Aug 17, 2023
5970d6a
Add max headers per request to deployment env vars
MitchTurner Aug 17, 2023
6132f5d
Helm lint, add other vars
MitchTurner Aug 17, 2023
46e2c17
Wrap headers in option to represent ambiguous failed request
MitchTurner Aug 21, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Description of the upcoming release here.
- [#1302](https://github.com/FuelLabs/fuel-core/pull/1302): Removed the usage of flake and building of the bridge contract ABI.
It simplifies the maintenance and updating of the events, requiring only putting the event definition into the codebase of the relayer.
- [#1293](https://github.com/FuelLabs/fuel-core/issues/1293): Parallelized the `estimate_predicates` endpoint to utilize all available threads.
- [#1270](https://github.com/FuelLabs/fuel-core/pull/1270): Modify the way block headers are retrieved from peers to be done in batches.

#### Breaking
- [#1279](https://github.com/FuelLabs/fuel-core/pull/1279): Added a new CLI flag to enable the Relayer service `--enable-relayer`, and disabled the Relayer service by default. When supplying the `--enable-relayer` flag, the `--relayer` argument becomes mandatory, and omitting it is an error. Similarly, providing a `--relayer` argument without the `--enable-relayer` flag is an error. Lastly, providing the `--keypair` or `--network` arguments will also produce an error if the `--enable-p2p` flag is not set.
Expand Down
101 changes: 30 additions & 71 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions bin/fuel-core/src/cli/run/p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ pub struct P2PArgs {
#[clap(long = "max-block-size", default_value = MAX_RESPONSE_SIZE_STR, env)]
pub max_block_size: usize,

/// Max number of headers in a single headers request response
#[clap(long = "max-headers-per-request", default_value = "100", env)]
pub max_headers_per_request: u32,

/// Addresses of the bootstrap nodes
/// They should contain PeerId within their `Multiaddr`
#[clap(long = "bootstrap-nodes", value_delimiter = ',', env)]
Expand Down Expand Up @@ -175,12 +179,15 @@ pub struct P2PArgs {

#[derive(Debug, Clone, Args)]
pub struct SyncArgs {
xgreenx marked this conversation as resolved.
Show resolved Hide resolved
/// The maximum number of get header requests to make in a single batch.
#[clap(long = "sync-max-get-header", default_value = "10", env)]
pub max_get_header_requests: usize,
/// The maximum number of get transaction requests to make in a single batch.
#[clap(long = "sync-max-get-txns", default_value = "10", env)]
pub max_get_txns_requests: usize,
/// The maximum number of headers to request in a single batch.
#[clap(long = "sync-header-batch-size", default_value = "10", env)]
pub header_batch_size: u32,
/// The maximum number of header batch requests to have active at one time.
#[clap(long = "sync-max-header-batch-requests", default_value = "10", env)]
pub max_header_batch_requests: usize,
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -211,8 +218,9 @@ impl KeypairArg {
impl From<SyncArgs> for fuel_core::sync::Config {
fn from(value: SyncArgs) -> Self {
Self {
max_get_header_requests: value.max_get_header_requests,
max_get_txns_requests: value.max_get_txns_requests,
header_batch_size: value.header_batch_size,
max_header_batch_requests: value.max_header_batch_requests,
}
}
}
Expand Down Expand Up @@ -282,6 +290,7 @@ impl P2PArgs {
public_address: self.public_address,
tcp_port: self.peering_port,
max_block_size: self.max_block_size,
max_headers_per_request: self.max_headers_per_request,
bootstrap_nodes: self.bootstrap_nodes,
reserved_nodes: self.reserved_nodes,
reserved_nodes_only_mode: self.reserved_nodes_only_mode,
Expand Down
15 changes: 15 additions & 0 deletions crates/fuel-core/src/database/sealed_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use fuel_core_types::{
fuel_tx::Transaction,
fuel_types::BlockHeight,
};
use std::ops::Range;

impl DatabaseColumn for SealedBlockConsensus {
fn column() -> Column {
Expand Down Expand Up @@ -93,6 +94,20 @@ impl Database {
self.get_sealed_block_header(&block_id)
}

pub fn get_sealed_block_headers(
&self,
block_height_range: Range<u32>,
) -> StorageResult<Vec<SealedBlockHeader>> {
let headers = block_height_range
.map(BlockHeight::from)
.map(|height| self.get_sealed_block_header_by_height(&height))
.collect::<StorageResult<Vec<_>>>()?
.into_iter()
.flatten()
.collect();
Ok(headers)
}

pub fn get_sealed_block_header(
&self,
block_id: &BlockId,
Expand Down
8 changes: 8 additions & 0 deletions crates/fuel-core/src/service/adapters/p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use fuel_core_types::{
fuel_tx::Transaction,
fuel_types::BlockHeight,
};
use std::ops::Range;

impl P2pDb for Database {
fn get_sealed_block(
Expand All @@ -31,6 +32,13 @@ impl P2pDb for Database {
self.get_sealed_block_header_by_height(height)
}

fn get_sealed_headers(
&self,
block_height_range: Range<u32>,
) -> StorageResult<Vec<SealedBlockHeader>> {
self.get_sealed_block_headers(block_height_range)
}

fn get_transactions(
&self,
block_id: &BlockId,
Expand Down
31 changes: 21 additions & 10 deletions crates/fuel-core/src/service/adapters/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ use fuel_core_types::{
},
fuel_tx::Transaction,
fuel_types::BlockHeight,
services::p2p::SourcePeer,
services::p2p::{
PeerId,
SourcePeer,
},
};
use std::ops::Range;

#[async_trait::async_trait]
impl PeerToPeerPort for P2PAdapter {
Expand All @@ -39,20 +43,27 @@ impl PeerToPeerPort for P2PAdapter {
}
}

async fn get_sealed_block_header(
async fn get_sealed_block_headers(
&self,
height: BlockHeight,
) -> anyhow::Result<Option<SourcePeer<SealedBlockHeader>>> {
block_range_height: Range<u32>,
) -> anyhow::Result<Vec<SourcePeer<SealedBlockHeader>>> {
if let Some(service) = &self.service {
Ok(service
.get_sealed_block_header(height)
.get_sealed_block_headers(block_range_height)
.await?
.map(|(peer_id, header)| SourcePeer {
peer_id: peer_id.into(),
data: header,
}))
.map(|(peer_id, headers)| {
let peer_id: PeerId = peer_id.into();
headers
.into_iter()
.map(|header| SourcePeer {
peer_id: peer_id.clone(),
data: header,
})
.collect()
})
.unwrap_or(Vec::new()))
} else {
Ok(None)
Ok(Vec::new())
}
}

Expand Down
Loading
Loading