Skip to content

Commit

Permalink
fix(rpc): validate sector duration and size in StateMinerInitialPledg…
Browse files Browse the repository at this point in the history
…eForSector method
  • Loading branch information
virajbhartiya committed Dec 18, 2024
1 parent 18bf588 commit de69cfa
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/rpc/methods/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2821,6 +2821,27 @@ impl RpcMethod<4> for StateMinerInitialPledgeForSector {
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
(sector_duration, sector_size, verified_size, ApiTipsetKey(tsk)): Self::Params,
) -> Result<Self::Ok, ServerError> {
if sector_duration <= 0 {
return Err(anyhow::anyhow!("sector duration must be greater than 0").into());
}
let sec_size: u64 = match sector_size {
SectorSize::_2KiB => 2 * 1024,
SectorSize::_8MiB => 8 * 1024 * 1024,
SectorSize::_512MiB => 512 * 1024 * 1024,
SectorSize::_32GiB => 32 * 1024 * 1024 * 1024,
SectorSize::_64GiB => 64 * 1024 * 1024 * 1024,
};

if sec_size == 0 {
return Err(anyhow::anyhow!("sector size must be non-zero").into());
}

if sec_size < verified_size {
return Err(
anyhow::anyhow!("verified deal size cannot be larger than sector size").into(),
);
}

let ts = ctx.chain_store().load_required_tipset_or_heaviest(&tsk)?;

let power_state: power::State = ctx.state_manager.get_actor_state(&ts)?;
Expand Down

0 comments on commit de69cfa

Please sign in to comment.