Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(node-api): Allow querying beacon blocks by execution numbers #1824

Merged
merged 21 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mod/beacon/block_store/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
package blockstore

const (
DefaultAvailabilityWindow = 1000
DefaultAvailabilityWindow = 8192
)

// Config is the configuration for the block service.
Expand Down
6 changes: 4 additions & 2 deletions mod/beacon/block_store/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ func (s *Service[BeaconBlockT, _]) listenAndStore(
case msg := <-subBlkCh:
if msg.Is(events.BeaconBlockFinalized) {
slot := msg.Data().GetSlot()
if err := s.store.Set(slot.Unwrap(), msg.Data()); err != nil {
s.logger.Error("failed to store block", "error", err)
if err := s.store.Set(slot, msg.Data()); err != nil {
s.logger.Error(
"failed to store block", "slot", slot, "error", err,
)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion mod/beacon/block_store/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type BeaconBlock interface {
// BlockStore is a generic interface for a block store.
type BlockStore[BeaconBlockT BeaconBlock] interface {
// Set sets a block at a given index.
Set(index uint64, blk BeaconBlockT) error
Set(index math.Slot, blk BeaconBlockT) error
}

// Event is an interface for block events.
Expand Down
6 changes: 6 additions & 0 deletions mod/consensus-types/pkg/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,9 @@ func (b *BeaconBlock) GetHeader() *BeaconBlockHeader {
BodyRoot: b.GetBody().HashTreeRoot(),
}
}

// GetTimestamp retrieves the timestamp of the BeaconBlock from the
// ExecutionPayload.
func (b *BeaconBlock) GetTimestamp() math.U64 {
return b.Body.ExecutionPayload.Timestamp
}
16 changes: 13 additions & 3 deletions mod/node-api/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func New[
}
}

// AttachNode sets the node on the backend for querying historical heights.
func (b *Backend[
_, _, _, _, _, _, _, _, _, _, _, _, _, _, NodeT, _, _, _, _, _, _,
]) AttachNode(node NodeT) {
Expand All @@ -134,12 +135,21 @@ func (b *Backend[
return b.cs
}

// GetSlotByRoot retrieves the slot by a given root from the block store.
func (b *Backend[
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
]) GetSlotByRoot(root [32]byte) (math.Slot, error) {
]) GetSlotByRoot(root common.Root) (math.Slot, error) {
return b.sb.BlockStore().GetSlotByRoot(root)
}

// GetSlotByTimestamp retrieves the slot by a given timestamp from the block
// store.
func (b *Backend[
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
]) GetSlotByTimestamp(timestamp math.U64) (math.Slot, error) {
return b.sb.BlockStore().GetSlotByTimestamp(timestamp)
}

// stateFromSlot returns the state at the given slot, after also processing the
// next slot to ensure the returned beacon state is up to date.
func (b *Backend[
Expand All @@ -165,8 +175,8 @@ func (b *Backend[
}

// stateFromSlotRaw returns the state at the given slot using query context,
// resolving an input slot of 0 to the latest slot. It does not process the next
// slot on the beacon state.
// resolving an input slot of 0 to the latest slot. It does not process the
// next slot on the beacon state.
func (b *Backend[
_, _, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
]) stateFromSlotRaw(slot math.Slot) (BeaconStateT, math.Slot, error) {
Expand Down
11 changes: 4 additions & 7 deletions mod/node-api/backend/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,11 @@ type BeaconState[

// BlockStore is the interface for block storage.
type BlockStore[BeaconBlockT any] interface {
// Get retrieves the block at the given slot.
Get(slot uint64) (BeaconBlockT, error)
// GetSlotByRoot retrieves the slot by a given root from the store.
GetSlotByRoot(root [32]byte) (math.Slot, error)
// Set sets the block at the given slot.
Set(slot uint64, block BeaconBlockT) error
// Prune prunes the block store of [start, end).
Prune(start, end uint64) error
GetSlotByRoot(root common.Root) (math.Slot, error)
// GetSlotByTimestamp retrieves the slot by a given timestamp from the
// store.
GetSlotByTimestamp(timestamp math.U64) (math.Slot, error)
}

// DepositStore defines the interface for deposit storage.
Expand Down
27 changes: 17 additions & 10 deletions mod/node-api/engines/echo/vaildator.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"regexp"
"strconv"

"github.com/berachain/beacon-kit/mod/node-api/handlers/utils"
"github.com/go-playground/validator/v10"
"github.com/labstack/echo/v4"
)
Expand Down Expand Up @@ -57,6 +58,7 @@ func ConstructValidator() *validator.Validate {
validators := map[string](func(fl validator.FieldLevel) bool){
"state_id": ValidateStateID,
"block_id": ValidateBlockID,
"timestamp_id": ValidateTimestampID,
"validator_id": ValidateValidatorID,
"validator_status": ValidateValidatorStatus,
"epoch": ValidateUint64,
Expand Down Expand Up @@ -93,6 +95,21 @@ func ValidateBlockID(fl validator.FieldLevel) bool {
return validateStateBlockIDs(fl, allowedValues)
}

func ValidateTimestampID(fl validator.FieldLevel) bool {
allowedValues := map[string]bool{
utils.StateIDHead: true,
utils.StateIDGenesis: true,
utils.StateIDFinalized: true,
utils.StateIDJustified: true,
}

if utils.IsTimestampPrefix(fl.Field().String()) {
return true
}

return validateStateBlockIDs(fl, allowedValues)
}

func ValidateUint64(fl validator.FieldLevel) bool {
value := fl.Field().String()
if value == "" {
Expand Down Expand Up @@ -169,20 +186,10 @@ func validateRegex(fl validator.FieldLevel, hexPattern string) (
return matched, nil
}

func fieldEmpty(fl validator.FieldLevel) bool {
if value := fl.Field().String(); value == "" {
return false
}
return true
}

func validateStateBlockIDs(
fl validator.FieldLevel,
allowedValues map[string]bool,
) bool {
if fieldEmpty(fl) {
return true
}
// Check if value is one of the allowed values
if validateAllowedStrings(fl, allowedValues) {
return true
Expand Down
6 changes: 6 additions & 0 deletions mod/node-api/engines/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,28 @@ require (
)

require (
github.com/berachain/beacon-kit/mod/chain-spec v0.0.0-20240705193247-d464364483df // indirect
github.com/berachain/beacon-kit/mod/primitives v0.0.0-20240726210727-594bfb4e7157 // indirect
github.com/cockroachdb/errors v1.11.3 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/ethereum/go-ethereum v1.14.6 // indirect
github.com/gabriel-vasile/mimetype v1.4.4 // indirect
github.com/getsentry/sentry-go v0.28.1 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/holiman/uint256 v1.3.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prysmaticlabs/gohashtree v0.0.4-beta // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
Expand Down
19 changes: 19 additions & 0 deletions mod/node-api/engines/go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
github.com/berachain/beacon-kit/mod/chain-spec v0.0.0-20240705193247-d464364483df h1:mnD1LKqDQ0n+OFdDqOuvKaEiUKRJzsO4V0wyyn/gJYg=
github.com/berachain/beacon-kit/mod/chain-spec v0.0.0-20240705193247-d464364483df/go.mod h1:bTFB4Rdvm7D/WdwPYkqQ+8T0XOMBv0pzXfp1E46BFX8=
github.com/berachain/beacon-kit/mod/errors v0.0.0-20240705193247-d464364483df h1:6MJllcmMFt6dtvftM5zmdl1WVDpqZkNy3hFXVZtNV0s=
github.com/berachain/beacon-kit/mod/errors v0.0.0-20240705193247-d464364483df/go.mod h1:yRD7rmnyaaqgq/6+eIVqvSkFJXuLXpBddUu59HUOrtc=
github.com/berachain/beacon-kit/mod/log v0.0.0-20240705193247-d464364483df h1:SnzeY9SCmKyEx0iGC/C/8E39ozpl/g5yI7lFXpmbMBI=
github.com/berachain/beacon-kit/mod/log v0.0.0-20240705193247-d464364483df/go.mod h1:mJ0ZlK+izcPWcveHAtM4+W0a+8jhu5Y4DMPL2Takacg=
github.com/berachain/beacon-kit/mod/primitives v0.0.0-20240726210727-594bfb4e7157 h1:2NHg24WWdkX7FgaFQsgNp3vbFRMnEIqchI6kKf6hs4I=
github.com/berachain/beacon-kit/mod/primitives v0.0.0-20240726210727-594bfb4e7157/go.mod h1:uSFWd+x3034sIGnSwxlJjhooh4zPXYX8DVc/r0TMvs4=
github.com/cockroachdb/errors v1.11.3 h1:5bA+k2Y6r+oz/6Z/RFlNeVCesGARKuC6YymtcDrbC/I=
github.com/cockroachdb/errors v1.11.3/go.mod h1:m4UIW4CDjx+R5cybPsNrRbreomiFqt8o1h1wUVazSd8=
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE=
Expand All @@ -11,6 +15,8 @@ github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZ
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/ethereum/go-ethereum v1.14.6 h1:ZTxnErSopkDyxdvB8zW/KcK+/AVrdil/TzoWXVKaaC8=
github.com/ethereum/go-ethereum v1.14.6/go.mod h1:hglUZo/5pVIYXNyYjWzsAUDpT/zI+WbWo/Nih7ot+G0=
github.com/gabriel-vasile/mimetype v1.4.4 h1:QjV6pZ7/XZ7ryI2KuyeEDE8wnh7fHP9YnQy+R0LnH8I=
github.com/gabriel-vasile/mimetype v1.4.4/go.mod h1:JwLei5XPtWdGiMFB5Pjle1oEeoSeEuJfJE+TtfvdB/s=
github.com/getsentry/sentry-go v0.28.1 h1:zzaSm/vHmGllRM6Tpx1492r0YDzauArdBfkJRtY6P5k=
Expand All @@ -25,14 +31,20 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.22.0 h1:k6HsTZ0sTnROkhS//R0O+55JgM8C4Bx7ia+JlgcnOao=
github.com/go-playground/validator/v10 v10.22.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/holiman/uint256 v1.3.0 h1:4wdcm/tnd0xXdu7iS3ruNvxkWwrb4aeBQv19ayYn8F4=
github.com/holiman/uint256 v1.3.0/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM=
github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Expand All @@ -48,13 +60,17 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM=
github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8=
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prysmaticlabs/gohashtree v0.0.4-beta h1:H/EbCuXPeTV3lpKeXGPpEV9gsUpkqOOVnWapUyeWro4=
github.com/prysmaticlabs/gohashtree v0.0.4-beta/go.mod h1:BFdtALS+Ffhg3lGQIHv9HDWuHS8cTvHZzrHWxwOtGOs=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
Expand Down Expand Up @@ -82,10 +98,13 @@ golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
Expand Down
2 changes: 1 addition & 1 deletion mod/node-api/handlers/beacon/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Backend[BlockHeaderT, ForkT, ValidatorT any] interface {
StateBackend[ForkT]
ValidatorBackend[ValidatorT]
HistoricalBackend[ForkT]
GetSlotByRoot(root [32]byte) (math.Slot, error)
GetSlotByRoot(root common.Root) (math.Slot, error)
calbera marked this conversation as resolved.
Show resolved Hide resolved
}

type GenesisBackend interface {
Expand Down
6 changes: 4 additions & 2 deletions mod/node-api/handlers/proof/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@

package proof

import "github.com/berachain/beacon-kit/mod/primitives/pkg/math"
import (
"github.com/berachain/beacon-kit/mod/primitives/pkg/math"
)

// Backend is the interface for backend of the proof API.
type Backend[BeaconBlockHeaderT, BeaconStateT, ValidatorT any] interface {
BlockBackend[BeaconBlockHeaderT]
StateBackend[BeaconStateT]
GetSlotByRoot([32]byte) (math.Slot, error)
GetSlotByTimestamp(timestamp math.U64) (math.Slot, error)
}

type BlockBackend[BeaconBlockHeaderT any] interface {
Expand Down
4 changes: 3 additions & 1 deletion mod/node-api/handlers/proof/block_proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ func (h *Handler[
if err != nil {
return nil, err
}
slot, beaconState, blockHeader, err := h.resolveBlockID(params.BlockID)
slot, beaconState, blockHeader, err := h.resolveTimestampID(
params.TimestampID,
)
if err != nil {
return nil, err
}
Expand Down
4 changes: 3 additions & 1 deletion mod/node-api/handlers/proof/execution_fee_recipient.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ func (h *Handler[
if err != nil {
return nil, err
}
slot, beaconState, blockHeader, err := h.resolveBlockID(params.BlockID)
slot, beaconState, blockHeader, err := h.resolveTimestampID(
params.TimestampID,
)
if err != nil {
return nil, err
}
Expand Down
4 changes: 3 additions & 1 deletion mod/node-api/handlers/proof/execution_number.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ func (h *Handler[
if err != nil {
return nil, err
}
slot, beaconState, blockHeader, err := h.resolveBlockID(params.BlockID)
slot, beaconState, blockHeader, err := h.resolveTimestampID(
params.TimestampID,
)
if err != nil {
return nil, err
}
Expand Down
32 changes: 32 additions & 0 deletions mod/node-api/handlers/proof/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ package proof
import (
"github.com/berachain/beacon-kit/mod/node-api/handlers"
"github.com/berachain/beacon-kit/mod/node-api/handlers/proof/types"
"github.com/berachain/beacon-kit/mod/node-api/handlers/utils"
"github.com/berachain/beacon-kit/mod/node-api/server/context"
"github.com/berachain/beacon-kit/mod/primitives/pkg/math"
)

// Handler is the handler for the proof API.
Expand Down Expand Up @@ -68,3 +70,33 @@ func NewHandler[
}
return h
}

// Get the slot from the given input of timestamp id, beacon state, and beacon
// block header for the resolved slot.
func (h *Handler[
ContextT, BeaconBlockHeaderT, BeaconStateT, _, _, _,
]) resolveTimestampID(timestampID string) (
math.Slot, BeaconStateT, BeaconBlockHeaderT, error,
) {
var (
beaconState BeaconStateT
blockHeader BeaconBlockHeaderT
)

slot, err := utils.SlotFromTimestampID(timestampID, h.backend)
if err != nil {
return 0, beaconState, blockHeader, err
}

beaconState, slot, err = h.backend.StateFromSlotForProof(slot)
if err != nil {
return 0, beaconState, blockHeader, err
}

blockHeader, err = h.backend.BlockHeaderAtSlot(slot)
if err != nil {
return 0, beaconState, blockHeader, err
}

return slot, beaconState, blockHeader, nil
}
6 changes: 3 additions & 3 deletions mod/node-api/handlers/proof/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ func (
h.BaseHandler.AddRoutes([]*handlers.Route[ContextT]{
{
Method: http.MethodGet,
Path: "bkit/v1/proof/block_proposer/:block_id",
Path: "bkit/v1/proof/block_proposer/:timestamp_id",
Handler: h.GetBlockProposer,
},
{
Method: http.MethodGet,
Path: "bkit/v1/proof/execution_number/:block_id",
Path: "bkit/v1/proof/execution_number/:timestamp_id",
Handler: h.GetExecutionNumber,
},
{
Method: http.MethodGet,
Path: "bkit/v1/proof/execution_fee_recipient/:block_id",
Path: "bkit/v1/proof/execution_fee_recipient/:timestamp_id",
Handler: h.GetExecutionFeeRecipient,
},
})
Expand Down
Loading
Loading