Skip to content
This repository was archived by the owner on Feb 12, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include <async/algorithm.h>
#include <async/FutureUtils.hpp>
#include <debug/Benchmarker.h>
#include <iostream>

#define NEW_BENCHMARK(x) std::make_shared<Benchmarker>(fmt::format(x"/{}", buddy->synchronizationTag), buddy->logger)

Expand Down Expand Up @@ -129,9 +128,7 @@ namespace ledger {
markAddress(transaction.inputs);
markAddress(transaction.outputs);
} else {
std::cout << "account transaction intepretation begin" << std::endl;
buddy->account->interpretTransaction(transaction, out);
std::cout << "account transaction intepretation end" << std::endl;
}
}

Expand Down Expand Up @@ -376,7 +373,6 @@ namespace ledger {

Future<BlockchainExplorerAccountSynchronizationResult> BlockchainExplorerAccountSynchronizer::performSynchronization(const std::shared_ptr<BitcoinLikeAccount>& account)
{
std::cout << "starting synchronization" << std::endl;
auto buddy = makeSynchronizationBuddy();
buddy->account = account;
buddy->preferences = std::static_pointer_cast<AbstractAccount>(account)->getInternalPreferences()
Expand Down Expand Up @@ -431,50 +427,38 @@ namespace ledger {
}
}
}
std::cout << "initializeSavedState" << std::endl;
initializeSavedState(buddy->savedState, buddy->halfBatchSize);
std::cout << "updateTransactionsToDrop" << std::endl;
updateTransactionsToDrop(sql, buddy, account->getAccountUid());
std::cout << "updateTransactionsToDrop finish" << std::endl;
auto self = getSharedFromThis();
self->_addresses.clear();
self->_cachedTransactionBulks.clear();
self->_hashkeys.clear();
_explorerBenchmark = NEW_BENCHMARK("explorer_calls");
std::cout << "updateCurrentBlock" << std::endl;
return self->updateCurrentBlock(buddy).template flatMap<Unit>(account->getContext(), [self, buddy](std::shared_ptr <BitcoinLikeBlockchainExplorer::Block> block) {
soci::session sql(buddy->account->getWallet()->getDatabase()->getPool());
soci::transaction tr(sql);
std::cout << "putBlock" << std::endl;
try {
buddy->account->putBlock(sql, *block);
tr.commit();
}
catch (...) {
tr.rollback();
}
std::cout << "extendKeychain" << std::endl;
return self->extendKeychain(0, buddy);
}).template flatMap<std::vector<std::shared_ptr<BitcoinLikeBlockchainExplorer::TransactionsBulk>>>(account->getContext(), [buddy, self](const Unit&) {
self->_explorerBenchmark->start();
std::cout << "requestTransactionsFromExplorer" << std::endl;
return self->requestTransactionsFromExplorer(buddy);})
.template flatMap<Unit>(account->getContext(), [buddy, self](const std::vector<std::shared_ptr<BitcoinLikeBlockchainExplorer::TransactionsBulk>>& txBulks) {
self->_explorerBenchmark->stop();
std::cout << "insert transaction bulks" << std::endl;
for (int i = 0; i < txBulks.size(); i++) {
self->_cachedTransactionBulks.insert(std::make_pair(self->_hashkeys[i], txBulks[i]));
}
std::cout << "synchronizeBatches" << std::endl;
return self->synchronizeBatches(0, buddy);
}).template flatMap<Unit>(account->getContext(), [self, buddy](auto) {
std::cout << "synchronizeMempool" << std::endl;
return self->synchronizeMempool(buddy);
}).template map<BlockchainExplorerAccountSynchronizationResult>(ImmediateExecutionContext::INSTANCE, [self, buddy](const Unit&) {
std::cout << "duration" << std::endl;
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(
(DateUtils::now() - buddy->startDate.time_since_epoch()).time_since_epoch());
std::cout << "End synchronization" << std::endl;
buddy->logger->info("End synchronization for account#{} of wallet {} in {}", buddy->account->getIndex(),
buddy->account->getWallet()->getName(), DurationUtils::formatDuration(duration));
auto const& batches = buddy->savedState.getValue().batches;
Expand All @@ -493,11 +477,9 @@ namespace ledger {
buddy->wallet->getCurrency().name).template map<uint64_t>([](const Block& block) {
return block.height;
}).getValueOr(0);
std::cout << "End!!" << std::endl;
self->_currentAccount = nullptr;
return buddy->context;
}).recover(ImmediateExecutionContext::INSTANCE, [self, buddy](const Exception& ex) {
std::cout << "Error synchronization" << std::endl;
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(
(DateUtils::now() - buddy->startDate.time_since_epoch()).time_since_epoch());
buddy->logger->error("Error during during synchronization for account#{} of wallet {} in {} ms", buddy->account->getIndex(),
Expand Down Expand Up @@ -704,17 +686,14 @@ namespace ledger {
Option<Block> lastBlock = Option<Block>::NONE;
std::vector<Operation> operations;
interpretBenchmark->start();
std::cout << "transaction intepretation1" << std::endl;
// Interpret transactions to operations and update last block
for (const auto& tx : bulk->transactions) {
// Update last block to chain query
if (lastBlock.isEmpty() ||
lastBlock.getValue().height < tx.block.getValue().height) {
lastBlock = tx.block;
}
std::cout << "transaction intepretation begin" << std::endl;
self->interpretTransaction(tx, buddy, operations);
std::cout << "transaction intepretation end" << std::endl;
//Update first pendingTxHash in savedState
auto it = buddy->transactionsToDrop.find(tx.hash);
if (it != buddy->transactionsToDrop.end()) {
Expand All @@ -729,12 +708,10 @@ namespace ledger {
//Remove from tx to drop
buddy->transactionsToDrop.erase(tx.hash);
}
std::cout << "transaction intepretation finish" << std::endl;
interpretBenchmark->stop();
auto insertionBenchmark = NEW_BENCHMARK("insert_operations");
insertionBenchmark->start();
Try<int> tryPutTx = buddy->account->bulkInsert(operations);
std::cout << "insert transaction finish" << std::endl;
insertionBenchmark->stop();
if (tryPutTx.isFailure()) {
buddy->logger->error("Failed to bulk insert for batch {} because: {}", currentBatchIndex, tryPutTx.getFailure().getMessage());
Expand Down