Skip to content

Commit e5308c9

Browse files
committed
Merge branch 'e24'
2 parents 4ed8dc1 + c0c3d59 commit e5308c9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2980
-1598
lines changed

apps/tpnode/src/apixiom.erl

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ handle_request(Method, Path, Req, Target, Format, _Opts) ->
100100
api_call,
101101
[{path, cowboy_req:path(Req)}, {client_addr, get_client_ip_headers(Req)}]
102102
),
103-
?LOG_INFO("api: ~p ~p", [cowboy_req:path(Req), get_client_ip_headers(Req)]),
103+
?LOG_DEBUG("api: ~p ~p", [cowboy_req:path(Req), get_client_ip_headers(Req)]),
104104

105105
Req1 =
106106
case Format of

apps/tpnode/src/block.erl

+1-1
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ mkblock2(#{ txs:=Txs, parent:=Parent,
564564
[]
565565
end,
566566

567-
?LOG_INFO("ER ~p",[ExtraRoots]),
567+
?LOG_DEBUG("ExtraRoots ~p",[ExtraRoots]),
568568
TempRoot=if TempID == false -> ExtraRoots;
569569
true -> [{tmp, <<TempID:64/big>>}|ExtraRoots]
570570
end,

apps/tpnode/src/blockchain_reader.erl

+18-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
-export([start_link/0]).
1111
-export([blkid/1,
1212
mychain/0,
13+
get_block/2,
14+
get_block/1,
1315
send_block_real/4]).
1416
%-export([mychain0/0]).
1517

@@ -132,6 +134,15 @@ handle_call({block_exists, BlockHash}, _From, #{ldb:=LDB} = State)
132134
end,
133135
{reply, Exists, State};
134136

137+
handle_call({get_block, Height}, _From, #{ldb:=LDB} = State) when is_integer(Height) ->
138+
case ldb:read_key(LDB, <<"h:", Height:64/big>>, undefined) of
139+
undefined ->
140+
{reply, not_found, State};
141+
Hash ->
142+
Res=block_rel(LDB, Hash, self),
143+
{reply, Res, State}
144+
end;
145+
135146
handle_call({get_hash, Height}, _From, #{ldb:=LDB} = State) when is_integer(Height) ->
136147
R=
137148
case ldb:read_key(LDB, <<"h:", Height:64/big>>, undefined) of
@@ -578,8 +589,8 @@ mychain() ->
578589
?LOG_ERROR("Can't parse node key ~p -> ~p",[Key, Val]),
579590
Acc
580591
end, #{}, KeyDB),
581-
?LOG_NOTICE("NodesDB ~p", [KeyDB]),
582-
?LOG_NOTICE("Nodes ~p", [ChainNodes0]),
592+
?LOG_DEBUG("NodesDB ~p", [KeyDB]),
593+
?LOG_INFO("Nodes ~p", [maps:values(ChainNodes0)]),
583594
MyName=maps:get(PubKey, ChainNodes0, undefined),
584595
MyChain=maps:get(MyName, NodeChain, 0),
585596
ChainNodes=maps:filter(
@@ -606,3 +617,8 @@ mychain(State) ->
606617
State
607618
end.
608619

620+
get_block(BlockHash, Rel) ->
621+
gen_server:call(?SERVER,{get_block, BlockHash, Rel}).
622+
get_block(H) when is_integer(H) ->
623+
gen_server:call(?SERVER,{get_block, H}).
624+

apps/tpnode/src/blockchain_updater.erl

+19-13
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,14 @@ handle_call({new_block, #{hash:=BlockHash,
273273
end,
274274
MBlk=case maps:get(BlockHash, Candidates, undefined) of
275275
undefined ->
276-
Blk;
276+
Blk#{
277+
<<"_install_t">> => os:system_time(microsecond)
278+
};
277279
#{sign:=BSig}=ExBlk ->
278280
NewSigs=lists:usort(BSig ++ Success),
279281
ExBlk#{
280-
sign=>NewSigs
282+
sign=>NewSigs,
283+
<<"_install_t">> => os:system_time(microsecond)
281284
}
282285
end,
283286
SigLen=length(maps:get(sign, MBlk)),
@@ -357,6 +360,7 @@ handle_call({new_block, #{hash:=BlockHash,
357360
}),
358361
gen_server:cast(blockchain_reader,{update,MBlk}),
359362
gen_server:cast(tpnode_ws_dispatcher, {new_block, MBlk}),
363+
gen_server:cast(tpnode_reporter, {new_block, maps:get(height, maps:get(header, Blk)), maps:get(temporary,Blk,false)}),
360364

361365
{reply, ok, State#{
362366
tmpblock=>MBlk
@@ -388,7 +392,7 @@ handle_call({new_block, #{hash:=BlockHash,
388392
_ ->
389393
{checkput, BlockLedgerHash}
390394
end, MBlk),
391-
?LOG_INFO("LApply ~p",[LApply]),
395+
?LOG_DEBUG("LApply ~p",[LApply]),
392396

393397
LHash=case LApply of
394398
{ok, LH11} ->
@@ -424,6 +428,8 @@ handle_call({new_block, #{hash:=BlockHash,
424428
end
425429
end,
426430

431+
gen_server:cast(tpnode_reporter, {new_block, maps:get(height, maps:get(header, Blk)), maps:get(temporary,Blk,false)}),
432+
427433
SendSuccess=lists:map(
428434
fun({TxID, #{register:=_, address:=Addr}}) ->
429435
{TxID, #{address=>Addr, block=>BlockHash}};
@@ -866,7 +872,7 @@ apply_ledger(Action, #{bals:=S, hash:=BlockHash, header:=#{height:=Height}}) ->
866872
put ->
867873
{ok,mledger:apply_patch(mledger:bals2patch(Patch), {commit, {Height, BlockHash}})}
868874
end,
869-
?LOG_INFO("Apply ~p ~p", [Action, LR]),
875+
?LOG_DEBUG("Apply ~p ~p", [Action, LR]),
870876
LR.
871877

872878
apply_block_conf_meta(#{hash:=Hash}=Block, Conf0) ->
@@ -923,10 +929,10 @@ mychain(#{lastblock:=#{header:=#{chain:=MyChain}}, settings:=Sets}=State) ->
923929
chainnodes=>ChainNodes,
924930
mychain=>MyChain
925931
}),
926-
SK=fun(SS) ->
927-
Req=[ candidates, ldb, settings, btable, lastblock, mychain ],
928-
[ {T,maps:is_key(T,SS)} || T <- Req ]
929-
end,
932+
%SK=fun(SS) ->
933+
% Req=[ candidates, ldb, settings, btable, lastblock, mychain ],
934+
% [ {T,maps:is_key(T,SS)} || T <- Req ]
935+
% end,
930936
%logger:error("MYCHAIN old ~p new ~p",[SK(State), SK(S1)]),
931937
S1;
932938

@@ -940,11 +946,11 @@ mychain(#{lastblock:=#{header:=_ChainLess}, settings:=Sets}=State) ->
940946
chainnodes=>ChainNodes,
941947
mychain=>0
942948
}),
943-
SK=fun(SS) ->
944-
Req=[ candidates, ldb, settings, btable, lastblock, mychain ],
945-
[ {T,maps:is_key(T,SS)} || T <- Req ]
946-
end,
947-
%logger:error("MYCHAIN old ~p new ~p",[SK(State), SK(S1)]),
949+
%SK=fun(SS) ->
950+
% Req=[ candidates, ldb, settings, btable, lastblock, mychain ],
951+
% [ {T,maps:is_key(T,SS)} || T <- Req ]
952+
% end,
953+
%?LOG_DEBUG("MYCHAIN old ~p new ~p",[SK(State), SK(S1)]),
948954
S1.
949955

950956
replace(Field, Value) ->

apps/tpnode/src/blockvote.erl

+6-4
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ handle_cast({tpic, _From, #{
9898
<<"sign">> := Sigs
9999
}},
100100
#{mychain:=MyChain}=State) when MyChain==MsgChain ->
101-
handle_cast({signature, BlockHash, Sigs}, State);
101+
LD = << 64 , (os:system_time(microsecond)):64/big >>,
102+
Sigs2 = [ bsig:set_localdata(E, LD) || E <- Sigs ],
103+
handle_cast({signature, BlockHash, Sigs2}, State);
102104

103105
handle_cast({tpic, _From, #{
104106
null:=<<"blockvote">>,
@@ -116,7 +118,7 @@ handle_cast({tpic, _From, #{
116118
handle_cast({signature, BlockHash, Sigs}=WholeSig,
117119
#{lastblock:=#{hash:=LBH}}=State) when LBH==BlockHash->
118120
?LOG_DEBUG("BV Got extra sig for ~s ~p", [blkid(BlockHash), WholeSig]),
119-
?LOG_INFO("BV Got extra sig for ~s", [blkid(BlockHash)]),
121+
%?LOG_DEBUG("BV Got extra sig for ~s", [blkid(BlockHash)]),
120122

121123
stout:log(
122124
bv_gotsig,
@@ -129,7 +131,7 @@ handle_cast({signature, BlockHash, Sigs}=WholeSig,
129131

130132
handle_cast({signature, BlockHash, Sigs},
131133
#{candidatesig:=Candidatesig, candidatets:=CandidateTS}=State) ->
132-
?LOG_INFO("BV Got sig for ~s", [blkid(BlockHash)]),
134+
?LOG_DEBUG("BV Got sig for ~s", [blkid(BlockHash)]),
133135
CSig0=maps:get(BlockHash, Candidatesig, #{}),
134136
CSig=checksig(BlockHash, Sigs, CSig0),
135137
%?LOG_DEBUG("BV S CS2 ~p", [maps:keys(CSig)]),
@@ -357,7 +359,7 @@ is_block_ready(BlockHash, #{extras:=Extras}=State) ->
357359
blockchain_updater:new_block(Blk),
358360
Extra=maps:get(BlockHash, Extras, #{}),
359361
if Extra =/= #{} andalso Extra =/= #{log=>[]} ->
360-
?LOG_INFO("Extra for blk ~w ~s: ~p",[Height, blkid(BlockHash), Extra]);
362+
?LOG_INFO("Extra for blk ~w ~s: ~p",[Height, blkid(BlockHash), maps:keys(Extra)]);
361363
true -> ok
362364
end,
363365
case maps:is_key(log, Extra) of

apps/tpnode/src/bsig.erl

+55-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
-export([checksig1/3, checksig1/2]).
44
-export([signhash/3, signhash1/3]).
55
-export([packsig/1, unpacksig/1]).
6+
-export([add_localdata/2]).
7+
-export([set_localdata/2]).
8+
-export([get_localdata/1]).
69
-export([pack_sign_ed/1, unpack_sign_ed/1]).
710
-export([add_sig/2]).
811
-export([extract_pubkey/1, extract_pubkeys/1]).
@@ -118,8 +121,9 @@ decode_edval(240, <<KL:8/integer, Rest/binary>>=Raw) ->
118121
{240, Raw}
119122
end;
120123

121-
decode_edval(254, Bin) -> {purpose, Bin};
124+
%decode_edval(254, Bin) -> {purpose, Bin};
122125
decode_edval(255, Bin) -> {signature, Bin};
126+
decode_edval(254, Bin) -> {local_data, Bin};
123127
decode_edval(Key, BinVal) -> {Key, BinVal}.
124128

125129
encode_edval(timestamp, Integer) -> <<1, 8, Integer:64/big>>;
@@ -134,7 +138,7 @@ encode_edval(baldep, {Address,Seq}) ->
134138
8=size(Address),
135139
<<7, 16, Address/binary, Seq:64/big>>;
136140
encode_edval(signature, PK) -> <<255, (size(PK)):8/integer, PK/binary>>;
137-
encode_edval(purpose, PK) -> <<254, (size(PK)):8/integer, PK/binary>>;
141+
%encode_edval(purpose, PK) -> <<254, (size(PK)):8/integer, PK/binary>>;
138142
encode_edval(N, PK) when is_binary(N) andalso is_binary(PK) ->
139143
TS=size(N)+size(PK)+1,
140144
if TS>=64 ->
@@ -144,23 +148,64 @@ encode_edval(N, PK) when is_binary(N) andalso is_binary(PK) ->
144148
end;
145149
encode_edval(_, _) -> <<>>.
146150

147-
splitsig(<<255, SLen:8/integer, Signature:SLen/binary, Rest/binary>>) ->
148-
{Signature, Rest}.
151+
splitsig(Bin) ->
152+
splitsig(Bin,#{}).
153+
154+
splitsig(<<255, SLen:8/integer, Signature:SLen/binary, Rest/binary>>,A) ->
155+
A#{signature => Signature,
156+
binextra => Rest};
157+
158+
splitsig(<<254, LLen:8/integer, LocalData:LLen/binary, Rest/binary>>,A) ->
159+
splitsig(Rest,A#{local_data => LocalData}).
149160

150161
unpacksig(HSig) when is_map(HSig) ->
151162
HSig;
152163

153164
unpacksig(BSig) when is_binary(BSig) ->
154-
{Signature, Hdr}=splitsig(BSig),
155-
#{ binextra => (Hdr),
156-
signature => (Signature),
157-
extra => unpack_sign_ed(Hdr)
158-
}.
165+
#{binextra:=BE}=Split=splitsig(BSig),
166+
Split#{extra=> unpack_sign_ed(BE)}.
167+
168+
get_localdata(<<254, LLen:8/integer, LD0:LLen/binary, _Rest/binary>>) ->
169+
LD0;
170+
get_localdata(#{local_data:=LD0}) ->
171+
LD0;
172+
get_localdata(_) ->
173+
<<>>.
174+
175+
add_localdata(<<255,_/binary>> = Sig, LD) ->
176+
<<254, (size(LD)):8/integer, LD/binary, Sig/binary>>;
177+
178+
add_localdata(#{local_data:=LD0}=Sig,LD1) ->
179+
Sig#{
180+
local_data => <<LD0/binary,LD1/binary>>
181+
};
182+
183+
add_localdata(#{}=Sig,LD1) ->
184+
Sig#{
185+
local_data => <<LD1/binary>>
186+
}.
187+
188+
set_localdata(<<255,_/binary>> = Sig, LD) ->
189+
<<254, (size(LD)):8/integer, LD/binary, Sig/binary>>;
190+
191+
set_localdata(<<254, LLen:8/integer, _LD0:LLen/binary, Rest/binary>>, LD1) ->
192+
<<254, (size(LD1)):8/integer, LD1/binary, Rest/binary>>;
193+
194+
set_localdata(#{}=Sig,LD1) ->
195+
Sig#{ local_data => <<LD1/binary>> }.
159196

160197
packsig(BinSig) when is_binary(BinSig) ->
161198
BinSig;
199+
200+
packsig(#{local_data:=LD, signature:=Signature, binextra:=BinExtra}) ->
201+
<<254, (size(LD)):8/integer, LD/binary,
202+
255, (size(Signature)):8/integer, Signature/binary,
203+
BinExtra/binary>>;
204+
162205
packsig(#{signature:=Signature, binextra:=BinExtra}) ->
163-
<<255, (size(Signature)):8/integer, Signature/binary, BinExtra/binary>>.
206+
<<255, (size(Signature)):8/integer, Signature/binary,
207+
BinExtra/binary>>.
208+
164209

165210
add_sig(OldSigs, NewSigs) ->
166211
Apply=fun(#{extra:=EPL}=Sig, Acc) ->

apps/tpnode/src/chainkeeper.erl

+8-8
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ handle_cast({tpic, NodeName, _From, Payload}, #{lookaround_timer := Timer} = Sta
132132
{ok, Decode} when is_map(Decode) ->
133133
case Decode of
134134
#{null := <<"block_installed">>,<<"blk">> := ReceivedBlk} ->
135-
?LOG_INFO("got ck_beacon from ~s, block: ~p", [NodeName, Payload]),
135+
?LOG_DEBUG("got ck_beacon from ~s ~p", [NodeName, ReceivedBlk]),
136136
block:unpack(ReceivedBlk);
137137
_ ->
138138
?LOG_INFO("got ck_beacon from ~s, unpacked payload: ~p", [NodeName, Decode]),
@@ -149,13 +149,13 @@ handle_cast({tpic, NodeName, _From, Payload}, #{lookaround_timer := Timer} = Sta
149149
#{}
150150
end,
151151

152-
?LOG_INFO("Blk: ~p", [Blk]),
153-
case Blk of
154-
#{hash:=H} ->
155-
Sig=gen_server:call(blockvote,{signatures, H}),
156-
?LOG_INFO("got signatures: ~p", [Sig]);
157-
_ -> ok
158-
end,
152+
?LOG_DEBUG("Blk: ~p", [Blk]),
153+
%case Blk of
154+
% #{hash:=H} ->
155+
% Sig=gen_server:call(blockvote,{signatures, H}),
156+
% ?LOG_INFO("got new signatures from node ~s: ~p", [NodeName,Sig]);
157+
% _ -> ok
158+
%end,
159159

160160

161161
stout:log(ck_beacon,

0 commit comments

Comments
 (0)