Skip to content

Commit

Permalink
pectra devnet 4 compatibility (spec v1.5.0-alpha.6)
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Sep 24, 2024
1 parent db7786b commit f373209
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 78 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,6 @@ require (
rsc.io/tmplfunc v0.0.3 // indirect
)

replace github.com/attestantio/go-eth2-client => github.com/attestantio/go-eth2-client v0.0.0-20240701211822-0a60485fce68
replace github.com/attestantio/go-eth2-client => github.com/pk910/go-eth2-client v0.0.0-20240923174943-8d64565c83ca

replace github.com/ethereum/go-ethereum => github.com/lightclient/go-ethereum v0.0.0-20240907155054-183e7b702a00
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERo
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/VictoriaMetrics/fastcache v1.12.2 h1:N0y9ASrJ0F6h0QaC3o6uJb3NIZ9VKLjCM7NQbSmF7WI=
github.com/VictoriaMetrics/fastcache v1.12.2/go.mod h1:AmC+Nzz1+3G2eCPapF6UcsnkThDcMsQicp4xDukwJYI=
github.com/attestantio/go-eth2-client v0.0.0-20240701211822-0a60485fce68 h1:7WPMn57cFdqlpYRwbEmMdHFXdwu9GVethzEXheTcIpk=
github.com/attestantio/go-eth2-client v0.0.0-20240701211822-0a60485fce68/go.mod h1:vy5jU/uDZ2+RcVzq5BfnG+bQ3/6uu9DGwCrGsPtjJ1A=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bits-and-blooms/bitset v1.13.0 h1:bAQ9OPNFYbGHV6Nez0tmNI0RiEu7/hxlYJRUA0wFAVE=
Expand Down Expand Up @@ -321,6 +319,8 @@ github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
github.com/pk910/dynamic-ssz v0.0.5 h1:VP9heGYUwzlpyhk28P2nCAzhvGsePJOOOO5vQMDh2qQ=
github.com/pk910/dynamic-ssz v0.0.5/go.mod h1:b6CrLaB2X7pYA+OSEEbkgXDEcRnjLOZIxZTsMuO/Y9c=
github.com/pk910/go-eth2-client v0.0.0-20240923174943-8d64565c83ca h1:rc6VVR79GdE58Wx1Arh9QNo+0qmXOfYjWQhrbkSeoI0=
github.com/pk910/go-eth2-client v0.0.0-20240923174943-8d64565c83ca/go.mod h1:vy5jU/uDZ2+RcVzq5BfnG+bQ3/6uu9DGwCrGsPtjJ1A=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down
12 changes: 9 additions & 3 deletions handlers/slot.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,6 @@ func getSlotPageBlockData(blockData *services.CombinedBlockResponse, epochStatsV
BlockNumber: uint64(executionPayload.BlockNumber),
}
getSlotPageTransactions(pageData, executionPayload.Transactions)
getSlotPageDepositRequests(pageData, executionPayload.DepositRequests)
getSlotPageWithdrawalRequests(pageData, executionPayload.WithdrawalRequests)
getSlotPageConsolidationRequests(pageData, executionPayload.ConsolidationRequests)
}
}

Expand Down Expand Up @@ -725,6 +722,15 @@ func getSlotPageBlockData(blockData *services.CombinedBlockResponse, epochStatsV
}
}

if specs.ElectraForkEpoch != nil && uint64(epoch) >= *specs.ElectraForkEpoch {
requests, err := blockData.Block.ExecutionRequests()
if err == nil && requests != nil {
getSlotPageDepositRequests(pageData, requests.DepositRequests)
getSlotPageWithdrawalRequests(pageData, requests.WithdrawalRequests)
getSlotPageConsolidationRequests(pageData, requests.ConsolidationRequests)
}
}

return pageData
}

Expand Down
69 changes: 0 additions & 69 deletions indexer/beacon/block_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,75 +223,6 @@ func getBlockExecutionExtraData(v *spec.VersionedSignedBeaconBlock) ([]byte, err
}
}

