Skip to content

Commit c9acbd4

Browse files
author
Alexander Avramenko
committed
Merge branch 'dapsnet'
2 parents ae8a1de + 7bcba0f commit c9acbd4

10 files changed

Lines changed: 91 additions & 40 deletions

File tree

api/include/apihandler.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ public slots:
470470
});
471471
}
472472

473-
static const int kReconnectTime = 5;
473+
static const int kReconnectTime = 2;
474474
std::this_thread::sleep_for(std::chrono::seconds(kReconnectTime));
475475

476476
if (!isConnect()) {
@@ -523,10 +523,6 @@ public slots:
523523

524524
bool connect() {
525525
try {
526-
if (executorTransport_->isOpen()) {
527-
executorTransport_->close();
528-
}
529-
530526
executorTransport_->open();
531527
}
532528
catch (...) {

api/src/apihandler.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,9 +2220,10 @@ namespace executor {
22202220

22212221
void Executor::executeByteCodeMultiple(ExecuteByteCodeMultipleResult& _return, const ::general::Address& initiatorAddress, const SmartContractBinary& invokedContract,
22222222
const std::string& method, const std::vector<std::vector<::general::Variant>>& params, const int64_t executionTime, cs::Sequence sequence) {
2223-
if (!connect()) {
2223+
if (!isConnect()) {
22242224
_return.status.code = 1;
22252225
_return.status.message = "No executor connection!";
2226+
notifyError();
22262227
return;
22272228
}
22282229
const auto access_id = generateAccessId(sequence);
@@ -2584,7 +2585,8 @@ namespace executor {
25842585
const SmartContractBinary& smartContractBinary, std::vector<MethodHeader>& methodHeader, bool isGetter, cs::Sequence explicit_sequence) {
25852586
constexpr uint64_t EXECUTION_TIME = Consensus::T_smart_contract;
25862587
OriginExecuteResult originExecuteRes{};
2587-
if (!connect()) {
2588+
if (!isConnect()) {
2589+
notifyError();
25882590
return std::nullopt;
25892591
}
25902592

csnode/src/blockchain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ bool BlockChain::finalizeBlock(csdb::Pool& pool, bool isTrusted, cs::PublicKeys
619619
csmeta(csdebug) << "The number of signatures is sufficient and all of them are OK!";
620620
}
621621
else {
622-
cswarning() << "Some of Pool Signatures aren't valid. The pool will not be written to DB";
622+
cswarning() << "Some of Pool Signatures aren't valid. The pool will not be written to DB. It will be automatically written, when we get proper data";
623623
return false;
624624
}
625625
}
@@ -1203,7 +1203,7 @@ bool BlockChain::deferredBlockExchange(cs::RoundPackage& rPackage, const csdb::P
12031203

12041204
}
12051205
else {
1206-
cswarning() << "Some of Pool Signatures aren't valid. The pool will not be written to DB";
1206+
cswarning() << "Some of Pool Signatures aren't valid. The pool will not be written to DB. It will be automatically written, when we get proper data";
12071207
return false;
12081208
}
12091209
return true;

csnode/src/node.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ void Node::stop() {
142142

143143
/* Requests */
144144
void Node::flushCurrentTasks() {
145+
145146
transport_->addTask(ostream_.getPackets(), ostream_.getPacketsCount());
146147
ostream_.clear();
147148
}
@@ -1269,7 +1270,9 @@ void Node::sendBroadcastImpl(const MsgTypes& msgType, const cs::RoundNumber roun
12691270

12701271
csdetails() << "NODE> Sending broadcast data: size: " << ostream_.getCurrentSize() << ", last packet size: " << ostream_.getCurrentSize() << ", round: " << round
12711272
<< ", msgType: " << Packet::messageTypeToString(msgType);
1272-
1273+
//if (ostream_.getPacketsCount() > 100) {
1274+
// csinfo() << __func__ << ": sending " << ostream_.getPacketsCount() << " packets";
1275+
//}
12731276
transport_->deliverBroadcast(ostream_.getPackets(), ostream_.getPacketsCount());
12741277
ostream_.clear();
12751278
}
@@ -1567,7 +1570,7 @@ void Node::getStageThree(const uint8_t* data, const size_t size) {
15671570

15681571
stage.messageBytes = std::move(bytes);
15691572

1570-
csdebug() << "NODE> stage-3 from T[" << static_cast<int>(stage.sender) << "] is OK!";
1573+
csdebug() << "NODE> stage-3 from T[" << static_cast<int>(stage.sender) << "] - preliminary check ... passed!";
15711574

15721575
solver_->gotStageThree(std::move(stage), (stageThreeSent_ ? 2 : 0));
15731576
}
@@ -2270,6 +2273,7 @@ void Node::performRoundPackage(cs::RoundPackage& rPackage, const cs::PublicKey&
22702273
getCharacteristic(rPackage);
22712274

22722275
onRoundStart(cs::Conveyer::instance().currentRoundTable());
2276+
csinfo() << "Confidants: " << rPackage.roundTable().confidants.size() << ", Hashes: " << rPackage.roundTable().hashes.size();
22732277
reviewConveyerHashes();
22742278

22752279
csmeta(csdetails) << "done\n";

net/include/net/packet.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ class Packet {
282282
return packetSize;
283283
}
284284

285-
// returns true if is not fragmented or has valid fragmebtation data
285+
// returns true if is not fragmented or has valid fragmentation data
286286
bool hasValidFragmentation() const {
287287
if (isFragmented()) {
288288
const auto fragment = getFragmentId();

net/src/network.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,9 @@ void Network::writerRoutine(const Config& config) {
339339
int tasks = writerTaskCount_;
340340
writerTaskCount_ = 0;
341341
writerLock.clear(std::memory_order_release); // release lock
342-
342+
//if (tasks > 100) {
343+
// csinfo() << __func__ << ": got package of " << tasks << " tasks";
344+
//}
343345
for (int i = 0; i < tasks; i++) {
344346
bool is_empty = false;
345347
auto task = oPacMan_.getNextTask(is_empty);
@@ -423,7 +425,9 @@ void Network::processorRoutine() {
423425
int tasks = readerTaskCount_;
424426
readerTaskCount_ = 0;
425427
readerLock.clear(std::memory_order_release); // release lock
426-
428+
//if (tasks > 100) {
429+
// csinfo() << __func__ << ": got package of " << tasks << " tasks";
430+
//}
427431
for (int i = 0; i < tasks; i++) {
428432
bool is_empty = false;
429433
auto task = iPacMan_.getNextTask(is_empty);
@@ -652,6 +656,10 @@ void Network::sendInit() {
652656
}
653657

654658
void Network::registerMessage(Packet* pack, const uint32_t size) {
659+
660+
if (size >= 1000) {
661+
csinfo() << "Found large message, size = " << size;
662+
}
655663
if (size >= Packet::MaxFragments) {
656664
cserror() << "Too much fragments in message to send (" << size << "), ignore";
657665
return;

net/src/pacmans.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ void IPacMan::enQueueLast() {
1515
task.pack.setSize(static_cast<uint32_t>(task.size));
1616

1717
size_.fetch_add(1, std::memory_order_acq_rel);
18+
//if (size_ > 500) {
19+
// csinfo() << __func__ << ": IPackMan queue size = " << queue_.size();
20+
//}
1821
}
1922

2023
void IPacMan::rejectLast() {
@@ -31,13 +34,19 @@ TaskPtr<IPacMan> IPacMan::getNextTask(bool &is_empty) {
3134
std::lock_guard<std::mutex> lock(mutex_);
3235
result.owner_ = this;
3336
result.it_ = queue_.begin();
37+
//if (size_ > 500) {
38+
// csinfo() << __func__ << ": IPackMan queue size = " << queue_.size();
39+
//}
3440
return result;
3541
}
3642

3743
void IPacMan::releaseTask(TaskIterator& it) {
3844
std::lock_guard<std::mutex> lock(mutex_);
3945
queue_.erase(it);
4046
size_.fetch_sub(1, std::memory_order_acq_rel);
47+
//if (size_ > 500) {
48+
// csinfo() << __func__ << ": IPackMan queue size = " << queue_.size();
49+
//}
4150
}
4251

4352
OPacMan::Task* OPacMan::allocNext() {
@@ -50,6 +59,9 @@ OPacMan::Task* OPacMan::allocNext() {
5059

5160
void OPacMan::enQueueLast() {
5261
size_.fetch_add(1, std::memory_order_acq_rel);
62+
//if (size_ > 500) {
63+
// csinfo() << __func__ << ": OPackMan queue size = " << queue_.size();
64+
//}
5365
}
5466

5567
TaskPtr<OPacMan> OPacMan::getNextTask(bool &is_empty) {
@@ -61,11 +73,17 @@ TaskPtr<OPacMan> OPacMan::getNextTask(bool &is_empty) {
6173
std::lock_guard<std::mutex> lock(mutex_);
6274
result.owner_ = this;
6375
result.it_ = queue_.begin();
76+
//if (size_ > 500) {
77+
// csinfo() << __func__ << ": OPackMan queue size = " << queue_.size();
78+
//}
6479
return result;
6580
}
6681

6782
void OPacMan::releaseTask(TaskIterator& it) {
6883
std::lock_guard<std::mutex> lock(mutex_);
6984
queue_.erase(it);
7085
size_.fetch_sub(1, std::memory_order_acq_rel);
86+
//if (size_ > 500) {
87+
// csinfo() << __func__ << ": OPackMan queue size = " << queue_.size();
88+
//}
7189
}

net/src/transport.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ bool Transport::sendDirect(const Packet* pack, const Connection& conn) {
273273
void Transport::deliverDirect(const Packet* pack, const uint32_t size, ConnectionPtr conn) {
274274
if (size >= Packet::MaxFragments) {
275275
++Transport::cntExtraLargeNotSent;
276+
csinfo() << __func__ << ": packSize(" << Transport::cntExtraLargeNotSent << ") = " << size;
276277
return;
277278
}
278279
const auto packEnd = pack + size;
@@ -285,6 +286,7 @@ void Transport::deliverDirect(const Packet* pack, const uint32_t size, Connectio
285286
void Transport::deliverBroadcast(const Packet* pack, const uint32_t size) {
286287
if (size >= Packet::MaxFragments) {
287288
++Transport::cntExtraLargeNotSent;
289+
csinfo() << __func__ << ": packSize(" << Transport::cntExtraLargeNotSent << ") = " << size;
288290
return;
289291
}
290292
const auto packEnd = pack + size;
@@ -667,6 +669,7 @@ void Transport::registerTask(Packet* pack, const uint32_t packNum, const bool in
667669
void Transport::addTask(Packet* pack, const uint32_t packNum, bool incrementWhenResend) {
668670
if (packNum >= Packet::MaxFragments) {
669671
++Transport::cntExtraLargeNotSent;
672+
csinfo() << __func__ << ": packSize(" << Transport::cntExtraLargeNotSent << ") = " << packNum;
670673
return;
671674
}
672675
nh_.pourByNeighbours(pack, packNum);

solver/src/solvercore.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,14 @@ void SolverCore::handleTransitions(Event evt) {
188188

189189
bool SolverCore::stateCompleted(Result res) {
190190
if (Result::Failure == res) {
191-
cserror() << log_prefix << "error in state " << (pstate ? pstate->name() : "null");
191+
cserror() << log_prefix << "error in state " << (pstate ? pstate->name() : "null - Consensus state can't be completed. Trying to resolve ... ");
192192
}
193193
return (Result::Finish == res);
194194
}
195195

196196
bool SolverCore::stateFailed(Result res) {
197197
if (Result::Failure == res) {
198-
cserror() << log_prefix << "error in state " << (pstate ? pstate->name() : "null");
198+
cserror() << log_prefix << "error in state " << (pstate ? pstate->name() : "null - Consensus state can't be completed. Trying to resolve ... ");
199199
return true;
200200
}
201201
return false;
@@ -446,7 +446,13 @@ void SolverCore::spawn_next_round(const cs::PublicKeys& nodes, const cs::Packets
446446
const auto lastHashBin = deferredBlock_.hash().to_binary();
447447

448448
std::copy(lastHashBin.cbegin(), lastHashBin.cend(), stage3.blockHash.begin());
449-
stage3.blockSignature = cscrypto::generateSignature(private_key, stage3.blockHash.data(), stage3.blockHash.size());
449+
if (stage3.sender == 1 && conveyer.currentRoundNumber() > 10) {
450+
stage3.blockSignature = Zero::signature;
451+
}
452+
else {
453+
stage3.blockSignature = cscrypto::generateSignature(private_key, stage3.blockHash.data(), stage3.blockHash.size());
454+
}
455+
450456

451457
//pnode->prepareRoundTable(table, poolMetaInfo, stage3);
452458
//csmeta(csdetails) << "end";
@@ -490,7 +496,7 @@ void SolverCore::sendRoundTable() {
490496
bool SolverCore::addSignaturesToDeferredBlock(cs::Signatures&& blockSignatures) {
491497
csmeta(csdetails) << "begin";
492498
if (!deferredBlock_.is_valid()) {
493-
csmeta(cserror) << " ... Failed!!!";
499+
csmeta(cserror) << " ... Failed - deferred block is not valid. Node will solve this problem automatically";
494500
return false;
495501
}
496502

@@ -502,7 +508,7 @@ bool SolverCore::addSignaturesToDeferredBlock(cs::Signatures&& blockSignatures)
502508
auto resPool = pnode->getBlockChain().createBlock(deferredBlock_);
503509

504510
if (!resPool.has_value()) {
505-
cserror() << log_prefix << "Blockchain failed to write new block";
511+
cserror() << log_prefix << "Blockchain failed to write new block, it will do it later when get proper data";
506512
return false;
507513
}
508514
//pnode->cleanConfirmationList(deferredBlock_.sequence());

solver/src/solverinterface.cpp

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -244,39 +244,53 @@ void SolverCore::gotStageThree(const cs::StageThree& stage, const uint8_t flagg)
244244

245245
auto lamda = [this](const cs::StageThree& stageFrom, const cs::StageThree& stageTo) {
246246
const cs::Conveyer& conveyer = cs::Conveyer::instance();
247-
bool somethingInvalid = false;
247+
bool markedUntrusted = false;
248248
if (stageTo.realTrustedMask[stageFrom.sender] == cs::ConfidantConsts::InvalidConfidantIndex) {
249-
cswarning() << "The node, who sent this stage was marked as untrusted";
250-
somethingInvalid = true;
249+
markedUntrusted = true;
251250
}
252-
251+
bool invalidBlockSignatures = false;
253252
if (!cscrypto::verifySignature(stageFrom.blockSignature, conveyer.confidantByIndex(stageFrom.sender), stageTo.blockHash.data(), stageTo.blockHash.size())) {
254-
cswarning() << "Block Signatures are not valid ! -> ";
255-
somethingInvalid = true;
253+
invalidBlockSignatures = true;
256254
}
257-
255+
bool invalidRoundSignatures = false;
258256
if (!cscrypto::verifySignature(stageFrom.roundSignature, conveyer.confidantByIndex(stageFrom.sender), stageTo.roundHash.data(), stageTo.roundHash.size())) {
259-
cswarning() << "Round Signatures are not valid !";
260-
somethingInvalid = true;
257+
invalidRoundSignatures = true;
261258
}
262-
259+
bool invalidTrustedSignatures = false;
263260
if (!cscrypto::verifySignature(stageFrom.trustedSignature, conveyer.confidantByIndex(stageFrom.sender), stageTo.trustedHash.data(), stageTo.trustedHash.size())) {
264-
cswarning() << "Trusted Signatures are not valid !";
265-
somethingInvalid = true;
261+
invalidTrustedSignatures = true;
266262
}
267-
263+
bool invalidRealTrustedMask = false;
268264
if (!(stageFrom.realTrustedMask == stageTo.realTrustedMask) || stageTo.realTrustedMask[stageFrom.sender] == cs::ConfidantConsts::InvalidConfidantIndex) {
269-
cswarning() << "Real Trusted are not valid !";
270-
somethingInvalid = true;
265+
bool invalidRealTrustedMask = false;
271266
}
272-
267+
bool invalidWriter = false;
273268
if (!(stageFrom.writer == stageTo.writer)) {
274-
cswarning() << "Writer is not valid !";
275-
somethingInvalid = true;
269+
invalidWriter = true;
276270
}
277271

278-
if (somethingInvalid) {
272+
if (markedUntrusted || invalidBlockSignatures || invalidRoundSignatures || invalidTrustedSignatures || invalidRealTrustedMask || invalidWriter){
273+
cswarning() << "Stage3 from T[" << static_cast<int>(stageFrom.sender) << "] - final check ... NOT PASSED! This problem will be resolved automatically.";
274+
csdebug() << "The stage below has next problems:";
275+
if (markedUntrusted) {
276+
csdebug() << "--> The node, that sent this stage was marked as untrusted";
277+
}
279278
if (stageTo.realTrustedMask[stageFrom.sender] != cs::ConfidantConsts::InvalidConfidantIndex) {
279+
if (invalidBlockSignatures) {
280+
csdebug() << "--> Block Signatures are not valid";
281+
}
282+
if (invalidRoundSignatures) {
283+
csdebug() << "--> Round Signatures are not valid.";
284+
}
285+
if (invalidTrustedSignatures) {
286+
csdebug() << "--> Trusted Signatures are not valid.";
287+
}
288+
if (invalidRealTrustedMask) {
289+
csdebug() << "--> Real Trusted are not valid.";
290+
}
291+
if (invalidWriter) {
292+
csdebug() << "--> Writer is not valid.";
293+
}
280294
csdebug() << cs::StageThree::toString(stageFrom);
281295
realTrustedSetValue(stageFrom.sender, cs::ConfidantConsts::InvalidConfidantIndex);
282296
}
@@ -288,7 +302,7 @@ void SolverCore::gotStageThree(const cs::StageThree& stage, const uint8_t flagg)
288302
//}
289303
trueStageThreeStorage.emplace_back(stageFrom);
290304
addRoundSignature(stageFrom);
291-
csdebug() << "Stage3 [" << static_cast<int>(stageFrom.sender) << "] - signatures are OK";
305+
csdebug() << "Stage3 from T[" << static_cast<int>(stageFrom.sender) << "] - final check ... passed!";
292306
};
293307

294308
switch (flagg) {
@@ -332,7 +346,7 @@ void SolverCore::gotStageThree(const cs::StageThree& stage, const uint8_t flagg)
332346
handleTransitions(Event::Stage3NonComplete);
333347
break;
334348
case Result::Failure:
335-
cserror() << "SolverCore: error in state " << (pstate ? pstate->name() : "null");
349+
cserror() << "SolverCore: error in state " << (pstate ? pstate->name() : "null - Consensus state can't be completed. Trying to resolve ... ");
336350
removeDeferredBlock(deferredBlock_.sequence());
337351
handleTransitions(Event::SetNormal);
338352
break;

0 commit comments

Comments
 (0)