Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael Sproul michaelsproul

View GitHub Profile
@michaelsproul
michaelsproul / ganache.sh
Last active Mar 25, 2022
Run Ganache in Docker transparently so that it appears to be running on the host
View ganache.sh
#!/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]
View slash.py
# Attempt to slash validators from https://papers.ssrn.com/sol3/papers.cfm?abstract_id=4036000
import requests
def get_attestations(slot):
res = requests.get("https://beaconcha.in/api/v1/block/{}/attestations".format(slot))
res.raise_for_status()
return res.json()
def get_validator_att(atts, validator):
return [att for att in atts["data"] if validator in att["validators"]][0]
@michaelsproul
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 - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -) && \
printf "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-12 main\ndeb-src http://apt.llvm.org/xenial/ 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
michaelsproul / README.md
Last active Nov 12, 2021
Early sync committees on mainnet
View README.md

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:

https://github.com/ethereum/annotated-spec/blob/master/altair/sync-protocol.md

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
michaelsproul / set_bits.fish
Created Jul 8, 2021
Sync committee set bits
View set_bits.fish
for i in (seq 416 520)
set set_bits (block.sh $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"
end
@michaelsproul
michaelsproul / Cargo.toml
Last active Jun 24, 2021
Single Integration Test Binary
View Cargo.toml
[package]
autotests = false
[[test]]
name = "lighthouse_tests"
path = "tests/main.rs"
@michaelsproul
michaelsproul / geth_sync.sh
Created May 16, 2021
Check Geth sync status via HTTP JSON RPC
View geth_sync.sh
curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":1}' "http://localhost:8545"
@michaelsproul
michaelsproul / empty_validator_definitions.md
Last active May 20, 2021
How to fix empty validator_definitions.yml
View empty_validator_definitions.md

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
michaelsproul / participation_rate.fish
Last active Oct 15, 2020
Participation rate script
View participation_rate.fish
#!/usr/bin/env fish
# Usage: ./participation_rate.fish 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
michaelsproul / get_slashed.sh
Last active Aug 15, 2020
Get list of slashed validators from Lighthouse
View get_slashed.sh
#!/usr/bin/env bash
curl -s "http://localhost:5052/beacon/validators/all" \
| jq -r 'map(select(.validator.slashed == true) | .validator_index) | join("\n")'