Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(platform)!: fix reference of items between epochs #2064

Merged
merged 23 commits into from
Aug 20, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
more work
QuantumExplorer committed Aug 20, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 8b08dc6ddf4ab0a70667f3795966c97f72569aea
239 changes: 131 additions & 108 deletions Cargo.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -266,7 +266,6 @@ pub(crate) mod tests {
contract_bounds: Option<ContractBounds>,
) -> IdentityPublicKey {
let platform_version = PlatformVersion::latest();
let mut signer = SimpleSigner::default();

let mut rng = StdRng::seed_from_u64(seed);

4 changes: 2 additions & 2 deletions packages/rs-drive-abci/src/main.rs
Original file line number Diff line number Diff line change
@@ -480,8 +480,7 @@ mod test {

let cf_handle = db.cf_handle(cf).unwrap();
let iter = db.iterator_cf(cf_handle, IteratorMode::Start);

// let iter = db.iterator(IteratorMode::Start);

for (i, item) in iter.enumerate() {
let (key, mut value) = item.unwrap();
// println!("{} = {}", hex::encode(&key), hex::encode(value));
@@ -502,6 +501,7 @@ mod test {
}

#[test]
#[ignore]
fn test_verify_grovedb_corrupt_0th_root() {
drive_abci::logging::init_for_tests(LogLevel::Silent);
let tempdir = tempfile::tempdir().unwrap();
9 changes: 0 additions & 9 deletions packages/rs-drive-abci/tests/strategy_tests/main.rs
Original file line number Diff line number Diff line change
@@ -2458,15 +2458,6 @@ mod tests {
.to_owned_document_type(),
};

let document_deletion_op = DocumentOp {
contract: contract.clone(),
action: DocumentAction::DocumentActionDelete,
document_type: contract
.document_type_for_name("contactRequest")
.expect("expected a profile document type")
.to_owned_document_type(),
};

let strategy = NetworkStrategy {
strategy: Strategy {
start_contracts: vec![(created_contract, None)],
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ use crate::fees::op::LowLevelDriveOperation::GroveOperation;
use crate::util::grove_operations::DirectQueryType;

use dpp::version::PlatformVersion;
use grovedb::batch::{GroveDbOp, KeyInfoPath};
use grovedb::batch::{KeyInfoPath, QualifiedGroveDbOp};
use grovedb::Element::Item;
use grovedb::{EstimatedLayerInformation, TransactionArg};
use integer_encoding::VarInt;
@@ -52,7 +52,7 @@ impl Drive {
"trying to add an amount that would overflow credits",
)))?;
let path_holding_total_credits_vec = misc_path_vec();
let replace_op = GroveDbOp::replace_op(
let replace_op = QualifiedGroveDbOp::replace_op(
path_holding_total_credits_vec,
TOTAL_SYSTEM_CREDITS_STORAGE_KEY.to_vec(),
Item(new_total.encode_var_vec(), None),
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ use crate::fees::op::LowLevelDriveOperation::GroveOperation;
use crate::util::grove_operations::DirectQueryType;

use dpp::version::PlatformVersion;
use grovedb::batch::{GroveDbOp, KeyInfoPath};
use grovedb::batch::{KeyInfoPath, QualifiedGroveDbOp};
use grovedb::Element::Item;
use grovedb::{EstimatedLayerInformation, TransactionArg};
use integer_encoding::VarInt;
@@ -53,7 +53,7 @@ impl Drive {
"trying to remove an amount that would underflow total system credits",
)))?;
let path_holding_total_credits_vec = misc_path_vec();
let replace_op = GroveDbOp::replace_op(
let replace_op = QualifiedGroveDbOp::replace_op(
path_holding_total_credits_vec,
TOTAL_SYSTEM_CREDITS_STORAGE_KEY.to_vec(),
Item(new_total.encode_var_vec(), None),
Original file line number Diff line number Diff line change
@@ -52,7 +52,6 @@ impl Drive {
platform_version,
)?;
let fetch_cost = LowLevelDriveOperation::combine_cost_operations(&batch_operations);
println!("operations are {:?}", batch_operations);
self.apply_batch_low_level_drive_operations(
estimated_costs_only_with_layer_info,
transaction,
@@ -112,7 +111,7 @@ impl Drive {
};

// We can do a get direct because there are no references involved
match self.grove_get_raw(
match self.grove_get_raw_optional(
(&contract_root_path(contract.id_ref().as_bytes())).into(),
&[0],
direct_query_type,
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ use dpp::block::epoch::Epoch;
use dpp::fee::Credits;
use dpp::util::deserializer::ProtocolVersion;
use dpp::version::PlatformVersion;
use grovedb::batch::GroveDbOp;
use grovedb::batch::QualifiedGroveDbOp;
use grovedb::{Element, TransactionArg};

/// Operations on Epochs
@@ -32,7 +32,7 @@ pub trait EpochOperations {
cached_previous_block_count: Option<u64>,
transaction: TransactionArg,
platform_version: &PlatformVersion,
) -> Result<GroveDbOp, Error>;
) -> Result<QualifiedGroveDbOp, Error>;
/// Adds to the groveDB op batch operations to insert an empty tree into the epoch
fn add_init_empty_without_storage_operations(&self, batch: &mut GroveDbOpBatch);
/// Adds to the groveDB op batch operations to insert an empty tree into the epoch
@@ -51,36 +51,36 @@ pub trait EpochOperations {
/// Adds to the groveDB op batch operations signifying that the epoch distribution fees were paid out.
fn add_mark_as_paid_operations(&self, batch: &mut GroveDbOpBatch);
/// Update Epoch's protocol version
fn update_protocol_version_operation(&self, protocol_version: ProtocolVersion) -> GroveDbOp;
fn update_protocol_version_operation(&self, protocol_version: ProtocolVersion) -> QualifiedGroveDbOp;
/// Returns a groveDB op which updates the epoch start time.
fn update_start_time_operation(&self, time_ms: u64) -> GroveDbOp;
fn update_start_time_operation(&self, time_ms: u64) -> QualifiedGroveDbOp;
/// Returns a groveDB op which updates the epoch start block height.
fn update_start_block_height_operation(&self, start_block_height: u64) -> GroveDbOp;
fn update_start_block_height_operation(&self, start_block_height: u64) -> QualifiedGroveDbOp;
/// Returns a groveDB op which updates the epoch start block height.
fn update_start_block_core_height_operation(&self, start_block_core_height: u32) -> GroveDbOp;
fn update_start_block_core_height_operation(&self, start_block_core_height: u32) -> QualifiedGroveDbOp;
/// Returns a groveDB op which updates the epoch fee multiplier.
fn update_fee_multiplier_operation(&self, multiplier_permille: u64) -> GroveDbOp;
fn update_fee_multiplier_operation(&self, multiplier_permille: u64) -> QualifiedGroveDbOp;
/// Returns a groveDB op which updates the epoch processing credits for distribution.
fn update_processing_fee_pool_operation(
&self,
processing_fee: Credits,
) -> Result<GroveDbOp, Error>;
) -> Result<QualifiedGroveDbOp, Error>;
/// Returns a groveDB op which deletes the epoch processing credits for distribution tree.
fn delete_processing_credits_for_distribution_operation(&self) -> GroveDbOp;
fn delete_processing_credits_for_distribution_operation(&self) -> QualifiedGroveDbOp;
/// Returns a groveDB op which updates the epoch storage credits for distribution.
fn update_storage_fee_pool_operation(&self, storage_fee: Credits) -> Result<GroveDbOp, Error>;
fn update_storage_fee_pool_operation(&self, storage_fee: Credits) -> Result<QualifiedGroveDbOp, Error>;
/// Returns a groveDB op which deletes the epoch storage credits for distribution tree.
fn delete_storage_credits_for_distribution_operation(&self) -> GroveDbOp;
fn delete_storage_credits_for_distribution_operation(&self) -> QualifiedGroveDbOp;
/// Returns a groveDB op which updates the given epoch proposer's block count.
fn update_proposer_block_count_operation(
&self,
proposer_pro_tx_hash: &[u8; 32],
block_count: u64,
) -> GroveDbOp;
) -> QualifiedGroveDbOp;
/// Returns a groveDB op which inserts an empty tree into the epoch proposers path.
fn init_proposers_tree_operation(&self) -> GroveDbOp;
fn init_proposers_tree_operation(&self) -> QualifiedGroveDbOp;
/// Returns a groveDB op which deletes the epoch proposers tree.
fn delete_proposers_tree_operation(&self) -> GroveDbOp;
fn delete_proposers_tree_operation(&self) -> QualifiedGroveDbOp;
/// Adds a groveDB op to the batch which deletes the given epoch proposers from the proposers tree.
fn add_delete_proposers_operations(
&self,
@@ -98,7 +98,7 @@ impl EpochOperations for Epoch {
cached_previous_block_count: Option<u64>,
transaction: TransactionArg,
platform_version: &PlatformVersion,
) -> Result<GroveDbOp, Error> {
) -> Result<QualifiedGroveDbOp, Error> {
// get current proposer's block count
let proposed_block_count = if let Some(block_count) = cached_previous_block_count {
block_count
@@ -171,44 +171,44 @@ impl EpochOperations for Epoch {
}

/// Returns a groveDB op which updates the epoch start time.
fn update_protocol_version_operation(&self, protocol_version: ProtocolVersion) -> GroveDbOp {
GroveDbOp::insert_op(
fn update_protocol_version_operation(&self, protocol_version: ProtocolVersion) -> QualifiedGroveDbOp {
QualifiedGroveDbOp::insert_or_replace_op(
self.get_path_vec(),
KEY_PROTOCOL_VERSION.to_vec(),
Element::Item(protocol_version.to_be_bytes().to_vec(), None),
)
}

/// Returns a groveDB op which updates the epoch start time.
fn update_start_time_operation(&self, time_ms: u64) -> GroveDbOp {
GroveDbOp::insert_op(
fn update_start_time_operation(&self, time_ms: u64) -> QualifiedGroveDbOp {
QualifiedGroveDbOp::insert_or_replace_op(
self.get_path_vec(),
KEY_START_TIME.to_vec(),
Element::Item(time_ms.to_be_bytes().to_vec(), None),
)
}

/// Returns a groveDB op which updates the epoch start block height.
fn update_start_block_height_operation(&self, start_block_height: u64) -> GroveDbOp {
GroveDbOp::insert_op(
fn update_start_block_height_operation(&self, start_block_height: u64) -> QualifiedGroveDbOp {
QualifiedGroveDbOp::insert_or_replace_op(
self.get_path_vec(),
KEY_START_BLOCK_HEIGHT.to_vec(),
Element::Item(start_block_height.to_be_bytes().to_vec(), None),
)
}

/// Returns a groveDB op which updates the epoch start block core height.
fn update_start_block_core_height_operation(&self, start_block_core_height: u32) -> GroveDbOp {
GroveDbOp::insert_op(
fn update_start_block_core_height_operation(&self, start_block_core_height: u32) -> QualifiedGroveDbOp {
QualifiedGroveDbOp::insert_or_replace_op(
self.get_path_vec(),
KEY_START_BLOCK_CORE_HEIGHT.to_vec(),
Element::Item(start_block_core_height.to_be_bytes().to_vec(), None),
)
}

/// Returns a groveDB op which updates the epoch fee multiplier.
fn update_fee_multiplier_operation(&self, multiplier_permille: u64) -> GroveDbOp {
GroveDbOp::insert_op(
fn update_fee_multiplier_operation(&self, multiplier_permille: u64) -> QualifiedGroveDbOp {
QualifiedGroveDbOp::insert_or_replace_op(
self.get_path_vec(),
KEY_FEE_MULTIPLIER.to_vec(),
Element::Item(multiplier_permille.to_be_bytes().to_vec(), None),
@@ -219,58 +219,58 @@ impl EpochOperations for Epoch {
fn update_processing_fee_pool_operation(
&self,
processing_fee: Credits,
) -> Result<GroveDbOp, Error> {
Ok(GroveDbOp::insert_op(
) -> Result<QualifiedGroveDbOp, Error> {
Ok(QualifiedGroveDbOp::insert_or_replace_op(
self.get_path_vec(),
KEY_POOL_PROCESSING_FEES.to_vec(),
Element::new_sum_item(processing_fee.to_signed()?),
))
}

/// Returns a groveDB op which deletes the epoch processing credits for distribution tree.
fn delete_processing_credits_for_distribution_operation(&self) -> GroveDbOp {
GroveDbOp::delete_op(self.get_path_vec(), KEY_POOL_PROCESSING_FEES.to_vec())
fn delete_processing_credits_for_distribution_operation(&self) -> QualifiedGroveDbOp {
QualifiedGroveDbOp::delete_op(self.get_path_vec(), KEY_POOL_PROCESSING_FEES.to_vec())
}

/// Returns a groveDB op which updates the epoch storage credits for distribution.
fn update_storage_fee_pool_operation(&self, storage_fee: Credits) -> Result<GroveDbOp, Error> {
Ok(GroveDbOp::insert_op(
fn update_storage_fee_pool_operation(&self, storage_fee: Credits) -> Result<QualifiedGroveDbOp, Error> {
Ok(QualifiedGroveDbOp::insert_or_replace_op(
self.get_path_vec(),
KEY_POOL_STORAGE_FEES.to_vec(),
Element::new_sum_item(storage_fee.to_signed()?),
))
}

/// Returns a groveDB op which deletes the epoch storage credits for distribution tree.
fn delete_storage_credits_for_distribution_operation(&self) -> GroveDbOp {
GroveDbOp::delete_op(self.get_path_vec(), KEY_POOL_STORAGE_FEES.to_vec())
fn delete_storage_credits_for_distribution_operation(&self) -> QualifiedGroveDbOp {
QualifiedGroveDbOp::delete_op(self.get_path_vec(), KEY_POOL_STORAGE_FEES.to_vec())
}

/// Returns a groveDB op which updates the given epoch proposer's block count.
fn update_proposer_block_count_operation(
&self,
proposer_pro_tx_hash: &[u8; 32],
block_count: u64,
) -> GroveDbOp {
GroveDbOp::insert_op(
) -> QualifiedGroveDbOp {
QualifiedGroveDbOp::insert_or_replace_op(
self.get_proposers_path_vec(),
proposer_pro_tx_hash.to_vec(),
Element::Item(block_count.to_be_bytes().to_vec(), None),
)
}

/// Returns a groveDB op which inserts an empty tree into the epoch proposers path.
fn init_proposers_tree_operation(&self) -> GroveDbOp {
GroveDbOp::insert_op(
fn init_proposers_tree_operation(&self) -> QualifiedGroveDbOp {
QualifiedGroveDbOp::insert_or_replace_op(
self.get_path_vec(),
KEY_PROPOSERS.to_vec(),
Element::empty_tree(),
)
}

/// Returns a groveDB op which deletes the epoch proposers tree.
fn delete_proposers_tree_operation(&self) -> GroveDbOp {
GroveDbOp::delete_tree_op(self.get_path_vec(), KEY_PROPOSERS.to_vec(), false)
fn delete_proposers_tree_operation(&self) -> QualifiedGroveDbOp {
QualifiedGroveDbOp::delete_tree_op(self.get_path_vec(), KEY_PROPOSERS.to_vec(), false)
}

/// Adds a groveDB op to the batch which deletes the given epoch proposers from the proposers tree.
6 changes: 3 additions & 3 deletions packages/rs-drive/src/drive/credit_pools/mod.rs
Original file line number Diff line number Diff line change
@@ -183,14 +183,14 @@ mod tests {
use crate::util::test_helpers::setup::setup_drive_with_initial_state_structure;

mod add_update_epoch_storage_fee_pools_operations {
use grovedb::batch::GroveOp;
use super::*;
use crate::drive::credit_pools::epochs::operations_factory::EpochOperations;
use crate::util::batch::grovedb_op_batch::GroveDbOpBatchV0Methods;
use dpp::block::epoch::EpochIndex;
use dpp::fee::epoch::GENESIS_EPOCH_INDEX;
use dpp::fee::Credits;
use dpp::version::PlatformVersion;
use grovedb::batch::Op;

#[test]
fn should_do_nothing_if_credits_per_epoch_are_empty() {
@@ -268,7 +268,7 @@ mod tests {
Epoch::new(i as EpochIndex).unwrap().get_path_vec()
);

let Op::Insert {
let GroveOp::InsertOrReplace {
element: Element::SumItem(credits, _),
} = operation.op
else {
@@ -332,7 +332,7 @@ mod tests {
let updated_credits: Vec<_> = batch
.into_iter()
.map(|operation| {
let Op::Insert {
let GroveOp::InsertOrReplace {
element: Element::SumItem(credits, _),
} = operation.op
else {
10 changes: 5 additions & 5 deletions packages/rs-drive/src/drive/credit_pools/operations.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ use crate::util::batch::GroveDbOpBatch;
use dpp::balances::credits::Creditable;
use dpp::block::epoch::EpochIndex;
use dpp::fee::Credits;
use grovedb::batch::GroveDbOp;
use grovedb::batch::QualifiedGroveDbOp;
use grovedb::Element;

#[cfg(feature = "server")]
@@ -21,8 +21,8 @@ pub fn add_create_pending_epoch_refunds_tree_operations(batch: &mut GroveDbOpBat
/// Updates the storage fee distribution pool with a new storage fee
pub fn update_storage_fee_distribution_pool_operation(
storage_fee: Credits,
) -> Result<GroveDbOp, Error> {
Ok(GroveDbOp::insert_op(
) -> Result<QualifiedGroveDbOp, Error> {
Ok(QualifiedGroveDbOp::insert_or_replace_op(
pools_vec_path(),
KEY_STORAGE_FEE_POOL.to_vec(),
Element::new_sum_item(storage_fee.to_signed()?),
@@ -31,8 +31,8 @@ pub fn update_storage_fee_distribution_pool_operation(

#[cfg(feature = "server")]
/// Updates the unpaid epoch index
pub fn update_unpaid_epoch_index_operation(epoch_index: EpochIndex) -> GroveDbOp {
GroveDbOp::insert_op(
pub fn update_unpaid_epoch_index_operation(epoch_index: EpochIndex) -> QualifiedGroveDbOp {
QualifiedGroveDbOp::insert_or_replace_op(
pools_vec_path(),
KEY_UNPAID_EPOCH_INDEX.to_vec(),
Element::new_item(epoch_index.to_be_bytes().to_vec()),
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@ mod tests {
use dpp::fee::epoch::CreditsPerEpoch;

use dpp::version::PlatformVersion;
use grovedb::batch::Op;
use grovedb::batch::GroveOp;

#[test]
fn should_add_delete_operations_v0() {
@@ -124,7 +124,7 @@ mod tests {
assert_eq!(batch.len(), expected_pending_refunds.len());

for operation in batch.into_iter() {
assert!(matches!(operation.op, Op::Delete));
assert!(matches!(operation.op, GroveOp::Delete));

assert_eq!(operation.path.to_path(), pending_epoch_refunds_path_vec());

Loading