Skip to content

Commit 13975b6

Browse files
committed
arrange logging
1 parent 730668d commit 13975b6

6 files changed

Lines changed: 44 additions & 24 deletions

File tree

apps/tpnode/src/blockchain_reader.erl

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -561,11 +561,20 @@ mychain1() ->
561561
{MyChain, MyName, ChainNodes}.
562562

563563
mychain(State) ->
564-
{MyChain, MyName, ChainNodes}=mychain(),
565-
?LOG_INFO("My name ~p chain ~p ournodes ~p", [MyName, MyChain, maps:values(ChainNodes)]),
566-
maps:merge(State,
567-
#{myname=>MyName,
568-
chainnodes=>ChainNodes,
569-
mychain=>MyChain
570-
}).
564+
New={MyChain, MyName, ChainNodes}=mychain(),
565+
Pre={
566+
maps:get(mychain, State, undefined),
567+
maps:get(myname, State, undefined),
568+
maps:get(chainnodes, State, undefined)
569+
},
570+
if Pre =/= New ->
571+
?LOG_INFO("My name ~p chain ~p ournodes ~p", [MyName, MyChain, maps:values(ChainNodes)]),
572+
maps:merge(State,
573+
#{myname=>MyName,
574+
chainnodes=>ChainNodes,
575+
mychain=>MyChain
576+
});
577+
true ->
578+
State
579+
end.
571580

