Truncate fresh transactions in BeginBlock

parent ef882ee0
Pipeline #36630092 failed with stages
in 5 minutes and 13 seconds
......@@ -84,7 +84,6 @@ handle_event(
fresh_txs=FreshTxs,
validators=Validators,
future_validators=FutureValidators}) ->
NewHeight = Height + 1,
Diffs =
case EpochStage of
drawing_to_be_announced ->
......@@ -92,8 +91,7 @@ handle_event(
_ ->
[]
end,
NewFreshTxs = lists:dropwhile(fun ({TxTimestamp, _}) -> TxTimestamp < Timestamp - EpochLength end, FreshTxs),
Data1 = Data#data{height=NewHeight, fresh_txs=NewFreshTxs},
Data1 = Data#data{height=Height + 1},
{keep_state, Data1, {reply, From, #'abci.ResponseEndBlock'{validator_updates=Diffs}}};
handle_event({call, From}, #'abci.RequestDeliverTx'{tx=MaybeTxBin}, committing, Data)->
{ErrorCode, NewData} = ercoin_tx:handle_bin(MaybeTxBin, Data),
......
......@@ -106,8 +106,9 @@ grant_fee_deposits(
Data1#data{fee_deposit_short=0, fee_deposit_long=DepositLong - DisposedDepositLong}.
-spec shift_to_timestamp(ercoin_timestamp:timestamp(), data()) -> data().
shift_to_timestamp(Timestamp, Data) ->
remove_old_and_unlock_accounts(Data#data{timestamp=Timestamp}).
shift_to_timestamp(Timestamp, Data=#data{epoch_length=EpochLength, fresh_txs=FreshTxs}) ->
NewFreshTxs = lists:dropwhile(fun ({TxTimestamp, _}) -> TxTimestamp < Timestamp - EpochLength end, FreshTxs),
remove_old_and_unlock_accounts(Data#data{timestamp=Timestamp, fresh_txs=NewFreshTxs}).
-spec now(data()) -> ercoin_timestamp:timestamp().
now(Data=#data{now_fun=F}) ->
......
......@@ -106,17 +106,6 @@ prop_end_block_increments_height() ->
data(),
get_value(height, end_block(Data)) =:= get_value(height, Data) + 1).
prop_end_block_truncates_fresh_txs() ->
%% TODO: Move this to BeginBlock.
?FORALL(
Data,
data(),
begin
FreshTxs = Data#data.fresh_txs,
#data{fresh_txs=NewFreshTxs, timestamp=Timestamp} = end_block(Data),
NewFreshTxs =:= ?SETS:filter(fun ({TxTimestamp, _Tx}) -> TxTimestamp >= Timestamp - Data#data.epoch_length end, FreshTxs)
end).
prop_deliver_tx_handles_binary_in_regard_to_data() ->
?FORALL(
{Data, MaybeTxBin},
......
......@@ -32,6 +32,18 @@ prop_shift_to_timestamp_expires_and_unlocks_some_accounts() ->
Data#data.accounts)
end).
prop_shift_to_timestamp_truncates_fresh_txs() ->
?FORALL(
{Data, TimestampDiff},
{ercoin_gen:data(), non_neg_integer()},
begin
NewTimestamp = Data#data.timestamp + TimestampDiff,
(ercoin_data:shift_to_timestamp(NewTimestamp, Data))#data.fresh_txs =:=
?SETS:filter(
fun ({TxTimestamp, _Tx}) -> TxTimestamp >= NewTimestamp - Data#data.epoch_length end,
Data#data.fresh_txs)
end).
prop_fee_deposit_granting() ->
?FORALL(
Data=
......
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