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

feat: serve forest CAR file as Blockstore #3365

Merged
merged 62 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
fb8b660
feat: serve forest CAR file as Blockstore
hanabi1224 Aug 14, 2023
17a7bd3
flush temp_snapshot_writer
hanabi1224 Aug 14, 2023
ab55388
log tipset epoch
hanabi1224 Aug 14, 2023
cb40894
fix auto-download logic
hanabi1224 Aug 15, 2023
1243dfb
Merge branch 'main' into hm/use-snapshot-file-as-db
hanabi1224 Aug 15, 2023
2c72852
Merge remote-tracking branch 'origin/main' into hm/use-snapshot-file-…
hanabi1224 Aug 15, 2023
f23a45c
fix ci
hanabi1224 Aug 15, 2023
229dda9
Fix tests
hanabi1224 Aug 15, 2023
d32961a
fix clippy
hanabi1224 Aug 15, 2023
8477da6
unblock parent process early before db init
hanabi1224 Aug 15, 2023
7a9d6b1
support multiple car files
hanabi1224 Aug 15, 2023
a33c566
log
hanabi1224 Aug 15, 2023
8b8a443
cleanup
hanabi1224 Aug 15, 2023
b3a2b49
Merge branch 'main' into hm/use-snapshot-file-as-db
hanabi1224 Aug 16, 2023
168505b
dettach right before DB setup
hanabi1224 Aug 16, 2023
f434632
fix forest_headless_encrypt_keystore_with_passphrase_should_succeed
hanabi1224 Aug 16, 2023
a68bf43
log level
hanabi1224 Aug 16, 2023
ee8046a
Merge remote-tracking branch 'origin/main' into hm/use-snapshot-file-…
hanabi1224 Aug 18, 2023
027b8ee
read_only_len
hanabi1224 Aug 18, 2023
c00679a
lint
hanabi1224 Aug 21, 2023
af159df
Merge remote-tracking branch 'origin/main' into hm/use-snapshot-file-…
hanabi1224 Aug 21, 2023
d2ad4d2
fix build
hanabi1224 Aug 21, 2023
437b108
Merge remote-tracking branch 'origin/main' into hm/use-snapshot-file-…
hanabi1224 Aug 22, 2023
632f4c9
refactor
hanabi1224 Aug 22, 2023
0435da6
revert debug change
hanabi1224 Aug 22, 2023
1bc8b85
Merge remote-tracking branch 'origin/main' into hm/use-snapshot-file-…
hanabi1224 Aug 23, 2023
4d74202
impl SettingsStore for ManyCar
hanabi1224 Aug 23, 2023
afcc687
bind rpc endpoint before unblock_parent_process
hanabi1224 Aug 23, 2023
d3894c3
sequential db file name
hanabi1224 Aug 23, 2023
26d9d82
use unix timestap as filename
hanabi1224 Aug 23, 2023
01c9ae9
bail on DB loading errors
hanabi1224 Aug 23, 2023
fecc381
parent process wait infinitely in detached mode
hanabi1224 Aug 23, 2023
d7a38d4
docs
hanabi1224 Aug 23, 2023
222bccf
Merge branch 'main' into hm/use-snapshot-file-as-db
hanabi1224 Aug 23, 2023
d8e49e7
verify_tipsets_integrity
hanabi1224 Aug 24, 2023
37710fe
fix verify_tipsets_integrity for devnet
hanabi1224 Aug 24, 2023
ca85e02
bail early
hanabi1224 Aug 24, 2023
6c533bb
remove verify_tipsets_integrity
hanabi1224 Aug 24, 2023
8eae7a0
Merge remote-tracking branch 'origin/main' into hm/use-snapshot-file-…
hanabi1224 Aug 24, 2023
1c78709
move `fetch_snapshot_if_required` back to `mod.rs`
hanabi1224 Aug 24, 2023
76bd05c
refactor import_chain_as_forest_car
hanabi1224 Aug 29, 2023
c4f3727
Merge remote-tracking branch 'origin/main' into hm/use-snapshot-file-…
hanabi1224 Aug 29, 2023
fd64150
use mmap
hanabi1224 Aug 29, 2023
ee6de57
refactor open_forest_car_union_db
hanabi1224 Aug 29, 2023
13eb826
Merge branch 'main' into hm/use-snapshot-file-as-db
hanabi1224 Aug 29, 2023
8db4c1c
test_prepare_and_open_forest_car_union_db
hanabi1224 Aug 29, 2023
3ec6bd6
Merge remote-tracking branch 'origin/main' into hm/use-snapshot-file-…
hanabi1224 Aug 29, 2023
596698a
change ManyCar APIs to not take mutable self
hanabi1224 Aug 29, 2023
7ab94b7
Update src/daemon/db_util.rs
hanabi1224 Aug 29, 2023
cdabf95
mmap governed by the environment variable
hanabi1224 Aug 29, 2023
8af856a
Merge remote-tracking branch 'origin/main' into hm/use-snapshot-file-…
hanabi1224 Aug 29, 2023
03d650c
fix lint
hanabi1224 Aug 29, 2023
9c2311b
doc
hanabi1224 Aug 30, 2023
b80a502
use RwLock for Vec<AnyCar> revert epoch param
hanabi1224 Aug 30, 2023
d4a1647
Merge remote-tracking branch 'origin/main' into hm/use-snapshot-file-…
hanabi1224 Aug 30, 2023
8e5b137
resolve comments
hanabi1224 Aug 30, 2023
b85ca72
rename to should_use_file_io
hanabi1224 Aug 30, 2023
c50b175
cleanup consume_snapshot_file
hanabi1224 Aug 30, 2023
8d19385
Merge branch 'main' into hm/use-snapshot-file-as-db
hanabi1224 Aug 30, 2023
d54fa61
resolve comments
hanabi1224 Aug 31, 2023
2a23e39
Merge branch 'main' into hm/use-snapshot-file-as-db
hanabi1224 Aug 31, 2023
8d6e339
resolve comments
hanabi1224 Aug 31, 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
57 changes: 28 additions & 29 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ url = { version = "2.3", features = ["serde"] }
uuid = { version = "1.3", features = ['v4'] }
walkdir = "2"
zstd = "0.12.3"
zstd-safe = "6.0.5"

[target.'cfg(unix)'.dependencies]
termios = "0.3"
Expand Down
4 changes: 4 additions & 0 deletions scripts/tests/calibnet_other_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ set -e

source "$(dirname "$0")/harness.sh"

forest_import_non_calibnet_snapshot
forest_init

echo "Verifying the non calibnet snapshot (./test-snapshots/chain4.car) is being served properly."
$FOREST_CLI_PATH chain read-obj -c bafy2bzacedjrqan2fwfvhfopi64yickki7miiksecglpeiavf7xueytnzevlu

echo "Running database garbage collection"
forest_check_db_stats
$FOREST_CLI_PATH db gc
Expand Down
5 changes: 5 additions & 0 deletions scripts/tests/harness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export TMP_DIR
export LOG_DIRECTORY
export FOREST_WALLET_PATH

function forest_import_non_calibnet_snapshot {
echo "Importing a non calibnet snapshot"
$FOREST_PATH --chain calibnet --encrypt-keystore false --halt-after-import --import-snapshot ./test-snapshots/chain4.car
}

function forest_download_and_import_snapshot {
echo "Downloading and importing snapshot"
$FOREST_PATH --chain calibnet --encrypt-keystore false --halt-after-import --height=-200 --auto-download-snapshot
Expand Down
20 changes: 20 additions & 0 deletions src/blocks/tipset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use std::{fmt, sync::OnceLock};

use crate::db::{SettingsStore, SettingsStoreExt};
use crate::ipld::FrozenCids;
use crate::networks::{calibnet, mainnet};
use crate::shim::{address::Address, clock::ChainEpoch};
Expand Down Expand Up @@ -151,6 +152,25 @@ impl Tipset {
.transpose()?)
}

/// Load the heaviest tipset from the blockstore
pub fn load_heaviest(
store: &impl Blockstore,
settings: &impl SettingsStore,
) -> anyhow::Result<Option<Tipset>> {
Ok(
match settings.read_obj::<TipsetKeys>(crate::db::setting_keys::HEAD_KEY)? {
Some(tsk) => tsk
.cids
.into_iter()
.map(|key| BlockHeader::load(store, key))
.collect::<anyhow::Result<Option<_>>>()?
.map(Tipset::new)
.transpose()?,
None => None,
},
)
}

/// Fetch a tipset from the blockstore. This calls fails if the tipset is
/// missing or invalid.
pub fn load_required(store: impl Blockstore, tsk: &TipsetKeys) -> anyhow::Result<Tipset> {
Expand Down
7 changes: 1 addition & 6 deletions src/chain/store/chain_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use super::{
tipset_tracker::TipsetTracker,
Error,
};
use crate::db::setting_keys::{ESTIMATED_RECORDS_KEY, HEAD_KEY};
use crate::db::setting_keys::HEAD_KEY;
use crate::db::{SettingsStore, SettingsStoreExt};

// A cap on the size of the future_sink
Expand Down Expand Up @@ -150,11 +150,6 @@ where
self.tipset_tracker.add(header);
}

pub fn set_estimated_records(&self, records: u64) -> anyhow::Result<()> {
self.settings.write_obj(ESTIMATED_RECORDS_KEY, &records)?;
Ok(())
}

/// Writes tipset block headers to data store and updates heaviest tipset
/// with other compatible tracked headers.
pub fn put_tipset(&self, ts: &Tipset) -> Result<(), Error> {
Expand Down
28 changes: 25 additions & 3 deletions src/cli_shared/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use std::{
str::FromStr,
};

use crate::networks::NetworkChain;
use crate::{
networks::NetworkChain,
utils::{retry, RetryArgs},
};
use anyhow::{anyhow, bail, Context as _};
use chrono::NaiveDate;
use tracing::{info, warn};
Expand Down Expand Up @@ -72,11 +75,30 @@ pub async fn fetch(
.date_and_height_and_forest();
let filename = filename(vendor, chain, date, height, forest_format);

match download_aria2c(&url, directory, &filename).await {
download_file_with_retry(&url, directory, &filename).await
}

pub async fn download_file_with_retry(
url: &Url,
directory: &Path,
filename: &str,
) -> anyhow::Result<PathBuf> {
Ok(retry(
RetryArgs {
timeout: None,
..Default::default()
},
|| download_file(url.clone(), directory, filename),
)
.await?)
}

pub async fn download_file(url: Url, directory: &Path, filename: &str) -> anyhow::Result<PathBuf> {
match download_aria2c(&url, directory, filename).await {
Ok(path) => Ok(path),
Err(AriaErr::CouldNotExec(reason)) => {
warn!(%reason, "couldn't run aria2c. Falling back to conventional download, which will be much slower - consider installing aria2c.");
download_http(url, directory, &filename).await
download_http(url, directory, filename).await
}
Err(AriaErr::Other(o)) => Err(o),
}
Expand Down
Loading