From 20a01fa980a2078f2d144aeafb2db02dabd2f901 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Thu, 11 Jan 2024 17:02:59 +0700 Subject: [PATCH 1/3] fix(drive-abci): internal error if vote extension block is already committed --- .../rs-drive-abci/src/abci/handler/mod.rs | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/packages/rs-drive-abci/src/abci/handler/mod.rs b/packages/rs-drive-abci/src/abci/handler/mod.rs index 68f709864fe..ba9db2aefb5 100644 --- a/packages/rs-drive-abci/src/abci/handler/mod.rs +++ b/packages/rs-drive-abci/src/abci/handler/mod.rs @@ -638,12 +638,17 @@ where } = request; 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 ignored because block already committed", + height, + round, + ); + + return Ok(proto::ResponseVerifyVoteExtension { + status: VerifyStatus::Reject.into(), + }); + }; let platform_version = block_execution_context .block_platform_state() @@ -678,6 +683,8 @@ where // }); // }; + // TODO: Verify hash, height and round to make sure we have vote extension for this specific proposal + let validation_result = self.platform.check_withdrawals( &got, &expected, @@ -689,6 +696,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(), }) @@ -697,8 +710,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(), }) From 9e022ce57c2d7037edbfaf5fa0b7c263d48a2d75 Mon Sep 17 00:00:00 2001 From: Quantum Explorer Date: Thu, 11 Jan 2024 23:24:32 +0700 Subject: [PATCH 2/3] added a check --- .../rs-drive-abci/src/abci/handler/mod.rs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/rs-drive-abci/src/abci/handler/mod.rs b/packages/rs-drive-abci/src/abci/handler/mod.rs index ba9db2aefb5..f72853b17cc 100644 --- a/packages/rs-drive-abci/src/abci/handler/mod.rs +++ b/packages/rs-drive-abci/src/abci/handler/mod.rs @@ -637,6 +637,9 @@ 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 Some(block_execution_context) = guarded_block_execution_context.as_ref() else { tracing::warn!( @@ -683,7 +686,24 @@ where // }); // }; - // TODO: Verify hash, height and round to make sure we have vote extension for this specific proposal + 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 ignored 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, From 98609d13297e142757cdd37edc17bf7ba78c46c8 Mon Sep 17 00:00:00 2001 From: Quantum Explorer Date: Thu, 11 Jan 2024 23:26:01 +0700 Subject: [PATCH 3/3] changed wording --- packages/rs-drive-abci/src/abci/handler/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/rs-drive-abci/src/abci/handler/mod.rs b/packages/rs-drive-abci/src/abci/handler/mod.rs index f72853b17cc..762112baca4 100644 --- a/packages/rs-drive-abci/src/abci/handler/mod.rs +++ b/packages/rs-drive-abci/src/abci/handler/mod.rs @@ -643,7 +643,7 @@ where let guarded_block_execution_context = self.platform.block_execution_context.read().unwrap(); let Some(block_execution_context) = guarded_block_execution_context.as_ref() else { tracing::warn!( - "vote extension for height: {}, round: {} is ignored because block already committed", + "vote extension for height: {}, round: {} is rejected because we are not in a block execution phase", height, round, ); @@ -693,7 +693,7 @@ where if block_state_info.height() != height || block_state_info.round() != round { tracing::warn!( - "vote extension for height: {}, round: {} is ignored because we are at height: {} round {}", + "vote extension for height: {}, round: {} is rejected because we are at height: {} round {}", height, round, block_state_info.height(),