Skip to content

Instantly share code, notes, and snippets.

@samsondav
samsondav / gist:f2ab337ef9729a13e7b6dd29d98d5a33
Last active July 17, 2023 13:40
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).

1 services/bulletprooftxmanager/bulletprooftxmanager.go: err = db.Create(&etx).Error
2 services/bulletprooftxmanager/eth_resender_test.go: require.NoError(t, db.Create(&attempt1_2).Error)
3 services/bulletprooftxmanager/eth_resender_test.go: require.NoError(t, db.Create(&attempt3_2).Error)
4 services/bulletprooftxmanager/eth_broadcaster_test.go: require.NoError(t, db.Create(&firstInProgress).Error)
5 services/bulletprooftxmanager/eth_broadcaster_test.go: err := db.Create(&secondInProgress).Error
6 services/bulletprooftxmanager/orm_test.go: require.NoError(t, db.Create(&attempt).Error)
7 services/bulletprooftxmanager/eth_confirmer_test.go: require.NoError(t, db.Create(&attempt2_3).Error)
8 services/bulletprooftxmanager/eth_confirmer_test.go: require.NoError(t, db.Create(&attempt2_2).Error)
9 services/bulletprooftxmanager/eth_confirmer_test.go: require.NoError(t, db.Create(&attempt4_2).Error)
10 services/bulletprooftxmanager/eth_confirmer_test.go: require.N
pragma solidity ^0.6.0;
import "https://github.com/smartcontractkit/chainlink/evm-contracts/src/v0.6/Oracle.sol";
pragma solidity ^0.6.0;
import "https://github.com/smartcontractkit/chainlink/evm-contracts/src/v0.6/ChainlinkClient.sol";
// MyContract inherits the ChainlinkClient contract to gain the
// functionality of creating Chainlink requests
contract ChainlinkExample is ChainlinkClient {
// Stores the answer from the Chainlink oracle
uint256 public currentPrice;
address public owner;
0. (Optional but recommended) Make a dump/backup of your DB
1. STOP your node
2. Set env vars: ETH_GAS_BUMP_WEI=10000000000 and ETH_GAS_BUMP_THRESHOLD=1 and ETH_GAS_PRICE_DEFAULT=200000000000 on the node
3. Make sure your gas updater is updated to latest master from github and running with MAX_GAS_PRICE set high (suggest 500000000000 or more). Note that units are in GWei.
4. Get the keystore file from the node (found in the .env/tempkeys directory on the server). To extract the private key inside the container:
$ yum install python3
$ pip3 install eth-keyfile
$ python3 -c "import eth_keyfile; password = input('enter your password: '); print(eth_keyfile.extract_key_from_keyfile('.env/tempkeys/0xYOUR_KEY_FILE.json', password).hex())"
# set these parameters
provider_url = 'YOUR_INFURA_URL'
wallet_password = 'YOUR_WALLET_PASSWORD'
nonce_start = 29936
nonce_end = 29940
gas_price = 112 * 10**9
from web3 import Web3
web3 = Web3(Web3.HTTPProvider(provider_url))
with open('node_key') as keyfile:
encrypted_key = keyfile.read()
lock_jobs = """
WITH RECURSIVE jobs AS (
SELECT (j).*, pg_try_advisory_lock($1::integer, (j).id) AS locked
FROM (
SELECT j
FROM #{table} AS j
WHERE NOT (id = ANY($3))
AND failed_at IS NULL
ORDER BY enqueued_at, j.id
FOR UPDATE SKIP LOCKED
@samsondav
samsondav / observer.md
Created November 30, 2017 13:11 — forked from pnc/observer.md
Using Erlang observer/appmon remotely

Using OTP's observer (appmon replacement) remotely

$ ssh remote-host "epmd -names"
epmd: up and running on port 4369 with data:
name some_node at port 58769

Note the running on port for epmd itself and the port of the node you're interested in debugging. Reconnect to the remote host with these ports forwarded:

$ ssh -L 4369:localhost:4369 -L 58769:localhost:58769 remote-host
@samsondav
samsondav / look_and_say.ex
Last active May 17, 2017 10:59
Look and Say in Elixir
defmodule LookAndSay do
@moduledoc """
Documentation for LookAndSay.
"""
def main(args) do
number = hd args
IO.puts(look_and_say(number))
end
@samsondav
samsondav / database_comment.rb
Created July 2, 2016 12:43
Rails read Postgres database column comments
# frozen_string_literal: true
# A tiny class for reading column database comments
class DatabaseComment
DATABASE_NAME = Rails.configuration.database_configuration[Rails.env]['database'].freeze
# Reads back a postgres comment based on table_name and column_name
# Sanitizes inputs but it would be better not to allow user input strings here regardless
def self.read(table_name, column_name)
unless table_name.is_a?(Symbol) && column_name.is_a?(Symbol)
raise TypeError, <<~STERN_WARNING