Skip to content

Commit 6c4471c

Browse files
authored
#239 Fix looping when not able to get result from transaction (#240)
* #239 fix looping when not able to get result from transaction * #239 check instruction owner * #239 check inner instruction ownership in indexer
1 parent 3c77797 commit 6c4471c

File tree

2 files changed

+60
-47
lines changed

2 files changed

+60
-47
lines changed

proxy/indexer/utils.py

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -45,50 +45,58 @@ def check_error(trx):
4545

4646

4747
def get_trx_results(trx):
48+
# init variables for instruction owner checks
49+
accounts = trx["transaction"]["message"]["accountKeys"]
50+
evm_loader_instructions = []
51+
for idx, instruction in enumerate(trx["transaction"]["message"]["instructions"]):
52+
if accounts[instruction["programIdIndex"]] == evm_loader_id:
53+
evm_loader_instructions.append(idx)
54+
4855
slot = trx['slot']
4956
block_number = hex(slot)
50-
# block_hash = '0x%064x'%slot
5157
got_result = False
5258
logs = []
5359
status = "0x1"
5460
gas_used = 0
5561
return_value = bytes
5662
log_index = 0
5763
for inner in (trx['meta']['innerInstructions']):
58-
for event in inner['instructions']:
59-
log = base58.b58decode(event['data'])
60-
instruction = log[:1]
61-
if (int().from_bytes(instruction, "little") == 7): # OnEvent evmInstruction code
62-
address = log[1:21]
63-
count_topics = int().from_bytes(log[21:29], 'little')
64-
topics = []
65-
pos = 29
66-
for _ in range(count_topics):
67-
topic_bin = log[pos:pos + 32]
68-
topics.append('0x'+topic_bin.hex())
69-
pos += 32
70-
data = log[pos:]
71-
rec = {
72-
'address': '0x'+address.hex(),
73-
'topics': topics,
74-
'data': '0x'+data.hex(),
75-
'transactionLogIndex': hex(0),
76-
'transactionIndex': hex(inner['index']),
77-
'blockNumber': block_number,
78-
# 'transactionHash': trxId, # set when transaction found
79-
'logIndex': hex(log_index),
80-
# 'blockHash': block_hash # set when transaction found
81-
}
82-
logs.append(rec)
83-
log_index +=1
84-
elif int().from_bytes(instruction, "little") == 6: # OnReturn evmInstruction code
85-
got_result = True
86-
if log[1] < 0xd0:
87-
status = "0x1"
88-
else:
89-
status = "0x0"
90-
gas_used = int.from_bytes(log[2:10], 'little')
91-
return_value = log[10:].hex()
64+
if inner["index"] in evm_loader_instructions:
65+
for event in inner['instructions']:
66+
if accounts[event['programIdIndex']] == evm_loader_id:
67+
log = base58.b58decode(event['data'])
68+
instruction = log[:1]
69+
if (int().from_bytes(instruction, "little") == 7): # OnEvent evmInstruction code
70+
address = log[1:21]
71+
count_topics = int().from_bytes(log[21:29], 'little')
72+
topics = []
73+
pos = 29
74+
for _ in range(count_topics):
75+
topic_bin = log[pos:pos + 32]
76+
topics.append('0x'+topic_bin.hex())
77+
pos += 32
78+
data = log[pos:]
79+
rec = {
80+
'address': '0x'+address.hex(),
81+
'topics': topics,
82+
'data': '0x'+data.hex(),
83+
'transactionLogIndex': hex(0),
84+
'transactionIndex': hex(inner['index']),
85+
'blockNumber': block_number,
86+
# 'transactionHash': trxId, # set when transaction found
87+
'logIndex': hex(log_index),
88+
# 'blockHash': block_hash # set when transaction found
89+
}
90+
logs.append(rec)
91+
log_index +=1
92+
elif int().from_bytes(instruction, "little") == 6: # OnReturn evmInstruction code
93+
got_result = True
94+
if log[1] < 0xd0:
95+
status = "0x1"
96+
else:
97+
status = "0x0"
98+
gas_used = int.from_bytes(log[2:10], 'little')
99+
return_value = log[10:].hex()
92100

93101
if got_result:
94102
return (logs, status, gas_used, return_value, slot)

proxy/plugin/solana_rest_api_tools.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import base58
12
import base64
23
import json
34
import logging
@@ -451,17 +452,21 @@ def check_if_program_exceeded_instructions(err_result):
451452

452453

453454
def check_if_continue_returned(result):
454-
acc_meta_lst = result["result"]["transaction"]["message"]["accountKeys"]
455-
evm_loader_index = acc_meta_lst.index(evm_loader_id)
456-
457-
innerInstruction = result['result']['meta']['innerInstructions']
458-
innerInstruction = next((i for i in innerInstruction if i["index"] == 0), None)
459-
if (innerInstruction and innerInstruction['instructions']):
460-
instruction = innerInstruction['instructions'][-1]
461-
if (instruction['programIdIndex'] == evm_loader_index):
462-
data = b58decode(instruction['data'])
463-
if (data[0] == 6):
464-
return (True, result['result']['transaction']['signatures'][0])
455+
tx_info = result['result']
456+
accounts = tx_info["transaction"]["message"]["accountKeys"]
457+
evm_loader_instructions = []
458+
459+
for idx, instruction in enumerate(tx_info["transaction"]["message"]["instructions"]):
460+
if accounts[instruction["programIdIndex"]] == evm_loader_id:
461+
evm_loader_instructions.append(idx)
462+
463+
for inner in (tx_info['meta']['innerInstructions']):
464+
if inner["index"] in evm_loader_instructions:
465+
for event in inner['instructions']:
466+
if accounts[event['programIdIndex']] == evm_loader_id:
467+
instruction = base58.b58decode(event['data'])[:1]
468+
if int().from_bytes(instruction, "little") == 6: # OnReturn evmInstruction code
469+
return (True, tx_info['transaction']['signatures'][0])
465470
return (False, ())
466471

467472

@@ -519,7 +524,7 @@ def call_continue_bucked(signer, client, perm_accs, trx_accs, steps):
519524
else:
520525
raise
521526

522-
logger.debug("Collect bucked results:")
527+
logger.debug("Collect bucked results: {}".format(result_list))
523528
for trx in result_list:
524529
confirm_transaction(client, trx)
525530
result = client.get_confirmed_transaction(trx)

0 commit comments

Comments
 (0)