-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: consensus error is missing in tx results (#1458)
Co-authored-by: QuantumExplorer <[email protected]>
- Loading branch information
1 parent
a255276
commit b466524
Showing
26 changed files
with
242 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/rs-drive-abci/src/abci/handler/error/consensus.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use crate::error::Error; | ||
use dpp::consensus::ConsensusError; | ||
use dpp::platform_value::platform_value; | ||
use dpp::platform_value::string_encoding::{encode, Encoding}; | ||
use dpp::serialization::PlatformSerializableWithPlatformVersion; | ||
use dpp::version::PlatformVersion; | ||
|
||
pub trait AbciResponseInfoGetter { | ||
/// Returns a base64 encoded consensus error for Tenderdash response info | ||
fn response_info_for_version( | ||
&self, | ||
platform_version: &PlatformVersion, | ||
) -> Result<String, Error>; | ||
} | ||
|
||
impl AbciResponseInfoGetter for ConsensusError { | ||
fn response_info_for_version( | ||
&self, | ||
platform_version: &PlatformVersion, | ||
) -> Result<String, Error> { | ||
let consensus_error_bytes = self | ||
.serialize_to_bytes_with_platform_version(platform_version) | ||
.map_err(Error::Protocol)?; | ||
|
||
let error_data_buffer = platform_value!({ | ||
"data": { | ||
"serializedError": consensus_error_bytes | ||
} | ||
}) | ||
.to_cbor_buffer() | ||
.map_err(|e| Error::Protocol(e.into()))?; | ||
|
||
let encoded_info = encode(&error_data_buffer, Encoding::Base64); | ||
|
||
Ok(encoded_info) | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/rs-drive-abci/src/error/handlers.rs → ...-drive-abci/src/abci/handler/error/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
packages/rs-drive-abci/src/abci/handler/execution_result.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use crate::abci::handler::error::consensus::AbciResponseInfoGetter; | ||
use crate::error::Error; | ||
use crate::platform_types::state_transition_execution_result::StateTransitionExecutionResult; | ||
use dpp::consensus::codes::ErrorWithCode; | ||
use dpp::fee::SignedCredits; | ||
use dpp::version::PlatformVersion; | ||
use dpp::version::TryIntoPlatformVersioned; | ||
use tenderdash_abci::proto::abci::ExecTxResult; | ||
|
||
// State transitions are never free, so we should filter out SuccessfulFreeExecution | ||
// So we use an option | ||
impl TryIntoPlatformVersioned<ExecTxResult> for StateTransitionExecutionResult { | ||
type Error = Error; | ||
|
||
fn try_into_platform_versioned( | ||
self, | ||
platform_version: &PlatformVersion, | ||
) -> Result<ExecTxResult, Self::Error> { | ||
let response = match self { | ||
Self::SuccessfulPaidExecution(dry_run_fee_result, fee_result) => ExecTxResult { | ||
code: 0, | ||
data: vec![], | ||
log: "".to_string(), | ||
info: "".to_string(), | ||
gas_wanted: dry_run_fee_result.total_base_fee() as SignedCredits, | ||
gas_used: fee_result.total_base_fee() as SignedCredits, | ||
events: vec![], | ||
codespace: "".to_string(), | ||
}, | ||
Self::SuccessfulFreeExecution => ExecTxResult { | ||
code: 0, | ||
data: vec![], | ||
log: "".to_string(), | ||
info: "".to_string(), | ||
gas_wanted: 0, | ||
gas_used: 0, | ||
events: vec![], | ||
codespace: "".to_string(), | ||
}, | ||
Self::ConsensusExecutionError(validation_result) => { | ||
let error = validation_result | ||
.errors | ||
.first() | ||
.expect("invalid execution result should have a consensus error"); | ||
|
||
ExecTxResult { | ||
code: error.code(), | ||
data: vec![], | ||
log: "".to_string(), | ||
info: error.response_info_for_version(platform_version)?, | ||
gas_wanted: 0, | ||
gas_used: 0, | ||
events: vec![], | ||
codespace: "".to_string(), | ||
} | ||
} | ||
}; | ||
|
||
Ok(response) | ||
} | ||
} |
Oops, something went wrong.