Skip to content

Commit

Permalink
fix!: replay issue when round is 0 on replay. (#2091)
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumExplorer authored Aug 30, 2024
1 parent 327b709 commit 20f692d
Show file tree
Hide file tree
Showing 26 changed files with 91,322 additions and 190 deletions.
36 changes: 18 additions & 18 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion packages/rs-dpp/src/identity/identity_public_key/key_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ lazy_static! {
(KeyType::ECDSA_SECP256K1, 33),
(KeyType::BLS12_381, 48),
(KeyType::ECDSA_HASH160, 20),
(KeyType::BIP13_SCRIPT_HASH, 20)
(KeyType::BIP13_SCRIPT_HASH, 20),
(KeyType::EDDSA_25519_HASH160, 20)
]
.iter()
.copied()
Expand Down
15 changes: 10 additions & 5 deletions packages/rs-drive-abci/src/abci/handler/prepare_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::platform_types::state_transitions_processing_result::StateTransitionE
use crate::rpc::core::CoreRPCLike;
use dpp::dashcore::hashes::Hash;
use dpp::version::TryIntoPlatformVersioned;
use drive::grovedb_storage::Error::{RocksDBError, StorageError};

Check warning on line 12 in packages/rs-drive-abci/src/abci/handler/prepare_proposal.rs

View workflow job for this annotation

GitHub Actions / Rust packages (drive-abci) / Linting

unused import: `StorageError`

warning: unused import: `StorageError` --> packages/rs-drive-abci/src/abci/handler/prepare_proposal.rs:12:51 | 12 | use drive::grovedb_storage::Error::{RocksDBError, StorageError}; | ^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default
use tenderdash_abci::proto::abci as proto;
use tenderdash_abci::proto::abci::tx_record::TxAction;
use tenderdash_abci::proto::abci::{ExecTxResult, TxRecord};
Expand Down Expand Up @@ -87,11 +88,15 @@ where
if transaction_guard.is_none() {
Err(Error::Abci(AbciError::BadRequest("received a prepare proposal request for the genesis height before an init chain request".to_string())))?;
};
if request.round > 0 {
transaction_guard
.as_ref()
.map(|tx| tx.rollback_to_savepoint());
};
tracing::debug!(
"rolling back to savepoint to process genesis proposal for round: {}",
request.round,
);
if let Some(tx) = transaction_guard.as_ref() {
tx.rollback_to_savepoint()
.map_err(|e| drive::grovedb::error::Error::StorageError(RocksDBError(e)))?;
tx.set_savepoint();
}
transaction_guard
} else {
app.start_transaction();
Expand Down
14 changes: 10 additions & 4 deletions packages/rs-drive-abci/src/abci/handler/process_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::platform_types::block_execution_outcome;
use crate::platform_types::state_transitions_processing_result::StateTransitionExecutionResult;
use crate::rpc::core::CoreRPCLike;
use dpp::version::TryIntoPlatformVersioned;
use drive::grovedb_storage::Error::RocksDBError;
use tenderdash_abci::proto::abci as proto;
use tenderdash_abci::proto::abci::tx_record::TxAction;

Expand Down Expand Up @@ -70,6 +71,7 @@ where
)))?;
}
} else {
// we were the proposer
let Some(proposal_info) = block_execution_context.proposer_results() else {
Err(Error::Abci(AbciError::BadRequest(
"received a process proposal request twice".to_string(),
Expand Down Expand Up @@ -154,10 +156,14 @@ where
if transaction_guard.is_none() {
Err(Error::Abci(AbciError::BadRequest("received a process proposal request for the genesis height before an init chain request".to_string())))?;
}
if request.round > 0 {
transaction_guard
.as_ref()
.map(|tx| tx.rollback_to_savepoint());
tracing::debug!(
"rolling back to savepoint to process genesis proposal for round: {}",
request.round,
);
if let Some(tx) = transaction_guard.as_ref() {
tx.rollback_to_savepoint()
.map_err(|e| drive::grovedb::error::Error::StorageError(RocksDBError(e)))?;
tx.set_savepoint();
}
transaction_guard
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ where
) -> Result<Identity, Error> {
let owner_identifier = Self::get_owner_identifier(masternode)?;
let mut identity = Identity::create_basic_identity(owner_identifier, platform_version)?;
identity.add_public_keys([Self::get_owner_identity_key(
identity.add_public_keys([Self::get_owner_identity_withdrawal_key(
masternode.state.payout_address,
0,
platform_version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ where
/// # Returns
///
/// * Result<IdentityPublicKey, Error> - Returns the derived identity public key if successful. Otherwise, returns an error.
pub(crate) fn get_owner_identity_key(
pub(crate) fn get_owner_identity_withdrawal_key(
payout_address: [u8; 20],
key_id: KeyID,
platform_version: &PlatformVersion,
Expand All @@ -36,11 +36,11 @@ where
.methods
.core_based_updates
.masternode_updates
.get_owner_identity_key
.get_owner_identity_withdrawal_key
{
0 => Self::get_owner_identity_key_v0(payout_address, key_id),
0 => Self::get_owner_identity_withdrawal_key_v0(payout_address, key_id),
version => Err(Error::Execution(ExecutionError::UnknownVersionMismatch {
method: "get_owner_identity_key".to_string(),
method: "get_owner_identity_withdrawal_key".to_string(),
known_versions: vec![0],
received: version,
})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ impl<C> Platform<C>
where
C: CoreRPCLike,
{
pub(super) fn get_owner_identity_key_v0(
pub(super) fn get_owner_identity_withdrawal_key_v0(
payout_address: [u8; 20],
key_id: KeyID,
) -> Result<IdentityPublicKey, Error> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use drive::util::batch::IdentityOperationType::AddNewIdentity;

use crate::platform_types::platform_state::v0::PlatformStateV0Methods;

use dpp::dashcore::hashes::Hash;
use drive::grovedb::Transaction;
use std::collections::BTreeMap;
use tracing::Level;
Expand Down Expand Up @@ -100,13 +101,19 @@ where
// On initialization there is no platform state, but we also don't need to update
// masternode identities.
for update in updated_mns.iter() {
self.update_owner_withdrawal_address(
update,
block_info,
transaction,
&mut drive_operations,
platform_version,
)?;
let (pro_tx_hash, state_diff) = update;
if let Some(new_withdrawal_address) = state_diff.payout_address {
let owner_identifier: [u8; 32] = pro_tx_hash.to_byte_array();
self.update_owner_withdrawal_address(
owner_identifier,
new_withdrawal_address,
block_info,
transaction,
&mut drive_operations,
platform_version,
)?;
};

self.update_voter_identity(
update,
block_info,
Expand All @@ -115,14 +122,21 @@ where
&mut drive_operations,
platform_version,
)?;
self.update_operator_identity(
update,
block_info,
platform_state,
transaction,
&mut drive_operations,
platform_version,
)?;
if state_diff.platform_node_id.is_some()
|| state_diff.operator_payout_address.is_some()
|| state_diff.pub_key_operator.is_some()
{
self.update_operator_identity(
pro_tx_hash,
state_diff.pub_key_operator.as_ref(),
state_diff.operator_payout_address,
state_diff.platform_node_id,
platform_state,
transaction,
&mut drive_operations,
platform_version,
)?;
}
}

for masternode in removed_masternodes.values() {
Expand All @@ -136,14 +150,14 @@ where
}
}

let previous_fee_verions = platform_state.map(|state| state.previous_fee_versions());
let previous_fee_versions = platform_state.map(|state| state.previous_fee_versions());
self.drive.apply_drive_operations(
drive_operations,
true,
block_info,
Some(transaction),
platform_version,
previous_fee_verions,
previous_fee_versions,
)?;

let height = block_info.height;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ where
/// does not match any of the known versions.
pub(in crate::execution::platform_events::core_based_updates::update_masternode_identities) fn update_operator_identity(
&self,
masternode: &(ProTxHash, DMNStateDiff),
block_info: &BlockInfo,
masternode_pro_tx_hash: &ProTxHash,
pub_key_operator_change: Option<&Vec<u8>>,
operator_payout_address_change: Option<Option<[u8; 20]>>,
platform_node_id_change: Option<[u8; 20]>,
platform_state: &PlatformState,
transaction: &Transaction,
drive_operations: &mut Vec<DriveOperation>,
Expand All @@ -60,8 +62,10 @@ where
.update_operator_identity
{
0 => self.update_operator_identity_v0(
masternode,
block_info,
masternode_pro_tx_hash,
pub_key_operator_change,
operator_payout_address_change,
platform_node_id_change,
platform_state,
transaction,
drive_operations,
Expand Down
Loading

0 comments on commit 20f692d

Please sign in to comment.