Repository navigation
test(devnet): miner integration test for sector termination #7874
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
Open
sudo-shashank
wants to merge
4
commits into
main
Choose a base branch
from
shashank/miner-test-terminate
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+278
−5
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| // Copyright 2019-2026 ChainSafe Systems | ||
| // SPDX-License-Identifier: Apache-2.0, MIT | ||
|
|
||
| //! Early termination of a pledged CC sector through Forest's RPC and VM. | ||
| //! | ||
| //! lotus-miner locates the sector via Forest, then sends `TerminateSectors`. | ||
| //! | ||
| //! Mirrors Lotus | ||
| //! [`TestTerminate`](https://github.com/filecoin-project/lotus/blob/v1.39.1/itests/sector_terminate_test.go#L35). | ||
| //! Terminates a pledged sector on the genesis miner (not a pre-seal), so block | ||
| //! production stays intact. | ||
|
|
||
| use super::api::TestMiner; | ||
| use super::devnet::{At, Devnet}; | ||
| use crate::dev::subcommands::tests_cmd::helpers::{ | ||
| block_on, poll, poll_until_message_executed, trial, | ||
| }; | ||
| use crate::rpc::prelude::*; | ||
| use crate::shim::address::Address; | ||
| use crate::shim::sector::SectorSize; | ||
| use anyhow::{Context as _, ensure}; | ||
| use libtest_mimic::Trial; | ||
| use num::BigInt; | ||
|
|
||
| pub(super) fn tests() -> Vec<Trial> { | ||
| vec![trial("terminate::pledged_sector", || { | ||
| block_on(pledged_sector()) | ||
| })] | ||
| } | ||
|
|
||
| async fn pledged_sector() -> anyhow::Result<()> { | ||
| let net = Devnet::connect()?; | ||
| let miner = TestMiner::genesis()?; | ||
|
|
||
| let at = net.synced().await?; | ||
| let before = at | ||
| .same(|tsk| StateMinerPower::request((miner.actor, tsk))) | ||
| .await?; | ||
| let info = at | ||
| .same(|tsk| StateMinerInfo::request((miner.actor, tsk))) | ||
| .await?; | ||
| ensure!( | ||
| info.sector_size == SectorSize::_2KiB, | ||
| "expected a 2 KiB miner, got {:?}", | ||
| info.sector_size | ||
| ); | ||
| let sector_power = BigInt::from(SectorSize::_2KiB as u64); | ||
|
|
||
| let sector = miner.api.pledge_sector().await?; | ||
| miner.api.wait_until_proving(sector).await?; | ||
|
|
||
| let location = net | ||
| .synced() | ||
| .await? | ||
| .same(|tsk| StateSectorPartition::request((miner.actor, sector, tsk))) | ||
| .await?; | ||
| let at = wait_for_sector_power( | ||
| &net, | ||
| miner.actor, | ||
| sector, | ||
| &before.miner_power.raw_byte_power, | ||
| ) | ||
| .await?; | ||
| let powered = at | ||
| .same(|tsk| StateMinerPower::request((miner.actor, tsk))) | ||
| .await?; | ||
| let expected_powered = &before.miner_power.raw_byte_power + §or_power; | ||
| ensure!( | ||
| powered.miner_power.raw_byte_power == expected_powered, | ||
| "after proving sector {sector}, raw power is {}, expected {expected_powered}", | ||
| powered.miner_power.raw_byte_power | ||
| ); | ||
|
|
||
| miner.api.terminate_sector(sector).await?; | ||
| let terminate_cid = miner.api.wait_until_terminated(sector).await?; | ||
|
sudo-shashank marked this conversation as resolved.
Resolved
|
||
| let lookup = poll_until_message_executed(&net.forest, terminate_cid).await?; | ||
| ensure!( | ||
| lookup.receipt.exit_code().is_success(), | ||
| "TerminateSectors {terminate_cid} exited {}", | ||
| lookup.receipt.exit_code() | ||
| ); | ||
| let at = net.synced().await?; | ||
| let after = at | ||
| .same(|tsk| StateMinerPower::request((miner.actor, tsk))) | ||
| .await?; | ||
| ensure!( | ||
| after.miner_power.raw_byte_power == before.miner_power.raw_byte_power, | ||
| "after terminating sector {sector}, raw power is {}, expected the pre-pledge {}", | ||
| after.miner_power.raw_byte_power, | ||
| before.miner_power.raw_byte_power | ||
| ); | ||
|
|
||
| let partitions = at | ||
| .same(|tsk| StateMinerPartitions::request((miner.actor, location.deadline, tsk))) | ||
| .await?; | ||
| let partition = partitions | ||
| .get(usize::try_from(location.partition)?) | ||
| .with_context(|| { | ||
| format!( | ||
| "deadline {} lost partition {} after terminate", | ||
| location.deadline, location.partition | ||
| ) | ||
| })?; | ||
| ensure!( | ||
| partition.all_sectors.get(sector), | ||
| "sector {sector} missing from AllSectors after terminate" | ||
| ); | ||
| ensure!( | ||
| !partition.live_sectors.get(sector), | ||
| "sector {sector} still in LiveSectors after terminate" | ||
| ); | ||
| ensure!( | ||
| !partition.active_sectors.get(sector), | ||
| "sector {sector} still in ActiveSectors after terminate" | ||
| ); | ||
| Ok(()) | ||
| } | ||
|
|
||
| /// Waits until `miner`'s raw power is `baseline` plus one 2 KiB sector, waiting through the | ||
| /// sector's next deadline close when prove-commit has not added power yet. | ||
| async fn wait_for_sector_power<'a>( | ||
| net: &'a Devnet, | ||
| miner: Address, | ||
| sector: u64, | ||
| baseline: &BigInt, | ||
| ) -> anyhow::Result<At<'a>> { | ||
| let target = baseline + BigInt::from(SectorSize::_2KiB as u64); | ||
| let at = net.synced().await?; | ||
| let power = at | ||
| .same(|tsk| StateMinerPower::request((miner, tsk))) | ||
| .await?; | ||
| if power.miner_power.raw_byte_power >= target { | ||
| return Ok(at); | ||
| } | ||
|
|
||
| let location = at | ||
| .same(|tsk| StateSectorPartition::request((miner, sector, tsk))) | ||
| .await?; | ||
| let current = at | ||
| .same(|tsk| StateMinerProvingDeadline::request((miner, tsk))) | ||
| .await? | ||
| .0; | ||
| let deadline = current.for_index(location.deadline).next_not_elapsed(); | ||
| eprintln!( | ||
| "raw power still {}; waiting for deadline {} to close at epoch {} so WindowPoSt can claim sector {sector}", | ||
| power.miner_power.raw_byte_power, location.deadline, deadline.close | ||
| ); | ||
| net.wait_for_epoch(deadline.close).await?; | ||
| poll( | ||
| &format!( | ||
| "raw power {target} after deadline {} for sector {sector}", | ||
| location.deadline | ||
| ), | ||
| || async { | ||
| let at = net.synced().await?; | ||
| let power = at | ||
| .same(|tsk| StateMinerPower::request((miner, tsk))) | ||
| .await?; | ||
| Ok((power.miner_power.raw_byte_power >= target).then_some(at)) | ||
| }, | ||
| ) | ||
| .await | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.