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(tool): forest-tool api generate-test-snapshot #5074

Open
wants to merge 27 commits into
base: main
Choose a base branch
from

Conversation

hanabi1224
Copy link
Contributor

@hanabi1224 hanabi1224 commented Dec 11, 2024

Summary of changes

This PR includes changes in #5034

Changes introduced in this pull request:

  • forest-tool api generate-test-snapshot
  • forest-tool api test
  • a few RPC unit tests (to be expanded with the manual steps below)

(Will use a separate PR to add below steps to dev docs)

Step 1: generating RPC test dumps

forest-tool api compare --dump-dir /var/tmp/rpc-dumps ...

Step 2: generate RPC test snapshots

forest-tool api generate-test-snapshot --db ~/.local/share/forest/calibnet/0.23.0 --chain calibnet --out-dir /var/tmp/rpc-snapshots /var/tmp/test-dumps/filecoin_stategetallallocations*.json

Step 2(b): zstd compress test snapshots

cd /var/tmp/rpc-snapshots
zstd *.json

Step 3: verify test snapshots

forest-tool api test /var/tmp/rpc-snapshots/*.json or forest-tool api test /var/tmp/rpc-snapshots/*.zst

Step 3(b): update unit test

  • upload test snapshots to DO space
  • update test_snapshots.txt
  • cargo test --lib -- --test rpc_regression_tests --nocapture

Reference issue to close (if applicable)

Closes #5034

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation. All new code adheres to the team's documentation standards,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

@hanabi1224 hanabi1224 force-pushed the hm/forest-tool-api-generate-test-snapshot branch from 7696c1a to f496aed Compare December 11, 2024 15:10
@hanabi1224 hanabi1224 force-pushed the hm/forest-tool-api-generate-test-snapshot branch from f496aed to 91e4716 Compare December 11, 2024 23:46
@hanabi1224 hanabi1224 marked this pull request as ready for review December 12, 2024 09:28
@hanabi1224 hanabi1224 requested a review from a team as a code owner December 12, 2024 09:28
@hanabi1224 hanabi1224 requested review from lemmih and sudo-shashank and removed request for a team December 12, 2024 09:28
@hanabi1224 hanabi1224 changed the title [WIP] feat(tool): forest-tool api generate-test-snapshot feat(tool): forest-tool api generate-test-snapshot Dec 12, 2024
Copy link
Contributor

@lemmih lemmih left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The format of the memory-db is not stable. If someone changes the memory-db internals, this code will fail. We'll either have to deal with it right now or in the future. I vote to deal with it right now.

@hanabi1224 hanabi1224 marked this pull request as draft December 13, 2024 12:24
Copy link

cloudflare-workers-and-pages bot commented Dec 16, 2024

Deploying forest-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: f69ad6e
Status: ✅  Deploy successful!
Preview URL: https://5597b3fc.forest-824.pages.dev
Branch Preview URL: https://hm-forest-tool-api-generate.forest-824.pages.dev

View logs

@hanabi1224 hanabi1224 marked this pull request as ready for review December 16, 2024 08:27
@hanabi1224
Copy link
Contributor Author

The format of the memory-db is not stable. If someone changes the memory-db internals, this code will fail. We'll either have to deal with it right now or in the future. I vote to deal with it right now.

@lemmih Switched to Forest CAR DB as discussed.

@hanabi1224 hanabi1224 force-pushed the hm/forest-tool-api-generate-test-snapshot branch from 827e63a to 18089eb Compare December 16, 2024 08:31
@hanabi1224 hanabi1224 requested a review from elmattic December 17, 2024 01:57
Comment on lines +28 to +54
pub async fn export_forest_car<W: tokio::io::AsyncWrite + Unpin>(
&self,
writer: &mut W,
) -> anyhow::Result<()> {
let roots =
SettingsStoreExt::read_obj::<TipsetKey>(self, crate::db::setting_keys::HEAD_KEY)?
.context("chain head is not tracked and cannot be exported")?
.into_cids();
let blocks = {
let blockchain_db = self.blockchain_db.read();
let blockchain_persistent_db = self.blockchain_persistent_db.read();
blockchain_db
.iter()
.chain(blockchain_persistent_db.iter())
.map(|(&cid, data)| {
anyhow::Ok(CarBlock {
cid,
data: data.clone(),
})
})
.collect_vec()
};
let frames =
crate::db::car::forest::Encoder::compress_stream_default(futures::stream::iter(blocks));
crate::db::car::forest::Encoder::write(writer, roots, frames).await
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we contrive a unit test for this functionality?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, unit test added.

Comment on lines +151 to +152
#[arg(num_args = 1.., required = true)]
test_dump_files: Vec<PathBuf>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's have docs for this as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment on lines +173 to +174
#[arg(num_args = 1.., required = true)]
files: Vec<PathBuf>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's have docs for this as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

CurrentNetwork::set_global(Network::Testnet);
}
let mut run = false;
let chain_config = Arc::new(ChainConfig::calibnet());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The chain config should depend on the chain parameter, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, fixed!

}

fn setting_keys(&self) -> anyhow::Result<Vec<String>> {
// HACKHACK: may need some care
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great to elaborate on why the care might be needed as a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved or removed all HACKHACKs, methods that read settings are no longer supported after migrating DB snapshot to CAR format.

Comment on lines 146 to 170
#[tokio::test]
async fn rpc_regression_tests() {
let urls = include_str!("test_snapshots.txt")
.trim()
.split("\n")
.filter_map(|n| {
Url::parse(
format!("https://forest-snapshots.fra1.digitaloceanspaces.com/rpc_test/{n}")
.as_str(),
)
.ok()
})
.collect_vec();
for url in urls {
print!("Testing {url} ...");
let tmp_dir = tempfile::tempdir().unwrap();
let tmp = tempfile::NamedTempFile::new_in(&tmp_dir)
.unwrap()
.into_temp_path();
println!("start downloading at {}", tmp.display());
download_to(&url, &tmp).await.unwrap();
println!("done downloading {}", tmp.display());
run_test_from_snapshot(&tmp).await.unwrap();
println!(" succeeded.");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, each test invocation will temporarily download the snapshots. The total snapshot size currently is around 4 MB, but I can easily see it going higher once we add more snapshots. This will be a pain for someone on a worse connection just trying to run tests.

Perhaps we could add something like /.local/share/forest-dev/rpc-regression-snapshots persistent path (it would vary from system to system, we could re-use the logic we have for the DB).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cache implemented.

Copy link
Member

@LesnyRumcajs LesnyRumcajs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff

@hanabi1224 hanabi1224 force-pushed the hm/forest-tool-api-generate-test-snapshot branch from 75caaf6 to c469b88 Compare January 10, 2025 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants