Skip to content

Commit

Permalink
Relayer fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SecretSaturn committed Sep 19, 2024
1 parent f3623d3 commit d95c9dc
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 21 deletions.
51 changes: 34 additions & 17 deletions TNLS-Relayers/eth_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,21 +134,30 @@ def get_transactions(self, contract_interface, height=None):
"""
See base_interface.py for documentation
"""
return self.get_last_txs(contract_interface=contract_interface, block_number=height)

def get_last_block(self):
"""
Gets the number of the most recent block
"""
return self.provider.eth.get_block('latest').number

def get_last_txs(self, block_number=None, contract_interface=None):
"""
Gets the transactions from a particular block for a particular address.
Args:
block_number: Which block to get
contract_interface: Which contract to get transactions for
Gets the transactions from a particular block for a particular address.
Args:
block_number: Which block to get
contract_interface: Which contract to get transactions for
Returns: a list of transaction receipts
Returns: a list of transaction receipts
"""
try:
if block_number is None:
block_number = self.get_last_block()
block_number = self.provider.eth.get_block('latest').number
valid_transactions = contract_interface.contract.events.logNewTask().get_logs(
fromBlock=height,
toBlock=height
fromBlock=block_number,
toBlock=block_number
)
except Exception as e:
self.logger.warning(e)
Expand All @@ -164,8 +173,7 @@ def get_transactions(self, contract_interface, height=None):
try:
with ThreadPoolExecutor(max_workers=50) as executor:
# Create a future for each transaction
future_to_transaction = {executor.submit(process_transaction, tx_hash): tx_hash for tx_hash in
transaction_hashes}
future_to_transaction = {executor.submit(self.process_transaction, tx_hash): tx_hash for tx_hash in transaction_hashes}
for future in as_completed(future_to_transaction):
result = future.result()
if result is not None:
Expand All @@ -176,11 +184,13 @@ def get_transactions(self, contract_interface, height=None):

return correct_transactions

def get_last_block(self):
"""
Gets the number of the most recent block
"""
return self.provider.eth.get_block('latest').number
def process_transaction(self, transaction_hash):
try:
tx_receipt = self.provider.eth.get_transaction_receipt(transaction_hash)
return tx_receipt
except Exception as e:
self.logger.warning(e)
return None


class EthContract(BaseContractInterface):
Expand All @@ -203,12 +213,20 @@ def __init__(self, interface, address, abi, **_kwargs):
self.logger.info("Initialized Eth contract with address: %s", self.address)
pass

def get_function(self, function_name):
"""
Gets a particular function from the contract.
Args:
function_name: The name of the function to get.
"""
return self.contract.functions[function_name]

def call_function(self, function_name, *args):
"""
See base_interface.py for documentation
"""
kwargs = None
function = self.contract.functions[function_name]
function = self.get_function(function_name)
if len(args) == 1:
args = json.loads(args[0])
if isinstance(args, dict):
Expand Down Expand Up @@ -258,4 +276,3 @@ def parse_event_from_txn(self, event_name, txn) -> List[Task]:

if __name__ == "__main__":
interface = EthInterface(address='')

2 changes: 1 addition & 1 deletion TNLS-Relayers/relayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def process_chain(name):
prev_height = curr_height - 1

def fetch_transactions(block_num):
block_num = 320426
#block_num = 320426
transactions = chain_interface.get_transactions(contract_interface, height=block_num)
tasks_tmp = []
for transaction in transactions:
Expand Down
2 changes: 1 addition & 1 deletion TNLS-Relayers/sol_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class PostExecution:
"post_execution_info" / CStruct(
"packet_hash" / U8[32],
"callback_address" / Bytes,
"callback_selector" / Bytes,
"callback_selector" / U8[40],
"callback_gas_limit" / U8[4],
"packet_signature" / U8[65],
"result" / Bytes,
Expand Down
12 changes: 10 additions & 2 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,21 @@
contract_address: "0xAaA666CE51E4c4dcB50781d4F84461e267392fC9"
timeout: 1

"SolDN": #Solana DevNet
"SolDN": #Solana DevNet
active: true
type: "solana"
chain_id: "SolDN"
api_endpoint: https://rpc.ankr.com/solana_devnet
program_id: "DKDX8XbTnCgEk8o1RNnCUokiCmadG1Ch5HLxaz7CnhcD"
timeout: 2
timeout: 1

"SolTN": #Solana TestNet
active: true
type: "solana"
chain_id: "SolTN"
api_endpoint: https://rpc.ankr.com/solana_testnet
program_id: "DKDX8XbTnCgEk8o1RNnCUokiCmadG1Ch5HLxaz7CnhcD"
timeout: 1

"pulsar-3":
active: true
Expand Down

0 comments on commit d95c9dc

Please sign in to comment.