From a762253e24c8c0bc446c4e94ee0f310198927567 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Wed, 29 Nov 2017 15:25:12 -0600 Subject: [PATCH] do not use AddBatch, prefer copying for now --- state/txindex/kv/kv.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/state/txindex/kv/kv.go b/state/txindex/kv/kv.go index 5228a3c4..ad108069 100644 --- a/state/txindex/kv/kv.go +++ b/state/txindex/kv/kv.go @@ -84,12 +84,23 @@ func (txi *TxIndex) AddBatch(b *txindex.Batch) error { // Index indexes a single transaction using the given list of tags. func (txi *TxIndex) Index(result *types.TxResult) error { - batch := txindex.NewBatch(1) - err := batch.Add(result) - if err != nil { - return errors.Wrap(err, "failed to add tx result to batch") + b := txi.store.NewBatch() + + hash := result.Tx.Hash() + + // index tx by tags + for _, tag := range result.Result.Tags { + if cmn.StringInSlice(tag.Key, txi.tagsToIndex) { + b.Set(keyForTag(tag, result), hash) + } } - return txi.AddBatch(batch) + + // index tx by hash + rawBytes := wire.BinaryBytes(result) + b.Set(hash, rawBytes) + + b.Write() + return nil } // Search performs a search using the given query. It breaks the query into