Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
block_info.cpp
Go to the documentation of this file.
3
4namespace {
5
6inline uint32_t block_height_from_id(const sysio::checksum256& block_id)
7{
8 auto arr = block_id.extract_as_byte_array();
9 // 32-bit block height is encoded in big endian as the sequence of bytes: arr[0], arr[1], arr[2], arr[3]
10 return ((arr[0] << 0x18) | (arr[1] << 0x10) | (arr[2] << 0x08) | arr[3]);
11}
12
13} // namespace
14
15namespace sysiosystem {
16
17void system_contract::add_to_blockinfo_table(const sysio::checksum256& previous_block_id,
18 const sysio::block_timestamp timestamp) const
19{
20 const uint32_t new_block_height = block_height_from_id(previous_block_id) + 1;
21 const auto new_block_timestamp = static_cast<sysio::time_point>(timestamp);
22
23 block_info::block_info_table t(get_self(), 0);
24
25 if (block_info::rolling_window_size > 0) {
26 // Add new entry to blockinfo table for the new block.
27 t.emplace(get_self(), [&](block_info::block_info_record& r) {
28 r.block_height = new_block_height;
29 r.block_timestamp = new_block_timestamp;
30 });
31 }
32
33 // Erase up to two entries that have fallen out of the rolling window.
34
35 const uint32_t last_prunable_block_height =
36 std::max(new_block_height, block_info::rolling_window_size) - block_info::rolling_window_size;
37
38 int count = 2;
39 for (auto itr = t.begin(), end = t.end(); //
40 itr != end && itr->block_height <= last_prunable_block_height && 0 < count; //
41 --count) //
42 {
43 itr = t.erase(itr);
44 }
45}
46
47} // namespace sysiosystem
const mie::Vuint & r
Definition bn.cpp:28
int * count
sysio::multi_index<"blockinfo"_n, block_info_record > block_info_table
unsigned int uint32_t
Definition stdint.h:126