-
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.
- Loading branch information
1 parent
ad720bf
commit 29dadbf
Showing
74 changed files
with
1,039 additions
and
298 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod total_credits_balance; | ||
|
||
pub mod credits; | ||
pub mod total_tokens_balance; |
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,53 @@ | ||
use crate::balances::credits::SumTokenAmount; | ||
use crate::ProtocolError; | ||
use std::fmt; | ||
|
||
/// The outcome of verifying token balances | ||
#[derive(Copy, Clone, Debug)] | ||
pub struct TotalTokensBalance { | ||
/// all the tokens in platform | ||
pub total_tokens_in_platform: SumTokenAmount, | ||
/// all the tokens in identity token balances | ||
pub total_identity_token_balances: SumTokenAmount, | ||
} | ||
|
||
impl fmt::Display for TotalTokensBalance { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
writeln!(f, "TotalTokensBalance {{")?; | ||
writeln!( | ||
f, | ||
" total_tokens_in_platform: {},", | ||
self.total_tokens_in_platform | ||
)?; | ||
writeln!( | ||
f, | ||
" total_identity_token_balances: {}", | ||
self.total_identity_token_balances | ||
)?; | ||
write!(f, "}}") | ||
} | ||
} | ||
impl TotalTokensBalance { | ||
/// Is the outcome okay? basically do the values match up | ||
/// Errors in case of overflow | ||
pub fn ok(&self) -> Result<bool, ProtocolError> { | ||
let TotalTokensBalance { | ||
total_tokens_in_platform, | ||
total_identity_token_balances, | ||
} = *self; | ||
|
||
if total_tokens_in_platform < 0 { | ||
return Err(ProtocolError::CriticalCorruptedCreditsCodeExecution( | ||
"Tokens in platform are less than 0".to_string(), | ||
)); | ||
} | ||
|
||
if total_identity_token_balances < 0 { | ||
return Err(ProtocolError::CriticalCorruptedCreditsCodeExecution( | ||
"Tokens in identity balances are less than 0".to_string(), | ||
)); | ||
} | ||
|
||
Ok(total_tokens_in_platform == total_identity_token_balances) | ||
} | ||
} |
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
1 change: 1 addition & 0 deletions
1
packages/rs-drive-abci/src/execution/platform_events/tokens/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mod validate_token_aggregated_balance; |
1 change: 1 addition & 0 deletions
1
...-drive-abci/src/execution/platform_events/tokens/validate_token_aggregated_balance/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mod v0; |
46 changes: 46 additions & 0 deletions
46
...s-drive-abci/src/execution/platform_events/tokens/validate_token_aggregated_balance/v0.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,46 @@ | ||
use dpp::block::epoch::Epoch; | ||
use drive::drive::Drive; | ||
use drive::grovedb::Transaction; | ||
|
||
use crate::error::execution::ExecutionError; | ||
use crate::error::Error; | ||
use crate::execution::types::block_execution_context::BlockExecutionContext; | ||
use crate::platform_types::platform::Platform; | ||
use platform_version::version::PlatformVersion; | ||
|
||
impl<CoreRPCLike> Platform<CoreRPCLike> { | ||
/// Adds operations to GroveDB op batch related to processing | ||
/// and distributing the block fees from the previous block and applies the batch. | ||
/// | ||
/// Returns `ProcessedBlockFeesOutcome`. | ||
#[inline(always)] | ||
pub(super) fn validate_token_aggregated_balance_v0( | ||
&self, | ||
block_execution_context: &BlockExecutionContext, | ||
transaction: &Transaction, | ||
platform_version: &PlatformVersion, | ||
) -> Result<(), Error> { | ||
if self.config.execution.verify_token_sum_trees { | ||
// Verify sum trees | ||
let credits_verified = self | ||
.drive | ||
.calculate_total_token_balance(Some(transaction), &platform_version.drive) | ||
.map_err(Error::Drive)?; | ||
|
||
if !credits_verified.ok()? { | ||
return Err(Error::Execution( | ||
ExecutionError::CorruptedCreditsNotBalanced(format!( | ||
"credits are not balanced after block execution {:?} off by {}", | ||
credits_verified, | ||
credits_verified | ||
.total_in_trees() | ||
.unwrap() | ||
.abs_diff(credits_verified.total_credits_in_platform) | ||
)), | ||
)); | ||
} | ||
} | ||
|
||
Ok(outcome) | ||
} | ||
} |
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
Oops, something went wrong.