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

Fix ExitCode Handling in load_deadline #1050

Merged
merged 3 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions blockchain/chain_sync/src/sync_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use forest_libp2p::chain_exchange::TipsetBundle;
use futures::stream::{FuturesUnordered, StreamExt};
use interpreter::price_list_by_epoch;
use ipld_blockstore::BlockStore;
use log::{debug, info, warn};
use log::{debug, error, info, warn};
use message::{Message, UnsignedMessage};
use networks::{get_network_version_default, BLOCK_DELAY_SECS, UPGRADE_SMOKE_HEIGHT};
use state_manager::StateManager;
Expand Down Expand Up @@ -94,7 +94,7 @@ where
Ok(()) => *state.lock().await = ChainSyncState::Follow,
Err(e) => {
let err = e.to_string();
warn!("failed to sync tipset: {}", &err);
error!("failed to sync tipset: {}", &err);
self.state.write().await.error(err);
}
}
Expand Down
24 changes: 10 additions & 14 deletions vm/actor/src/builtin/miner/deadline_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,22 @@ impl Deadlines {
&self,
store: &BS,
deadline_idx: usize,
) -> Result<Deadline, ActorError> {
) -> Result<Deadline, Box<dyn StdError>> {
if deadline_idx >= WPOST_PERIOD_DEADLINES as usize {
return Err(actor_error!(
return Err(Box::new(actor_error!(
ErrIllegalArgument,
"invalid deadline {}",
deadline_idx
));
)));
}

store
.get(&self.due[deadline_idx])
.ok()
.flatten()
.ok_or_else(|| {
actor_error!(
ErrIllegalState,
"failed to lookup deadline {}",
deadline_idx
)
})
Ok(store.get(&self.due[deadline_idx])?.ok_or_else(|| {
Box::new(actor_error!(
ErrIllegalState,
"failed to lookup deadline {}",
deadline_idx
))
})?)
}

pub fn for_each<BS: BlockStore>(
Expand Down
54 changes: 39 additions & 15 deletions vm/actor/src/builtin/miner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,12 @@ impl Actor {

let mut deadline = deadlines
.load_deadline(rt.store(), params.deadline)
.map_err(|e| e.wrap(format!("failed to load deadline {}", params.deadline)))?;
.map_err(|e| {
e.downcast_default(
ExitCode::ErrIllegalState,
format!("failed to load deadline {}", params.deadline),
)
})?;

// Record proven sectors/partitions, returning updates to power and the final set of sectors
// proven/skipped.
Expand Down Expand Up @@ -734,7 +739,9 @@ impl Actor {

let mut dl_current = deadlines_current
.load_deadline(rt.store(), params.deadline)
.map_err(|e| e.wrap("failed to load deadline"))?;
.map_err(|e| {
e.downcast_default(ExitCode::ErrIllegalState, "failed to load deadline")
})?;

// Take the post from the snapshot for dispute.
// This operation REMOVES the PoSt from the snapshot so
Expand Down Expand Up @@ -1721,9 +1728,12 @@ impl Actor {
let mut pledge_delta = TokenAmount::zero();

for deadline_idx in deadlines_to_load {
let mut deadline = deadlines
.load_deadline(store, deadline_idx)
.map_err(|e| e.wrap(format!("failed to load deadline {}", deadline_idx)))?;
let mut deadline = deadlines.load_deadline(store, deadline_idx).map_err(|e| {
e.downcast_default(
ExitCode::ErrIllegalState,
format!("failed to load deadline {}", deadline_idx),
)
})?;

let mut partitions = deadline.partitions_amt(store).map_err(|e| {
e.downcast_default(
Expand Down Expand Up @@ -2004,9 +2014,12 @@ impl Actor {
}

let quant = state.quant_spec_for_deadline(deadline_idx);
let mut deadline = deadlines
.load_deadline(store, deadline_idx)
.map_err(|e| e.wrap(format!("failed to load deadline {}", deadline_idx)))?;
let mut deadline = deadlines.load_deadline(store, deadline_idx).map_err(|e| {
e.downcast_default(
ExitCode::ErrIllegalState,
format!("failed to load deadline {}", deadline_idx),
)
})?;

let removed_power = deadline
.terminate_sectors(
Expand Down Expand Up @@ -2157,9 +2170,12 @@ impl Actor {
)
})?;

let mut deadline = deadlines
.load_deadline(store, deadline_idx)
.map_err(|e| e.wrap(format!("failed to load deadline {}", deadline_idx)))?;
let mut deadline = deadlines.load_deadline(store, deadline_idx).map_err(|e| {
e.downcast_default(
ExitCode::ErrIllegalState,
format!("failed to load deadline {}", deadline_idx),
)
})?;

let fault_expiration_epoch = target_deadline.last() + FAULT_MAX_AGE;

Expand Down Expand Up @@ -2308,9 +2324,12 @@ impl Actor {
)
})?;

let mut deadline = deadlines
.load_deadline(store, deadline_idx)
.map_err(|e| e.wrap(format!("failed to load deadline {}", deadline_idx)))?;
let mut deadline = deadlines.load_deadline(store, deadline_idx).map_err(|e| {
e.downcast_default(
ExitCode::ErrIllegalState,
format!("failed to load deadline {}", deadline_idx),
)
})?;

deadline
.declare_faults_recovered(store, &sectors, info.sector_size, partition_map)
Expand Down Expand Up @@ -2430,7 +2449,12 @@ impl Actor {

let mut deadline = deadlines
.load_deadline(store, params_deadline)
.map_err(|e| e.wrap(format!("failed to load deadline {}", params_deadline)))?;
.map_err(|e| {
e.downcast_default(
ExitCode::ErrIllegalState,
format!("failed to load deadline {}", params_deadline),
)
})?;

let (live, dead, removed_power) = deadline
.remove_partitions(store, partitions, quant)
Expand Down