Skip to content

Commit

Permalink
Merge pull request #9 from makerdao/TECH-2201-fixes
Browse files Browse the repository at this point in the history
Tech 2201 fixes
  • Loading branch information
jeannettemcd authored Sep 25, 2023
2 parents a2b2f68 + 1471b2c commit 20b951d
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions maker_keeper/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import eth_utils
import time


from io import StringIO
from web3 import Web3, HTTPProvider
from pymaker.keys import register_private_key
from pymaker.lifecycle import Lifecycle
Expand Down Expand Up @@ -90,29 +90,54 @@ def process_block(self):
"""
isConnected = self.web3.isConnected()
logging.info(f'web3 isConntected is: {isConnected}')
latestBlock = self.web3.eth.block_number
logging.info(f'current block number: {latestBlock}')

if self.errors >= self.max_errors:
logging.error("Number of errors reached max configured, exiting keeper")
self.lifecycle.terminate()
else:
results = self.sequencer.getNextJobs(self.network_id)
for address, success, calldata in results:
logging.info(f"Success: {success} | Address: {address} | Calldata: {calldata}")
self.execute(success, address, calldata)
for address, canWork, calldata in results:
logging.info(f"canWork: {canWork} | Address: {address} | Calldata: {calldata}")
self.execute(canWork, address, calldata)

def execute(self, success: bool, address: str, calldata: str):
if success:
def execute(self, canWork: bool, address: str, calldata: str):
if canWork:
gas_strategy = GeometricGasPrice(
web3=self.web3,
initial_price=None,
initial_tip=self.get_initial_tip(self.arguments),
every_secs=180
)
try:
# Create StringIO object to capture logs from pymaker class
log_capture_string = StringIO()

# Set up logging
ch = logging.StreamHandler(log_capture_string)
ch.setLevel(logging.WARNING) # Adjust this to capture the log levels you want
formatter = logging.Formatter('%(levelname)s - %(message)s')
ch.setFormatter(formatter)

# Add custom handler to the logger
logging.getLogger().addHandler(ch)

# execute the job
job = IJob(self.web3, Address(address))
receipt = job.work(self.network_id, calldata).transact(gas_strategy=gas_strategy)
receipt = job.work(self.network_id, calldata).transact(gas_strategy=gas_strategy)

# Extract log messages from StringIO object
log_contents = log_capture_string.getvalue()

if receipt is not None and receipt.successful:
logging.info("Exec on IJob done!")
# Capture the result of an oracleJob transaction and do not throw an error if it is mined.
elif receipt is None and "0xe717Ec34b2707fc8c226b34be5eae8482d06ED03" in log_contents and "mined successfully but generated no single log entry" in log_contents:
logging.info(f"Exec on IJob done with exceptions in job: {address}")
# Capture the result of the flapJob transaction and do not throw an error, if the flapJob was not ready to be executed.
elif receipt is None and "0xc32506E9bB590971671b649d9B8e18CB6260559F" in log_contents and "execution reverted: Vow/insufficient-surplus" in log_contents:
logging.info(f"IJob, {address}, will not be executed due to 'Vow/insufficient-surplus'.")
else:
logging.error("Failed to run exec on IJob!")

Expand All @@ -121,7 +146,7 @@ def execute(self, success: bool, address: str, calldata: str):
logging.error("Failed to run exec on IJob!")

else:
logging.info("No update available")
logging.info(f"No update available. canWork: {canWork}")


@staticmethod
Expand Down

0 comments on commit 20b951d

Please sign in to comment.