@@ -44,14 +44,16 @@ type BlockAPI struct {
4444 includeShellReceipts bool
4545 includeBankTransfers bool
4646 watermarks * WatermarkManager
47+ globalBlockCache BlockCache
48+ cacheCreationMutex * sync.Mutex
4749}
4850
4951type SeiBlockAPI struct {
5052 * BlockAPI
5153 isPanicTx func (ctx context.Context , hash common.Hash ) (bool , error )
5254}
5355
54- func NewBlockAPI (tmClient rpcclient.Client , k * keeper.Keeper , ctxProvider func (int64 ) sdk.Context , txConfigProvider func (int64 ) client.TxConfig , connectionType ConnectionType , watermarks * WatermarkManager ) * BlockAPI {
56+ func NewBlockAPI (tmClient rpcclient.Client , k * keeper.Keeper , ctxProvider func (int64 ) sdk.Context , txConfigProvider func (int64 ) client.TxConfig , connectionType ConnectionType , watermarks * WatermarkManager , globalBlockCache BlockCache , cacheCreationMutex * sync. Mutex ) * BlockAPI {
5557 return & BlockAPI {
5658 tmClient : tmClient ,
5759 keeper : k ,
@@ -62,6 +64,8 @@ func NewBlockAPI(tmClient rpcclient.Client, k *keeper.Keeper, ctxProvider func(i
6264 includeBankTransfers : false ,
6365 namespace : EthNamespace ,
6466 watermarks : watermarks ,
67+ globalBlockCache : globalBlockCache ,
68+ cacheCreationMutex : cacheCreationMutex ,
6569 }
6670}
6771
@@ -73,6 +77,8 @@ func NewSeiBlockAPI(
7377 connectionType ConnectionType ,
7478 isPanicTx func (ctx context.Context , hash common.Hash ) (bool , error ),
7579 watermarks * WatermarkManager ,
80+ globalBlockCache BlockCache ,
81+ cacheCreationMutex * sync.Mutex ,
7682) * SeiBlockAPI {
7783 blockAPI := & BlockAPI {
7884 tmClient : tmClient ,
@@ -84,6 +90,8 @@ func NewSeiBlockAPI(
8490 includeBankTransfers : false ,
8591 namespace : SeiNamespace ,
8692 watermarks : watermarks ,
93+ globalBlockCache : globalBlockCache ,
94+ cacheCreationMutex : cacheCreationMutex ,
8795 }
8896 return & SeiBlockAPI {
8997 BlockAPI : blockAPI ,
@@ -99,8 +107,10 @@ func NewSei2BlockAPI(
99107 connectionType ConnectionType ,
100108 isPanicTx func (ctx context.Context , hash common.Hash ) (bool , error ),
101109 watermarks * WatermarkManager ,
110+ globalBlockCache BlockCache ,
111+ cacheCreationMutex * sync.Mutex ,
102112) * SeiBlockAPI {
103- blockAPI := NewSeiBlockAPI (tmClient , k , ctxProvider , txConfigProvider , connectionType , isPanicTx , watermarks )
113+ blockAPI := NewSeiBlockAPI (tmClient , k , ctxProvider , txConfigProvider , connectionType , isPanicTx , watermarks , globalBlockCache , cacheCreationMutex )
104114 blockAPI .namespace = Sei2Namespace
105115 blockAPI .includeBankTransfers = true
106116 return blockAPI
@@ -163,7 +173,7 @@ func (a *BlockAPI) getBlockByHash(ctx context.Context, blockHash common.Hash, fu
163173 if err != nil {
164174 return nil , err
165175 }
166- return EncodeTmBlock (a .ctxProvider , a .txConfigProvider , block , blockRes , a .keeper , fullTx , a .includeBankTransfers , includeSyntheticTxs , isPanicTx )
176+ return EncodeTmBlock (a .ctxProvider , a .txConfigProvider , block , blockRes , a .keeper , fullTx , a .includeBankTransfers , includeSyntheticTxs , isPanicTx , a . globalBlockCache , a . cacheCreationMutex )
167177}
168178
169179func (a * BlockAPI ) GetBlockByNumber (ctx context.Context , number rpc.BlockNumber , fullTx bool ) (result map [string ]interface {}, returnErr error ) {
@@ -225,7 +235,7 @@ func (a *BlockAPI) getBlockByNumber(
225235 if err != nil {
226236 return nil , err
227237 }
228- return EncodeTmBlock (a .ctxProvider , a .txConfigProvider , block , blockRes , a .keeper , fullTx , a .includeBankTransfers , includeSyntheticTxs , isPanicTx )
238+ return EncodeTmBlock (a .ctxProvider , a .txConfigProvider , block , blockRes , a .keeper , fullTx , a .includeBankTransfers , includeSyntheticTxs , isPanicTx , a . globalBlockCache , a . cacheCreationMutex )
229239}
230240
231241func (a * BlockAPI ) GetBlockReceipts (ctx context.Context , blockNrOrHash rpc.BlockNumberOrHash ) (result []map [string ]interface {}, returnErr error ) {
@@ -244,7 +254,9 @@ func (a *BlockAPI) GetBlockReceipts(ctx context.Context, blockNrOrHash rpc.Block
244254
245255 // Get all tx hashes for the block
246256 height := block .Block .Height
247- txHashes := getTxHashesFromBlock (a .ctxProvider , a .txConfigProvider , a .keeper , block , shouldIncludeSynthetic (a .namespace ))
257+
258+ txHashes := getTxHashesFromBlock (a .ctxProvider , a .txConfigProvider , a .keeper , block , shouldIncludeSynthetic (a .namespace ), a .cacheCreationMutex , a .globalBlockCache )
259+
248260 // Get tx receipts for all hashes in parallel
249261 wg := sync.WaitGroup {}
250262 mtx := sync.Mutex {}
@@ -263,7 +275,7 @@ func (a *BlockAPI) GetBlockReceipts(ctx context.Context, blockNrOrHash rpc.Block
263275 mtx .Unlock ()
264276 }
265277 } else {
266- encodedReceipt , err := encodeReceipt (a .ctxProvider , a .txConfigProvider , receipt , a .keeper , block , a .includeShellReceipts )
278+ encodedReceipt , err := encodeReceipt (a .ctxProvider , a .txConfigProvider , receipt , a .keeper , block , a .includeShellReceipts , a . globalBlockCache , a . cacheCreationMutex )
267279 if err != nil {
268280 mtx .Lock ()
269281 returnErr = err
@@ -299,6 +311,8 @@ func EncodeTmBlock(
299311 includeBankTransfers bool ,
300312 includeSyntheticTxs bool ,
301313 isPanicOrSynthetic func (ctx context.Context , hash common.Hash ) (bool , error ),
314+ globalBlockCache BlockCache ,
315+ cacheCreationMutex * sync.Mutex ,
302316) (map [string ]interface {}, error ) {
303317 number := big .NewInt (block .Block .Height )
304318 blockhash := common .HexToHash (block .BlockID .Hash .String ())
@@ -320,7 +334,7 @@ func EncodeTmBlock(
320334 transactions := []interface {}{}
321335 latestCtx := ctxProvider (LatestCtxHeight )
322336
323- msgs := filterTransactions (k , ctxProvider , txConfigProvider , block , includeSyntheticTxs , includeBankTransfers )
337+ msgs := filterTransactions (k , ctxProvider , txConfigProvider , block , includeSyntheticTxs , includeBankTransfers , cacheCreationMutex , globalBlockCache )
324338
325339 blockBloom := make ([]byte , ethtypes .BloomByteLength )
326340 for _ , msg := range msgs {
0 commit comments