Create the initial block when initial epoch starts

Normally some time passes before the first block is created in an
epoch, but before initial block there may be no network operating (see
commit 192ff0664f8507a0bce8c in Tendermint), so we don’t count this
time as an element of an epoch.
parent 6e6f1d4f
Pipeline #36203891 passed with stages
in 20 minutes and 20 seconds
......@@ -96,7 +96,7 @@
epoch_length=604800 :: epoch_length(),
epoch_stage=beginning :: ercoin_epoch:stage(),
height=0 :: block_height() | 0,
last_epoch_end=(ercoin_timestamp:now() - ?BLOCK_LENGTH) :: ercoin_timestamp:timestamp(),
last_epoch_end=ercoin_timestamp:now() :: ercoin_timestamp:timestamp(),
timestamp=ercoin_timestamp:now() :: ercoin_timestamp:timestamp(),
%% We provide the field below to allow deterministic time progress in tests.
now_fun=fun ercoin_timestamp:now/1 :: fun((data()) -> ercoin_timestamp:timestamp()),
......
......@@ -18,7 +18,6 @@
-export(
[binary_to_hex/1,
data_to_genesis_json/1,
data_to_genesis_json/2,
initial_distribution/3,
initial_data/5,
filter_genesis_txs/0,
......@@ -76,13 +75,9 @@ hexstr_to_bin([X,Y|Tail], Acc) ->
{ok, [Byte], []} = io_lib:fread("~16u", [X,Y]),
hexstr_to_bin(Tail, <<Acc/binary, Byte>>).
%% @doc Convert data to a genesis.json file for Tendermint.
-spec data_to_genesis_json(data()) -> binary().
data_to_genesis_json(Data) ->
data_to_genesis_json(Data, Data#data.last_epoch_end + ?BLOCK_LENGTH).
%% @doc Convert data and a starting timestamp to a genesis.json file for Tendermint.
-spec data_to_genesis_json(data(), ercoin_timestamp:timestamp()) -> binary().
data_to_genesis_json(Genesis, Timestamp) ->
data_to_genesis_json(Genesis) ->
Options = [pretty],
Validators =
[{[{<<"power">>, integer_to_binary(Power)},
......@@ -94,7 +89,7 @@ data_to_genesis_json(Genesis, Timestamp) ->
ToEncode =
{[{<<"app_hash">>, <<"">>},
{<<"app_state">>, base64:encode(term_to_binary(Genesis, [{compressed, 9}]))},
{<<"genesis_time">>, ercoin_timestamp:to_iso(Timestamp)},
{<<"genesis_time">>, ercoin_timestamp:to_iso(Genesis#data.last_epoch_end)},
{<<"chain_id">>, <<"ercoin-test">>},
{<<"validators">>, Validators}]},
jiffy:encode(ToEncode, Options).
......@@ -287,8 +282,8 @@ initial_data_without_votes(Accounts, BurningEnd, Beginning) ->
#data{
epoch_length=3600*24*7,
epoch_stage=beginning,
last_epoch_end=Beginning - ?BLOCK_LENGTH,
timestamp=Beginning - ?BLOCK_LENGTH,
last_epoch_end=Beginning,
timestamp=Beginning,
accounts=Accounts,
entropy_fun=fun ercoin_entropy:reliable_entropy/1},
Validators = ercoin_validators:draw(Data1#data{timestamp=BurningEnd + 60}),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment