Skip to content

Commit 7ff3a2f

Browse files
authored
mpool bls cache size (#473)
Signed-off-by: turuslan <[email protected]>
1 parent 6b40763 commit 7ff3a2f

File tree

7 files changed

+15
-11
lines changed

7 files changed

+15
-11
lines changed

core/node/main/builder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ namespace fc::node {
525525
log()->debug("Creating API...");
526526

527527
o.mpool = storage::mpool::MessagePool::create(
528-
o.env_context, o.ts_main, o.chain_store);
528+
o.env_context, o.ts_main, config.mpool_bls_cache_size, o.chain_store);
529529

530530
auto msg_waiter = storage::blockchain::MsgWaiter::create(
531531
o.ts_load, o.ipld, o.io_context, o.chain_store);

core/node/main/config.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ namespace fc::node {
9494
po::value(&config.wallet_default_key_path),
9595
"on first run, imports a default key from a given file. The key "
9696
"must be a BLS private key.");
97+
option("mpool_bls_cache_size", po::value(&config.mpool_bls_cache_size));
9798

9899
po::options_description drand_desc("Drand server options");
99100
auto drand_option{drand_desc.add_options()};

core/node/main/config.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ namespace fc::node {
4747
/** Node default key path */
4848
boost::optional<std::string> wallet_default_key_path;
4949

50+
size_t mpool_bls_cache_size{1000};
51+
5052
static Config read(int argc, char *argv[]);
5153

5254
std::string join(const std::string &path) const;

core/node/sync_job.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ namespace fc::sync {
9090
std::queue<std::pair<PeerId, TipsetKey>> requests_;
9191
std::mutex requests_mutex_;
9292

93-
std::queue<TipsetCPtr> interpret_queue_;
94-
9593
std::shared_ptr<events::Events> events_;
9694

9795
events::Connection message_event_;

core/storage/mpool/mpool.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ namespace fc::storage::mpool {
452452
std::shared_ptr<MessagePool> MessagePool::create(
453453
const EnvironmentContext &env_context,
454454
TsBranchPtr ts_main,
455+
size_t bls_cache_size,
455456
std::shared_ptr<ChainStore> chain_store) {
456457
auto mpool{std::make_shared<MessagePool>()};
457458
mpool->env_context = env_context;
@@ -468,6 +469,7 @@ namespace fc::storage::mpool {
468469
}
469470
}
470471
});
472+
mpool->bls_cache = {bls_cache_size};
471473
return mpool;
472474
}
473475

@@ -518,9 +520,8 @@ namespace fc::storage::mpool {
518520
[&](auto, auto bls, auto &cid, auto *smsg, auto *msg)
519521
-> outcome::result<void> {
520522
if (bls) {
521-
auto sig{bls_cache.find(cid)};
522-
if (sig != bls_cache.end()) {
523-
mpool::add(pending, {*msg, sig->second});
523+
if (auto sig{bls_cache.get(cid)}) {
524+
mpool::add(pending, {*msg, *sig});
524525
}
525526
} else {
526527
mpool::add(pending, *smsg);
@@ -715,7 +716,7 @@ namespace fc::storage::mpool {
715716

716717
outcome::result<void> MessagePool::add(const SignedMessage &message) {
717718
if (message.signature.isBls()) {
718-
bls_cache.emplace(message.getCid(), message.signature);
719+
bls_cache.insert(message.getCid(), message.signature);
719720
}
720721
OUTCOME_TRY(setCbor(ipld, message));
721722
OUTCOME_TRY(setCbor(ipld, message.message));
@@ -743,9 +744,8 @@ namespace fc::storage::mpool {
743744
remove(msg->from, msg->nonce);
744745
} else {
745746
if (bls) {
746-
auto sig{bls_cache.find(cid)};
747-
if (sig != bls_cache.end()) {
748-
OUTCOME_TRY(add({*msg, sig->second}));
747+
if (auto sig{bls_cache.get(cid)}) {
748+
OUTCOME_TRY(add({*msg, *sig}));
749749
}
750750
} else {
751751
OUTCOME_TRY(add(*smsg));

core/storage/mpool/mpool.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#pragma once
77

8+
#include <boost/compute/detail/lru_cache.hpp>
89
#include <random>
910

1011
#include "fwd.hpp"
@@ -41,6 +42,7 @@ namespace fc::storage::mpool {
4142
static std::shared_ptr<MessagePool> create(
4243
const EnvironmentContext &env_context,
4344
TsBranchPtr ts_main,
45+
size_t bls_cache_size,
4446
std::shared_ptr<ChainStore> chain_store);
4547
std::vector<SignedMessage> pending() const;
4648
// https://github.com/filecoin-project/lotus/blob/8f78066d4f3c4981da73e3328716631202c6e614/chain/messagepool/selection.go#L41
@@ -66,7 +68,7 @@ namespace fc::storage::mpool {
6668
ChainStore::connection_t head_sub;
6769
TipsetCPtr head;
6870
std::map<Address, std::map<Nonce, SignedMessage>> by_from;
69-
std::map<CID, Signature> bls_cache;
71+
mutable boost::compute::detail::lru_cache<CID, Signature> bls_cache{0};
7072
boost::signals2::signal<Subscriber> signal;
7173
mutable std::default_random_engine generator;
7274
mutable std::normal_distribution<> distribution;

test/core/storage/mpool/message_pool_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ namespace fc::storage::mpool {
7979
MessagePool::create(
8080
{ipld, nullptr, nullptr, ts_load, interpreter_cache},
8181
nullptr,
82+
1000,
8283
chain_store));
8384

8485
void addMsgs(std::vector<SignedMessage> msgs, bool remove) {

0 commit comments

Comments
 (0)