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

[MIRAI] Add annotations to libra-mempool crate #1682

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions mempool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ failure = { path = "../common/failure-ext", version = "0.1.0", package = "libra-
grpc-helpers = { path = "../common/grpc-helpers", version = "0.1.0" }
libra-logger = { path = "../common/logger", version = "0.1.0" }
libra-metrics = { path = "../common/metrics", version = "0.1.0" }
mirai-annotations = "1.5.0"
network = { path = "../network", version = "0.1.0" }
libra-crypto = { path = "../crypto/crypto", version = "0.1.0" }
storage-client = { path = "../storage/storage-client", version = "0.1.0" }
Expand Down
4 changes: 4 additions & 0 deletions mempool/src/core_mempool/transaction_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use libra_mempool_shared_proto::{
proto::mempool_status::MempoolAddTransactionStatusCode, MempoolAddTransactionStatus,
};
use libra_types::{account_address::AccountAddress, transaction::SignedTransaction};
use mirai_annotations::*;
use std::{
collections::HashMap,
ops::Bound,
Expand Down Expand Up @@ -281,6 +282,9 @@ impl TransactionStore {
pub(crate) fn get_required_balance(&mut self, address: &AccountAddress) -> u64 {
self.transactions.get_mut(&address).map_or(0, |txns| {
txns.iter().fold(0, |acc, (_, txn)| {
assume!(txn.gas_amount < u32::max_value() as u64); // seems more than reasonable
tzakian marked this conversation as resolved.
Show resolved Hide resolved
assume!(txn.txn.gas_unit_price() < u32::max_value() as u64);
tzakian marked this conversation as resolved.
Show resolved Hide resolved
assume!(acc <= u64::max_value() - txn.txn.gas_unit_price() * txn.gas_amount);
acc + txn.txn.gas_unit_price() * txn.gas_amount
})
})
Expand Down