Skip to content

Instantly share code, notes, and snippets.

@samsondav
Last active July 17, 2023 13:40
Show Gist options
  • Save samsondav/f2ab337ef9729a13e7b6dd29d98d5a33 to your computer and use it in GitHub Desktop.
Save samsondav/f2ab337ef9729a13e7b6dd29d98d5a33 to your computer and use it in GitHub Desktop.
PROPOSAL: OCR config persistence in contract state

See slack thread for context: https://chainlink-core.slack.com/archives/C05G9M9SBKR/p1689175479236369

Some chains e.g. BSC (and others?) try to manage state bloat by pruning logs older than a certain threshold. This does not happen on Eth mainnet and was not factored into the design of OCR. Nonetheless, we need to work around it, since it's becoming an increasingly severe problem.

We propose to implement the following:

Remove the need for logs to read config by storing the config in state. This is an optimization from a different time, and we have some options.

We propose to add a boolean persistConfig to the contract constructor. If unset, no state will be persisted in the contract and it will work exactly as it currently does (this can be used on chains that support long log lookbacks e.g. Eth mainnet).

If the boolean is set to true, config will be persisted to the contract state when setConfig is called. In contracts with multiple configs (i.e. Mercury) the config will be scoped by feed ID.

Only the latest config is ever persisted. It can be read by off-chain code by calling a readConfig method implemented on the contract. This method may only be called by the zero address to prevent on-chain reads. For contracts with a feedID, it may be called as readConfig(feedID). This method should return null or zero values if no config is present in state.

The off-chain code will prefer the result of readConfig if present. If this method is non-existent or returns nothing/zero values then the logs will be used as a fallback. LatestConfigDetails and LatestConfig in all config poller implementations will need to be modified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment