Skip to content

Commit

Permalink
add txpool.check_block_limit config
Browse files Browse the repository at this point in the history
  • Loading branch information
bxq2011hust committed Dec 7, 2023
1 parent 286323e commit c45e80f
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bcos-executor/src/executive/TransactionExecutive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ std::tuple<std::unique_ptr<HostContext>, CallParameters::UniquePtr> TransactionE
try
{
m_storageWrapper->createTable(tableName, std::string(STORAGE_VALUE));
EXECUTIVE_LOG(INFO) << "create contract table " << LOG_KV("table", tableName)
EXECUTIVE_LOG(DEBUG) << "create contract table " << LOG_KV("table", tableName)
<< LOG_KV("sender", callParameters->senderAddress);
if (m_blockContext.isAuthCheck() ||
(!m_blockContext.isWasm() &&
Expand Down
2 changes: 2 additions & 0 deletions bcos-tool/bcos-tool/NodeConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,11 @@ void NodeConfig::loadTxPoolConfig(boost::property_tree::ptree const& _pt)
m_txsExpirationTime = std::max(
{txsExpirationTime * 1000, (int64_t)DEFAULT_MIN_CONSENSUS_TIME_MS, (int64_t)m_minSealTime});

m_checkBlockLimit = _pt.get<bool>("txpool.check_block_limit", true);
NodeConfig_LOG(INFO) << LOG_DESC("loadTxPoolConfig") << LOG_KV("txpoolLimit", m_txpoolLimit)
<< LOG_KV("notifierWorkers", m_notifyWorkerNum)
<< LOG_KV("verifierWorkers", m_verifierWorkerNum)
<< LOG_KV("checkBlockLimit", m_checkBlockLimit)
<< LOG_KV("txsExpirationTime(ms)", m_txsExpirationTime);
}

Expand Down
2 changes: 2 additions & 0 deletions bcos-tool/bcos-tool/NodeConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class NodeConfig
size_t notifyWorkerNum() const { return m_notifyWorkerNum; }
size_t verifierWorkerNum() const { return m_verifierWorkerNum; }
int64_t txsExpirationTime() const { return m_txsExpirationTime; }
bool checkBlockLimit() const { return m_checkBlockLimit; }

bool smCryptoType() const { return m_genesisConfig.m_smCrypto; }
std::string const& chainId() const { return m_genesisConfig.m_chainID; }
Expand Down Expand Up @@ -320,6 +321,7 @@ class NodeConfig
size_t m_notifyWorkerNum;
size_t m_verifierWorkerNum;
int64_t m_txsExpirationTime;
bool m_checkBlockLimit = true;
// TODO: the block sync module need some configurations?

// chain configuration
Expand Down
7 changes: 4 additions & 3 deletions bcos-txpool/bcos-txpool/TxPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,10 @@ void TxPool::init()
TXPOOL_LOG(INFO) << LOG_DESC("fetch history nonces success");

// create LedgerNonceChecker and set it into the validator
TXPOOL_LOG(INFO) << LOG_DESC("init txs validator");
auto ledgerNonceChecker = std::make_shared<LedgerNonceChecker>(
ledgerConfigFetcher->nonceList(), ledgerConfig->blockNumber(), blockLimit);
TXPOOL_LOG(INFO) << LOG_DESC("init txs validator")
<< LOG_KV("checkBlockLimit", m_checkBlockLimit);
auto ledgerNonceChecker = std::make_shared<LedgerNonceChecker>(ledgerConfigFetcher->nonceList(),
ledgerConfig->blockNumber(), blockLimit, m_checkBlockLimit);

auto validator = std::dynamic_pointer_cast<TxValidator>(m_config->txValidator());
validator->setLedgerNonceChecker(ledgerNonceChecker);
Expand Down
3 changes: 3 additions & 0 deletions bcos-txpool/bcos-txpool/TxPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ class TxPool : public TxPoolInterface, public std::enable_shared_from_this<TxPoo

auto treeRouter() const { return m_treeRouter; }

void setCheckBlockLimit(bool _checkBlockLimit) { m_checkBlockLimit = _checkBlockLimit; }

protected:
virtual bool checkExistsInGroup(bcos::protocol::TxSubmitCallback _txSubmitCallback);
virtual void getTxsFromLocalLedger(bcos::crypto::HashListPtr _txsHash,
Expand Down Expand Up @@ -170,5 +172,6 @@ class TxPool : public TxPoolInterface, public std::enable_shared_from_this<TxPoo
// Note: This x_markTxsMutex is used for locking asyncSealTxs() during sealBlock
// because memory storage is not contain a big lock now
mutable bcos::SharedMutex x_markTxsMutex;
bool m_checkBlockLimit = true;
};
} // namespace bcos::txpool
1 change: 0 additions & 1 deletion bcos-txpool/bcos-txpool/TxPoolConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class TxPoolConfig
}
std::shared_ptr<bcos::ledger::LedgerInterface> ledger() { return m_ledger; }
int64_t blockLimit() const { return m_blockLimit; }

