edit src/index/base.cpp #24354

issue katesalazar opened this issue on February 16, 2022
  1. katesalazar commented at 12:07 PM on February 16, 2022: contributor

    Is your feature request related to a problem? Please describe. txindex sync message will print more than exactly twice a minute because current_time and last_log_time are in seconds, it jitters by one second https://github.com/bitcoin/bitcoin/blob/1e8aa02ec5cc2819c67ef40a7573c4b23a4c11cc/src/index/base.cpp#L168

    Describe the solution you'd like change '<' with '<=' makes the message appear twice exactly a minute, in https://github.com/bitcoin/bitcoin/blob/1e8aa02ec5cc2819c67ef40a7573c4b23a4c11cc/src/index/base.cpp#L168 for consistency, probably as well in https://github.com/bitcoin/bitcoin/blob/1e8aa02ec5cc2819c67ef40a7573c4b23a4c11cc/src/index/base.cpp#L174 (among others?) but I'm not interested in analyzing implications of changing that line 174

    Describe alternatives you've considered I suppose there's a way to change this by using millisec resolution in these time variables.

    Additional context thanks!

  2. katesalazar added the label Feature on Feb 16, 2022
  3. RandyMcMillan commented at 9:58 PM on February 18, 2022: contributor

    git grep "= current_time"

    src/index/base.cpp:                last_log_time = current_time;
    src/index/base.cpp:                last_locator_write_time = current_time;
    src/net.cpp:        cache_entry.m_cache_entry_expiration = current_time + std::chrono::hours(21) + GetRandMillis(std::chrono::hours(6));
    src/net_processing.cpp:        peer->m_addr_token_timestamp = current_time;
    src/net_processing.cpp:        pto.m_tx_relay->m_next_send_feefilter = current_time + GetRandomDuration<std::chrono::microseconds>(MAX_FEEFILTER_CHANGE_DELAY);
    src/net_processing.cpp:                state.m_headers_sync_timeout = current_time + HEADERS_DOWNLOAD_TIMEOUT_BASE +
    src/net_processing.cpp:                    State(staller)->m_stalling_since = current_time;
    src/randomenv.cpp:    last_perfmon = current_time;
    

    git grep "HEADERS_DOWNLOAD_TIMEOUT_BASE"

    src/net_processing.cpp:static constexpr auto HEADERS_DOWNLOAD_TIMEOUT_BASE = 15min;
    src/net_processing.cpp:                state.m_headers_sync_timeout = current_time + HEADERS_DOWNLOAD_TIMEOUT_BASE +
    

    git grep " Commit()"

    src/index/base.cpp:                Commit();
    src/index/base.cpp:                    Commit();
    src/index/base.cpp:                Commit();
    src/index/base.cpp:    Commit();
    src/index/base.h:    bool Commit();
    

    git grep "< current_time"

    src/index/base.cpp:            if (last_log_time + SYNC_LOG_INTERVAL < current_time) {
    src/index/base.cpp:            if (last_locator_write_time + SYNC_LOCATOR_WRITE_INTERVAL < current_time) {
    src/net.cpp:    if (cache_entry.m_cache_entry_expiration < current_time) { // If emplace() added new one it has expiration 0.
    src/net_processing.cpp:        peer.m_next_local_addr_send < current_time) {
    src/net_processing.cpp:                if (pto->m_tx_relay->nNextInvSend < current_time) {
    src/net_processing.cpp:                            while (!g_relay_expiration.empty() && g_relay_expiration.front().first < current_time)
    src/net_processing.cpp:        if (state.m_stalling_since.count() && state.m_stalling_since < current_time - BLOCK_STALLING_TIMEOUT) {
    

    git grep "SYNC_LOCATOR_WRITE_INTERVAL"

    src/index/base.cpp:constexpr int64_t SYNC_LOCATOR_WRITE_INTERVAL = 30; // seconds
    src/index/base.cpp:            if (last_locator_write_time + SYNC_LOCATOR_WRITE_INTERVAL < current_time) {
    

    git grep "SYNC_LOG_INTERVAL"

    src/index/base.cpp:constexpr int64_t SYNC_LOG_INTERVAL = 30; // seconds
    src/index/base.cpp:            if (last_log_time + SYNC_LOG_INTERVAL < current_time) {
    

    It is interesting to think about this in context of other events that's are potentially going on at current_time and what is forced to trail behind current_time and by how much.

    base.cpp: LINE: 167

                int64_t current_time = GetTime();
                if (last_log_time + SYNC_LOG_INTERVAL < current_time) {
                    LogPrintf("Syncing %s with block chain from height %d\n",
                              GetName(), pindex->nHeight);
                    last_log_time = current_time;
                }
    
                if (last_locator_write_time + SYNC_LOCATOR_WRITE_INTERVAL < current_time) {
                    m_best_block_index = pindex;
                    last_locator_write_time = current_time;
                    // No need to handle errors in Commit. See rationale above.
                    Commit();
                }
    

    One possible optimization would be to compare the difference between last_log_time and last_locator_write_time on different systems - in fact SYNC_LOG_INTERVAL and SYNC_LOCATOR_WRITE_INTERVAL could be incremented +/- 1 second based on success/fail write commits that are tracked/counted.

    Just a thought. :)

  4. RandyMcMillan commented at 11:11 PM on February 18, 2022: contributor

    REF: 94b4f8bbb9e7e37f3057b47bf13a74de12b8e0cc

    We can deduce that these PARAMETERS were actually set arbitrarily. SYNC_LOG_INTERVAL and SYNC_LOCATOR_WRITE_INTERVAL currently equal 30 seconds. In both cases the LogPrintf() and the Commit() are limited to at best executing at 30+1 seconds intervals - this is due to GetTime() returning time in seconds by default. @katesalazar is correct in her assertion that millisecond resolution may be beneficial. Coupled with benchmarking analysis, 30 seconds could safely be reduced to 20 seconds or even 15 seconds?

  5. MarcoFalke commented at 4:25 PM on March 25, 2022: member

    The feature request didn't seem to attract much attention in the past. Also, the issue seems not important enough right now to keep it sitting around idle in the list of open issues.

    Closing due to lack of interest. Pull requests with improvements are always welcome.

  6. MarcoFalke closed this on Mar 25, 2022

  7. DrahtBot locked this on Mar 25, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-02 12:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me