-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add threading to add block #1637
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,7 +144,6 @@ namespace wallet | |
Wallet::add_block(const Block& block) | ||
{ | ||
oxen::log::trace(logcat, "add block called with block height {}", block.height); | ||
auto db_tx = db->db_transaction(); | ||
|
||
db->store_block(block); | ||
|
||
|
@@ -164,9 +163,7 @@ namespace wallet | |
} | ||
} | ||
|
||
db_tx.commit(); | ||
|
||
last_scan_height++; | ||
} | ||
|
||
void | ||
|
@@ -185,11 +182,24 @@ namespace wallet | |
return; | ||
} | ||
|
||
std::vector<std::thread> threads; | ||
|
||
auto db_tx = db->db_transaction(); | ||
for (const auto& block : blocks) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we could There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also the insides of do we mark all functions that are pure with |
||
{ | ||
if (block.height == last_scan_height + 1) | ||
add_block(block); | ||
{ | ||
threads.emplace_back([&]() { | ||
add_block(block); | ||
}); | ||
last_scan_height++; | ||
} | ||
} | ||
// Wait for all threads to finish | ||
for (auto& t : threads) { | ||
t.join(); | ||
} | ||
db_tx.commit(); | ||
daemon_comms->register_wallet(*this, last_scan_height + 1 /*next needed block*/, false); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thinking here: what if we used a threadpool kind of entity where we put heavy but pure jobs onto. then have the these heavy functions (if they can be pure) return a
std::future
that will be fulfilled when the operation is done in the thread pool. we could have those fan out onto as many threads as we want.the following idea could look something looking like: