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): use timestamp ID instead of execution ID for proof namespace #2066

Merged
merged 11 commits into from
Oct 16, 2024
6 changes: 3 additions & 3 deletions mod/consensus-types/pkg/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ func (b *BeaconBlock) GetHeader() *BeaconBlockHeader {
}
}

// GetExecutionNumber retrieves the execution number of the BeaconBlock from
// GetTimestamp retrieves the timestamp of the BeaconBlock from
// the ExecutionPayload.
func (b *BeaconBlock) GetExecutionNumber() math.U64 {
return b.Body.ExecutionPayload.Number
func (b *BeaconBlock) GetTimestamp() math.U64 {
return b.Body.ExecutionPayload.Timestamp
}
calbera marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 2 additions & 1 deletion mod/consensus-types/pkg/types/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func generateValidBeaconBlock() *types.BeaconBlock {
Body: &types.BeaconBlockBody{
ExecutionPayload: &types.ExecutionPayload{
Number: 10,
Timestamp: 10,
calbera marked this conversation as resolved.
Show resolved Hide resolved
calbera marked this conversation as resolved.
Show resolved Hide resolved
calbera marked this conversation as resolved.
Show resolved Hide resolved
ExtraData: []byte("dummy extra data for testing"),
Transactions: [][]byte{
[]byte("tx1"),
Expand Down Expand Up @@ -101,7 +102,7 @@ func TestBeaconBlock(t *testing.T) {
block := generateValidBeaconBlock()

require.NotNil(t, block.Body)
require.Equal(t, math.U64(10), block.GetExecutionNumber())
require.Equal(t, math.U64(10), block.GetTimestamp())
require.Equal(t, version.Deneb, block.Version())
require.False(t, block.IsNil())

Expand Down
6 changes: 3 additions & 3 deletions mod/node-api/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ func (b *Backend[
return b.sb.BlockStore().GetSlotByStateRoot(root)
}

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

// stateFromSlot returns the state at the given slot, after also processing the
Expand Down
80 changes: 40 additions & 40 deletions mod/node-api/backend/mocks/block_store.mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions mod/node-api/backend/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ type BlockStore[BeaconBlockT any] interface {
GetSlotByBlockRoot(root common.Root) (math.Slot, error)
// GetSlotByStateRoot retrieves the slot by a given state root.
GetSlotByStateRoot(root common.Root) (math.Slot, error)
// GetSlotByExecutionNumber retrieves the slot by a given execution number.
GetSlotByExecutionNumber(executionNumber math.U64) (math.Slot, error)
// GetParentSlotByTimestamp retrieves the parent slot by a given timestamp.
GetParentSlotByTimestamp(timestamp math.U64) (math.Slot, error)
calbera marked this conversation as resolved.
Show resolved Hide resolved
}

// DepositStore defines the interface for deposit storage.
Expand Down
6 changes: 3 additions & 3 deletions mod/node-api/engines/echo/vaildator.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func ConstructValidator() *validator.Validate {
validators := map[string](func(fl validator.FieldLevel) bool){
"state_id": ValidateStateID,
"block_id": ValidateBlockID,
"execution_id": ValidateExecutionID,
"timestamp_id": ValidateTimestampID,
"validator_id": ValidateValidatorID,
"epoch": ValidateUint64,
"slot": ValidateUint64,
Expand Down Expand Up @@ -96,7 +96,7 @@ func ValidateBlockID(fl validator.FieldLevel) bool {
return validateStateBlockIDs(fl.Field().String(), allowedValues)
}

func ValidateExecutionID(fl validator.FieldLevel) bool {
func ValidateTimestampID(fl validator.FieldLevel) bool {
allowedValues := map[string]bool{
utils.StateIDHead: true,
utils.StateIDGenesis: true,
Expand All @@ -105,7 +105,7 @@ func ValidateExecutionID(fl validator.FieldLevel) bool {
}

value := fl.Field().String()
if utils.IsExecutionNumberPrefix(value) {
if utils.IsTimestampIDPrefix(value) {
return ValidateUint64Dec(value[1:])
}

Expand Down
2 changes: 1 addition & 1 deletion mod/node-api/handlers/proof/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
type Backend[BeaconBlockHeaderT, BeaconStateT, ValidatorT any] interface {
BlockBackend[BeaconBlockHeaderT]
StateBackend[BeaconStateT]
GetSlotByExecutionNumber(executionNumber math.U64) (math.Slot, error)
GetParentSlotByTimestamp(timestamp math.U64) (math.Slot, error)
}

type BlockBackend[BeaconBlockHeaderT any] interface {
Expand Down
9 changes: 5 additions & 4 deletions mod/node-api/handlers/proof/block_proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ import (
"github.com/berachain/beacon-kit/mod/node-api/handlers/utils"
)

// GetBlockProposer returns the block proposer pubkey for the given block id
// along with a merkle proof that can be verified against the beacon block root.
// GetBlockProposer returns the block proposer pubkey for the given timestamp
// id along with a merkle proof that can be verified against the beacon block
abi87 marked this conversation as resolved.
Show resolved Hide resolved
// root.
func (h *Handler[
BeaconBlockHeaderT, _, _, ContextT, _, _,
]) GetBlockProposer(c ContextT) (any, error) {
Expand All @@ -37,8 +38,8 @@ func (h *Handler[
if err != nil {
return nil, err
}
slot, beaconState, blockHeader, err := h.resolveExecutionID(
params.ExecutionID,
slot, beaconState, blockHeader, err := h.resolveTimestampID(
params.TimestampID,
)
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions mod/node-api/handlers/proof/execution_fee_recipient.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

// GetExecutionFeeRecipient returns the fee recipient from the latest execution
// payload header for the given block id, along with the proof that can be
abi87 marked this conversation as resolved.
Show resolved Hide resolved
// payload header for the given timestamp id, along with the proof that can be
// verified against the beacon block root.
func (h *Handler[
BeaconBlockHeaderT, _, _, ContextT, _, _,
Expand All @@ -38,8 +38,8 @@ func (h *Handler[
if err != nil {
return nil, err
}
slot, beaconState, blockHeader, err := h.resolveExecutionID(
params.ExecutionID,
slot, beaconState, blockHeader, err := h.resolveTimestampID(
params.TimestampID,
calbera marked this conversation as resolved.
Show resolved Hide resolved
)
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions mod/node-api/handlers/proof/execution_number.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

// GetExecutionNumber returns the block number from the latest execution
// payload header for the given block id, along with the proof that can be
// payload header for the given timestamp id, along with the proof that can be
// verified against the beacon block root.
func (h *Handler[
BeaconBlockHeaderT, _, _, ContextT, _, _,
Expand All @@ -38,8 +38,8 @@ func (h *Handler[
if err != nil {
return nil, err
}
slot, beaconState, blockHeader, err := h.resolveExecutionID(
params.ExecutionID,
slot, beaconState, blockHeader, err := h.resolveTimestampID(
params.TimestampID,
calbera marked this conversation as resolved.
Show resolved Hide resolved
)
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions mod/node-api/handlers/proof/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,19 @@ func NewHandler[
return h
}

// Get the slot from the given input of execution id, beacon state, and beacon
// Get the slot from the given input of timestamp id, beacon state, and beacon
calbera marked this conversation as resolved.
Show resolved Hide resolved
// block header for the resolved slot.
func (h *Handler[
BeaconBlockHeaderT, BeaconStateT, _, _, _, _,
]) resolveExecutionID(executionID string) (
]) resolveTimestampID(timestampID string) (
calbera marked this conversation as resolved.
Show resolved Hide resolved
math.Slot, BeaconStateT, BeaconBlockHeaderT, error,
) {
var (
beaconState BeaconStateT
blockHeader BeaconBlockHeaderT
)

slot, err := utils.SlotFromExecutionID(executionID, h.backend)
slot, err := utils.ParentSlotFromTimestampID(timestampID, h.backend)
if err != nil {
return 0, beaconState, blockHeader, err
}
Expand Down
12 changes: 6 additions & 6 deletions mod/node-api/handlers/proof/types/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ package types
import "github.com/berachain/beacon-kit/mod/node-api/handlers/types"

// BlockProposerRequest is the request for the
// `/proof/block_proposer/{execution_id}` endpoint.
// `/proof/block_proposer/{timestamp_id}` endpoint.
type BlockProposerRequest struct {
types.ExecutionIDRequest
types.TimestampIDRequest
calbera marked this conversation as resolved.
Show resolved Hide resolved
}

// ExecutionNumberRequest is the request for the
// `/proof/execution_number/{execution_id}` endpoint.
// `/proof/execution_number/{timestamp_id}` endpoint.
type ExecutionNumberRequest struct {
types.ExecutionIDRequest
types.TimestampIDRequest
calbera marked this conversation as resolved.
Show resolved Hide resolved
}

// ExecutionFeeRecipientRequest is the request for the
// `/proof/execution_fee_recipient/{execution_id}` endpoint.
// `/proof/execution_fee_recipient/{timestamp_id}` endpoint.
type ExecutionFeeRecipientRequest struct {
types.ExecutionIDRequest
types.TimestampIDRequest
}
4 changes: 2 additions & 2 deletions mod/node-api/handlers/types/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ type BlockIDRequest struct {
BlockID string `param:"block_id" validate:"required,block_id"`
}

type ExecutionIDRequest struct {
ExecutionID string `param:"execution_id" validate:"required,execution_id"`
type TimestampIDRequest struct {
TimestampID string `param:"timestamp_id" validate:"required,timestamp_id"`
}
calbera marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion mod/node-api/handlers/utils/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const (
StateIDFinalized = "finalized"
StateIDJustified = "justified"
StateIDHead = "head"
ExecutionIDPrefix = "n"
TimestampIDPrefix = "t"
)

const (
Expand Down
Loading
Loading