apps/tpnode/src/blockchain_updater.erl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,9 @@ handle_call({new_block, #{hash:=BlockHash,
203203
is_tuple(PID) -> PID;
204204
true -> emulator
205205
end,
206-
?LOG_INFO("Arrived block from ~p Verify block with ~p",
207-
[FromNode, maps:keys(Blk)]),
208-
209-
?LOG_INFO("New block (~p/~p) hash ~s (~s/~s)",
206+
?LOG_INFO("New block from ~p (~p/~p) hash ~s (~s/~s)",
210207
[
208+
FromNode,
211209
Hei,
212210
maps:get(height, maps:get(header, LastBlock)),
213211
blkid(BlockHash),
@@ -250,8 +248,8 @@ handle_call({new_block, #{hash:=BlockHash,
250248
Txs=maps:get(txs, Blk, []),
251249
Txsl=length(Txs),
252250
if LenSucc>0 ->
253-
?LOG_INFO("from ~p New block ~w arrived ~s, txs ~b, verify ~w sig (~.3f ms)",
254-
[FromNode, maps:get(height, maps:get(header, Blk)),
251+
?LOG_INFO("Block ~w verified ~s, txs ~b, verify ~w sig (~.3f ms)",
252+
[maps:get(height, maps:get(header, Blk)),
255253
blkid(BlockHash), Txsl, length(Success), (T1-T0)/1000000]),
256254
ok;
257255
true ->
@@ -272,7 +270,6 @@ handle_call({new_block, #{hash:=BlockHash,
272270
SigLen=length(maps:get(sign, MBlk)),
273271
?LOG_DEBUG("Signs ~p", [Success]),
274272
MinSig=getset(minsig,State),
275-
?LOG_INFO("Sig ~p ~p", [SigLen, MinSig]),
276273
if SigLen>=MinSig ->
277274
IsTemp=maps:get(temporary,Blk,false) =/= false,
278275
Header=maps:get(header, Blk),
@@ -554,6 +551,7 @@ handle_call({new_block, #{hash:=BlockHash,
554551
end;
555552
true ->
556553
%not enough
554+
?LOG_NOTICE("Block arrived to updater, but insufficient signature ~p, required ~p", [SigLen, MinSig]),
557555
{reply, {ok, no_enough_sig}, State#{
558556
candidates=>
559557
maps:put(BlockHash,

apps/tpnode/src/blockvote.erl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ is_block_ready(BlockHash, #{extras:=Extras}=State) ->
300300
{true, {Success, _}}=block:verify(Blk1),
301301
T1=erlang:system_time(),
302302
Txs=maps:get(txs, Blk0, []),
303-
?LOG_INFO("TODO: Check keys ~p of ~p", [length(Success), MinSig]),
303+
?LOG_DEBUG("TODO: Check keys ~p of ~p", [length(Success), MinSig]),
304304
if length(Success)<MinSig ->
305305
?LOG_INFO("BV New block ~w arrived ~s, txs ~b, verify ~w (~.3f ms)",
306306
[maps:get(height, maps:get(header, Blk0)),
@@ -310,7 +310,7 @@ is_block_ready(BlockHash, #{extras:=Extras}=State) ->
310310
(T1-T0)/1000000]),
311311
throw({notready, minsig});
312312
true ->
313-
?LOG_INFO("BV New block ~w arrived ~s, txs ~b, verify ~w (~.3f ms)",
313+
?LOG_DEBUG("BV New block ~w arrived ~s, txs ~b, verify ~w (~.3f ms)",
314314
[maps:get(height, maps:get(header, Blk0)),
315315
blkid(BlockHash),
316316
length(Txs),
@@ -338,7 +338,10 @@ is_block_ready(BlockHash, #{extras:=Extras}=State) ->
338338

339339
blockchain_updater:new_block(Blk),
340340
Extra=maps:get(BlockHash, Extras, #{}),
341-
?LOG_INFO("Extra for blk ~w ~s: ~p",[Height, blkid(BlockHash), Extra]),
341+
if Extra =/= #{} andalso Extra =/= #{log=>[]} ->
342+
?LOG_INFO("Extra for blk ~w ~s: ~p",[Height, blkid(BlockHash), Extra]);
343+
true -> ok
344+
end,
342345
case maps:is_key(log, Extra) of
343346
false -> ok;
344347
true ->

apps/tpnode/src/generate_block.erl

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,19 @@ generate_block(PreTXL, {Parent_Height, Parent_Hash}, GetSettings, GetAddr, Extra
131131
settings:=Settings,
132132
outbound:=Outbound,
133133
pick_block:=PickBlocks,
134-
fee:=_FeeCollected,
135-
tip:=_TipCollected,
134+
fee:=FeeCollected,
135+
tip:=TipCollected,
136136
emit:=EmitTXs0,
137137
log:=Logs0,
138138
new_settings := NewSettings
139139
}=finish_processing(generate_block_process:try_process(TXL, GBInit)),
140-
?LOG_INFO("MB Collected fee ~p tip ~p", [_FeeCollected, _TipCollected]),
140+
if(FeeCollected == #{amount => #{},changes => []}
141+
andalso
142+
TipCollected == #{amount => #{},changes => []}) ->
143+
ok;
144+
true ->
145+
?LOG_INFO("MB Collected fee ~p tip ~p", [FeeCollected, TipCollected])
146+
end,
141147
Logs=lists:reverse(Logs0),
142148

143149
if length(Settings)>0 ->
@@ -485,7 +491,10 @@ txfind([_|Rest],TxID) ->
485491
txfind(Rest,TxID).
486492

487493
cleanup_delayed(#{delayed:=DTX, new_settings:=NS, settings:=Sets} = Acc) ->
488-
?LOG_INFO("Delayed ~p",[DTX]),
494+
if(DTX==[]) -> ok;
495+
true ->
496+
?LOG_INFO("Delayed txs ~p",[DTX])
497+
end,
489498
ToDel=lists:foldl(
490499
fun({TxID,DT},Acc1) ->
491500
case settings:get([<<"current">>, <<"delaytx">>, DT], NS) of

apps/tpnode/src/generate_block_process.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ try_process([], #{
9191
}
9292
end, {SetState, Settings}, OutChains),
9393

94-
?LOG_INFO("try_process finish"),
94+
?LOG_DEBUG("try_process finish"),
9595
Acc#{settings=>Set2, set_state=>SS2};
9696

9797
%process inbound block
@@ -308,6 +308,7 @@ try_process([{TxID, #{
308308
last => failed
309309
});
310310
throw:X:S ->
311+
io:format("~s Throw ~p at ~p/~p~n",[TxID,X,hd(S),hd(tl(S))]),
311312
try_process(Rest,
312313
Acc#{failed=>[{TxID, fmterr(X)}|Failed],
313314
last => failed});

apps/tpnode/src/mkblock.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,13 @@ hei_and_has(B) ->
324324
PTmp=maps:get(temporary,B,false),
325325

326326
case PTmp of false ->
327-
?LOG_INFO("Prev block is permanent, make child"),
327+
?LOG_DEBUG("Prev block is permanent, make child"),
328328
#{header:=#{height:=Last_Height1}, hash:=Last_Hash1}=B,
329329
{Last_Height1,
330330
Last_Hash1,
331331
<<(bnot Last_Height1):64/big,Last_Hash1/binary>>};
332332
X when is_integer(X) ->
333-
?LOG_INFO("Prev block is temporary, make replacement"),
333+
?LOG_DEBUG("Prev block is temporary, make replacement"),
334334
#{header:=#{height:=Last_Height1, parent:=Last_Hash1}}=B,
335335
{Last_Height1-1,
336336
Last_Hash1,

0 commit comments

Comments
 (0)