-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aad215e
commit 9e18942
Showing
4 changed files
with
28 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,18 +55,22 @@ get_recent() -> | |
<<"forks">> => get_recent_forks() | ||
}. | ||
|
||
%% @doc Return the the most recent blocks in reverse chronological order. | ||
get_recent_blocks() -> | ||
Anchors = lists:sublist(ar_node:get_block_anchors(), ?CHECKPOINT_DEPTH), | ||
CutOff = length(Anchors) - ?RECENT_BLOCKS_WITHOUT_TIMESTAMP, | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
JamesPiechota
Author
Collaborator
|
||
lists:foldl( | ||
fun(H, Acc) -> | ||
Acc ++ [#{ | ||
[#{ | ||
<<"id">> => ar_util:encode(H), | ||
<<"received">> => get_block_timestamp(H, length(Acc)) | ||
}] | ||
<<"received">> => get_block_timestamp(H, length(Acc), CutOff) | ||
} | Acc] | ||
end, | ||
[], | ||
lists:sublist(ar_node:get_block_anchors(), ?CHECKPOINT_DEPTH) | ||
Anchors | ||
). | ||
|
||
%% @doc Return the the most recent forks in reverse chronological order. | ||
get_recent_forks() -> | ||
CutOffTime = os:system_time(seconds) - ?RECENT_FORKS_AGE, | ||
case ar_chain_stats:get_forks(CutOffTime) of | ||
|
@@ -77,21 +81,21 @@ get_recent_forks() -> | |
#fork{ | ||
id = ID, height = Height, timestamp = Timestamp, | ||
block_ids = BlockIDs} = Fork, | ||
Acc ++ [#{ | ||
[#{ | ||
<<"id">> => ar_util:encode(ID), | ||
<<"height">> => Height, | ||
<<"timestamp">> => Timestamp div 1000, | ||
<<"blocks">> => [ ar_util:encode(BlockID) || BlockID <- BlockIDs ] | ||
}] | ||
} | Acc] | ||
end, | ||
[], | ||
lists:sublist(Forks, ?RECENT_FORKS_LENGTH) | ||
) | ||
end. | ||
|
||
get_block_timestamp(H, Depth) when Depth < ?RECENT_BLOCKS_WITHOUT_TIMESTAMP -> | ||
get_block_timestamp(H, Depth, CutOff) when Depth >= CutOff -> | ||
<<"pending">>; | ||
get_block_timestamp(H, _Depth) -> | ||
get_block_timestamp(H, _Depth, _Cutoff) -> | ||
B = ar_block_cache:get(block_cache, H), | ||
case B#block.receive_timestamp of | ||
undefined -> <<"pending">>; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Should not CutOff be
?RECENT_BLOCKS_WITHOUT_TIMESTAMP
and the guard belowwhen Depth < CutOff ->
? The block anchors are latest first and we traverse them from the left in foldl so the first iteration would call get_block_timestamp(H, 0, CutOff)