Skip to content

fix(drive-abci)!: internal error if vote extension block is already committed #1663

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

Merged
merged 4 commits into from
Jan 11, 2024
Merged
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
49 changes: 42 additions & 7 deletions packages/rs-drive-abci/src/abci/handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,13 +637,21 @@ where
..
} = request;

let height: u64 = height as u64;
let round: u32 = round as u32;

let guarded_block_execution_context = self.platform.block_execution_context.read().unwrap();
let block_execution_context =
guarded_block_execution_context
.as_ref()
.ok_or(Error::Execution(ExecutionError::CorruptedCodeExecution(
"block execution context must be set in block begin handler for verify vote extension",
)))?;
let Some(block_execution_context) = guarded_block_execution_context.as_ref() else {
tracing::warn!(
"vote extension for height: {}, round: {} is rejected because we are not in a block execution phase",
height,
round,
);

return Ok(proto::ResponseVerifyVoteExtension {
status: VerifyStatus::Reject.into(),
});
};

let platform_version = block_execution_context
.block_platform_state()
Expand Down Expand Up @@ -678,6 +686,25 @@ where
// });
// };

let block_state_info = block_execution_context.block_state_info();

//// Verification that vote extension is for our current executed block
// When receiving the vote extension, we need to make sure that info matches our current block

if block_state_info.height() != height || block_state_info.round() != round {
tracing::warn!(
"vote extension for height: {}, round: {} is rejected because we are at height: {} round {}",
height,
round,
block_state_info.height(),
block_state_info.round()
);

return Ok(proto::ResponseVerifyVoteExtension {
status: VerifyStatus::Reject.into(),
});
}

let validation_result = self.platform.check_withdrawals(
&got,
&expected,
Expand All @@ -689,6 +716,12 @@ where
)?;

if validation_result.is_valid() {
tracing::debug!(
"vote extension for height: {}, round: {} is successfully verified",
height,
round,
);

Ok(proto::ResponseVerifyVoteExtension {
status: VerifyStatus::Accept.into(),
})
Expand All @@ -697,8 +730,10 @@ where
?got,
?expected,
?validation_result.errors,
"vote extension mismatch"
"vote extension for height: {}, round: {} mismatch",
height, round
);

Ok(proto::ResponseVerifyVoteExtension {
status: VerifyStatus::Reject.into(),
})
Expand Down