Skip to content

Commit

Permalink
split echo and beacon response
Browse files Browse the repository at this point in the history
Signed-off-by: nidhi-singh02 <[email protected]>
  • Loading branch information
nidhi-singh02 committed Sep 27, 2024
1 parent f4be7e8 commit 707f4eb
Show file tree
Hide file tree
Showing 18 changed files with 354 additions and 382 deletions.
11 changes: 6 additions & 5 deletions mod/node-api/backend/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
package backend

import (
types "github.com/berachain/beacon-kit/mod/node-api/handlers/beacon/types"
"github.com/berachain/beacon-kit/mod/node-api/handlers/beacon/types/data"
"github.com/berachain/beacon-kit/mod/primitives/pkg/common"
"github.com/berachain/beacon-kit/mod/primitives/pkg/math"
)

// BlockHeader returns the block header at the given slot.
// BlockHeaderAtSlot returns the block header at the given slot.
func (b Backend[
_, _, _, BeaconBlockHeaderT, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_,
Expand All @@ -42,7 +42,7 @@ func (b Backend[
return blockHeader, err
}

// GetBlockRoot returns the root of the block at the given stateID.
// BlockRootAtSlot returns the root of the block at the given stateID.
func (b Backend[
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
]) BlockRootAtSlot(slot math.Slot) (common.Root, error) {
Expand All @@ -56,11 +56,12 @@ func (b Backend[
return st.GetBlockRootAtIndex(slot.Unwrap() % b.cs.SlotsPerHistoricalRoot())
}

// BlockRewardsAtSlot returns the block rewards at the given slot.
// TODO: Implement this.
func (b Backend[
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
]) BlockRewardsAtSlot(math.Slot) (*types.BlockRewardsData, error) {
return &types.BlockRewardsData{
]) BlockRewardsAtSlot(math.Slot) (*data.BlockRewardsData, error) {
return &data.BlockRewardsData{
ProposerIndex: 1,
Total: 1,
Attestations: 1,
Expand Down
2 changes: 1 addition & 1 deletion mod/node-api/backend/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/berachain/beacon-kit/mod/primitives/pkg/math"
)

// GetGenesis returns the genesis state of the beacon chain.
// GenesisValidatorsRoot returns the genesis validators root at the given slot.
func (b Backend[
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
]) GenesisValidatorsRoot(slot math.Slot) (common.Root, error) {
Expand Down
1 change: 1 addition & 0 deletions mod/node-api/backend/randao.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/berachain/beacon-kit/mod/primitives/pkg/math"
)

// RandaoAtEpoch returns the randao mix at the given slot and epoch.
func (b Backend[
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
]) RandaoAtEpoch(slot math.Slot, epoch math.Epoch) (common.Bytes32, error) {
Expand Down
4 changes: 2 additions & 2 deletions mod/node-api/backend/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (b *Backend[
return b.stateFromSlotRaw(slot)
}

// GetStateRoot returns the root of the state at the given slot.
// StateRootAtSlot returns the root of the state at the given slot.
func (b Backend[
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
]) StateRootAtSlot(slot math.Slot) (common.Root, error) {
Expand All @@ -48,7 +48,7 @@ func (b Backend[
return st.StateRootAtIndex(slot.Unwrap() % b.cs.SlotsPerHistoricalRoot())
}

// GetStateFork returns the fork of the state at the given stateID.
// StateForkAtSlot returns the fork of the state at the given slot.
func (b Backend[
_, _, _, _, _, _, _, _, _, _, _, _, _, ForkT, _, _, _, _, _, _, _,
]) StateForkAtSlot(slot math.Slot) (ForkT, error) {
Expand Down
22 changes: 13 additions & 9 deletions mod/node-api/backend/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ package backend

import (
"github.com/berachain/beacon-kit/mod/node-api/backend/utils"
beacontypes "github.com/berachain/beacon-kit/mod/node-api/handlers/beacon/types"
"github.com/berachain/beacon-kit/mod/node-api/handlers/beacon/types/data"
"github.com/berachain/beacon-kit/mod/primitives/pkg/math"
)

// ValidatorByID returns the validator at the given slot and ID.
func (b Backend[
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, ValidatorT, _, _,
WithdrawalCredentialsT,
]) ValidatorByID(
slot math.Slot, id string,
) (*beacontypes.ValidatorData[ValidatorT, WithdrawalCredentialsT], error) {
) (*data.ValidatorData[ValidatorT, WithdrawalCredentialsT], error) {
// TODO: to adhere to the spec, this shouldn't error if the error
// is not found, but i can't think of a way to do that without coupling
// db impl to the api impl.
Expand All @@ -51,8 +52,8 @@ func (b Backend[
if err != nil {
return nil, err
}
return &beacontypes.ValidatorData[ValidatorT, WithdrawalCredentialsT]{
ValidatorBalanceData: beacontypes.ValidatorBalanceData{
return &data.ValidatorData[ValidatorT, WithdrawalCredentialsT]{
ValidatorBalanceData: data.ValidatorBalanceData{
Index: index.Unwrap(),
Balance: balance.Unwrap(),
},
Expand All @@ -61,15 +62,16 @@ func (b Backend[
}, nil
}

// ValidatorsByIDs returns the validators at the given slot and IDs.
// TODO: filter by status
func (b Backend[
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, ValidatorT, _, _,
WithdrawalCredentialsT,
]) ValidatorsByIDs(
slot math.Slot, ids []string, _ []string,
) ([]*beacontypes.ValidatorData[ValidatorT, WithdrawalCredentialsT], error) {
) ([]*data.ValidatorData[ValidatorT, WithdrawalCredentialsT], error) {
validatorsData := make(
[]*beacontypes.ValidatorData[ValidatorT, WithdrawalCredentialsT],
[]*data.ValidatorData[ValidatorT, WithdrawalCredentialsT],
0)
for _, id := range ids {
// TODO: we can probably optimize this via a getAllValidators
Expand All @@ -84,17 +86,19 @@ func (b Backend[
return validatorsData, nil
}

// ValidatorBalancesByIDs returns the balances of the validators at the given
// slot and IDs.
func (b Backend[
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
]) ValidatorBalancesByIDs(
slot math.Slot, ids []string,
) ([]*beacontypes.ValidatorBalanceData, error) {
) ([]*data.ValidatorBalanceData, error) {
var index math.U64
st, _, err := b.stateFromSlot(slot)
if err != nil {
return nil, err
}
balances := make([]*beacontypes.ValidatorBalanceData, 0)
balances := make([]*data.ValidatorBalanceData, 0)
for _, id := range ids {
index, err = utils.ValidatorIndexByID(st, id)
if err != nil {
Expand All @@ -106,7 +110,7 @@ func (b Backend[
if err != nil {
return nil, err
}
balances = append(balances, &beacontypes.ValidatorBalanceData{
balances = append(balances, &data.ValidatorBalanceData{
Index: index.Unwrap(),
Balance: balance.Unwrap(),
})
Expand Down
5 changes: 3 additions & 2 deletions mod/node-api/engines/echo/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package echo

import (
"github.com/berachain/beacon-kit/mod/log"
"github.com/berachain/beacon-kit/mod/node-api/engines/echo/validator"
"github.com/berachain/beacon-kit/mod/node-api/handlers"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
Expand All @@ -46,8 +47,8 @@ func NewDefaultEngine() *Engine {
engine.Use(middleware.CORSWithConfig(
middleware.DefaultCORSConfig,
))
engine.Validator = &CustomValidator{
Validator: ConstructValidator(),
engine.Validator = &validator.CustomValidator{
Validator: validator.ConstructValidator(),
}
engine.HideBanner = true
return New(engine)
Expand Down
208 changes: 0 additions & 208 deletions mod/node-api/engines/echo/vaildator.go

This file was deleted.

Loading

0 comments on commit 707f4eb

Please sign in to comment.