Skip to content

Commit

Permalink
Merge pull request #1715 from gobitfly/feature/withdrawals
Browse files Browse the repository at this point in the history
[bids-1211] Add withdrawals
  • Loading branch information
recy21 authored Feb 9, 2023
2 parents d10fe11 + 9f372b5 commit bf5a85d
Show file tree
Hide file tree
Showing 78 changed files with 4,237 additions and 998 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/publish-feature-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Publish Docker feature images

on:
# Trigger the workflow on push or pull request,
# but only for the feature branch
push:
branches:
- feature/withdrawals

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Publish to Dockerhub Registry
uses: elgohr/Publish-Docker-Github-Action@master
with:
name: gobitfly/eth2-beaconchain-explorer
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
tags: "withdrawals"
35 changes: 27 additions & 8 deletions cmd/explorer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/sirupsen/logrus"

_ "eth2-exporter/docs"
_ "net/http/pprof"

"github.com/gorilla/csrf"
"github.com/gorilla/mux"
Expand All @@ -55,6 +56,7 @@ func init() {

func main() {
configPath := flag.String("config", "", "Path to the config file, if empty string defaults will be used")

flag.Parse()

cfg := &types.Config{}
Expand All @@ -74,6 +76,13 @@ func main() {
logrus.Fatalf("error check / preload imprint: %v", err)
}

if utils.Config.Pprof.Enabled {
go func() {
logrus.Infof("starting pprof http server on port %s", utils.Config.Pprof.Port)
logrus.Info(http.ListenAndServe(fmt.Sprintf("0.0.0.0:%s", utils.Config.Pprof.Port), nil))
}()
}

wg := &sync.WaitGroup{}

wg.Add(1)
Expand Down Expand Up @@ -248,6 +257,7 @@ func main() {
apiV1Router := router.PathPrefix("/api/v1").Subrouter()
router.PathPrefix("/api/v1/docs/").Handler(httpSwagger.WrapHandler)
apiV1Router.HandleFunc("/epoch/{epoch}", handlers.ApiEpoch).Methods("GET", "OPTIONS")

// deprecated use slot
apiV1Router.HandleFunc("/epoch/{epoch}/blocks", handlers.ApiEpochSlots).Methods("GET", "OPTIONS")
apiV1Router.HandleFunc("/epoch/{epoch}/slots", handlers.ApiEpochSlots).Methods("GET", "OPTIONS")
Expand All @@ -269,6 +279,8 @@ func main() {
apiV1Router.HandleFunc("/slot/{slot}/voluntaryexits", handlers.ApiSlotVoluntaryExits).Methods("GET", "OPTIONS")
// deprecated use slot
apiV1Router.HandleFunc("/block/{slot}/voluntaryexits", handlers.ApiSlotVoluntaryExits).Methods("GET", "OPTIONS")
apiV1Router.HandleFunc("/slot/{slot}/withdrawals", handlers.ApiSlotWithdrawals).Methods("GET", "OPTIONS")

apiV1Router.HandleFunc("/sync_committee/{period}", handlers.ApiSyncCommittee).Methods("GET", "OPTIONS")
apiV1Router.HandleFunc("/eth1deposit/{txhash}", handlers.ApiEth1Deposit).Methods("GET", "OPTIONS")
apiV1Router.HandleFunc("/validator/leaderboard", handlers.ApiValidatorLeaderboard).Methods("GET", "OPTIONS")
Expand Down Expand Up @@ -384,7 +396,6 @@ func main() {
if err != nil {
logrus.WithError(err).Error("error decoding csrf auth key falling back to empty csrf key")
}

csrfHandler := csrf.Protect(
csrfBytes,
csrf.FieldName("CsrfField"),
Expand All @@ -396,18 +407,21 @@ func main() {
router.HandleFunc("/latestState", handlers.LatestState).Methods("GET")
router.HandleFunc("/launchMetrics", handlers.SlotVizMetrics).Methods("GET")
router.HandleFunc("/index/data", handlers.IndexPageData).Methods("GET")
router.HandleFunc("/slot/{slotOrHash}", handlers.Block).Methods("GET")
router.HandleFunc("/slot/{slotOrHash}/deposits", handlers.BlockDepositData).Methods("GET")
router.HandleFunc("/slot/{slotOrHash}/votes", handlers.BlockVoteData).Methods("GET")
router.HandleFunc("/slot/{slot}/attestations", handlers.BlockAttestationsData).Methods("GET")
router.HandleFunc("/slots", handlers.Blocks).Methods("GET")
router.HandleFunc("/slots/data", handlers.BlocksData).Methods("GET")
router.HandleFunc("/slot/{slotOrHash}", handlers.Slot).Methods("GET")
router.HandleFunc("/slot/{slotOrHash}/deposits", handlers.SlotDepositData).Methods("GET")
router.HandleFunc("/slot/{slotOrHash}/votes", handlers.SlotVoteData).Methods("GET")
router.HandleFunc("/slot/{slot}/attestations", handlers.SlotAttestationsData).Methods("GET")
router.HandleFunc("/slot/{slot}/withdrawals", handlers.SlotWithdrawalData).Methods("GET")
router.HandleFunc("/slot/{slot}/blsChange", handlers.SlotBlsChangeData).Methods("GET")
router.HandleFunc("/slots", handlers.Slots).Methods("GET")
router.HandleFunc("/slots/data", handlers.SlotsData).Methods("GET")
router.HandleFunc("/blocks", handlers.Eth1Blocks).Methods("GET")
router.HandleFunc("/blocks/data", handlers.Eth1BlocksData).Methods("GET")
router.HandleFunc("/blocks/highest", handlers.Eth1BlocksHighest).Methods("GET")
router.HandleFunc("/address/{address}", handlers.Eth1Address).Methods("GET")
router.HandleFunc("/address/{address}/blocks", handlers.Eth1AddressBlocksMined).Methods("GET")
router.HandleFunc("/address/{address}/uncles", handlers.Eth1AddressUnclesMined).Methods("GET")
router.HandleFunc("/address/{address}/withdrawals", handlers.Eth1AddressWithdrawals).Methods("GET")
router.HandleFunc("/address/{address}/transactions", handlers.Eth1AddressTransactions).Methods("GET")
router.HandleFunc("/address/{address}/internalTxns", handlers.Eth1AddressInternalTransactions).Methods("GET")
router.HandleFunc("/address/{address}/erc20", handlers.Eth1AddressErc20Transactions).Methods("GET")
Expand Down Expand Up @@ -441,13 +455,14 @@ func main() {
router.HandleFunc("/validator/{index}", handlers.Validator).Methods("GET")
router.HandleFunc("/validator/{index}/proposedblocks", handlers.ValidatorProposedBlocks).Methods("GET")
router.HandleFunc("/validator/{index}/attestations", handlers.ValidatorAttestations).Methods("GET")
router.HandleFunc("/validator/{index}/withdrawals", handlers.ValidatorWithdrawals).Methods("GET")
router.HandleFunc("/validator/{index}/sync", handlers.ValidatorSync).Methods("GET")
router.HandleFunc("/validator/{index}/history", handlers.ValidatorHistory).Methods("GET")
router.HandleFunc("/validator/{pubkey}/deposits", handlers.ValidatorDeposits).Methods("GET")
router.HandleFunc("/validator/{index}/slashings", handlers.ValidatorSlashings).Methods("GET")
router.HandleFunc("/validator/{index}/effectiveness", handlers.ValidatorAttestationInclusionEffectiveness).Methods("GET")
router.HandleFunc("/validator/{pubkey}/save", handlers.ValidatorSave).Methods("POST")
router.HandleFunc("/validator/{pubkey}/add", handlers.UserValidatorWatchlistAdd).Methods("POST")
router.HandleFunc("/watchlist/add", handlers.UsersModalAddValidator).Methods("POST")
router.HandleFunc("/validator/{pubkey}/remove", handlers.UserValidatorWatchlistRemove).Methods("POST")
router.HandleFunc("/validator/{index}/stats", handlers.ValidatorStatsTable).Methods("GET")
router.HandleFunc("/validators", handlers.Validators).Methods("GET")
Expand All @@ -458,6 +473,10 @@ func main() {
router.HandleFunc("/validators/leaderboard/data", handlers.ValidatorsLeaderboardData).Methods("GET")
router.HandleFunc("/validators/streakleaderboard", handlers.ValidatorsStreakLeaderboard).Methods("GET")
router.HandleFunc("/validators/streakleaderboard/data", handlers.ValidatorsStreakLeaderboardData).Methods("GET")
router.HandleFunc("/validators/withdrawals", handlers.Withdrawals).Methods("GET")
router.HandleFunc("/validators/withdrawals/data", handlers.WithdrawalsData).Methods("GET")
router.HandleFunc("/validators/withdrawals/bls", handlers.BLSChangeData).Methods("GET")
router.HandleFunc("/validators/deposits", handlers.Deposits).Methods("GET")
router.HandleFunc("/validators/initiated-deposits", handlers.Eth1Deposits).Methods("GET")
router.HandleFunc("/validators/initiated-deposits/data", handlers.Eth1DepositsData).Methods("GET")
router.HandleFunc("/validators/deposit-leaderboard", handlers.Eth1DepositsLeaderboard).Methods("GET")
Expand Down
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ var RopstenChainYml string

//go:embed sepolia.chain.yml
var SepoliaChainYml string

//go:embed testnet.chain.yml
var TestnetChainYml string
129 changes: 129 additions & 0 deletions config/testnet.chain.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Extends the mainnet preset
PRESET_BASE: 'mainnet'
CONFIG_NAME: testnet # needs to exist because of Prysm. Otherwise it conflicts with mainnet genesis

# Genesis
# ---------------------------------------------------------------
# `2**14` (= 16,384)
MIN_GENESIS_ACTIVE_VALIDATOR_COUNT: 58000
# Feb-01-2023 15:00:00 PM UTC
# This is an invalid valid and should be updated when you create the genesis
MIN_GENESIS_TIME: 1675263480
GENESIS_FORK_VERSION: 0x00000069
GENESIS_DELAY: 120


# Forking
# ---------------------------------------------------------------
# Some forks are disabled for now:
# - These may be re-assigned to another fork-version later
# - Temporarily set to max uint64 value: 2**64 - 1

# Altair
ALTAIR_FORK_VERSION: 0x00000070
ALTAIR_FORK_EPOCH: 0
# Merge
BELLATRIX_FORK_VERSION: 0x00000071
BELLATRIX_FORK_EPOCH: 0
TERMINAL_TOTAL_DIFFICULTY: 0
TERMINAL_BLOCK_HASH: 0x0000000000000000000000000000000000000000000000000000000000000000
TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH: 18446744073709551615

# Capella
CAPELLA_FORK_VERSION: 0x00000072
CAPELLA_FORK_EPOCH: 1350

# EIP4844
EIP4844_FORK_VERSION: 0x00000073
EIP4844_FORK_EPOCH: 18446744073709551615

# Time parameters
# ---------------------------------------------------------------
# 12 seconds
SECONDS_PER_SLOT: 12
# 14 (estimate from Eth1 mainnet)
SECONDS_PER_ETH1_BLOCK: 14
# 2**8 (= 256) epochs ~27 hours
MIN_VALIDATOR_WITHDRAWABILITY_DELAY: 256
# 2**8 (= 256) epochs ~27 hours
SHARD_COMMITTEE_PERIOD: 256
# 2**11 (= 2,048) Eth1 blocks ~8 hours
ETH1_FOLLOW_DISTANCE: 12


# Validator cycle
# ---------------------------------------------------------------
# 2**2 (= 4)
INACTIVITY_SCORE_BIAS: 4
# 2**4 (= 16)
INACTIVITY_SCORE_RECOVERY_RATE: 16
# 2**4 * 10**9 (= 16,000,000,000) Gwei
EJECTION_BALANCE: 16000000000
# 2**2 (= 4)
MIN_PER_EPOCH_CHURN_LIMIT: 4
# 2**16 (= 65,536)
CHURN_LIMIT_QUOTIENT: 65536

# Fork choice
# ---------------------------------------------------------------
# 40%
PROPOSER_SCORE_BOOST: 40

# Deposit contract
# ---------------------------------------------------------------
DEPOSIT_CHAIN_ID: 1337803
DEPOSIT_NETWORK_ID: 1337803
DEPOSIT_CONTRACT_ADDRESS: 0x4242424242424242424242424242424242424242
INACTIVITY_PENALTY_QUOTIENT_ALTAIR: 50331648
MIN_SLASHING_PENALTY_QUOTIENT_ALTAIR: 64
PROPORTIONAL_SLASHING_MULTIPLIER_ALTAIR: 2
SYNC_COMMITTEE_SIZE: 512
EPOCHS_PER_SYNC_COMMITTEE_PERIOD: 256
MIN_SYNC_COMMITTEE_PARTICIPANTS: 1
UPDATE_TIMEOUT: 8192
INACTIVITY_PENALTY_QUOTIENT_BELLATRIX: 16777216
MIN_SLASHING_PENALTY_QUOTIENT_BELLATRIX: 32
PROPORTIONAL_SLASHING_MULTIPLIER_BELLATRIX: 3
MAX_BYTES_PER_TRANSACTION: 1073741824
MAX_TRANSACTIONS_PER_PAYLOAD: 1048576
BYTES_PER_LOGS_BLOOM: 256
MAX_EXTRA_DATA_BYTES: 32
RANDAO_PENALTY_EPOCHS: 2
EARLY_DERIVED_SECRET_PENALTY_MAX_FUTURE_EPOCHS: 32768
EPOCHS_PER_CUSTODY_PERIOD: 16384
CUSTODY_PERIOD_TO_RANDAO_PADDING: 2048
MAX_CHUNK_CHALLENGE_DELAY: 32768
MAX_CUSTODY_KEY_REVEALS: 256
MAX_EARLY_DERIVED_SECRET_REVEALS: 1
MAX_CUSTODY_CHUNK_CHALLENGES: 4
MAX_CUSTODY_CHUNK_CHALLENGE_RESP: 16
MAX_CUSTODY_SLASHINGS: 1
EARLY_DERIVED_SECRET_REVEAL_SLOT_REWARD_MULTIPLE: 2
MINOR_REWARD_QUOTIENT: 256
MAX_COMMITTEES_PER_SLOT: 64
TARGET_COMMITTEE_SIZE: 128
MAX_VALIDATORS_PER_COMMITTEE: 2048
SHUFFLE_ROUND_COUNT: 90
HYSTERESIS_QUOTIENT: 4
SLOTS_PER_EPOCH: 32
MAX_EFFECTIVE_BALANCE: 32000000000



# Minimal preset - Capella

# Max operations per block
# ---------------------------------------------------------------
# 2**4 (= 16)
MAX_BLS_TO_EXECUTION_CHANGES: 16


# Execution
# ---------------------------------------------------------------
# [customized] 2**2 (= 4)
MAX_WITHDRAWALS_PER_PAYLOAD: 4

# Withdrawals processing
# ---------------------------------------------------------------
# [customized] 2**4 (= 16) validators
MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP: 16
10 changes: 8 additions & 2 deletions db/bigtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -949,10 +949,16 @@ func (bigtable *Bigtable) GetValidatorSyncDutiesHistory(validators []uint64, sta

func (bigtable *Bigtable) GetValidatorMissedAttestationsCount(validators []uint64, startEpoch uint64, endEpoch uint64) (map[uint64]*types.ValidatorMissedAttestationsStatistic, error) {

if startEpoch < endEpoch {
return nil, fmt.Errorf("error invalid range startEpoch: %v endEpoch: %v", startEpoch, endEpoch)
}

res := make(map[uint64]*types.ValidatorMissedAttestationsStatistic)

for i := startEpoch; i >= startEpoch-endEpoch; i-- {
data, err := bigtable.GetValidatorAttestationHistory(validators, i, 1)
rangeEnd := startEpoch - endEpoch

for i := int64(startEpoch); i >= int64(rangeEnd); i-- {
data, err := bigtable.GetValidatorAttestationHistory(validators, uint64(i), 1)

if err != nil {
return nil, err
Expand Down
3 changes: 1 addition & 2 deletions db/bigtable_eth1.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ func (bigtable *Bigtable) GetMostRecentBlockFromDataTable() (*types.Eth1BlockInd

rowRange := gcp_bigtable.PrefixRange(prefix)
rowFilter := gcp_bigtable.RowFilter(gcp_bigtable.ColumnFilter("d"))
limit := gcp_bigtable.LimitRows(1)

block := types.Eth1BlockIndexed{}

Expand All @@ -348,7 +347,7 @@ func (bigtable *Bigtable) GetMostRecentBlockFromDataTable() (*types.Eth1BlockInd
return c == 0
}

err := bigtable.tableData.ReadRows(ctx, rowRange, rowHandler, rowFilter, limit)
err := bigtable.tableData.ReadRows(ctx, rowRange, rowHandler, rowFilter)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit bf5a85d

Please sign in to comment.