private:
TxValidatorInterface::Ptr m_txValidator;
bcos::protocol::TransactionSubmitResultFactory::Ptr m_txResultFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ TransactionStatus LedgerNonceChecker::checkNonce(Transaction::ConstPtr _tx, bool
{
return status;
}
// check blockLimit
return checkBlockLimit(_tx);
if (m_checkBlockLimit)
{ // check blockLimit
return checkBlockLimit(_tx);
}
return TransactionStatus::None;
}

TransactionStatus LedgerNonceChecker::checkBlockLimit(bcos::protocol::Transaction::ConstPtr _tx)
Expand Down
11 changes: 8 additions & 3 deletions bcos-txpool/bcos-txpool/txpool/validator/LedgerNonceChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ class LedgerNonceChecker : public TxPoolNonceChecker
public:
LedgerNonceChecker(
std::shared_ptr<std::map<int64_t, bcos::protocol::NonceListPtr> > _initialNonces,
bcos::protocol::BlockNumber _blockNumber, int64_t _blockLimit)
: TxPoolNonceChecker(), m_blockNumber(_blockNumber), m_blockLimit(_blockLimit)
bcos::protocol::BlockNumber _blockNumber, int64_t _blockLimit, bool _checkBlockLimit)
: TxPoolNonceChecker(),
m_blockNumber(_blockNumber),
m_blockLimit(_blockLimit),
m_checkBlockLimit(_checkBlockLimit)
{
if (_initialNonces)
{
Expand All @@ -46,11 +49,13 @@ class LedgerNonceChecker : public TxPoolNonceChecker
protected:
virtual bcos::protocol::TransactionStatus checkBlockLimit(
bcos::protocol::Transaction::ConstPtr _tx);
void initNonceCache(std::shared_ptr<std::map<int64_t, bcos::protocol::NonceListPtr> > _initialNonces);
void initNonceCache(
std::shared_ptr<std::map<int64_t, bcos::protocol::NonceListPtr> > _initialNonces);

private:
std::atomic<bcos::protocol::BlockNumber> m_blockNumber = {0};
int64_t m_blockLimit;
bool m_checkBlockLimit = true;

/// cache the block nonce to in case of accessing the DB to get nonces of given block frequently
/// key: block number
Expand Down
2 changes: 1 addition & 1 deletion libinitializer/TxPoolInitializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ TxPoolInitializer::TxPoolInitializer(bcos::tool::NodeConfig::Ptr _nodeConfig,

m_txpool = txpoolFactory->createTxPool(m_nodeConfig->notifyWorkerNum(),
m_nodeConfig->verifierWorkerNum(), m_nodeConfig->txsExpirationTime());

m_txpool->setCheckBlockLimit(m_nodeConfig->checkBlockLimit());
if (m_nodeConfig->enableSendTxByTree())
{
INITIALIZER_LOG(INFO) << LOG_DESC("enableSendTxByTree");
Expand Down

0 comments on commit c45e80f

Please sign in to comment.