chain: improvements to IndexedTxGraph and TxGraph APIs

For `IndexedTxGraph`:
- Remove `InsertTxItem` type (this is too complex).
    - `batch_insert_relevant` now uses a simple tuple `(&tx, anchors)`.
    - `batch_insert` is now also removed, as the same functionality can be
      done elsewhere.
- Add internal helper method `index_tx_graph_changeset` so we don't need
  to create a seprate `TxGraph` update in each method.
- `batch_insert_<relevant>_unconfirmed` no longer takes in an option of
  last_seen.
- `batch_insert_unconfirmed` no longer takes a reference of a
  transaction (since we apply all transactions anyway, so there is no
  need to clone).

For `TxGraph`:
- Add `batch_insert_unconfirmed` method.
This commit is contained in:
志宇
2023-10-06 02:05:31 +08:00
parent 150d6f8ab6
commit 4f5695d43a
6 changed files with 104 additions and 115 deletions

View File

@@ -212,8 +212,7 @@ fn main() -> anyhow::Result<()> {
// mempool
let mempool_txs = emitter.mempool()?;
let graph_changeset = graph
.batch_insert_unconfirmed(mempool_txs.iter().map(|(tx, time)| (tx, Some(*time))));
let graph_changeset = graph.batch_insert_unconfirmed(mempool_txs);
db.stage((local_chain::ChangeSet::default(), graph_changeset));
// commit one last time!
@@ -291,7 +290,7 @@ fn main() -> anyhow::Result<()> {
}
Emission::Mempool(mempool_txs) => {
let graph_changeset = graph.batch_insert_relevant_unconfirmed(
mempool_txs.iter().map(|(tx, time)| (tx, Some(*time))),
mempool_txs.iter().map(|(tx, time)| (tx, *time)),
);
(local_chain::ChangeSet::default(), graph_changeset)
}