66
77	"github.com/hashicorp/golang-lru/arc/v2" 
88	"github.com/ipfs/go-cid" 
9+ 	ipld "github.com/ipfs/go-ipld-format" 
910	"golang.org/x/xerrors" 
1011
1112	"github.com/filecoin-project/go-state-types/abi" 
@@ -14,6 +15,7 @@ import (
1415	builtinactors "github.com/filecoin-project/lotus/chain/actors/builtin" 
1516	builtinevm "github.com/filecoin-project/lotus/chain/actors/builtin/evm" 
1617	"github.com/filecoin-project/lotus/chain/index" 
18+ 	"github.com/filecoin-project/lotus/chain/stmgr" 
1719	"github.com/filecoin-project/lotus/chain/types" 
1820	"github.com/filecoin-project/lotus/chain/types/ethtypes" 
1921)
@@ -186,28 +188,36 @@ func (e *ethTransaction) EthGetTransactionByHash(ctx context.Context, txHash *et
186188	return  e .EthGetTransactionByHashLimited (ctx , txHash , api .LookbackNoLimit )
187189}
188190
191+ func  (e  * ethTransaction ) getCidForTransaction (ctx  context.Context , txHash  * ethtypes.EthHash ) (cid.Cid , error ) {
192+ 	if  e .chainIndexer  ==  nil  {
193+ 		return  cid .Undef , ErrChainIndexerDisabled 
194+ 	}
195+ 
196+ 	c , err  :=  e .chainIndexer .GetCidFromHash (ctx , * txHash )
197+ 	if  err  !=  nil  {
198+ 		if  errors .Is (err , index .ErrNotFound ) {
199+ 			log .Debug ("could not find transaction hash %s in chain indexer" , txHash .String ())
200+ 		} else  {
201+ 			log .Errorf ("failed to lookup transaction hash %s in chain indexer: %s" , txHash .String (), err )
202+ 			return  cid .Undef , xerrors .Errorf ("failed to lookup transaction hash %s in chain indexer: %w" , txHash .String (), err )
203+ 		}
204+ 	}
205+ 	if  c  ==  cid .Undef  {
206+ 		// This isn't an eth transaction we have the mapping for, so let's look it up as a filecoin message 
207+ 		return  txHash .ToCid (), nil 
208+ 	}
209+ 	return  c , nil 
210+ }
211+ 
189212func  (e  * ethTransaction ) EthGetTransactionByHashLimited (ctx  context.Context , txHash  * ethtypes.EthHash , limit  abi.ChainEpoch ) (* ethtypes.EthTx , error ) {
190213	// Ethereum's behavior is to return null when the txHash is invalid, so we use nil to check if txHash is valid 
191214	if  txHash  ==  nil  {
192215		return  nil , nil 
193216	}
194- 	if  e .chainIndexer  ==  nil  {
195- 		return  nil , ErrChainIndexerDisabled 
196- 	}
197217
198- 	var  c  cid.Cid 
199- 	var  err  error 
200- 	c , err  =  e .chainIndexer .GetCidFromHash (ctx , * txHash )
201- 	if  err  !=  nil  &&  errors .Is (err , index .ErrNotFound ) {
202- 		log .Debug ("could not find transaction hash %s in chain indexer" , txHash .String ())
203- 	} else  if  err  !=  nil  {
204- 		log .Errorf ("failed to lookup transaction hash %s in chain indexer: %s" , txHash .String (), err )
205- 		return  nil , xerrors .Errorf ("failed to lookup transaction hash %s in chain indexer: %w" , txHash .String (), err )
206- 	}
207- 
208- 	// This isn't an eth transaction we have the mapping for, so let's look it up as a filecoin message 
209- 	if  c  ==  cid .Undef  {
210- 		c  =  txHash .ToCid ()
218+ 	c , err  :=  e .getCidForTransaction (ctx , txHash )
219+ 	if  err  !=  nil  {
220+ 		return  nil , err 
211221	}
212222
213223	// first, try to get the cid from mined transactions 
@@ -285,29 +295,10 @@ func (e *ethTransaction) EthGetMessageCidByTransactionHash(ctx context.Context,
285295	if  txHash  ==  nil  {
286296		return  nil , nil 
287297	}
288- 	if  e .chainIndexer  ==  nil  {
289- 		return  nil , ErrChainIndexerDisabled 
290- 	}
291298
292- 	var  c  cid.Cid 
293- 	var  err  error 
294- 	c , err  =  e .chainIndexer .GetCidFromHash (ctx , * txHash )
295- 	if  err  !=  nil  &&  errors .Is (err , index .ErrNotFound ) {
296- 		log .Debug ("could not find transaction hash %s in chain indexer" , txHash .String ())
297- 	} else  if  err  !=  nil  {
298- 		log .Errorf ("failed to lookup transaction hash %s in chain indexer: %s" , txHash .String (), err )
299- 		return  nil , xerrors .Errorf ("failed to lookup transaction hash %s in chain indexer: %w" , txHash .String (), err )
300- 	}
301- 
302- 	if  errors .Is (err , index .ErrNotFound ) {
303- 		log .Debug ("could not find transaction hash %s in lookup table" , txHash .String ())
304- 	} else  if  e .chainIndexer  !=  nil  {
305- 		return  & c , nil 
306- 	}
307- 
308- 	// This isn't an eth transaction we have the mapping for, so let's try looking it up as a filecoin message 
309- 	if  c  ==  cid .Undef  {
310- 		c  =  txHash .ToCid ()
299+ 	c , err  :=  e .getCidForTransaction (ctx , txHash )
300+ 	if  err  !=  nil  {
301+ 		return  nil , err 
311302	}
312303
313304	_ , err  =  e .chainStore .GetSignedMessage (ctx , c )
@@ -391,30 +382,19 @@ func (e *ethTransaction) EthGetTransactionReceipt(ctx context.Context, txHash et
391382}
392383
393384func  (e  * ethTransaction ) EthGetTransactionReceiptLimited (ctx  context.Context , txHash  ethtypes.EthHash , limit  abi.ChainEpoch ) (* api.EthTxReceipt , error ) {
394- 	var  c  cid.Cid 
395- 	var  err  error 
396- 	if  e .chainIndexer  ==  nil  {
397- 		return  nil , ErrChainIndexerDisabled 
398- 	}
399- 
400- 	c , err  =  e .chainIndexer .GetCidFromHash (ctx , txHash )
401- 	if  err  !=  nil  &&  errors .Is (err , index .ErrNotFound ) {
402- 		log .Debug ("could not find transaction hash %s in chain indexer" , txHash .String ())
403- 	} else  if  err  !=  nil  {
404- 		log .Errorf ("failed to lookup transaction hash %s in chain indexer: %s" , txHash .String (), err )
405- 		return  nil , xerrors .Errorf ("failed to lookup transaction hash %s in chain indexer: %w" , txHash .String (), err )
406- 	}
407- 
408- 	// This isn't an eth transaction we have the mapping for, so let's look it up as a filecoin message 
409- 	if  c  ==  cid .Undef  {
410- 		c  =  txHash .ToCid ()
385+ 	c , err  :=  e .getCidForTransaction (ctx , & txHash )
386+ 	if  err  !=  nil  {
387+ 		return  nil , err 
411388	}
412389
413390	msgLookup , err  :=  e .stateApi .StateSearchMsg (ctx , types .EmptyTSK , c , limit , true )
414391	if  err  !=  nil  {
415- 		return  nil , xerrors .Errorf ("failed to lookup Eth Txn %s as %s: %w" , txHash , c , err )
416- 	}
417- 	if  msgLookup  ==  nil  {
392+ 		if  ipld .IsNotFound (err ) ||  errors .Is (err , stmgr .ErrFailedToLoadMessage ) {
393+ 			// error came from not being able to turn the cid into something we can find in the chainstore 
394+ 			return  nil , nil 
395+ 		}
396+ 		return  nil , xerrors .Errorf ("could not find transaction %s: %w" , txHash , err )
397+ 	} else  if  msgLookup  ==  nil  {
418398		// This is the best we can do. In theory, we could have just not indexed this 
419399		// transaction, but there's no way to check that here. 
420400		return  nil , nil 
0 commit comments