From 8e5ccaede24c5a0f4d3413ee3a56edc734627bdd Mon Sep 17 00:00:00 2001 From: Sam Calder-Mason Date: Tue, 3 Dec 2024 12:36:57 +1000 Subject: [PATCH] feat: Add function to create epoch defaults from fork epochs --- pkg/cannon/iterator/epoch_defaults.go | 38 +++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 pkg/cannon/iterator/epoch_defaults.go diff --git a/pkg/cannon/iterator/epoch_defaults.go b/pkg/cannon/iterator/epoch_defaults.go new file mode 100644 index 00000000..991631c2 --- /dev/null +++ b/pkg/cannon/iterator/epoch_defaults.go @@ -0,0 +1,38 @@ +package iterator + +import ( + "github.com/attestantio/go-eth2-client/spec" + "github.com/attestantio/go-eth2-client/spec/phase0" + "github.com/ethpandaops/beacon/pkg/beacon/state" + "github.com/ethpandaops/xatu/pkg/proto/xatu" +) + +func NewEpochDefaultsFromForkEpochs(forkEpochs state.ForkEpochs) map[xatu.CannonType]phase0.Epoch { + var ( + bellatrixEpoch, + capellaEpoch, + denebEpoch phase0.Epoch + ) + + bellatrix, err := forkEpochs.GetByName(spec.DataVersionBellatrix.String()) + if err == nil { + bellatrixEpoch = bellatrix.Epoch + } + + capella, err := forkEpochs.GetByName(spec.DataVersionCapella.String()) + if err == nil { + capellaEpoch = capella.Epoch + } + + deneb, err := forkEpochs.GetByName(spec.DataVersionDeneb.String()) + if err == nil { + denebEpoch = deneb.Epoch + } + + return map[xatu.CannonType]phase0.Epoch{ + xatu.CannonType_BEACON_API_ETH_V2_BEACON_BLOCK_BLS_TO_EXECUTION_CHANGE: capellaEpoch, + xatu.CannonType_BEACON_API_ETH_V2_BEACON_BLOCK_WITHDRAWAL: capellaEpoch, + xatu.CannonType_BEACON_API_ETH_V2_BEACON_BLOCK_EXECUTION_TRANSACTION: bellatrixEpoch, + xatu.CannonType_BEACON_API_ETH_V1_BEACON_BLOB_SIDECAR: denebEpoch, + } +}