Skip to content

Commit

Permalink
add txpool.check_block_limit and storage.enable_rocksdb_blob
Browse files Browse the repository at this point in the history
  • Loading branch information
bxq2011hust committed Dec 8, 2023
1 parent f11a57f commit 0f433d7
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 9 deletions.
4 changes: 4 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 Expand Up @@ -652,6 +654,7 @@ void NodeConfig::loadStorageConfig(boost::property_tree::ptree const& _pt)
m_minWriteBufferNumberToMerge = _pt.get<int32_t>("storage.min_write_buffer_number_to_merge", 1);
m_blockCacheSize = _pt.get<size_t>("storage.block_cache_size", 128 << 20);
m_enableDBStatistics = _pt.get<bool>("storage.enable_statistics", false);
m_enableRocksDBBlob = _pt.get<bool>("storage.enable_rocksdb_blob", false);
m_pdCaPath = _pt.get<std::string>("storage.pd_ssl_ca_path", "");
m_pdCertPath = _pt.get<std::string>("storage.pd_ssl_cert_path", "");
m_pdKeyPath = _pt.get<std::string>("storage.pd_ssl_key_path", "");
Expand All @@ -678,6 +681,7 @@ void NodeConfig::loadStorageConfig(boost::property_tree::ptree const& _pt)
<< LOG_KV("enableArchive", m_enableArchive)
<< LOG_KV("archiveListenIP", m_archiveListenIP)
<< LOG_KV("archiveListenPort", m_archiveListenPort)
<< LOG_KV("enable_rocksdb_blob", m_enableRocksDBBlob)
<< LOG_KV("enableLRUCacheStorage", m_enableLRUCacheStorage);
}

Expand Down
4 changes: 4 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 All @@ -131,6 +132,7 @@ class NodeConfig
size_t writeBufferSize() const { return m_writeBufferSize; }
int minWriteBufferNumberToMerge() const { return m_minWriteBufferNumberToMerge; }
size_t blockCacheSize() const { return m_blockCacheSize; }
bool enableRocksDBBlob() const { return m_enableRocksDBBlob; }
std::vector<std::string> const& pdAddrs() const { return m_pd_addrs; }
std::string const& pdCaPath() const { return m_pdCaPath; }
std::string const& pdCertPath() const { return m_pdCertPath; }
Expand Down Expand Up @@ -319,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 Expand Up @@ -364,6 +367,7 @@ class NodeConfig
size_t m_writeBufferSize = 64 << 21;
int m_minWriteBufferNumberToMerge = 2;
size_t m_blockCacheSize = 128 << 20;
bool m_enableRocksDBBlob = false;

bool m_enableArchive = false;
std::string m_archiveListenIP;
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 @@ -137,6 +137,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 @@ -171,5 +173,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
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: 2 additions & 0 deletions libinitializer/Initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "bcos-tool/BfsFileFactory.h"
#include "fisco-bcos-tars-service/Common/TarsUtils.h"
#include "libinitializer/BaselineSchedulerInitializer.h"
#include "rocksdb/statistics.h"
#include <bcos-crypto/hasher/AnyHasher.h>
#include <bcos-crypto/interfaces/crypto/CommonType.h>
#include <bcos-crypto/signature/key/KeyFactoryImpl.h>
Expand Down Expand Up @@ -165,6 +166,7 @@ void Initializer::init(bcos::protocol::NodeArchitectureType _nodeArchType,
option.writeBufferSize = m_nodeConfig->writeBufferSize();
option.minWriteBufferNumberToMerge = m_nodeConfig->minWriteBufferNumberToMerge();
option.blockCacheSize = m_nodeConfig->blockCacheSize();
option.enable_blob_files = m_nodeConfig->enableRocksDBBlob();

// m_protocolInitializer->dataEncryption() will return nullptr when storage_security = false
storage =
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 0f433d7

Please sign in to comment.