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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::platform_types::platform::Platform;
use crate::rpc::core::CoreRPCLike;

use dpp::block::block_info::BlockInfo;
use drive::error::Error::GroveDB;
use drive::error;
use drive::grovedb::Transaction;

use crate::execution::engine::consensus_params_update::consensus_params_update;
Expand Down Expand Up @@ -131,7 +131,7 @@ where
.grove
.root_hash(Some(transaction), &platform_version.drive.grove_version)
.unwrap()
.map_err(GroveDB)?;
.map_err(error::Error::from)?;

// We use first platform version because Tenderdash starts genesis with first versions
// by default
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use dpp::block::epoch::Epoch;

use dpp::validation::ValidationResult;
use drive::error::Error::GroveDB;

use dpp::version::PlatformVersion;
use drive::grovedb::Transaction;
Expand Down Expand Up @@ -383,7 +382,7 @@ where
.grove
.root_hash(Some(transaction), &platform_version.drive.grove_version)
.unwrap()
.map_err(|e| Error::Drive(GroveDB(e)))?; //GroveDb errors are system errors
.map_err(|e| Error::Drive(drive::error::Error::from(e)))?; //GroveDb errors are system errors

block_execution_context
.block_state_info_mut()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ impl<C> Platform<C> {
)
.or_else(|e| match e {
// Handle epoch change when storage fees are not set yet
error::Error::GroveDB(grovedb::Error::PathKeyNotFound(_)) => Ok(0u64),
error::Error::GroveDB(inner)
if matches!(inner.as_ref(), grovedb::Error::PathKeyNotFound(_)) =>
{
Ok(0u64)
}
_ => Err(e),
})?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,7 @@ mod tests {

assert!(matches!(
result,
Err(DriveError::GroveDB(
grovedb::Error::PathParentLayerNotFound(_)
))
Err(DriveError::GroveDB(e)) if matches!(e.as_ref(), grovedb::Error::PathParentLayerNotFound(_))
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,7 @@ mod tests {

assert!(matches!(
result,
Err(DriveError::GroveDB(
grovedb::Error::PathParentLayerNotFound(_)
))
Err(DriveError::GroveDB(e)) if matches!(e.as_ref(), grovedb::Error::PathParentLayerNotFound(_))
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl<C> Platform<C> {
.map(|element| {
let contested_document_resource_vote_poll_bytes = element
.into_item_bytes()
.map_err(drive::error::Error::GroveDB)?;
.map_err(drive::error::Error::from)?;
let vote_poll =
VotePoll::deserialize_from_bytes(&contested_document_resource_vote_poll_bytes)?;
match vote_poll {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9785,9 +9785,8 @@ mod tests {

assert_matches!(
query_validation_result,
Err(Error::Drive(drive::error::Error::GroveDB(
drive::grovedb::Error::CorruptedReferencePathKeyNotFound(_)
)))
Err(Error::Drive(drive::error::Error::GroveDB(e)))
if matches!(e.as_ref(), drive::grovedb::Error::CorruptedReferencePathKeyNotFound(_))
)
}

Expand Down Expand Up @@ -10564,9 +10563,8 @@ mod tests {

assert_matches!(
query_validation_result,
Err(Error::Drive(drive::error::Error::GroveDB(
drive::grovedb::Error::CorruptedReferencePathKeyNotFound(_)
)))
Err(Error::Drive(drive::error::Error::GroveDB(e)))
if matches!(e.as_ref(), drive::grovedb::Error::CorruptedReferencePathKeyNotFound(_))
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl<C> Platform<C> {
.map(|element| {
element
.serialize(&platform_version.drive.grove_version)
.map_err(|e| Error::Drive(drive::error::Error::GroveDB(e)))
.map_err(|e| Error::Drive(drive::error::Error::from(e)))
})
.collect::<Result<Vec<Vec<u8>>, Error>>()?;

Expand Down
2 changes: 1 addition & 1 deletion packages/rs-drive-proof-verifier/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl<O> MapGroveDbError<O> for Result<O, drive::error::Error> {

Err(drive::error::Error::GroveDB(grove_err)) => {
// If InvalidProof error is returned, extract the path query from it
let maybe_query = match &grove_err {
let maybe_query = match grove_err.as_ref() {
GroveError::InvalidProof(path_query, ..) => Some(path_query.clone()),
_ => None,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-drive-proof-verifier/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ impl FromProof<platform::GetIdentityByNonUniquePublicKeyHashRequest> for Identit
.map_err(|e| match e {
drive::error::Error::GroveDB(e) => {
// If InvalidProof error is returned, extract the path query from it
let maybe_query = match &e {
let maybe_query = match e.as_ref() {
GroveError::InvalidProof(path_query, ..) => Some(path_query.clone()),
_ => None,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl Drive {
) -> Result<Vec<LowLevelDriveOperation>, Error> {
let serialized_contract = contract
.serialize_to_bytes_with_platform_version(platform_version)
.map_err(Error::Protocol)?;
.map_err(Error::from)?;

if serialized_contract.len() as u64 > u32::MAX as u64
|| serialized_contract.len() as u32
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,14 @@ impl Drive {
// we are in estimated costs
// keep already_exists at false
}
Err(Error::GroveDB(grovedb::Error::PathKeyNotFound(_)))
| Err(Error::GroveDB(grovedb::Error::PathNotFound(_)))
| Err(Error::GroveDB(grovedb::Error::PathParentLayerNotFound(_))) => {
Err(Error::GroveDB(e))
if matches!(
e.as_ref(),
grovedb::Error::PathKeyNotFound(_)
| grovedb::Error::PathNotFound(_)
| grovedb::Error::PathParentLayerNotFound(_)
) =>
{
// keep already_exists at false
}
Err(e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl Drive {
false,
platform_version
)
.map_err(Error::Protocol)
.map_err(Error::from)
);
let drive_operation = CalculatedCostOperation(cost.clone());
let fee = if let Some(epoch) = epoch {
Expand Down Expand Up @@ -140,7 +140,7 @@ impl Drive {
false,
platform_version
)
.map_err(Error::Protocol)
.map_err(Error::from)
);
let drive_operation = CalculatedCostOperation(cost.clone());
let fee = if let Some(epoch) = epoch {
Expand Down Expand Up @@ -183,7 +183,7 @@ impl Drive {
| grovedb::Error::PathParentLayerNotFound(_)
| grovedb::Error::PathNotFound(_),
) => Ok(None).wrap_with_cost(cost),
Err(e) => Err(Error::GroveDB(e)).wrap_with_cost(cost),
Err(e) => Err(Error::from(e)).wrap_with_cost(cost),
}
}
Ok(_) => Err(Error::Drive(DriveError::CorruptedContractPath(
Expand All @@ -195,7 +195,7 @@ impl Drive {
| grovedb::Error::PathParentLayerNotFound(_)
| grovedb::Error::PathNotFound(_),
) => Ok(None).wrap_with_cost(cost),
Err(e) => Err(Error::GroveDB(e)).wrap_with_cost(cost),
Err(e) => Err(Error::from(e)).wrap_with_cost(cost),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Drive {
Element::Item(item, _flags) => {
let contract =
DataContract::versioned_deserialize(item, false, platform_version)
.map_err(Error::Protocol)?;
.map_err(Error::from)?;
Ok((contract_time, contract))
}
_ => Err(Error::Drive(DriveError::CorruptedContractPath(
Expand Down
3 changes: 1 addition & 2 deletions packages/rs-drive/src/drive/contract/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::drive::contract::{paths, MAX_CONTRACT_HISTORY_FETCH_LIMIT};
use crate::drive::{Drive, RootTree};
use crate::error::drive::DriveError;
use crate::error::Error;
use crate::error::Error::GroveDB;
use crate::query::{Query, QueryItem};
use crate::util::common::encode::encode_u64;
use grovedb::{PathQuery, SizedQuery};
Expand Down Expand Up @@ -143,7 +142,7 @@ impl Drive {
vec![&contracts_query, &historical_contracts_query],
&platform_version.drive.grove_version,
)
.map_err(GroveDB)
.map_err(Error::from)
}

/// Creates a merged path query for multiple historical contracts.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ impl Drive {
};

if amount > i64::MAX as u64 {
return Err(Error::Protocol(ProtocolError::Overflow(
return Err(Error::Protocol(Box::new(ProtocolError::Overflow(
"adding over i64::Max to processing fee pool",
)));
))));
}

let updated_value = existing_value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Drive {
&platform_version.drive.grove_version,
)
.unwrap()
.map_err(Error::GroveDB)?;
.map_err(Error::from)?;

let Element::Item(encoded_multiplier, _) = element else {
return Err(Error::Drive(DriveError::UnexpectedElementType(
Expand Down Expand Up @@ -72,7 +72,7 @@ mod tests {

assert!(matches!(
result,
Err(Error::GroveDB(grovedb::Error::PathParentLayerNotFound(_)))
Err(Error::GroveDB(e)) if matches!(e.as_ref(), grovedb::Error::PathParentLayerNotFound(_))
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Drive {
&platform_version.drive.grove_version,
)
.unwrap()
.map_err(Error::GroveDB)?;
.map_err(Error::from)?;

let Element::SumItem(credits, _) = element else {
return Err(Error::Drive(DriveError::UnexpectedElementType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Drive {
&platform_version.drive.grove_version,
)
.unwrap()
.map_err(Error::GroveDB)?;
.map_err(Error::from)?;

let Element::SumItem(item, _) = element else {
return Err(Error::Drive(DriveError::UnexpectedElementType(
Expand Down Expand Up @@ -68,7 +68,7 @@ mod tests {

assert!(matches!(
result,
Err(Error::GroveDB(grovedb::Error::PathParentLayerNotFound(_)))
Err(Error::GroveDB(e)) if matches!(e.as_ref(), grovedb::Error::PathParentLayerNotFound(_))
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Drive {
&platform_version.drive.grove_version,
)
.unwrap()
.map_err(Error::GroveDB)?;
.map_err(Error::from)?;

let Element::Item(encoded_protocol_version, _) = element else {
return Err(Error::Drive(DriveError::UnexpectedElementType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Drive {
&platform_version.drive.grove_version,
)
.unwrap()
.map_err(Error::GroveDB)
.map_err(Error::from)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ impl EpochOperations for Epoch {
platform_version,
)
.or_else(|e| match e {
Error::GroveDB(grovedb::Error::PathKeyNotFound(_)) => Ok(0u64),
Error::GroveDB(inner)
if matches!(inner.as_ref(), grovedb::Error::PathKeyNotFound(_)) =>
{
Ok(0u64)
}
_ => Err(e),
})?
};
Expand Down Expand Up @@ -444,7 +448,7 @@ mod tests {

assert!(matches!(
result,
Err(Error::GroveDB(grovedb::Error::InvalidPath(_)))
Err(Error::GroveDB(e)) if matches!(e.as_ref(), grovedb::Error::InvalidPath(_))
));
}

Expand Down Expand Up @@ -615,7 +619,7 @@ mod tests {

assert!(matches!(
result,
Err(Error::GroveDB(grovedb::Error::PathKeyNotFound(_)))
Err(Error::GroveDB(e)) if matches!(e.as_ref(), grovedb::Error::PathKeyNotFound(_))
));

let result = drive.get_epoch_storage_credits_for_distribution(
Expand All @@ -626,7 +630,7 @@ mod tests {

assert!(matches!(
result,
Err(Error::GroveDB(grovedb::Error::PathKeyNotFound(_)))
Err(Error::GroveDB(e)) if matches!(e.as_ref(), grovedb::Error::PathKeyNotFound(_))
));
}
}
Expand Down Expand Up @@ -764,7 +768,7 @@ mod tests {

assert!(matches!(
result,
Err(Error::GroveDB(grovedb::Error::InvalidPath(_)))
Err(Error::GroveDB(e)) if matches!(e.as_ref(), grovedb::Error::InvalidPath(_))
));
}

Expand Down Expand Up @@ -820,7 +824,7 @@ mod tests {

assert!(matches!(
result,
Err(Error::GroveDB(grovedb::Error::InvalidPath(_)))
Err(Error::GroveDB(e)) if matches!(e.as_ref(), grovedb::Error::InvalidPath(_))
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl Drive {
&platform_version.drive.grove_version,
)
.unwrap()
.map_err(Error::GroveDB)?
.map_err(Error::from)?
.0
.to_key_elements();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl Drive {
&platform_version.drive.grove_version,
)
.unwrap()
.map_err(Error::GroveDB)?;
.map_err(Error::from)?;

let Element::Item(encoded_proposer_block_count, _) = element else {
return Err(Error::Drive(DriveError::UnexpectedElementType(
Expand Down Expand Up @@ -117,7 +117,7 @@ mod tests {

assert!(matches!(
result,
Err(Error::GroveDB(grovedb::Error::PathParentLayerNotFound(_)))
Err(Error::GroveDB(e)) if matches!(e.as_ref(), grovedb::Error::PathParentLayerNotFound(_))
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Drive {
&platform_version.drive.grove_version,
)
.unwrap()
.map_err(Error::GroveDB)?;
.map_err(Error::from)?;

let Element::Item(encoded_start_block_core_height, _) = element else {
return Err(Error::Drive(DriveError::UnexpectedElementType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Drive {
&platform_version.drive.grove_version,
)
.unwrap()
.map_err(Error::GroveDB)?;
.map_err(Error::from)?;

let Element::Item(encoded_start_block_height, _) = element else {
return Err(Error::Drive(DriveError::UnexpectedElementType(
Expand Down
Loading
Loading