Ensuring Reliable Operations in MakerDAO’s Ecosystem with Poker Keeper

We are a 24/7 globally distributed team

In the fast-evolving landscape of decentralized finance (DeFi), certain innovations stand out for their crucial role in enhancing system reliability and efficiency. One such innovation at MakerDAO is the Poker Keeper, a system designed to ensure critical functions are executed reliably on the regular basis, no matter the state of the blockchain.

The Poker Keeper's primary task is to ensure that specific smart contract functions, critical for the system's health and stability, trigger on schedule. This regular triggering is vital not only for operational efficiency but also for maintaining the system's integrity and trustworthiness.

In the blockchain world, where network congestion or fluctuating gas prices can delay transactions, ensuring the punctuality of critical operations poses a significant challenge. To tackle this, the Poker Keeper employs a transaction retry mechanism that we'll go into the detail below.

Implemented Solutions

The heart of the Poker Keeper's robustness lies in its transaction management system, specifically designed to handle retries effectively. Each Ethereum transaction requires a unique nonce, which represents the transaction count from a specific address. The Poker Keeper script manages this nonce, ensuring that transaction retries don't clash with new transactions. This is crucial when a transaction needs to be retried with a higher gas limit due to initial underestimation or network congestion.

# Returns the next nonce to use based on the confirmed and pending transactions.
nonce = self.web3.eth_get_transaction_count(self.account.address, block_identifier='pending')
self.logger.info(f"nonce is: {nonce}")

When a transaction does not confirm within a preset timeout, it triggers a TimeExhausted exception. This exception isn't just a signal of delay; it's a cue for the Keeper to retry the transaction with the same nonce but adjusted gas settings. This ensures the transaction remains valid and can be processed without being overtaken by newer transactions.

# Wait for the transaction receipt (successful inclusion in a block)
receipt = self.web3.eth.wait_for_transaction_receipt(tx_hash, timeout=self.timeout, poll_latency=1)

Before executing any transaction, the Keeper estimates the necessary gas, considering the current network conditions. This proactive measure sets the stage for determining the initial gas limit. We add a buffer to the gas limit given the inherent unpredictability of gas prices and network activity. This buffer — a calculated increase over the estimated gas — is crucial during times of unexpected network congestion, helping ensure that transactions are processed without a delay.

# Add buffer to gas estimate to avoid running out of gas
percentage_buffer = int(gas_estimate * 0.2) # 20% buffer
absolute_buffer = 20000 # 20,000 gas units
additional_gas = max(percentage_buffer, absolute_buffer) # Choose the higher of the two buffers
gas_limit = gas_estimate + additional_gas # Calculate the total gas limit

Moreover, the management of in-flight transactions — those not yet included in a block — is integral to the system's logic. It ensures that nonce management considers transactions that are pending on the network, which is vital to avoid nonce conflicts and ensure that scheduled operations aren't skipped or duplicated.

Exception Handling with Backoff

The Keeper’s resilience is further reinforced by its error handling strategy. It uses a backoff library that intelligently handles exceptions by recalculating gas estimates and adjusting nonces based on the latest network conditions. This mechanism is adept at dealing with a range of exceptions — from ValueError and InvalidAddress to ConnectionError and HTTPError. Each is a potential indicator of issues ranging from incorrect transaction parameters to underlying network problems.


The Poker Keeper is not just a functional component of the MakerDAO ecosystem; it is a crucial element engineered with foresight and adaptability. The code underpinning the Poker Keeper is written to anticipate unforeseen environmental factors and incorporates self-healing properties. This ensures that it can autonomously address and recover from operational disruptions, maintaining the integrity and reliability required.

Subscribe to get
the latest updates

Our HQ Locations

Copenhagen Denmark

Melbourne Australia

Tallinn Estonia

Privacy policy||

Copyright © 2024. All rights reserved