From fb3f2750411c56f36515223a4a38311efbf21bbf Mon Sep 17 00:00:00 2001 From: Gregor Gololicic Date: Tue, 30 Jan 2024 17:12:11 +0100 Subject: [PATCH] Revert "update change in receipt indexer api" This reverts commit 2105329484ff88dc1dd3dbacdbc3700c786fc5ba. --- storage/memory/storage.go | 40 +++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/storage/memory/storage.go b/storage/memory/storage.go index 87e1a3d3..97b501f4 100644 --- a/storage/memory/storage.go +++ b/storage/memory/storage.go @@ -24,9 +24,9 @@ type baseStorage struct { firstHeight uint64 lastHeight uint64 - receiptsTxIDs map[common.Hash]*gethTypes.Receipt - receiptBlockHeightTxID map[*big.Int]common.Hash - bloomHeight map[*big.Int]gethTypes.Bloom + receiptsTxIDs map[common.Hash]*gethTypes.Receipt + receiptBlockIDTxIDs map[common.Hash]common.Hash + bloomHeight map[int64]gethTypes.Bloom transactionsIDs map[common.Hash]*gethTypes.Transaction } @@ -36,14 +36,14 @@ var store *baseStorage func baseStorageFactory() *baseStorage { if store == nil { store = &baseStorage{ - blocksIDs: make(map[common.Hash]*types.Block), - blockHeightsIDs: make(map[uint64]common.Hash), - firstHeight: unknownHeight, - lastHeight: unknownHeight, - receiptsTxIDs: make(map[common.Hash]*gethTypes.Receipt), - receiptBlockHeightTxID: make(map[*big.Int]common.Hash), - bloomHeight: make(map[*big.Int]gethTypes.Bloom), - transactionsIDs: make(map[common.Hash]*gethTypes.Transaction), + blocksIDs: make(map[common.Hash]*types.Block), + blockHeightsIDs: make(map[uint64]common.Hash), + firstHeight: unknownHeight, + lastHeight: unknownHeight, + receiptsTxIDs: make(map[common.Hash]*gethTypes.Receipt), + receiptBlockIDTxIDs: make(map[common.Hash]common.Hash), + bloomHeight: make(map[int64]gethTypes.Bloom), + transactionsIDs: make(map[common.Hash]*gethTypes.Transaction), } } return store @@ -169,8 +169,13 @@ func (r ReceiptStorage) Store(receipt *gethTypes.Receipt) error { } r.base.receiptsTxIDs[receipt.TxHash] = receipt - r.base.receiptBlockHeightTxID[receipt.BlockNumber] = receipt.TxHash - r.base.bloomHeight[receipt.BlockNumber] = receipt.Bloom + r.base.receiptBlockIDTxIDs[receipt.BlockHash] = receipt.TxHash + + if _, ok := r.base.bloomHeight[receipt.BlockNumber.Int64()]; ok { + return errors.Duplicate + } + + r.base.bloomHeight[receipt.BlockNumber.Int64()] = receipt.Bloom return nil } @@ -187,11 +192,11 @@ func (r ReceiptStorage) GetByTransactionID(ID common.Hash) (*gethTypes.Receipt, return receipt, nil } -func (r ReceiptStorage) GetByBlockHeight(height *big.Int) (*gethTypes.Receipt, error) { +func (r ReceiptStorage) GetByBlockID(ID common.Hash) (*gethTypes.Receipt, error) { r.base.mu.RLock() defer r.base.mu.RUnlock() - txID, exists := r.base.receiptBlockHeightTxID[height] + txID, exists := r.base.receiptBlockIDTxIDs[ID] if !exists { return nil, errors.NotFound } @@ -208,15 +213,14 @@ func (r ReceiptStorage) BloomsForBlockRange(start, end *big.Int) ([]*gethTypes.B r.base.mu.RLock() defer r.base.mu.RUnlock() - // make sure start is not bigger than end - if start.Cmp(end) > 0 { + if start.Cmp(end) > -1 { return nil, errors.InvalidRange } blooms := make([]*gethTypes.Bloom, 0) // Iterate through the range of block heights and add the blooms to the result - for i := start.Int64(); i <= end.Int64(); i++ { + for i := start.Int64(); i < end.Int64(); i++ { b, exists := r.base.bloomHeight[i] if exists { blooms = append(blooms, &b)