Skip to content

Commit ce6c299

Browse files
committed
Get rid of std::cerr logs in collator/validator
1 parent 3c245c6 commit ce6c299

File tree

14 files changed

+310
-200
lines changed

14 files changed

+310
-200
lines changed

crypto/block/block.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,6 @@ MsgProcessedUptoCollection::MsgProcessedUptoCollection(ton::ShardIdFull _owner,
360360
z.shard = key.get_uint(64);
361361
z.mc_seqno = (unsigned)((key + 64).get_uint(32));
362362
z.last_inmsg_lt = value.write().fetch_ulong(64);
363-
// std::cerr << "ProcessedUpto shard " << std::hex << z.shard << std::dec << std::endl;
364363
return value.write().fetch_bits_to(z.last_inmsg_hash) && z.shard && ton::shard_contains(owner.shard, z.shard);
365364
});
366365
}
@@ -862,8 +861,10 @@ td::Status ShardState::unpack_out_msg_queue_info(Ref<vm::Cell> out_msg_queue_inf
862861
out_msg_queue_ =
863862
std::make_unique<vm::AugmentedDictionary>(std::move(qinfo.out_queue), 352, block::tlb::aug_OutMsgQueue);
864863
if (verbosity >= 3 * 1) {
865-
LOG(DEBUG) << "unpacking ProcessedUpto of our previous block " << id_.to_str();
866-
block::gen::t_ProcessedInfo.print(std::cerr, qinfo.proc_info);
864+
FLOG(DEBUG) {
865+
sb << "unpacking ProcessedUpto of our previous block " << id_.to_str();
866+
block::gen::t_ProcessedInfo.print(sb, qinfo.proc_info);
867+
};
867868
}
868869
if (!block::gen::t_ProcessedInfo.validate_csr(1024, qinfo.proc_info)) {
869870
return td::Status::Error(

crypto/block/mc-config.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,11 @@ td::Status ConfigInfo::unpack() {
163163
}
164164
gen::McStateExtra::Record extra_info;
165165
if (!tlb::unpack_cell(state_extra_root_, extra_info)) {
166-
vm::load_cell_slice(state_extra_root_).print_rec(std::cerr);
167-
block::gen::t_McStateExtra.print_ref(std::cerr, state_extra_root_);
166+
FLOG(WARNING) {
167+
sb << "state extra information is invalid: ";
168+
vm::load_cell_slice(state_extra_root_).print_rec(sb);
169+
block::gen::t_McStateExtra.print_ref(sb, state_extra_root_);
170+
};
168171
return td::Status::Error("state extra information is invalid");
169172
}
170173
gen::ValidatorInfo::Record validator_info;
@@ -1067,7 +1070,6 @@ Ref<McShardHash> ShardConfig::get_shard_hash(ton::ShardIdFull id, bool exact) co
10671070
ton::ShardIdFull true_id;
10681071
vm::CellSlice cs;
10691072
if (get_shard_hash_raw(cs, id, true_id, exact)) {
1070-
// block::gen::t_ShardDescr.print(std::cerr, vm::CellSlice{cs});
10711073
return McShardHash::unpack(cs, true_id);
10721074
} else {
10731075
return {};
@@ -1637,8 +1639,10 @@ bool ShardConfig::set_shard_info(ton::ShardIdFull shard, Ref<vm::Cell> value) {
16371639
if (!gen::t_BinTree_ShardDescr.validate_ref(1024, value)) {
16381640
LOG(ERROR) << "attempting to store an invalid (BinTree ShardDescr) at shard configuration position "
16391641
<< shard.to_str();
1640-
gen::t_BinTree_ShardDescr.print_ref(std::cerr, value);
1641-
vm::load_cell_slice(value).print_rec(std::cerr);
1642+
FLOG(WARNING) {
1643+
gen::t_BinTree_ShardDescr.print_ref(sb, value);
1644+
vm::load_cell_slice(value).print_rec(sb);
1645+
};
16421646
return false;
16431647
}
16441648
auto root = shard_hashes_dict_->lookup_ref(td::BitArray<32>{shard.workchain});

crypto/block/output-queue-merger.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ bool OutputQueueMerger::add_root(int src, Ref<vm::Cell> outmsg_root) {
138138
if (outmsg_root.is_null()) {
139139
return true;
140140
}
141-
//block::gen::HashmapAug{352, block::gen::t_EnqueuedMsg, block::gen::t_uint64}.print_ref(std::cerr, outmsg_root);
142141
auto kv = std::make_unique<MsgKeyValue>(src, std::move(outmsg_root));
143142
if (kv->replace_by_prefix(common_pfx.cbits(), common_pfx_len)) {
144143
heap.push_back(std::move(kv));

crypto/block/transaction.cpp

Lines changed: 59 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,10 @@ bool Account::unpack(Ref<vm::CellSlice> shard_account, ton::UnixTime now, bool s
446446
return false;
447447
}
448448
if (verbosity > 2) {
449-
shard_account->print_rec(std::cerr, 2);
450-
block::gen::t_ShardAccount.print(std::cerr, *shard_account);
449+
FLOG(INFO) {
450+
shard_account->print_rec(sb, 2);
451+
block::gen::t_ShardAccount.print(sb, shard_account);
452+
};
451453
}
452454
block::gen::ShardAccount::Record acc_info;
453455
if (!(block::tlb::t_ShardAccount.validate_csr(shard_account) && tlb::unpack_exact(shard_account.write(), acc_info))) {
@@ -737,9 +739,11 @@ bool Transaction::unpack_input_msg(bool ihr_delivered, const ActionPhaseConfig*
737739
return false;
738740
}
739741
if (verbosity > 2) {
740-
fprintf(stderr, "unpacking inbound message for a new transaction: ");
741-
block::gen::t_Message_Any.print_ref(std::cerr, in_msg);
742-
load_cell_slice(in_msg).print_rec(std::cerr);
742+
FLOG(INFO) {
743+
sb << "unpacking inbound message for a new transaction: ";
744+
block::gen::t_Message_Any.print_ref(sb, in_msg);
745+
load_cell_slice(in_msg).print_rec(sb);
746+
};
743747
}
744748
auto cs = vm::load_cell_slice(in_msg);
745749
int tag = block::gen::t_CommonMsgInfo.get_tag(cs);
@@ -1550,11 +1554,13 @@ bool Transaction::run_precompiled_contract(const ComputePhaseConfig& cfg, precom
15501554
cp.actions = impl.get_c5();
15511555
int out_act_num = output_actions_count(cp.actions);
15521556
if (verbosity > 2) {
1553-
std::cerr << "new smart contract data: ";
1554-
bool can_be_special = true;
1555-
load_cell_slice_special(cp.new_data, can_be_special).print_rec(std::cerr);
1556-
std::cerr << "output actions: ";
1557-
block::gen::OutList{out_act_num}.print_ref(std::cerr, cp.actions);
1557+
FLOG(INFO) {
1558+
sb << "new smart contract data: ";
1559+
bool can_be_special = true;
1560+
load_cell_slice_special(cp.new_data, can_be_special).print_rec(sb);
1561+
sb << "output actions: ";
1562+
block::gen::OutList{out_act_num}.print_ref(sb, cp.actions);
1563+
};
15581564
}
15591565
}
15601566
cp.mode = 0;
@@ -1619,7 +1625,6 @@ bool Transaction::prepare_compute_phase(const ComputePhaseConfig& cfg) {
16191625
if (in_msg_state.not_null()) {
16201626
LOG(DEBUG) << "HASH(in_msg_state) = " << in_msg_state->get_hash().bits().to_hex(256)
16211627
<< ", account_state_hash = " << account.state_hash.to_hex();
1622-
// vm::load_cell_slice(in_msg_state).print_rec(std::cerr);
16231628
} else {
16241629
LOG(DEBUG) << "in_msg_state is null";
16251630
}
@@ -1775,11 +1780,13 @@ bool Transaction::prepare_compute_phase(const ComputePhaseConfig& cfg) {
17751780
cp.actions = vm.get_committed_state().c5; // c5 -> action list
17761781
int out_act_num = output_actions_count(cp.actions);
17771782
if (verbosity > 2) {
1778-
std::cerr << "new smart contract data: ";
1779-
bool can_be_special = true;
1780-
load_cell_slice_special(cp.new_data, can_be_special).print_rec(std::cerr);
1781-
std::cerr << "output actions: ";
1782-
block::gen::OutList{out_act_num}.print_ref(std::cerr, cp.actions);
1783+
FLOG(INFO) {
1784+
sb << "new smart contract data: ";
1785+
bool can_be_special = true;
1786+
load_cell_slice_special(cp.new_data, can_be_special).print_rec(sb);
1787+
sb << "output actions: ";
1788+
block::gen::OutList{out_act_num}.print_ref(sb, cp.actions);
1789+
};
17831790
}
17841791
}
17851792
cp.mode = 0;
@@ -2725,14 +2732,18 @@ int Transaction::try_action_send_msg(const vm::CellSlice& cs0, ActionPhase& ap,
27252732
}
27262733
if (!block::gen::t_Message_Any.validate_ref(new_msg)) {
27272734
LOG(ERROR) << "generated outbound message is not a valid (Message Any) according to automated check";
2728-
block::gen::t_Message_Any.print_ref(std::cerr, new_msg);
2729-
vm::load_cell_slice(new_msg).print_rec(std::cerr);
2735+
FLOG(INFO) {
2736+
block::gen::t_Message_Any.print_ref(sb, new_msg);
2737+
vm::load_cell_slice(new_msg).print_rec(sb);
2738+
};
27302739
collect_fine();
27312740
return -1;
27322741
}
27332742
if (verbosity > 2) {
2734-
std::cerr << "converted outbound message: ";
2735-
block::gen::t_Message_Any.print_ref(std::cerr, new_msg);
2743+
FLOG(INFO) {
2744+
sb << "converted outbound message: ";
2745+
block::gen::t_Message_Any.print_ref(sb, new_msg);
2746+
};
27362747
}
27372748

27382749
ap.msgs_created++;
@@ -3045,8 +3056,10 @@ bool Transaction::prepare_bounce_phase(const ActionPhaseConfig& cfg) {
30453056
}
30463057
CHECK(cb.finalize_to(bp.out_msg));
30473058
if (verbosity > 2) {
3048-
LOG(INFO) << "generated bounced message: ";
3049-
block::gen::t_Message_Any.print_ref(std::cerr, bp.out_msg);
3059+
FLOG(INFO) {
3060+
sb << "generated bounced message: ";
3061+
block::gen::t_Message_Any.print_ref(sb, bp.out_msg);
3062+
};
30503063
}
30513064
out_msgs.push_back(bp.out_msg);
30523065
bp.ok = true;
@@ -3167,11 +3180,13 @@ bool Transaction::compute_state() {
31673180
auto frozen_state = cb2.finalize();
31683181
frozen_hash = frozen_state->get_hash().bits();
31693182
if (verbosity >= 3 * 1) { // !!!DEBUG!!!
3170-
std::cerr << "freezing state of smart contract: ";
3171-
block::gen::t_StateInit.print_ref(std::cerr, frozen_state);
3172-
CHECK(block::gen::t_StateInit.validate_ref(frozen_state));
3173-
CHECK(block::tlb::t_StateInit.validate_ref(frozen_state));
3174-
std::cerr << "with hash " << frozen_hash.to_hex() << std::endl;
3183+
FLOG(INFO) {
3184+
sb << "freezing state of smart contract: ";
3185+
block::gen::t_StateInit.print_ref(sb, frozen_state);
3186+
CHECK(block::gen::t_StateInit.validate_ref(frozen_state));
3187+
CHECK(block::tlb::t_StateInit.validate_ref(frozen_state));
3188+
sb << "with hash " << frozen_hash.to_hex();
3189+
};
31753190
}
31763191
}
31773192
new_code.clear();
@@ -3229,8 +3244,10 @@ bool Transaction::compute_state() {
32293244
CHECK(cb.append_data_cell_bool(std::move(storage)));
32303245
new_total_state = cb.finalize();
32313246
if (verbosity > 2) {
3232-
std::cerr << "new account state: ";
3233-
block::gen::t_Account.print_ref(std::cerr, new_total_state);
3247+
FLOG(INFO) {
3248+
sb << "new account state: ";
3249+
block::gen::t_Account.print_ref(sb, new_total_state);
3250+
};
32343251
}
32353252
CHECK(block::tlb::t_Account.validate_ref(new_total_state));
32363253
return true;
@@ -3322,22 +3339,28 @@ bool Transaction::serialize() {
33223339
return false;
33233340
}
33243341
if (verbosity >= 3 * 1) {
3325-
std::cerr << "new transaction: ";
3326-
block::gen::t_Transaction.print_ref(std::cerr, root);
3327-
vm::load_cell_slice(root).print_rec(std::cerr);
3342+
FLOG(INFO) {
3343+
sb << "new transaction: ";
3344+
block::gen::t_Transaction.print_ref(sb, root);
3345+
vm::load_cell_slice(root).print_rec(sb);
3346+
};
33283347
}
33293348

33303349
if (!block::gen::t_Transaction.validate_ref(4096, root)) {
33313350
LOG(ERROR) << "newly-generated transaction failed to pass automated validation:";
3332-
vm::load_cell_slice(root).print_rec(std::cerr);
3333-
block::gen::t_Transaction.print_ref(std::cerr, root);
3351+
FLOG(INFO) {
3352+
vm::load_cell_slice(root).print_rec(sb);
3353+
block::gen::t_Transaction.print_ref(sb, root);
3354+
};
33343355
root.clear();
33353356
return false;
33363357
}
33373358
if (!block::tlb::t_Transaction.validate_ref(4096, root)) {
33383359
LOG(ERROR) << "newly-generated transaction failed to pass hand-written validation:";
3339-
vm::load_cell_slice(root).print_rec(std::cerr);
3340-
block::gen::t_Transaction.print_ref(std::cerr, root);
3360+
FLOG(INFO) {
3361+
vm::load_cell_slice(root).print_rec(sb);
3362+
block::gen::t_Transaction.print_ref(sb, root);
3363+
};
33413364
root.clear();
33423365
return false;
33433366
}

crypto/tl/tlblib.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ bool TLB::print_ref(std::ostream& os, Ref<vm::Cell> cell_ref, int indent, int re
196196
return pp.fail_unless(print_ref(pp, std::move(cell_ref)));
197197
}
198198

199+
bool TLB::print_ref(td::StringBuilder& sb, Ref<vm::Cell> cell_ref, int indent, int rec_limit) const {
200+
std::ostringstream ss;
201+
auto result = print_ref(ss, std::move(cell_ref), indent, rec_limit);
202+
sb << ss.str();
203+
return result;
204+
}
205+
199206
std::string TLB::as_string_skip(vm::CellSlice& cs, int indent) const {
200207
std::ostringstream os;
201208
print_skip(os, cs, indent);

crypto/tl/tlblib.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,14 @@ class TLB {
246246
bool print(std::ostream& os, Ref<vm::CellSlice> cs_ref, int indent = 0, int rec_limit = 0) const {
247247
return print(os, *cs_ref, indent, rec_limit);
248248
}
249+
bool print(td::StringBuilder& sb, Ref<vm::CellSlice> cs_ref, int indent = 0, int rec_limit = 0) const {
250+
std::ostringstream ss;
251+
auto result = print(ss, *cs_ref, indent, rec_limit);
252+
sb << ss.str();
253+
return result;
254+
}
249255
bool print_ref(std::ostream& os, Ref<vm::Cell> cell_ref, int indent = 0, int rec_limit = 0) const;
256+
bool print_ref(td::StringBuilder& sb, Ref<vm::Cell> cell_ref, int indent = 0, int rec_limit = 0) const;
250257
bool print_ref(int rec_limit, std::ostream& os, Ref<vm::Cell> cell_ref, int indent = 0) const {
251258
return print_ref(os, std::move(cell_ref), indent, rec_limit);
252259
}

crypto/vm/cells/CellSlice.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,13 @@ bool CellSlice::print_rec(std::ostream& os, int indent) const {
10261026
return print_rec(os, &limit, indent);
10271027
}
10281028

1029+
bool CellSlice::print_rec(td::StringBuilder& sb, int indent) const {
1030+
std::ostringstream ss;
1031+
auto result = print_rec(ss, indent);
1032+
sb << ss.str();
1033+
return result;
1034+
}
1035+
10291036
bool CellSlice::print_rec(int limit, std::ostream& os, int indent) const {
10301037
return print_rec(os, &limit, indent);
10311038
}

crypto/vm/cells/CellSlice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ class CellSlice : public td::CntObject {
257257
void dump(std::ostream& os, int level = 0, bool endl = true) const;
258258
void dump_hex(std::ostream& os, int mode = 0, bool endl = false) const;
259259
bool print_rec(std::ostream& os, int indent = 0) const;
260+
bool print_rec(td::StringBuilder& sb, int indent = 0) const;
260261
bool print_rec(std::ostream& os, int* limit, int indent = 0) const;
261262
bool print_rec(int limit, std::ostream& os, int indent = 0) const;
262263
void error() const {

tdutils/td/utils/logging.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,8 @@ class Logger {
264264
sb_ << other;
265265
return *this;
266266
}
267-
LambdaPrintHelper<td::Logger> operator<<(const LambdaPrint &) {
268-
return LambdaPrintHelper<td::Logger>{*this};
267+
LambdaPrintHelper<td::StringBuilder> operator<<(const LambdaPrint &) {
268+
return LambdaPrintHelper<td::StringBuilder>{sb_};
269269
}
270270

271271
MutableCSlice as_cslice() {

validator/impl/accept-block.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,11 @@ bool AcceptBlockQuery::create_new_proof() {
308308
}
309309
// 10. check resulting object
310310
if (!block::gen::t_BlockProof.validate_ref(bs_cell)) {
311-
block::gen::t_BlockProof.print_ref(std::cerr, bs_cell);
312-
vm::load_cell_slice(bs_cell).print_rec(std::cerr);
311+
FLOG(WARNING) {
312+
sb << "BlockProof object just created failed to pass automated consistency checks: ";
313+
block::gen::t_BlockProof.print_ref(sb, bs_cell);
314+
vm::load_cell_slice(bs_cell).print_rec(sb);
315+
};
313316
return fatal_error("BlockProof object just created failed to pass automated consistency checks");
314317
}
315318
// 11. create a proof object from this cell
@@ -851,15 +854,12 @@ bool AcceptBlockQuery::create_top_shard_block_description() {
851854
&& (root.is_null() || cb.store_ref_bool(std::move(root))) && cb.finalize_to(td_cell))) {
852855
return fatal_error("cannot serialize ShardTopBlockDescription for the newly-accepted block "s + id_.to_str());
853856
}
854-
if (false) {
855-
// debug output
856-
std::cerr << "new ShardTopBlockDescription: ";
857-
block::gen::t_TopBlockDescr.print_ref(std::cerr, td_cell);
858-
vm::load_cell_slice(td_cell).print_rec(std::cerr);
859-
}
860857
if (!block::gen::t_TopBlockDescr.validate_ref(td_cell)) {
861-
block::gen::t_TopBlockDescr.print_ref(std::cerr, td_cell);
862-
vm::load_cell_slice(td_cell).print_rec(std::cerr);
858+
FLOG(WARNING) {
859+
sb << "just created ShardTopBlockDescription is invalid: ";
860+
block::gen::t_TopBlockDescr.print_ref(sb, td_cell);
861+
vm::load_cell_slice(td_cell).print_rec(sb);
862+
};
863863
return fatal_error("just created ShardTopBlockDescription for "s + id_.to_str() + " is invalid");
864864
}
865865
auto res = vm::std_boc_serialize(td_cell, 0);

0 commit comments

Comments
 (0)