Skip to content
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
35 changes: 17 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/rs-drive-abci/src/abci/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ pub enum AbciError {
#[error("finalize block received before processing from Tenderdash: {0}")]
FinalizeBlockReceivedBeforeProcessing(String),
/// Wrong finalize block received
#[error("wrong block from Tenderdash: {0}")]
WrongBlockReceived(String),
/// Wrong finalize block received
#[error("wrong finalize block from Tenderdash: {0}")]
WrongFinalizeBlockReceived(String),
/// Bad request received from Tenderdash that can't be translated to the correct size
Expand Down
43 changes: 24 additions & 19 deletions packages/rs-drive-abci/src/abci/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ use tenderdash_abci::proto::types::{CoreChainLock, VoteExtensionType};

use crate::error::execution::ExecutionError;
use crate::error::Error;
use crate::execution::block_proposal::BlockProposal;
use crate::execution::engine::BlockExecutionOutcome;

use super::withdrawal::WithdrawalTxs;
Expand Down Expand Up @@ -93,6 +94,28 @@ where
&self,
request: RequestPrepareProposal,
) -> Result<ResponsePrepareProposal, ResponseException> {
// We should get the latest CoreChainLock from core
// It is possible that we will not get a chain lock from core, in this case, just don't
// propose one
// This is done before all else

let core_chain_lock_update = match self.platform.core_rpc.get_best_chain_lock() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should also check in ProcessProposal if received core chain lock height is valid

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah there's a todo there already.

Ok(latest_chain_lock) => {
if request.core_chain_locked_height < latest_chain_lock.core_block_height {
Some(latest_chain_lock)
} else {
None
}
}
Err(_) => None,
};

let mut block_proposal: BlockProposal = (&request).try_into()?;

if let Some(core_chain_lock_update) = core_chain_lock_update.as_ref() {
block_proposal.core_chain_locked_height = core_chain_lock_update.core_block_height;
}

let transaction_guard = if request.height == self.platform.config.abci.genesis_height as i64
{
// special logic on init chain
Expand All @@ -110,7 +133,7 @@ where
// Running the proposal executes all the state transitions for the block
let run_result = self
.platform
.run_block_proposal((&request).try_into()?, transaction)?;
.run_block_proposal(block_proposal, transaction)?;

if !run_result.is_valid() {
// This is a system error, because we are proposing
Expand Down Expand Up @@ -151,24 +174,6 @@ where

let tx_results = tx_results.into_iter().flatten().collect();

// We should get the latest CoreChainLock from core
// It is possible that we will not get a chain lock from core, in this case, just don't
// propose one

let core_chain_lock_update = match self.platform.core_rpc.get_best_chain_lock() {
Ok(latest_chain_lock) => {
if request.core_chain_locked_height < latest_chain_lock.core_block_height {
Some(latest_chain_lock)
} else {
None
}
}
Err(_) => None,
};

// Next we should check for validator set updates
// todo: validator set updates

// TODO: implement all fields, including tx processing; for now, just leaving bare minimum
let response = ResponsePrepareProposal {
tx_results,
Expand Down
8 changes: 6 additions & 2 deletions packages/rs-drive-abci/src/abci/mimic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl<'a, C: CoreRPCLike> AbciApplication<'a, C> {
let BlockInfo {
time_ms,
height,
core_height,
mut core_height,
epoch: _,
} = block_info;

Expand Down Expand Up @@ -95,10 +95,14 @@ impl<'a, C: CoreRPCLike> AbciApplication<'a, C> {
app_hash,
tx_results,
consensus_param_updates: _,
core_chain_lock_update: _,
core_chain_lock_update,
validator_set_update,
} = response_prepare_proposal;

if let Some(core_chain_lock_update) = core_chain_lock_update.as_ref() {
core_height = core_chain_lock_update.core_block_height;
}

if !expect_validation_errors {
if tx_results.len() != tx_records.len() {
return Err(Error::Abci(AbciError::GenericWithCode(0)));
Expand Down
11 changes: 8 additions & 3 deletions packages/rs-drive-abci/src/execution/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ where
// First let's check that this is the follower to a previous block
if !block_state_info.next_block_to(last_block_height, last_block_core_height)? {
// we are on the wrong height or round
return Ok(ValidationResult::new_with_error(AbciError::WrongFinalizeBlockReceived(format!(
return Ok(ValidationResult::new_with_error(AbciError::WrongBlockReceived(format!(
"received a block proposal for height: {} core height: {}, current height: {} core height: {}",
block_state_info.height, block_state_info.core_chain_locked_height, last_block_height, last_block_core_height
)).into()));
Expand Down Expand Up @@ -679,8 +679,13 @@ where
)? {
// we are on the wrong height or round
validation_result.add_error(AbciError::WrongFinalizeBlockReceived(format!(
"received a block for h: {} r: {}, expected h: {} r: {}",
height, round, block_state_info.height, block_state_info.round
"received a block for h: {} r: {} c-h: {}, expected h: {} r: {} c-h: {}",
height,
round,
block_header.core_chain_locked_height,
block_state_info.height,
block_state_info.round,
block_state_info.core_chain_locked_height
)));
return Ok(validation_result.into());
}
Expand Down
4 changes: 2 additions & 2 deletions packages/rs-drive-abci/tests/strategy_tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ pub fn generate_test_masternodes(
service: SocketAddr::from_str(format!("1.0.{}.{}:1234", i / 256, i % 256).as_str())
.unwrap(),
registered_height: 0,
pose_revived_height: 0,
pose_revived_height: None,
pose_ban_height: None,
revocation_reason: 0,
owner_address: rng.gen::<[u8; 20]>(),
Expand Down Expand Up @@ -1090,7 +1090,7 @@ pub fn generate_test_masternodes(
service: SocketAddr::from_str(format!("1.1.{}.{}:1234", i / 256, i % 256).as_str())
.unwrap(),
registered_height: 0,
pose_revived_height: 0,
pose_revived_height: None,
pose_ban_height: None,
revocation_reason: 0,
owner_address: rng.gen::<[u8; 20]>(),
Expand Down