@@ -39,8 +39,48 @@ type BlockAPI struct {
3939 includeShellReceipts bool
4040}
4141
42- func NewBlockAPI (tmClient rpcclient.Client , k * keeper.Keeper , ctxProvider func (int64 ) sdk.Context , txConfig client.TxConfig , connectionType ConnectionType , namespace string ) * BlockAPI {
43- return & BlockAPI {tmClient : tmClient , keeper : k , ctxProvider : ctxProvider , txConfig : txConfig , connectionType : connectionType , includeShellReceipts : shouldIncludeSynthetic (namespace )}
42+ type SeiBlockAPI struct {
43+ * BlockAPI
44+ isPanicTx func (ctx context.Context , hash common.Hash ) (bool , error )
45+ }
46+
47+ func NewBlockAPI (tmClient rpcclient.Client , k * keeper.Keeper , ctxProvider func (int64 ) sdk.Context , txConfig client.TxConfig , connectionType ConnectionType ) * BlockAPI {
48+ return & BlockAPI {
49+ tmClient : tmClient ,
50+ keeper : k ,
51+ ctxProvider : ctxProvider ,
52+ txConfig : txConfig ,
53+ connectionType : connectionType ,
54+ includeShellReceipts : false ,
55+ namespace : "eth" ,
56+ }
57+ }
58+
59+ func NewSeiBlockAPI (
60+ tmClient rpcclient.Client ,
61+ k * keeper.Keeper ,
62+ ctxProvider func (int64 ) sdk.Context ,
63+ txConfig client.TxConfig ,
64+ connectionType ConnectionType ,
65+ isPanicTx func (ctx context.Context , hash common.Hash ) (bool , error ),
66+ ) * SeiBlockAPI {
67+ blockAPI := & BlockAPI {
68+ tmClient : tmClient ,
69+ keeper : k ,
70+ ctxProvider : ctxProvider ,
71+ txConfig : txConfig ,
72+ connectionType : connectionType ,
73+ includeShellReceipts : true ,
74+ namespace : "sei" ,
75+ }
76+ return & SeiBlockAPI {
77+ BlockAPI : blockAPI ,
78+ isPanicTx : isPanicTx ,
79+ }
80+ }
81+
82+ func (a * SeiBlockAPI ) GetBlockByNumberExcludeTraceFail (ctx context.Context , number rpc.BlockNumber , fullTx bool ) (result map [string ]interface {}, returnErr error ) {
83+ return a .getBlockByNumber (ctx , number , fullTx , a .isPanicTx )
4484}
4585
4686func (a * BlockAPI ) GetBlockTransactionCountByNumber (ctx context.Context , number rpc.BlockNumber ) (result * hexutil.Uint , returnErr error ) {
@@ -68,12 +108,20 @@ func (a *BlockAPI) GetBlockTransactionCountByHash(ctx context.Context, blockHash
68108}
69109
70110func (a * BlockAPI ) GetBlockByHash (ctx context.Context , blockHash common.Hash , fullTx bool ) (result map [string ]interface {}, returnErr error ) {
71- startTime := time .Now ()
72- defer recordMetrics (fmt .Sprintf ("%s_getBlockByHash" , a .namespace ), a .connectionType , startTime , returnErr == nil )
73- return a .getBlockByHash (ctx , blockHash , fullTx )
111+ return a .getBlockByHash (ctx , blockHash , fullTx , nil )
112+ }
113+
114+ func (a * SeiBlockAPI ) GetBlockByHash (ctx context.Context , blockHash common.Hash , fullTx bool ) (result map [string ]interface {}, returnErr error ) {
115+ return a .getBlockByHash (ctx , blockHash , fullTx , nil )
74116}
75117
76- func (a * BlockAPI ) getBlockByHash (ctx context.Context , blockHash common.Hash , fullTx bool ) (result map [string ]interface {}, returnErr error ) {
118+ func (a * SeiBlockAPI ) GetBlockByHashExcludeTraceFail (ctx context.Context , blockHash common.Hash , fullTx bool ) (result map [string ]interface {}, returnErr error ) {
119+ return a .getBlockByHash (ctx , blockHash , fullTx , a .isPanicTx )
120+ }
121+
122+ func (a * BlockAPI ) getBlockByHash (ctx context.Context , blockHash common.Hash , fullTx bool , isPanicTx func (ctx context.Context , hash common.Hash ) (bool , error )) (result map [string ]interface {}, returnErr error ) {
123+ startTime := time .Now ()
124+ defer recordMetrics (fmt .Sprintf ("%s_getBlockByHash" , a .namespace ), a .connectionType , startTime , returnErr == nil )
77125 block , err := blockByHashWithRetry (ctx , a .tmClient , blockHash [:], 1 )
78126 if err != nil {
79127 return nil , err
@@ -83,7 +131,7 @@ func (a *BlockAPI) getBlockByHash(ctx context.Context, blockHash common.Hash, fu
83131 return nil , err
84132 }
85133 blockBloom := a .keeper .GetBlockBloom (a .ctxProvider (block .Block .Height ))
86- return EncodeTmBlock (a .ctxProvider (block .Block .Height ), block , blockRes , blockBloom , a .keeper , a .txConfig .TxDecoder (), fullTx , a .includeShellReceipts )
134+ return EncodeTmBlock (a .ctxProvider (block .Block .Height ), block , blockRes , blockBloom , a .keeper , a .txConfig .TxDecoder (), fullTx , a .includeShellReceipts , isPanicTx )
87135}
88136
89137func (a * BlockAPI ) GetBlockByNumber (ctx context.Context , number rpc.BlockNumber , fullTx bool ) (result map [string ]interface {}, returnErr error ) {
@@ -93,7 +141,7 @@ func (a *BlockAPI) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber,
93141 // for compatibility with the graph, always return genesis block
94142 return map [string ]interface {}{
95143 "number" : (* hexutil .Big )(big .NewInt (0 )),
96- "hash" : common . HexToHash ( "F9D3845DF25B43B1C6926F3CEDA6845C17F5624E12212FD8847D0BA01DA1AB9E" ) ,
144+ "hash" : "0xF9D3845DF25B43B1C6926F3CEDA6845C17F5624E12212FD8847D0BA01DA1AB9E" ,
97145 "parentHash" : common.Hash {},
98146 "nonce" : ethtypes.BlockNonce {}, // inapplicable to Sei
99147 "mixHash" : common.Hash {}, // inapplicable to Sei
@@ -114,10 +162,17 @@ func (a *BlockAPI) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber,
114162 "baseFeePerGas" : (* hexutil .Big )(big .NewInt (0 )),
115163 }, nil
116164 }
117- return a .getBlockByNumber (ctx , number , fullTx )
165+ return a .getBlockByNumber (ctx , number , fullTx , nil )
118166}
119167
120- func (a * BlockAPI ) getBlockByNumber (ctx context.Context , number rpc.BlockNumber , fullTx bool ) (result map [string ]interface {}, returnErr error ) {
168+ func (a * BlockAPI ) getBlockByNumber (
169+ ctx context.Context ,
170+ number rpc.BlockNumber ,
171+ fullTx bool ,
172+ isPanicTx func (ctx context.Context , hash common.Hash ) (bool , error ),
173+ ) (result map [string ]interface {}, returnErr error ) {
174+ startTime := time .Now ()
175+ defer recordMetrics (fmt .Sprintf ("%s_getBlockByNumber" , a .namespace ), a .connectionType , startTime , returnErr == nil )
121176 numberPtr , err := getBlockNumber (ctx , a .tmClient , number )
122177 if err != nil {
123178 return nil , err
@@ -131,7 +186,7 @@ func (a *BlockAPI) getBlockByNumber(ctx context.Context, number rpc.BlockNumber,
131186 return nil , err
132187 }
133188 blockBloom := a .keeper .GetBlockBloom (a .ctxProvider (block .Block .Height ))
134- return EncodeTmBlock (a .ctxProvider (block .Block .Height ), block , blockRes , blockBloom , a .keeper , a .txConfig .TxDecoder (), fullTx , a .includeShellReceipts )
189+ return EncodeTmBlock (a .ctxProvider (block .Block .Height ), block , blockRes , blockBloom , a .keeper , a .txConfig .TxDecoder (), fullTx , a .includeShellReceipts , isPanicTx )
135190}
136191
137192func (a * BlockAPI ) GetBlockReceipts (ctx context.Context , blockNrOrHash rpc.BlockNumberOrHash ) (result []map [string ]interface {}, returnErr error ) {
@@ -150,7 +205,7 @@ func (a *BlockAPI) GetBlockReceipts(ctx context.Context, blockNrOrHash rpc.Block
150205
151206 // Get all tx hashes for the block
152207 height := block .Block .Header .Height
153- txHashes := getEvmTxHashesFromBlock (block , a .txConfig )
208+ txHashes := getTxHashesFromBlock (block , a .txConfig , shouldIncludeSynthetic ( a . namespace ) )
154209 // Get tx receipts for all hashes in parallel
155210 wg := sync.WaitGroup {}
156211 mtx := sync.Mutex {}
@@ -172,6 +227,11 @@ func (a *BlockAPI) GetBlockReceipts(ctx context.Context, blockNrOrHash rpc.Block
172227 if ! a .includeShellReceipts && receipt .TxType == ShellEVMTxType {
173228 return
174229 }
230+ // tx hash is included in a future block (because it failed in the current block due to
231+ // checks before the account's nonce is updated)
232+ if receipt .BlockNumber != uint64 (height ) {
233+ return
234+ }
175235 encodedReceipt , err := encodeReceipt (receipt , a .txConfig .TxDecoder (), block , func (h common.Hash ) bool {
176236 _ , err := a .keeper .GetReceipt (a .ctxProvider (height ), h )
177237 return err == nil
@@ -207,6 +267,7 @@ func EncodeTmBlock(
207267 txDecoder sdk.TxDecoder ,
208268 fullTx bool ,
209269 includeSyntheticTxs bool ,
270+ isPanicTx func (ctx context.Context , hash common.Hash ) (bool , error ),
210271) (map [string ]interface {}, error ) {
211272 number := big .NewInt (block .Block .Height )
212273 blockhash := common .HexToHash (block .BlockID .Hash .String ())
@@ -235,16 +296,25 @@ func EncodeTmBlock(
235296 }
236297 ethtx , _ := m .AsTransaction ()
237298 hash := ethtx .Hash ()
238- if ! fullTx {
239- transactions = append (transactions , hash )
240- } else {
241- receipt , err := k .GetReceipt (ctx , hash )
299+ if isPanicTx != nil {
300+ isPanic , err := isPanicTx (ctx .Context (), hash )
242301 if err != nil {
243- continue
302+ return nil , fmt . Errorf ( "failed to check if tx is panic tx: %w" , err )
244303 }
245- if ! includeSyntheticTxs && receipt . TxType == ShellEVMTxType {
304+ if isPanic {
246305 continue
247306 }
307+ }
308+ receipt , err := k .GetReceipt (ctx , hash )
309+ if err != nil {
310+ continue
311+ }
312+ if ! includeSyntheticTxs && receipt .TxType == ShellEVMTxType {
313+ continue
314+ }
315+ if ! fullTx {
316+ transactions = append (transactions , hash )
317+ } else {
248318 newTx := ethapi .NewRPCTransaction (ethtx , blockhash , number .Uint64 (), uint64 (blockTime .Second ()), uint64 (receipt .TransactionIndex ), baseFeePerGas , chainConfig )
249319 transactions = append (transactions , newTx )
250320 }
0 commit comments