Skip to content

Instantly share code, notes, and snippets.


Michael Sproul michaelsproul

View GitHub Profile
michaelsproul /
Last active Mar 25, 2022
Run Ganache in Docker transparently so that it appears to be running on the host
#!/usr/bin/env fish
# - Use exec so that the parent can signal `docker run` directly.
# - Proxy signals from `docker run` to the container, allowing it to terminate gracefully.
# - Use host networking so that Lighthouse tests which expect to fork from localhost continue
# to work.
exec docker run -i --sig-proxy=true --network=host trufflesuite/ganache:latest $argv[1..-1]
# Attempt to slash validators from
import requests
def get_attestations(slot):
res = requests.get("{}/attestations".format(slot))
return res.json()
def get_validator_att(atts, validator):
return [att for att in atts["data"] if validator in att["validators"]][0]
michaelsproul / cross-clang-aarch64.dockerfile
Last active Nov 22, 2021
Cross with Clang Dockerfiles
View cross-clang-aarch64.dockerfile
FROM rustembedded/cross:aarch64-unknown-linux-gnu-0.2.1
RUN dpkg --add-architecture arm64 && \
apt-get update && \
apt-get install -y apt-transport-https wget && \
(wget -O - | apt-key add -) && \
printf "deb llvm-toolchain-xenial-12 main\ndeb-src llvm-toolchain-xenial-12 main" > /etc/apt/sources.list.d/backports.list && \
apt-get update && \
apt-get install -y llvm-3.9-dev libclang-3.9-dev clang-3.9 && \
apt-get purge -y apt-transport-https wget
michaelsproul /
Last active Nov 12, 2021
Early sync committees on mainnet

You might be reading this because you've noticed that some validator on mainnet are earning extra rewards.

This is due to a new feature of the beacon chain added in the Altair fork called sync committees. Sync committees are groups of 512 validators which are randomly selected every 256 epochs (~27 hours) to perform additional duties. They sign a message called a SyncCommitteeMessage every slot, which is similar to an attestation. For more information, you can read Vitalik's write-up in the annotated spec:

So far none of the explorers show the sync committees explicitly, so they are chronicled here in the meantime.

Some of the early sync committees are included below as sync_committee_$epoch.txt files, where $epoch is the epoch at which that committee begins performing duties. Each line of the file is a validator index (512 total). You'll notice that the first two committees are identical: this is intentional (it si

michaelsproul /
Created Jul 8, 2021
Sync committee set bits
for i in (seq 416 520)
set set_bits ( $i | jq .data.message.body.sync_aggregate.sync_committee_bits | python3 -c "print(bin(int(input().strip('\"').replace('null', '0x0'), base=16)).count('1'))")
echo "block $i: $set_bits"
michaelsproul / Cargo.toml
Last active Jun 24, 2021
Single Integration Test Binary
View Cargo.toml
autotests = false
name = "lighthouse_tests"
path = "tests/"
michaelsproul /
Created May 16, 2021
Check Geth sync status via HTTP JSON RPC
curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":1}' "http://localhost:8545"
michaelsproul /
Last active May 20, 2021
How to fix empty validator_definitions.yml

Lighthouse: how to fix empty validator_definitions.yml

Lighthouse is affected by a bug (sigp/lighthouse#2159) which can cause the validator_definitions.yml file to become corrupted if the disk where Lighthouse's datadir is stored becomes completely full.

Preventing the bug

The best defense against this bug is to ensure your disk doesn't fill to 100%. If you have been running Geth since December 2020 with a 1TB SSD, you may be close to reaching this limit and we recommend that you:

  1. Stop Geth immediately: sudo systemctl stop geth.service (tweak the service name appropriately)
  2. [Optional] If you do not already have an Eth1 failover configured, add one to your Lighthouse beacon node config. You can sign up for a free service like Infura or Alchemy and add the URL to the ExecStart line for your Lighthouse beacon node. More info in the book.
michaelsproul /
Last active Oct 15, 2020
Participation rate script
#!/usr/bin/env fish
# Usage: ./ 3150
# Requires: fish, curl, jq, Lighthouse BN API on port 5052
# Set the target epoch to at least 2 before the current epoch
set target_epoch (math "$argv[1] + 1")
set global_votes (curl --fail --show-error -s "http://localhost:5052/consensus/global_votes?epoch=$target_epoch"; or exit)
set prev_active_gwei (echo $global_votes | jq .previous_epoch_active_gwei)
set prev_attesting_gwei (echo $global_votes | jq .previous_epoch_attesting_gwei)
michaelsproul /
Last active Aug 15, 2020
Get list of slashed validators from Lighthouse
#!/usr/bin/env bash
curl -s "http://localhost:5052/beacon/validators/all" \
| jq -r 'map(select(.validator.slashed == true) | .validator_index) | join("\n")'