Skip to content

Commit

Permalink
Fix FeeOfMultipleMaxBlockProposalsLimit failed
Browse files Browse the repository at this point in the history
  • Loading branch information
eval-exec authored and doitian committed Oct 10, 2023
1 parent 45104e0 commit 1e74aa3
Show file tree
Hide file tree
Showing 8 changed files with 371 additions and 26 deletions.
14 changes: 12 additions & 2 deletions tx-pool/src/chunk_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ use ckb_types::{
use ckb_verification::cache::TxVerificationCache;
use ckb_verification::{
cache::{CacheEntry, Completed},
ContextualWithoutScriptTransactionVerifier, ScriptError, ScriptVerifier, ScriptVerifyResult,
ScriptVerifyState, TimeRelativeTransactionVerifier, TransactionSnapshot, TxVerifyEnv,
ContextualWithoutScriptTransactionVerifier, DaoScriptSizeVerifier, ScriptError, ScriptVerifier,
ScriptVerifyResult, ScriptVerifyState, TimeRelativeTransactionVerifier, TransactionSnapshot,
TxVerifyEnv,
};
use std::sync::Arc;
use tokio::sync::watch;
Expand Down Expand Up @@ -269,6 +270,15 @@ impl ChunkProcess {
Arc::clone(&tx_env),
)
.verify()
.and_then(|result| {
DaoScriptSizeVerifier::new(
Arc::clone(&rtx),
consensus.dao_type_hash(),
data_loader.clone(),
)
.verify()?;
Ok(result)
})
.map_err(Reject::Verification);
let fee = try_or_return_with_snapshot!(ret, snapshot);

Expand Down
13 changes: 11 additions & 2 deletions tx-pool/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use ckb_types::{
use ckb_util::LinkedHashSet;
use ckb_verification::{
cache::{CacheEntry, Completed},
ContextualTransactionVerifier, ScriptVerifyResult, TimeRelativeTransactionVerifier,
TxVerifyEnv,
ContextualTransactionVerifier, DaoScriptSizeVerifier, ScriptVerifyResult,
TimeRelativeTransactionVerifier, TxVerifyEnv,
};
use std::collections::HashSet;
use std::collections::{HashMap, VecDeque};
Expand Down Expand Up @@ -654,6 +654,15 @@ impl TxPoolService {

match ret {
ScriptVerifyResult::Completed(cycles) => {
if let Err(e) = DaoScriptSizeVerifier::new(
Arc::clone(&rtx),
self.consensus.dao_type_hash(),
snapshot.as_data_loader(),
)
.verify()
{
return Err(Reject::Verification(e));
}
if let Some((declared, _)) = remote {
if declared != cycles {
return Err(Reject::DeclaredWrongCycles(declared, cycles));
Expand Down
24 changes: 21 additions & 3 deletions tx-pool/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ckb_types::core::{
};
use ckb_verification::{
cache::{CacheEntry, Completed},
ContextualTransactionVerifier, NonContextualTransactionVerifier,
ContextualTransactionVerifier, DaoScriptSizeVerifier, NonContextualTransactionVerifier,
TimeRelativeTransactionVerifier, TxVerifyEnv,
};
use std::sync::Arc;
Expand Down Expand Up @@ -101,15 +101,33 @@ pub(crate) fn verify_rtx(
.map_err(Reject::Verification)
}
CacheEntry::Suspended(suspended) => {
ContextualTransactionVerifier::new(rtx, consensus, data_loader, tx_env)
ContextualTransactionVerifier::new(Arc::clone(&rtx), consensus, data_loader, tx_env)
.complete(max_tx_verify_cycles, false, &suspended.snap)
.and_then(|result| {
DaoScriptSizeVerifier::new(
rtx,
snapshot.cloned_consensus().dao_type_hash(),
snapshot.as_data_loader(),
)
.verify()?;
Ok(result)
})
.map_err(Reject::Verification)
}
}
} else {
block_in_place(|| {
ContextualTransactionVerifier::new(rtx, consensus, data_loader, tx_env)
ContextualTransactionVerifier::new(Arc::clone(&rtx), consensus, data_loader, tx_env)
.verify(max_tx_verify_cycles, false)
.and_then(|result| {
DaoScriptSizeVerifier::new(
rtx,
snapshot.cloned_consensus().dao_type_hash(),
snapshot.as_data_loader(),
)
.verify()?;
Ok(result)
})
.map_err(Reject::Verification)
})
}
Expand Down
8 changes: 8 additions & 0 deletions util/types/src/core/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ pub enum TransactionError {
feature: &'static str,
},

/// Nervos DAO lock size mismatch.
#[error("The lock script size of deposit cell at index {} does not match the withdrawing cell at the same index", index)]
DaoLockSizeMismatch {
/// The index of mismatched DAO cells.
index: usize,
},

/// The internal error.
#[error("Internal: {description}, this error shouldn't happen, please report this bug to developers.")]
Internal {
Expand Down Expand Up @@ -204,6 +211,7 @@ impl TransactionError {
| TransactionError::CellbaseImmaturity { .. }
| TransactionError::MismatchedVersion { .. }
| TransactionError::Compatible { .. }
| TransactionError::DaoLockSizeMismatch { .. }
| TransactionError::Internal { .. } => false,
}
}
Expand Down
21 changes: 17 additions & 4 deletions verification/contextual/src/contextual_block_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use ckb_verification::cache::{
};
use ckb_verification::{
BlockErrorKind, CellbaseError, CommitError, ContextualTransactionVerifier,
TimeRelativeTransactionVerifier, UnknownParentError,
DaoScriptSizeVerifier, TimeRelativeTransactionVerifier, UnknownParentError,
};
use ckb_verification::{BlockTransactionsError, EpochError, TxVerifyEnv};
use ckb_verification_traits::Switch;
Expand Down Expand Up @@ -327,25 +327,28 @@ impl<'a, 'b, 'c, CS: ChainStore + VersionbitsIndexer> DaoHeaderVerifier<'a, 'b,
}
}

struct BlockTxsVerifier<'a, CS> {
struct BlockTxsVerifier<'a, 'b, CS> {
context: VerifyContext<CS>,
header: HeaderView,
handle: &'a Handle,
txs_verify_cache: &'a Arc<RwLock<TxVerificationCache>>,
parent: &'b HeaderView,
}

impl<'a, CS: ChainStore + VersionbitsIndexer + 'static> BlockTxsVerifier<'a, CS> {
impl<'a, 'b, CS: ChainStore + VersionbitsIndexer + 'static> BlockTxsVerifier<'a, 'b, CS> {
pub fn new(
context: VerifyContext<CS>,
header: HeaderView,
handle: &'a Handle,
txs_verify_cache: &'a Arc<RwLock<TxVerificationCache>>,
parent: &'b HeaderView,
) -> Self {
BlockTxsVerifier {
context,
header,
handle,
txs_verify_cache,
parent,
}
}

Expand Down Expand Up @@ -465,7 +468,16 @@ impl<'a, CS: ChainStore + VersionbitsIndexer + 'static> BlockTxsVerifier<'a, CS>
.into()
})
.map(|completed| (tx_hash, completed))
}
}.and_then(|result| {
if self.context.versionbits_active(DeploymentPos::LightClient, self.parent) {
DaoScriptSizeVerifier::new(
Arc::clone(tx),
self.context.consensus.dao_type_hash(),
self.context.store.as_data_loader(),
).verify()?;
}
Ok(result)
})
})
.skip(1) // skip cellbase tx
.collect::<Result<Vec<(Byte32, Completed)>, Error>>()?;
Expand Down Expand Up @@ -697,6 +709,7 @@ impl<'a, CS: ChainStore + VersionbitsIndexer + 'static, MS: MMRStore<HeaderDiges
header,
self.handle,
&self.txs_verify_cache,
&parent,
)
.verify(resolved, self.switch.disable_script())?;
Ok(ret)
Expand Down
2 changes: 1 addition & 1 deletion verification/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub use crate::genesis_verifier::GenesisVerifier;
pub use crate::header_verifier::HeaderVerifier;
pub use crate::transaction_verifier::{
CapacityVerifier, ContextualTransactionVerifier, ContextualWithoutScriptTransactionVerifier,
NonContextualTransactionVerifier, ScriptVerifier, Since, SinceMetric,
DaoScriptSizeVerifier, NonContextualTransactionVerifier, ScriptVerifier, Since, SinceMetric,
TimeRelativeTransactionVerifier,
};
pub use ckb_script::{
Expand Down
Loading

0 comments on commit 1e74aa3

Please sign in to comment.