github.com/unicornultrafoundation/go-u2u@v1.0.0-rc1.0.20240205080301-e74a83d3fadc/gossip/evmstore/store_tx_position.go (about) 1 package evmstore 2 3 /* 4 In LRU cache data stored like pointer 5 */ 6 7 import ( 8 "github.com/unicornultrafoundation/go-helios/hash" 9 "github.com/unicornultrafoundation/go-helios/native/idx" 10 "github.com/unicornultrafoundation/go-u2u/common" 11 ) 12 13 type TxPosition struct { 14 Block idx.Block 15 Event hash.Event 16 EventOffset uint32 17 BlockOffset uint32 18 } 19 20 // SetTxPosition stores transaction block and position. 21 func (s *Store) SetTxPosition(txid common.Hash, position TxPosition) { 22 s.rlp.Set(s.table.TxPositions, txid.Bytes(), &position) 23 24 // Add to LRU cache. 25 s.cache.TxPositions.Add(txid.String(), &position, nominalSize) 26 } 27 28 // GetTxPosition returns stored transaction block and position. 29 func (s *Store) GetTxPosition(txid common.Hash) *TxPosition { 30 // Get data from LRU cache first. 31 if c, ok := s.cache.TxPositions.Get(txid.String()); ok { 32 if b, ok := c.(*TxPosition); ok { 33 return b 34 } 35 } 36 37 txPosition, _ := s.rlp.Get(s.table.TxPositions, txid.Bytes(), &TxPosition{}).(*TxPosition) 38 39 // Add to LRU cache. 40 if txPosition != nil { 41 s.cache.TxPositions.Add(txid.String(), txPosition, nominalSize) 42 } 43 44 return txPosition 45 }