Skip to content

Commit a7f4a35

Browse files
author
Alexander Avramenko
committed
Merge branch 'dapsnet' of https://gitlab.com/credits_bc/core/node into dapsnet
2 parents 5dc18d0 + 176365e commit a7f4a35

21 files changed

Lines changed: 455 additions & 783 deletions

api/include/apihandler.hpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,12 +436,15 @@ public slots:
436436
const std::string& p_exec_ip, const std::string& p_exec_cmdline)
437437
: blockchain_(p_blockchain)
438438
, solver_(solver)
439-
, executorTransport_(new ::apache::thrift::transport::TBufferedTransport(
440-
::apache::thrift::stdcxx::make_shared<::apache::thrift::transport::TSocket>(p_exec_ip, p_exec_port)))
439+
, socket_(::apache::thrift::stdcxx::make_shared<::apache::thrift::transport::TSocket>(p_exec_ip, p_exec_port))
440+
, executorTransport_(new ::apache::thrift::transport::TBufferedTransport(socket_))
441441
, origExecutor_(
442442
std::make_unique<executor::ContractExecutorConcurrentClient>(::apache::thrift::stdcxx::make_shared<apache::thrift::protocol::TBinaryProtocol>(executorTransport_))) {
443443
std::string executorCmdline = p_exec_cmdline;
444444

445+
socket_->setSendTimeout(kSendTimeout);
446+
socket_->setRecvTimeout(kReceiveTimeout);
447+
445448
if (executorCmdline.empty()) {
446449
cswarning() << "Executor command line args are empty, process would not be created";
447450
return;
@@ -561,7 +564,10 @@ public slots:
561564
private:
562565
const BlockChain& blockchain_;
563566
const cs::SolverCore& solver_;
567+
568+
::apache::thrift::stdcxx::shared_ptr<::apache::thrift::transport::TSocket> socket_;
564569
::apache::thrift::stdcxx::shared_ptr<::apache::thrift::transport::TTransport> executorTransport_;
570+
565571
std::unique_ptr<executor::ContractExecutorConcurrentClient> origExecutor_;
566572
std::unique_ptr<cs::Process> executorProcess_;
567573

@@ -577,8 +583,13 @@ public slots:
577583

578584
std::condition_variable cvErrorConnect_;
579585
std::atomic_bool requestStop_{ false };
586+
580587
const int16_t EXECUTOR_VERSION = 2;
581588

589+
// timeout in ms
590+
const int kSendTimeout = 4000;
591+
const int kReceiveTimeout = 4000;
592+
582593
// temporary solution?
583594
std::mutex callExecutorLock_;
584595
};

api/src/apihandler.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -273,16 +273,12 @@ api::SealedTransaction APIHandler::convertTransaction(const csdb::Transaction& t
273273
csdb::Currency currency = transaction.currency();
274274
csdb::Address address = transaction.source();
275275
if (address.is_wallet_id()) {
276-
BlockChain::WalletData data_to_fetch_pulic_key;
277-
s_blockchain.findWalletData(transaction.source().wallet_id(), data_to_fetch_pulic_key);
278-
address = csdb::Address::from_public_key(data_to_fetch_pulic_key.address_);
276+
address = s_blockchain.getAddressByType(transaction.source(), BlockChain::AddressType::PublicKey);
279277
}
280278

281279
csdb::Address target = transaction.target();
282280
if (target.is_wallet_id()) {
283-
BlockChain::WalletData data_to_fetch_pulic_key;
284-
s_blockchain.findWalletData(transaction.target().wallet_id(), data_to_fetch_pulic_key);
285-
target = csdb::Address::from_public_key(data_to_fetch_pulic_key.address_);
281+
target = s_blockchain.getAddressByType(transaction.target(), BlockChain::AddressType::PublicKey);
286282
}
287283

288284
result.id = convert_transaction_id(transaction.id());
@@ -1978,9 +1974,9 @@ void APIHandler::TokensListGet(api::TokensListResult& _return, int64_t offset, i
19781974
}
19791975

19801976
//////////Wallets
1981-
typedef std::list<std::pair<const cs::WalletsCache::WalletData::Address*, const cs::WalletsCache::WalletData*>> WCSortedList;
1977+
typedef std::list<std::pair<const cs::PublicKey*, const cs::WalletsCache::WalletData*>> WCSortedList;
19821978
template <typename T>
1983-
void walletStep(const cs::WalletsCache::WalletData::Address* addr, const cs::WalletsCache::WalletData* wd, const uint64_t num,
1979+
void walletStep(const cs::PublicKey* addr, const cs::WalletsCache::WalletData* wd, const uint64_t num,
19841980
std::function<const T&(const cs::WalletsCache::WalletData&)> getter, std::function<bool(const T&, const T&)> comparator, WCSortedList& lst) {
19851981
assert(num > 0);
19861982

@@ -2005,7 +2001,7 @@ void iterateOverWallets(std::function<const T&(const cs::WalletsCache::WalletDat
20052001
using Comparer = std::function<bool(const T&, const T&)>;
20062002
Comparer comparator = desc ? Comparer(std::greater<T>()) : Comparer(std::less<T>());
20072003

2008-
bc.iterateOverWallets([&lst, num, getter, comparator](const cs::WalletsCache::WalletData::Address& addr, const cs::WalletsCache::WalletData& wd) {
2004+
bc.iterateOverWallets([&lst, num, getter, comparator](const cs::PublicKey& addr, const cs::WalletsCache::WalletData& wd) {
20092005
if (!addr.empty() && wd.balance_ >= csdb::Amount(0)) {
20102006
walletStep(&addr, &wd, num, getter, comparator, lst);
20112007
}
@@ -2069,7 +2065,7 @@ void APIHandler::TrustedGet(TrustedGetResult& _return, int32_t _page) {
20692065
uint32_t limit = PER_PAGE;
20702066
uint32_t total = 0;
20712067

2072-
s_blockchain.iterateOverWriters([&_return, &offset, &limit, &total](const cs::WalletsCache::WalletData::Address& addr, const cs::WalletsCache::TrustedData& wd) {
2068+
s_blockchain.iterateOverWriters([&_return, &offset, &limit, &total](const cs::PublicKey& addr, const cs::WalletsCache::TrustedData& wd) {
20732069
if (addr.empty()) {
20742070
return true;
20752071
}

csdb/include/csdb/database.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class Database {
4747

4848
virtual bool putToTransIndex(const cs::Bytes& key, const cs::Bytes& value) = 0;
4949
virtual bool getFromTransIndex(const cs::Bytes& key, cs::Bytes* value) = 0;
50+
virtual bool removeLastFromTrxIndex(const cs::Bytes& key) = 0;
5051
virtual void truncateTransIndex() = 0;
5152

5253
virtual bool updateContractData(const cs::Bytes& key, const cs::Bytes& data) = 0;

csdb/include/csdb/database_berkeleydb.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class DatabaseBerkeleyDB : public Database {
4040

4141
bool putToTransIndex(const cs::Bytes& key, const cs::Bytes& value) override final;
4242
bool getFromTransIndex(const cs::Bytes& key, cs::Bytes* value) override final;
43+
bool removeLastFromTrxIndex(const cs::Bytes& key) override final;
4344
void truncateTransIndex() override final;
4445

4546
bool updateContractData(const cs::Bytes& key, const cs::Bytes& data) override;

csdb/include/csdb/storage.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ class Storage final {
227227
// And now for something completely different
228228
cs::Sequence get_previous_transaction_block(const Address&, cs::Sequence) const;
229229
void set_previous_transaction_block(const Address&, cs::Sequence currTransBlock, cs::Sequence prevTransBlock);
230+
void remove_last_from_trx_index(const Address&, cs::Sequence lastIndexed);
230231
void truncate_trxs_index();
231232

232233
/**

csdb/src/database_berkeleydb.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,24 @@ bool DatabaseBerkeleyDB::putToTransIndex(const cs::Bytes &key, const cs::Bytes &
497497
return true;
498498
}
499499

500+
bool DatabaseBerkeleyDB::removeLastFromTrxIndex(const cs::Bytes &key) {
501+
if (!db_trans_idx_) {
502+
set_last_error(NotOpen);
503+
return false;
504+
}
505+
506+
Dbt_copy<cs::Bytes> db_key(key);
507+
508+
int status = db_trans_idx_->del(nullptr, &db_key, 0);
509+
if (status != 0) {
510+
set_last_error_from_berkeleydb(status);
511+
return false;
512+
}
513+
514+
set_last_error();
515+
return true;
516+
}
517+
500518
bool DatabaseBerkeleyDB::getFromTransIndex(const cs::Bytes &key, cs::Bytes *value) {
501519
if (!db_trans_idx_) {
502520
set_last_error(NotOpen);

csdb/src/storage.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,10 @@ void Storage::set_previous_transaction_block(const Address& addr, cs::Sequence c
871871
d->db->putToTransIndex(key, os.buffer());
872872
}
873873

874+
void Storage::remove_last_from_trx_index(const Address& addr, cs::Sequence lastIndexed) {
875+
d->db->removeLastFromTrxIndex(get_trans_index_key(addr, lastIndexed));
876+
}
877+
874878
void Storage::truncate_trxs_index() {
875879
d->db->truncateTransIndex();
876880
}

csnode/include/csnode/blockchain.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class BlockChain {
115115
}
116116

117117
void removeWalletsInPoolFromCache(const csdb::Pool& pool);
118+
void removeLastBlockFromTrxIndex(const csdb::Pool&);
118119
void removeLastBlock();
119120

120121
// updates fees in every transaction
@@ -214,7 +215,7 @@ public slots:
214215
csdb::Pool loadBlock(const cs::Sequence sequence) const;
215216
csdb::Pool loadBlockMeta(const csdb::PoolHash&, size_t& cnt) const;
216217
csdb::Transaction loadTransaction(const csdb::TransactionID&) const;
217-
void iterateOverWallets(const std::function<bool(const cs::WalletsCache::WalletData::Address&, const cs::WalletsCache::WalletData&)>);
218+
void iterateOverWallets(const std::function<bool(const cs::PublicKey&, const cs::WalletsCache::WalletData&)>);
218219
csdb::Pool getLastBlock() const {
219220
return loadBlock(getLastSeq());
220221
}
@@ -234,11 +235,9 @@ public slots:
234235
bool findWalletId(const WalletAddress& address, WalletId& id) const;
235236
// wallet transactions: pools cache + db search
236237
void getTransactions(Transactions& transactions, csdb::Address address, uint64_t offset, uint64_t limit);
237-
// wallets modified by last new block
238-
bool getModifiedWallets(Mask& dest) const;
239238

240239
#ifdef MONITOR_NODE
241-
void iterateOverWriters(const std::function<bool(const cs::WalletsCache::WalletData::Address&, const cs::WalletsCache::TrustedData&)>);
240+
void iterateOverWriters(const std::function<bool(const cs::PublicKey&, const cs::WalletsCache::TrustedData&)>);
242241
void applyToWallet(const csdb::Address&, const std::function<void(const cs::WalletsCache::WalletData&)>);
243242
#endif
244243
uint32_t getTransactionsCount(const csdb::Address&);
@@ -257,6 +256,10 @@ public slots:
257256
bool updateContractData(const csdb::Address& abs_addr, const cs::Bytes& data) const;
258257
bool getContractData(const csdb::Address& abs_addr, cs::Bytes& data) const;
259258

259+
const cs::WalletsCache::Updater& getCacheUpdater() const {
260+
return *(walletsCacheUpdater_.get());
261+
}
262+
260263
private:
261264
void createCachesPath();
262265
bool findAddrByWalletId(const WalletId id, csdb::Address& addr) const;
@@ -271,9 +274,7 @@ public slots:
271274
void onReadFromDB(csdb::Pool block, bool* shouldStop);
272275
bool postInitFromDB();
273276

274-
template <typename WalletCacheProcessor>
275-
bool updateWalletIds(const csdb::Pool& pool, WalletCacheProcessor& proc);
276-
bool insertNewWalletId(const csdb::Address& newWallAddress, WalletId newWalletId, cs::WalletsCache::Initer& initer);
277+
bool updateWalletIds(const csdb::Pool& pool, cs::WalletsCache::Updater& updater);
277278
bool insertNewWalletId(const csdb::Address& newWallAddress, WalletId newWalletId, cs::WalletsCache::Updater& updater);
278279

279280
void addNewWalletToPool(const csdb::Address& walletAddress, const csdb::Pool::NewWalletInfo::AddressId& addressId, csdb::Pool::NewWallets& newWallets);

csnode/include/csnode/transactionstail.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include "bitheap.hpp"
55

6+
#include <sstream>
7+
68
namespace cs {
79
class TransactionsTail {
810
public:

0 commit comments

Comments
 (0)