Skip to content

Feature request: sync faster using stored state from last time. #1168

Closed

Description

@Ulmo

Issue and Steps to Reproduce

It takes only a fraction of a second to crash lightningd, but many hours to sync. I'd prefer if it at least attempt to save some of the sync state so that when it recovers, it can resume syncing at a less drastically long sync size.

I understand that one of the things you don't want with Lightning Network is a node using old state on a channel.

The hardball way to get around that is to do periodic saves of state, and then when restarting, load the state from a fresh perspective and sync from that periodic save point. The only items that need to be saved are those items that the node would recover upon a restart by scanning the blocks. One idea is to simply save every relevant transaction in the blockchain as the node runs, and then know the last fully saved transaction block, and upon restart, load all of those transactions instead of parsing full blocks; that is slower than saving a state and resuming from that state, but it might just be faster than going through full blocks and the code would be less intense. A hybrid approach of doing both would work, too. As implementation, both could be programmed, with attention paid to the journaling of transactions first, and get it running first, then keep saving state but not using it to resume, slowly implementing a background "what if" state checker that checks to see if saved state equals journaled transaction state recovery, just to test the idea. Ideas?

getinfo output

{ "id" : "031c527494f295220d26a1814c18e7db3f4f03203ce1a53a0b74b52ed570a3972a",
[
"version" : "v0.5.2-2016-11-21-2207-g31b9b6b", "blockheight" : 506218, "network" : "bitcoin" }

Activity

  1. Ulmo commented on Mar 4, 2018

    @Ulmo
    Author

    I'm trying to understand the scanning functions. Here's one function I'm reading in lightningd/watch.c:

     void watch_topology_changed(struct chain_topology *topo)
     {
             struct txwatch_hash_iter i;
             struct txwatch *w;
             bool needs_rerun;
    
     again:
             /* Iterating a htable during deletes is safe, but might skip entries. */
             needs_rerun = false;
             for (w = txwatch_hash_first(&topo->txwatches, &i);
                  w;
                  w = txwatch_hash_next(&topo->txwatches, &i)) {
                     u32 depth;
                     const struct bitcoin_tx *tx;
    
                     depth = get_tx_depth(topo, &w->txid, &tx);
                     if (depth)
                             needs_rerun |= txw_fire(w, tx, depth);
             }
             if (needs_rerun)
                     goto again;
     }
    

    Where is txwatch_hash_first and txwatch_hash_next defined? Aha, found it:

     HTABLE_DEFINE_TYPE(struct txwatch, txwatch_keyof, txid_hash, txwatch_eq,                                                                        
                        txwatch_hash);                                                                                                               
    

    Would implementing a journaling function of relevent transactions to sync from be good in this function?

  2. Ulmo commented on Mar 4, 2018

    @Ulmo
    Author

    All the table hashing is interfering with my reading of it. I'll get back to this later. What's being table hashed?

  3. cdecker commented on Mar 4, 2018

    @cdecker
    Member

    I profiled the block sync for #1117, which also attempts what you are describing:

    https://www.dropbox.com/s/d0sevdhbdmz5gm9/lightning-perf-20180304.svg

    Most of the time is spent parsing the block (no surprise there, they're sort of big), and computing the txid.

  4. cdecker commented on Mar 6, 2018

    @cdecker
    Member

    The main blocking issue before we can just continue at the last height minus some overlap is described in #1179, as soon as we get that fixed we can speed this up a lot.

  5. cdecker commented on Mar 29, 2018

    @cdecker
    Member

    Duplicate of #1179

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions