Open LLFourn opened 1 year ago
Another option is to:
sparse_chain::ChangeSet
s with ChainGraph
(instead of another ChangeSet
type for chain_graph
).TxGraph
of ChainGraph
.The API will be used like this:
ChainGraph::apply_changeset()
will error if changeset
has missing full transactions.ChainGraph
without ChainPosition
.ChainGraph::apply_changest()
again.
Non-monotone changes (i.e.
SparseChain
changesets) must be generated and applied in order. If in between generating a changeset and applying it you apply another changeset that changeset must be thrown away. This is especially likely to happen if you need to do some IO after generating a changeset before you apply it and so you drop your mutex lock on the chain allowing another thread to make modifications while you wait for the result of your IO.We current have baked in this mistake into our electrum example and the idea the "inflate_changeset" API on chaingraph. There we first generate a sparse chain changeset, we do some IO to get the full transactions (and drop the lock), and then inflate the changeset and apply it. What if another thread makes contradictory changes to the blockchain during this time i.e. there is a new block and the blocks and transactions have moved position since then? It breaks. This particular approach can be changed by instead of keeping a changeset over the IO boundry we inflate to a full
ChainGraph
and apply that -- this will enforce consistency.We may wan to come up with a more general solution that makes it impossible to make this mistake:
70 would do this but we could also,
This does not need to be fixed for first release.