mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-05-13 09:08:02 +08:00
cleanup, apply some feedback
This commit is contained in:
@@ -154,7 +154,6 @@ pub enum MemPoolRejection {
|
||||
FailedToValidate(Error),
|
||||
FeeTooLow(u64, u64),
|
||||
BadNonces(TransactionNonceMismatch),
|
||||
IgnoreBadNonces(TransactionNonceMismatch),
|
||||
NotEnoughFunds(u128, u128),
|
||||
NoSuchContract,
|
||||
NoSuchPublicFunction,
|
||||
@@ -196,14 +195,6 @@ impl MemPoolRejection {
|
||||
"actual": actual,
|
||||
"principal": principal.to_string(),
|
||||
"is_origin": is_origin}))),
|
||||
IgnoreBadNonces(TransactionNonceMismatch {
|
||||
expected, actual, principal, is_origin, .. }) =>
|
||||
("IgnoreBadNonces",
|
||||
Some(json!({
|
||||
"expected": expected,
|
||||
"actual": actual,
|
||||
"principal": principal.to_string(),
|
||||
"is_origin": is_origin}))),
|
||||
NotEnoughFunds(expected, actual) =>
|
||||
("NotEnoughFunds",
|
||||
Some(json!({
|
||||
@@ -2650,8 +2641,7 @@ impl StacksChainState {
|
||||
for microblock in microblocks.iter() {
|
||||
debug!("Process microblock {}", µblock.block_hash());
|
||||
for tx in microblock.txs.iter() {
|
||||
// TODO(psq): not quiet in this case???
|
||||
let (tx_fee, tx_receipt) = StacksChainState::process_transaction(clarity_tx, tx, true)
|
||||
let (tx_fee, tx_receipt) = StacksChainState::process_transaction(clarity_tx, tx, false)
|
||||
.map_err(|e| (e, microblock.block_hash()))?;
|
||||
|
||||
fees = fees.checked_add(tx_fee as u128).expect("Fee overflow");
|
||||
@@ -2669,8 +2659,7 @@ impl StacksChainState {
|
||||
let mut burns = 0u128;
|
||||
let mut receipts = vec![];
|
||||
for tx in block.txs.iter() {
|
||||
// TODO(psq): not quiet in this case
|
||||
let (tx_fee, tx_receipt) = StacksChainState::process_transaction(clarity_tx, tx, true)?;
|
||||
let (tx_fee, tx_receipt) = StacksChainState::process_transaction(clarity_tx, tx, false)?;
|
||||
fees = fees.checked_add(tx_fee as u128).expect("Fee overflow");
|
||||
burns = burns.checked_add(tx_receipt.stx_burned as u128).expect("Burns overflow");
|
||||
receipts.push(tx_receipt);
|
||||
|
||||
@@ -187,7 +187,7 @@ pub struct TransactionNonceMismatch {
|
||||
pub txid: Txid,
|
||||
pub principal: PrincipalData,
|
||||
pub is_origin: bool,
|
||||
pub ignore: bool,
|
||||
pub quiet: bool,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for TransactionNonceMismatch {
|
||||
@@ -200,7 +200,7 @@ impl std::fmt::Display for TransactionNonceMismatch {
|
||||
|
||||
impl From<TransactionNonceMismatch, T> for Error {
|
||||
fn from(e: TransactionNonceMismatch, T) -> Error {
|
||||
if e.ignore {
|
||||
if e.quiet {
|
||||
Error::IgnoreStacksTransaction(e.0.to_string())
|
||||
} else {
|
||||
Error::InvalidStacksTransaction(e.0.to_string())
|
||||
@@ -210,11 +210,7 @@ impl From<TransactionNonceMismatch, T> for Error {
|
||||
|
||||
impl From<TransactionNonceMismatch> for MemPoolRejection {
|
||||
fn from(e: TransactionNonceMismatch) -> MemPoolRejection {
|
||||
if e.ignore {
|
||||
MemPoolRejection::IgnoreBadNonces(e)
|
||||
} else {
|
||||
MemPoolRejection::BadNonces(e)
|
||||
}
|
||||
MemPoolRejection::BadNonces(e)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,8 +232,8 @@ impl StacksChainState {
|
||||
|
||||
/// Check the account nonces for the supplied stacks transaction,
|
||||
/// returning the origin and payer accounts if valid.
|
||||
pub fn check_transaction_nonces<T: ClarityConnection>(clarity_tx: &mut T, tx: &StacksTransaction, warn_on_bad_nonces: bool) -> Result<(StacksAccount, StacksAccount),
|
||||
(TransactionNonceMismatch, (StacksAccount, StacksAccount)) {
|
||||
pub fn check_transaction_nonces<T: ClarityConnection>(clarity_tx: &mut T, tx: &StacksTransaction, quiet: bool) -> Result<(StacksAccount, StacksAccount),
|
||||
(TransactionNonceMismatch, (StacksAccount, StacksAccount)) {
|
||||
// who's sending it?
|
||||
let origin = tx.get_origin();
|
||||
let origin_account = StacksChainState::get_account(clarity_tx, &tx.origin_address().into());
|
||||
@@ -254,8 +250,8 @@ impl StacksChainState {
|
||||
txid: tx.txid(),
|
||||
principal: payer_account.principal.clone(),
|
||||
is_origin: false,
|
||||
ignore: !warn_on_bad_nonces };
|
||||
if warn_on_bad_nonces {
|
||||
quiet: quiet };
|
||||
if !quiet {
|
||||
warn!("{}", &e);
|
||||
}
|
||||
return Err((e, (origin_account, payer_account)))
|
||||
@@ -273,8 +269,8 @@ impl StacksChainState {
|
||||
txid: tx.txid(),
|
||||
principal: origin_account.principal.clone(),
|
||||
is_origin: true,
|
||||
ignore: !warn_on_bad_nonces };
|
||||
if warn_on_bad_nonces {
|
||||
quiet: quiet };
|
||||
if !quiet {
|
||||
warn!("{}", &e);
|
||||
}
|
||||
return Err((e, (origin_account, payer_account)))
|
||||
@@ -732,13 +728,13 @@ impl StacksChainState {
|
||||
}
|
||||
|
||||
/// Process a transaction. Return the fee and the transaction receipt
|
||||
pub fn process_transaction(clarity_block: &mut ClarityTx, tx: &StacksTransaction, warn_on_bad_nonces: bool) -> Result<(u64, StacksTransactionReceipt), Error> {
|
||||
pub fn process_transaction(clarity_block: &mut ClarityTx, tx: &StacksTransaction, quiet: bool) -> Result<(u64, StacksTransactionReceipt), Error> {
|
||||
debug!("Process transaction {} ({})", tx.txid(), tx.payload.name());
|
||||
|
||||
StacksChainState::process_transaction_precheck(&clarity_block.config, tx)?;
|
||||
|
||||
let mut transaction = clarity_block.connection().start_transaction_processing();
|
||||
let (origin_account, payer_account) = StacksChainState::check_transaction_nonces(&mut transaction, tx, warn_on_bad_nonces)?;
|
||||
let (origin_account, payer_account) = StacksChainState::check_transaction_nonces(&mut transaction, tx, quiet)?;
|
||||
|
||||
let tx_receipt = StacksChainState::process_transaction_payload(&mut transaction, tx, &origin_account)?;
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ use chainstate::stacks::db::{
|
||||
use chainstate::stacks::index::TrieHash;
|
||||
use chainstate::burn::BlockHeaderHash;
|
||||
use chainstate::stacks::events::StacksTransactionReceipt;
|
||||
// use chainstate::stacks::db::transactions::TransactionNonceMismatch;
|
||||
|
||||
use net::StacksMessageCodec;
|
||||
use net::Error as net_error;
|
||||
@@ -375,8 +374,7 @@ impl StacksBlockBuilder {
|
||||
return Err(Error::InvalidStacksTransaction("Invalid transaction anchor mode for anchored data".to_string()));
|
||||
}
|
||||
|
||||
// TODO(psq): quiet in this case
|
||||
let (fee, _receipt) = StacksChainState::process_transaction(clarity_tx, tx, false)
|
||||
let (fee, _receipt) = StacksChainState::process_transaction(clarity_tx, tx, true)
|
||||
.map_err(|e| {
|
||||
match e {
|
||||
Error::CostOverflowError(cost_before, cost_after, total_budget) => {
|
||||
@@ -398,8 +396,7 @@ impl StacksBlockBuilder {
|
||||
return Err(Error::InvalidStacksTransaction("Invalid transaction anchor mode for streamed data".to_string()));
|
||||
}
|
||||
|
||||
// TODO(psq): quiet in this case
|
||||
let (fee, _receipt) = StacksChainState::process_transaction(clarity_tx, tx, false)
|
||||
let (fee, _receipt) = StacksChainState::process_transaction(clarity_tx, tx, true)
|
||||
.map_err(|e| {
|
||||
match e {
|
||||
Error::CostOverflowError(cost_before, cost_after, total_budget) => {
|
||||
@@ -434,8 +431,7 @@ impl StacksBlockBuilder {
|
||||
|
||||
if !self.anchored_done {
|
||||
// save
|
||||
// TODO(psq): quiet in this case, does it matter???
|
||||
match StacksChainState::process_transaction(clarity_tx, tx, false) {
|
||||
match StacksChainState::process_transaction(clarity_tx, tx, true) {
|
||||
Ok((fee, receipt)) => {
|
||||
self.total_anchored_fees += fee;
|
||||
},
|
||||
@@ -447,8 +443,7 @@ impl StacksBlockBuilder {
|
||||
self.txs.push(tx.clone());
|
||||
}
|
||||
else {
|
||||
// TODO(psq): quiet in this case, does it matter
|
||||
match StacksChainState::process_transaction(clarity_tx, tx, false) {
|
||||
match StacksChainState::process_transaction(clarity_tx, tx, true) {
|
||||
Ok((fee, receipt)) => {
|
||||
self.total_streamed_fees += fee;
|
||||
},
|
||||
@@ -715,8 +710,7 @@ impl StacksBlockBuilder {
|
||||
|
||||
considered.insert(txinfo.tx.txid());
|
||||
|
||||
let err = builder.try_mine_tx_with_len(&mut epoch_tx, &txinfo.tx, txinfo.metadata.len);
|
||||
match err {
|
||||
match builder.try_mine_tx_with_len(&mut epoch_tx, &txinfo.tx, txinfo.metadata.len) {
|
||||
Ok(_) => {},
|
||||
Err(Error::BlockTooBigError) => {
|
||||
// done mining -- our execution budget is exceeded.
|
||||
|
||||
Reference in New Issue
Block a user