Skip to content

Commit 6af65f0

Browse files
authored
fix: no proposal rejections for status mismatch (#634)
1 parent e88a530 commit 6af65f0

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

fendermint/vm/interpreter/src/chain.rs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,10 @@ where
350350
// We start a blockstore transaction that can be reverted
351351
state.state_tree_mut().begin_transaction();
352352
for item in local_finalized_blobs.iter() {
353-
if is_blob_finalized(&mut state, item.subscriber, item.hash, item.id.clone())? {
354-
tracing::debug!(hash = %item.hash, "blob already finalized on chain; removing from pool");
353+
let (finalized, status) =
354+
is_blob_finalized(&mut state, item.subscriber, item.hash, item.id.clone())?;
355+
if finalized {
356+
tracing::debug!(hash = %item.hash, "blob already finalized on chain (status={:?}); removing from pool", status);
355357
atomically(|| chain_env.blob_pool.remove_task(item)).await;
356358
// Remove the result from the pool
357359
atomically(|| chain_env.blob_pool.remove_result(item)).await;
@@ -647,9 +649,11 @@ where
647649
ChainMessage::Ipc(IpcMessage::BlobPending(blob)) => {
648650
// Check that blobs that are being enqueued are still in "added" state in the actor
649651
// Once we enqueue a blob, the actor will transition it to "pending" state.
650-
if !is_blob_added(&mut state, blob.subscriber, blob.hash, blob.id)? {
651-
tracing::warn!(hash = %blob.hash, "blob is not added onchain; rejecting proposal");
652-
return Ok(false);
652+
let (added, status) = with_state_transaction(&mut state, |state| {
653+
is_blob_added(state, blob.subscriber, blob.hash, blob.id)
654+
})?;
655+
if !added {
656+
tracing::warn!(hash = %blob.hash, "blob is not added onchain (status={:?})", status);
653657
}
654658

655659
// Reject the proposal if the current processor is not keeping up with blob
@@ -664,12 +668,12 @@ where
664668
// Ensure that the blob is ready to be included on-chain.
665669
// We can accept the proposal if the blob has reached a global quorum and is
666670
// not yet finalized.
667-
let is_blob_finalized = with_state_transaction(&mut state, |state| {
668-
is_blob_finalized(state, blob.subscriber, blob.hash, blob.id.clone())
669-
})?;
671+
let (is_blob_finalized, status) =
672+
with_state_transaction(&mut state, |state| {
673+
is_blob_finalized(state, blob.subscriber, blob.hash, blob.id.clone())
674+
})?;
670675
if is_blob_finalized {
671-
tracing::warn!(hash = %blob.hash, "blob is already finalized on chain; rejecting proposal");
672-
return Ok(false);
676+
tracing::warn!(hash = %blob.hash, "blob is already finalized on chain (status={:?}))", status);
673677
}
674678

675679
let (is_globally_finalized, succeeded) = atomically(|| {
@@ -717,10 +721,11 @@ where
717721
}
718722
ChainMessage::Ipc(IpcMessage::ReadRequestPending(read_request)) => {
719723
// Check that the read request is still open
720-
let status = get_read_request_status(&mut state, read_request.id)?;
724+
let status = with_state_transaction(&mut state, |state| {
725+
get_read_request_status(state, read_request.id)
726+
})?;
721727
if !matches!(status, Some(ReadRequestStatus::Open)) {
722-
tracing::warn!(request_id = %read_request.id, "read request is not open; rejecting proposal");
723-
return Ok(false);
728+
tracing::warn!(request_id = %read_request.id, "read request is not open");
724729
}
725730

726731
// Reject the proposal if the current processor is not keeping up with read
@@ -739,8 +744,7 @@ where
739744
get_read_request_status(state, read_request.id)
740745
})?;
741746
if !matches!(status, Some(ReadRequestStatus::Pending)) {
742-
tracing::warn!(hash = %read_request.id, "only pending read requests can be closed; rejecting proposal");
743-
return Ok(false);
747+
tracing::warn!(hash = %read_request.id, "only pending read requests can be closed");
744748
}
745749

746750
let read_response = read_request.response.clone();
@@ -1398,23 +1402,23 @@ where
13981402
.map_err(|e| anyhow!("error parsing blob status: {e}"))
13991403
}
14001404

1401-
/// Check if a blob is in added state, by reading its on-chain state.
1405+
/// Check if a blob is in the added state, by reading its on-chain state.
14021406
fn is_blob_added<DB>(
14031407
state: &mut FvmExecState<ReadOnlyBlockstore<DB>>,
14041408
subscriber: Address,
14051409
hash: Hash,
14061410
id: SubscriptionId,
1407-
) -> anyhow::Result<bool>
1411+
) -> anyhow::Result<(bool, Option<BlobStatus>)>
14081412
where
14091413
DB: Blockstore + Clone + 'static + Send + Sync,
14101414
{
14111415
let status = get_blob_status(state, subscriber, hash, id)?;
1412-
let added = if let Some(status) = status {
1416+
let added = if let Some(status) = status.clone() {
14131417
matches!(status, BlobStatus::Added)
14141418
} else {
14151419
false
14161420
};
1417-
Ok(added)
1421+
Ok((added, status))
14181422
}
14191423

14201424
/// Check if a blob is finalized (if it is resolved or failed), by reading its on-chain state.
@@ -1423,17 +1427,17 @@ fn is_blob_finalized<DB>(
14231427
subscriber: Address,
14241428
hash: Hash,
14251429
id: SubscriptionId,
1426-
) -> anyhow::Result<bool>
1430+
) -> anyhow::Result<(bool, Option<BlobStatus>)>
14271431
where
14281432
DB: Blockstore + Clone + 'static + Send + Sync,
14291433
{
14301434
let status = get_blob_status(state, subscriber, hash, id)?;
1431-
let finalized = if let Some(status) = status {
1435+
let finalized = if let Some(status) = status.clone() {
14321436
matches!(status, BlobStatus::Resolved | BlobStatus::Failed)
14331437
} else {
14341438
false
14351439
};
1436-
Ok(finalized)
1440+
Ok((finalized, status))
14371441
}
14381442

14391443
/// Returns credit and blob stats from on-chain state.

0 commit comments

Comments
 (0)