Skip to content

Commit

Permalink
refactor: get protocol version from block execution outcome
Browse files Browse the repository at this point in the history
  • Loading branch information
shumkov committed Oct 10, 2023
1 parent 7b58fda commit b8bd80f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
22 changes: 8 additions & 14 deletions packages/rs-drive-abci/src/abci/handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use crate::rpc::core::CoreRPCLike;
use dpp::errors::consensus::codes::ErrorWithCode;
use tenderdash_abci::proto::abci::response_verify_vote_extension::VerifyStatus;
use tenderdash_abci::proto::abci::tx_record::TxAction;
use tenderdash_abci::proto::abci::{self as proto};
use tenderdash_abci::proto::abci::{self as proto, ResponseException};
use tenderdash_abci::proto::abci::{
ExecTxResult, RequestCheckTx, RequestFinalizeBlock, RequestInitChain, RequestPrepareProposal,
RequestProcessProposal, RequestQuery, ResponseCheckTx, ResponseFinalizeBlock,
Expand Down Expand Up @@ -200,13 +200,6 @@ where

let transaction = transaction_guard.as_ref().unwrap();

// Get current platform version
let state = self.platform.state.read().expect("expected to get state");
let current_protocol_version = state.current_protocol_version_in_consensus();
drop(state);
let platform_version = PlatformVersion::get(current_protocol_version)
.map_err(|e| proto::ResponseException::from(Error::from(e)))?;

// Running the proposal executes all the state transitions for the block
let run_result = self
.platform
Expand All @@ -221,8 +214,12 @@ where
app_hash,
state_transition_results,
validator_set_update,
protocol_version,
} = run_result.into_data().map_err(Error::Protocol)?;

let platform_version = PlatformVersion::get(protocol_version)
.expect("must be set in run block proposal from existing protocol version");

// We need to let Tenderdash know about the transactions we should remove from execution
let mut tx_results = Vec::new();
let mut tx_records = Vec::new();
Expand Down Expand Up @@ -389,14 +386,11 @@ where
app_hash,
state_transition_results,
validator_set_update,
protocol_version,
} = run_result.into_data().map_err(Error::Protocol)?;

// Get current platform version
let state = self.platform.state.read().expect("expected to get state");
let current_protocol_version = state.current_protocol_version_in_consensus();
drop(state);
let platform_version = PlatformVersion::get(current_protocol_version)
.map_err(|e| proto::ResponseException::from(Error::from(e)))?;
let platform_version = PlatformVersion::get(protocol_version)
.expect("must be set in run block proposer from existing platform version");

let tx_results = state_transition_results
.into_iter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ where
app_hash: root_hash,
state_transition_results,
validator_set_update,
protocol_version: platform_version.protocol_version,
},
))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::abci::AbciError;
use crate::platform_types::state_transition_execution_result::StateTransitionExecutionResult;
use dpp::util::deserializer::ProtocolVersion;
use dpp::validation::SimpleValidationResult;
use tenderdash_abci::proto::abci::ValidatorSetUpdate;

Expand All @@ -14,6 +15,8 @@ pub struct BlockExecutionOutcome {
/// The changes to the validator set
// TODO We should use another DTO, only abci module should deal with Tenderdash proto structures
pub validator_set_update: Option<ValidatorSetUpdate>,
/// Current block protocol version
pub protocol_version: ProtocolVersion,
}

/// The outcome of the finalization of the block
Expand Down

0 comments on commit b8bd80f

Please sign in to comment.