mirror of
https://github.com/logos-messaging/logos-messaging-simulator.git
synced 2026-01-04 06:53:08 +00:00
Update block time to be the same as linea and add retries for token cast send functions
This commit is contained in:
parent
e5bb677abe
commit
4e24c78611
@ -24,7 +24,7 @@ services:
|
|||||||
--host=0.0.0.0
|
--host=0.0.0.0
|
||||||
--accounts=520
|
--accounts=520
|
||||||
--allow-origin=*
|
--allow-origin=*
|
||||||
--block-time=12
|
--block-time=3
|
||||||
--chain-id=1234
|
--chain-id=1234
|
||||||
--gas-limit=30000000
|
--gas-limit=30000000
|
||||||
--gas-price=1
|
--gas-price=1
|
||||||
|
|||||||
@ -78,82 +78,102 @@ class NodeTokenInitializer:
|
|||||||
|
|
||||||
def mint_tokens(self) -> bool:
|
def mint_tokens(self) -> bool:
|
||||||
"""Mint tokens to this node's address using the node's own private key."""
|
"""Mint tokens to this node's address using the node's own private key."""
|
||||||
try:
|
for attempt in range(3):
|
||||||
logger.info(f"Minting {self.mint_amount} tokens to {self.node_address}")
|
try:
|
||||||
|
logger.info(f"Minting {self.mint_amount} tokens to {self.node_address} (attempt {attempt + 1}/3)")
|
||||||
# Use the node's own private key since mint() is public
|
|
||||||
nonce = self.w3.eth.get_transaction_count(self.node_address)
|
|
||||||
|
|
||||||
# Build mint transaction
|
|
||||||
function_signature = self.w3.keccak(text="mint(address,uint256)")[:4]
|
|
||||||
encoded_address = self.node_address[2:].lower().zfill(64)
|
|
||||||
encoded_amount = hex(self.mint_amount)[2:].zfill(64)
|
|
||||||
data = function_signature.hex() + encoded_address + encoded_amount
|
|
||||||
|
|
||||||
transaction = {
|
|
||||||
'to': self.token_address,
|
|
||||||
'value': 0,
|
|
||||||
'gas': 200000,
|
|
||||||
'gasPrice': self.w3.eth.gas_price,
|
|
||||||
'nonce': nonce,
|
|
||||||
'data': data,
|
|
||||||
}
|
|
||||||
|
|
||||||
# Sign and send with node's own key
|
|
||||||
signed_txn = self.w3.eth.account.sign_transaction(transaction, self.private_key)
|
|
||||||
tx_hash = self.w3.eth.send_raw_transaction(signed_txn.rawTransaction)
|
|
||||||
|
|
||||||
logger.info(f"Mint transaction sent: {tx_hash.hex()}")
|
|
||||||
|
|
||||||
if self.wait_for_transaction(tx_hash.hex()):
|
|
||||||
logger.info(f"✓ Mint successful for node {self.node_index}")
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
logger.error(f"✗ Mint failed for node {self.node_index}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
except Exception as e:
|
# Use the node's own private key since mint() is public
|
||||||
logger.error(f"✗ Mint failed for node {self.node_index}: {str(e)}")
|
nonce = self.w3.eth.get_transaction_count(self.node_address)
|
||||||
return False
|
|
||||||
|
# Build mint transaction
|
||||||
|
function_signature = self.w3.keccak(text="mint(address,uint256)")[:4]
|
||||||
|
encoded_address = self.node_address[2:].lower().zfill(64)
|
||||||
|
encoded_amount = hex(self.mint_amount)[2:].zfill(64)
|
||||||
|
data = function_signature.hex() + encoded_address + encoded_amount
|
||||||
|
|
||||||
|
transaction = {
|
||||||
|
'to': self.token_address,
|
||||||
|
'value': 0,
|
||||||
|
'gas': 200000,
|
||||||
|
'gasPrice': self.w3.eth.gas_price,
|
||||||
|
'nonce': nonce,
|
||||||
|
'data': data,
|
||||||
|
}
|
||||||
|
|
||||||
|
# Sign and send with node's own key
|
||||||
|
signed_txn = self.w3.eth.account.sign_transaction(transaction, self.private_key)
|
||||||
|
tx_hash = self.w3.eth.send_raw_transaction(signed_txn.rawTransaction)
|
||||||
|
|
||||||
|
logger.info(f"Mint transaction sent: {tx_hash.hex()}")
|
||||||
|
|
||||||
|
if self.wait_for_transaction(tx_hash.hex()):
|
||||||
|
logger.info(f"✓ Mint successful for node {self.node_index}")
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
logger.error(f"✗ Mint failed for node {self.node_index} (attempt {attempt + 1})")
|
||||||
|
if attempt < 2:
|
||||||
|
logger.info(f"Retrying mint in 5 seconds...")
|
||||||
|
time.sleep(5)
|
||||||
|
continue
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"✗ Mint failed for node {self.node_index} (attempt {attempt + 1}): {str(e)}")
|
||||||
|
if attempt < 2:
|
||||||
|
logger.info(f"Retrying mint in 5 seconds...")
|
||||||
|
time.sleep(5)
|
||||||
|
continue
|
||||||
|
|
||||||
|
logger.error(f"✗ Mint failed for node {self.node_index} after 3 attempts")
|
||||||
|
return False
|
||||||
|
|
||||||
def approve_tokens(self) -> bool:
|
def approve_tokens(self) -> bool:
|
||||||
"""Approve RLN contract to spend tokens."""
|
"""Approve RLN contract to spend tokens."""
|
||||||
try:
|
for attempt in range(3):
|
||||||
logger.info(f"Approving {self.mint_amount} tokens for contract {self.contract_address}")
|
try:
|
||||||
|
logger.info(f"Approving {self.mint_amount} tokens for contract {self.contract_address} (attempt {attempt + 1}/3)")
|
||||||
nonce = self.w3.eth.get_transaction_count(self.node_address)
|
|
||||||
|
|
||||||
# Build approve transaction
|
|
||||||
function_signature = self.w3.keccak(text="approve(address,uint256)")[:4]
|
|
||||||
encoded_contract = self.contract_address[2:].lower().zfill(64)
|
|
||||||
encoded_amount = hex(self.mint_amount)[2:].zfill(64)
|
|
||||||
data = function_signature.hex() + encoded_contract + encoded_amount
|
|
||||||
|
|
||||||
transaction = {
|
|
||||||
'to': self.token_address,
|
|
||||||
'value': 0,
|
|
||||||
'gas': 200000,
|
|
||||||
'gasPrice': self.w3.eth.gas_price,
|
|
||||||
'nonce': nonce,
|
|
||||||
'data': data,
|
|
||||||
}
|
|
||||||
|
|
||||||
# Sign and send with node's own key
|
|
||||||
signed_txn = self.w3.eth.account.sign_transaction(transaction, self.private_key)
|
|
||||||
tx_hash = self.w3.eth.send_raw_transaction(signed_txn.rawTransaction)
|
|
||||||
|
|
||||||
logger.info(f"Approve transaction sent: {tx_hash.hex()}")
|
|
||||||
|
|
||||||
if self.wait_for_transaction(tx_hash.hex()):
|
|
||||||
logger.info(f"✓ Approval successful for node {self.node_index}")
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
logger.error(f"✗ Approval failed for node {self.node_index}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
except Exception as e:
|
nonce = self.w3.eth.get_transaction_count(self.node_address)
|
||||||
logger.error(f"✗ Approval failed for node {self.node_index}: {str(e)}")
|
|
||||||
return False
|
# Build approve transaction
|
||||||
|
function_signature = self.w3.keccak(text="approve(address,uint256)")[:4]
|
||||||
|
encoded_contract = self.contract_address[2:].lower().zfill(64)
|
||||||
|
encoded_amount = hex(self.mint_amount)[2:].zfill(64)
|
||||||
|
data = function_signature.hex() + encoded_contract + encoded_amount
|
||||||
|
|
||||||
|
transaction = {
|
||||||
|
'to': self.token_address,
|
||||||
|
'value': 0,
|
||||||
|
'gas': 200000,
|
||||||
|
'gasPrice': self.w3.eth.gas_price,
|
||||||
|
'nonce': nonce,
|
||||||
|
'data': data,
|
||||||
|
}
|
||||||
|
|
||||||
|
# Sign and send with node's own key
|
||||||
|
signed_txn = self.w3.eth.account.sign_transaction(transaction, self.private_key)
|
||||||
|
tx_hash = self.w3.eth.send_raw_transaction(signed_txn.rawTransaction)
|
||||||
|
|
||||||
|
logger.info(f"Approve transaction sent: {tx_hash.hex()}")
|
||||||
|
|
||||||
|
if self.wait_for_transaction(tx_hash.hex()):
|
||||||
|
logger.info(f"✓ Approval successful for node {self.node_index}")
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
logger.error(f"✗ Approval failed for node {self.node_index} (attempt {attempt + 1})")
|
||||||
|
if attempt < 2:
|
||||||
|
logger.info(f"Retrying approval in 5 seconds...")
|
||||||
|
time.sleep(5)
|
||||||
|
continue
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"✗ Approval failed for node {self.node_index} (attempt {attempt + 1}): {str(e)}")
|
||||||
|
if attempt < 2:
|
||||||
|
logger.info(f"Retrying approval in 5 seconds...")
|
||||||
|
time.sleep(5)
|
||||||
|
continue
|
||||||
|
|
||||||
|
logger.error(f"✗ Approval failed for node {self.node_index} after 3 attempts")
|
||||||
|
return False
|
||||||
|
|
||||||
def run(self) -> bool:
|
def run(self) -> bool:
|
||||||
"""Run the token initialization process."""
|
"""Run the token initialization process."""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user