func getBlockExecutionDepositRequests(v *spec.VersionedSignedBeaconBlock) ([]*electra.DepositRequest, error) {
switch v.Version {
case spec.DataVersionPhase0:
return nil, errors.New("no deposit requests in phase0")
case spec.DataVersionAltair:
return nil, errors.New("no deposit requests in altair")
case spec.DataVersionBellatrix:
return nil, errors.New("no deposit requests in bellatrix")
case spec.DataVersionCapella:
return nil, errors.New("no deposit requests in capella")
case spec.DataVersionDeneb:
return nil, errors.New("no deposit requests in deneb")
case spec.DataVersionElectra:
if v.Electra == nil || v.Electra.Message == nil || v.Electra.Message.Body == nil || v.Electra.Message.Body.ExecutionPayload == nil {
return nil, errors.New("no electra block")
}

return v.Electra.Message.Body.ExecutionPayload.DepositRequests, nil
default:
return nil, errors.New("unknown version")
}
}

func getBlockExecutionConsolidationRequests(v *spec.VersionedSignedBeaconBlock) ([]*electra.ConsolidationRequest, error) {
switch v.Version {
case spec.DataVersionPhase0:
return nil, errors.New("no deposit requests in phase0")
case spec.DataVersionAltair:
return nil, errors.New("no deposit requests in altair")
case spec.DataVersionBellatrix:
return nil, errors.New("no deposit requests in bellatrix")
case spec.DataVersionCapella:
return nil, errors.New("no deposit requests in capella")
case spec.DataVersionDeneb:
return nil, errors.New("no deposit requests in deneb")
case spec.DataVersionElectra:
if v.Electra == nil || v.Electra.Message == nil || v.Electra.Message.Body == nil || v.Electra.Message.Body.ExecutionPayload == nil {
return nil, errors.New("no electra block")
}

return v.Electra.Message.Body.ExecutionPayload.ConsolidationRequests, nil
default:
return nil, errors.New("unknown version")
}
}

func getBlockExecutionWithdrawalRequests(v *spec.VersionedSignedBeaconBlock) ([]*electra.WithdrawalRequest, error) {
switch v.Version {
case spec.DataVersionPhase0:
return nil, errors.New("no deposit requests in phase0")
case spec.DataVersionAltair:
return nil, errors.New("no deposit requests in altair")
case spec.DataVersionBellatrix:
return nil, errors.New("no deposit requests in bellatrix")
case spec.DataVersionCapella:
return nil, errors.New("no deposit requests in capella")
case spec.DataVersionDeneb:
return nil, errors.New("no deposit requests in deneb")
case spec.DataVersionElectra:
if v.Electra == nil || v.Electra.Message == nil || v.Electra.Message.Body == nil || v.Electra.Message.Body.ExecutionPayload == nil {
return nil, errors.New("no electra block")
}

return v.Electra.Message.Body.ExecutionPayload.WithdrawalRequests, nil
default:
return nil, errors.New("unknown version")
}
}

// getStateRandaoMixes returns the RANDAO mixes from a versioned beacon state.
func getStateRandaoMixes(v *spec.VersionedBeaconState) ([]phase0.Root, error) {
switch v.Version {
Expand Down
12 changes: 9 additions & 3 deletions indexer/beacon/writedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,11 +485,13 @@ func (dbw *dbWriter) buildDbDepositRequests(block *Block, orphaned bool, overrid
return nil
}

deposits, err := getBlockExecutionDepositRequests(blockBody)
requests, err := blockBody.ExecutionRequests()
if err != nil {
return nil
}

deposits := requests.DepositRequests

dbDeposits := make([]*dbtypes.Deposit, len(deposits))
for idx, deposit := range deposits {
dbDeposit := &dbtypes.Deposit{
Expand Down Expand Up @@ -673,11 +675,13 @@ func (dbw *dbWriter) buildDbConsolidationRequests(block *Block, orphaned bool, o
return nil
}

consolidations, err := getBlockExecutionConsolidationRequests(blockBody)
requests, err := blockBody.ExecutionRequests()
if err != nil {
return nil
}

consolidations := requests.ConsolidationRequests

if len(consolidations) == 0 {
return []*dbtypes.ConsolidationRequest{}
}
Expand Down Expand Up @@ -736,11 +740,13 @@ func (dbw *dbWriter) buildDbWithdrawalRequests(block *Block, orphaned bool, over
return nil
}

withdrawalRequests, err := getBlockExecutionWithdrawalRequests(blockBody)
requests, err := blockBody.ExecutionRequests()
if err != nil {
return nil
}

withdrawalRequests := requests.WithdrawalRequests

if len(withdrawalRequests) == 0 {
return []*dbtypes.WithdrawalRequest{}
}
Expand Down

0 comments on commit f373209

Please sign in to comment.