Skip to content

Commit

Permalink
feat(node-api): wire to backend (#1756)
Browse files Browse the repository at this point in the history
Co-authored-by: Cal Bera <calbera@berachain.com>
  • Loading branch information
archbear and calbera authored Jul 24, 2024
1 parent cf93ce3 commit 201979a
Show file tree
Hide file tree
Showing 101 changed files with 4,121 additions and 1,509 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ COPY ./mod/engine-primitives/go.mod ./mod/engine-primitives/go.sum ./mod/engine-
COPY ./mod/execution/go.mod ./mod/execution/go.sum ./mod/execution/
COPY ./mod/log/go.mod ./mod/log/go.sum ./mod/log/
COPY ./mod/node-api/go.mod ./mod/node-api/go.sum ./mod/node-api/
COPY ./mod/node-api/engines/go.mod ./mod/node-api/engines/go.sum ./mod/node-api/engines/
COPY ./mod/node-core/go.mod ./mod/node-core/go.sum ./mod/node-core/
COPY ./mod/p2p/go.mod ./mod/p2p/
COPY ./mod/payload/go.mod ./mod/payload/go.sum ./mod/payload/
Expand All @@ -73,6 +74,7 @@ RUN go work init && \
go work use ./mod/execution && \
go work use ./mod/log && \
go work use ./mod/node-api && \
go work use ./mod/node-api/engines && \
go work use ./mod/node-core && \
go work use ./mod/p2p && \
go work use ./mod/payload && \
Expand Down
1 change: 1 addition & 0 deletions go.work
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use (
./mod/geth-primitives
./mod/log
./mod/node-api
./mod/node-api/engines
./mod/node-core
./mod/p2p
./mod/payload
Expand Down
2 changes: 1 addition & 1 deletion mod/beacon/blockchain/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (s *Service[
// If the blobs needed to process the block are not available, we
// return an error. It is safe to use the slot off of the beacon block
// since it has been verified as correct already.
if !s.sb.AvailabilityStore(ctx).IsDataAvailable(
if !s.sb.AvailabilityStore().IsDataAvailable(
ctx, blk.GetSlot(), blk.GetBody(),
) {
return nil, ErrDataNotAvailable
Expand Down
2 changes: 1 addition & 1 deletion mod/beacon/blockchain/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ type StorageBackend[
BlobSidecarsT any,
] interface {
// AvailabilityStore returns the availability store for the given context.
AvailabilityStore(context.Context) AvailabilityStoreT
AvailabilityStore() AvailabilityStoreT
// StateFromContext retrieves the beacon state from the given context.
StateFromContext(context.Context) BeaconStateT
}
Expand Down
2 changes: 1 addition & 1 deletion mod/beacon/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (

replace (
github.com/berachain/beacon-kit/mod/engine-primitives => ../engine-primitives
github.com/berachain/beacon-kit/mod/primitives => ../primitives
github.com/berachain/beacon-kit/mod/storage => ../storage
)

require (
Expand Down
2 changes: 2 additions & 0 deletions mod/beacon/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ github.com/berachain/beacon-kit/mod/geth-primitives v0.0.0-20240630225951-a50753
github.com/berachain/beacon-kit/mod/geth-primitives v0.0.0-20240630225951-a5075323fa26/go.mod h1:UhtXsU+9A175Ntrsrc7h9ZplRQ3ih0F87vONgS1P6Uc=
github.com/berachain/beacon-kit/mod/log v0.0.0-20240610210054-bfdc14c4013c h1:7f9dLYGOCMoV7LxT6YRmVSWLTPbGTTcxDPLPLvHGrOk=
github.com/berachain/beacon-kit/mod/log v0.0.0-20240610210054-bfdc14c4013c/go.mod h1:nFybcw/ZhJ6Gu66dna301W2I7u61skm2HfHxQmdR68Q=
github.com/berachain/beacon-kit/mod/primitives v0.0.0-20240710021622-37e8e3e7e155 h1:vmQElnXj5uPg+eCWrpy55CZeaYCScFFV0X6M4RYW/GM=
github.com/berachain/beacon-kit/mod/primitives v0.0.0-20240710021622-37e8e3e7e155/go.mod h1:Jeco1800cfads+X8ma4hPeYx9Tizqob9PJefWPhEn+4=
github.com/bits-and-blooms/bitset v1.13.0 h1:bAQ9OPNFYbGHV6Nez0tmNI0RiEu7/hxlYJRUA0wFAVE=
github.com/bits-and-blooms/bitset v1.13.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8=
github.com/btcsuite/btcd/btcec/v2 v2.3.3 h1:6+iXlDKE8RMtKsvK0gshlXIuPbyWM/h84Ensb7o3sC0=
Expand Down
4 changes: 2 additions & 2 deletions mod/beacon/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ type StorageBackend[
DepositStoreT DepositStore[DepositT],
] interface {
// AvailabilityStore returns the availability store for the given context.
AvailabilityStore(context.Context) AvailabilityStoreT
AvailabilityStore() AvailabilityStoreT
// DepositStore retrieves the deposit store.
DepositStore(context.Context) DepositStoreT
DepositStore() DepositStoreT
// StateFromContext retrieves the beacon state from the given context.
StateFromContext(context.Context) BeaconStateT
}
4 changes: 2 additions & 2 deletions mod/beacon/validator/block_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func (s *Service[
AttestationDataT, BeaconBlockT, _, BeaconStateT, _,
_, _, Eth1DataT, ExecutionPayloadT, _, _, SlashingInfoT, SlotDataT,
]) buildBlockBody(
ctx context.Context,
_ context.Context,
st BeaconStateT,
blk BeaconBlockT,
reveal crypto.BLSSignature,
Expand Down Expand Up @@ -296,7 +296,7 @@ func (s *Service[
}

// Dequeue deposits from the state.
deposits, err := s.bsb.DepositStore(ctx).GetDepositsByIndex(
deposits, err := s.bsb.DepositStore().GetDepositsByIndex(
depositIndex,
s.chainSpec.MaxDepositsPerBlock(),
)
Expand Down
2 changes: 1 addition & 1 deletion mod/beacon/validator/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ type StorageBackend[
ExecutionPayloadHeaderT any,
] interface {
// DepositStore retrieves the deposit store.
DepositStore(context.Context) DepositStoreT
DepositStore() DepositStoreT
// StateFromContext retrieves the beacon state from the context.
StateFromContext(context.Context) BeaconStateT
}
Expand Down
1 change: 0 additions & 1 deletion mod/cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ replace (
// The following are required to build with the latest version of the cosmos-sdk main branch:
cosmossdk.io/api => cosmossdk.io/api v0.7.3-0.20240623110059-dec2d5583e39
cosmossdk.io/core/testing => cosmossdk.io/core/testing v0.0.0-20240623110059-dec2d5583e39
github.com/berachain/beacon-kit/mod/primitives => ../primitives
github.com/cosmos/cosmos-sdk => github.com/berachain/cosmos-sdk v0.46.0-beta2.0.20240624014538-75ba469b1881
)

Expand Down
2 changes: 2 additions & 0 deletions mod/cli/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ github.com/berachain/beacon-kit/mod/p2p v0.0.0-20240618214413-d5ec0e66b3dd h1:QH
github.com/berachain/beacon-kit/mod/p2p v0.0.0-20240618214413-d5ec0e66b3dd/go.mod h1:ft214cxJaqrRPOuAjpYwgA9AOElJnHrDZZEQ0jZPWwQ=
github.com/berachain/beacon-kit/mod/payload v0.0.0-20240705193247-d464364483df h1:fLL+7ZZcbVOmE3XE0o+ZGS8zyPLjki7LrZAsXpcG4Sc=
github.com/berachain/beacon-kit/mod/payload v0.0.0-20240705193247-d464364483df/go.mod h1:wbSa9W1CDDzR9AptQfYf/16bWqktaIQIZdJsuKWeqC8=
github.com/berachain/beacon-kit/mod/primitives v0.0.0-20240710022448-e56f337d051f h1:EYhinHdIWJ8qHkATYHZ6s7DyemXhA8NovnWPqk3kU8Y=
github.com/berachain/beacon-kit/mod/primitives v0.0.0-20240710022448-e56f337d051f/go.mod h1:Jeco1800cfads+X8ma4hPeYx9Tizqob9PJefWPhEn+4=
github.com/berachain/beacon-kit/mod/runtime v0.0.0-20240710022902-57d64ab384c7 h1:tp0Uz98lIQJ9ZnTsxyOxtP+NjbfQM5GRyNH2DlEZEJQ=
github.com/berachain/beacon-kit/mod/runtime v0.0.0-20240710022902-57d64ab384c7/go.mod h1:qeqdziAxd63Zh1rnUXwDA5m7vNOsx4Rr2d6CJv7ADRw=
github.com/berachain/beacon-kit/mod/state-transition v0.0.0-20240710023256-e9246f6a35e1 h1:7GTVZXBsV4BExOT3mC+64OSaRlkqDQFMDnOXac19vvQ=
Expand Down
15 changes: 15 additions & 0 deletions mod/cli/pkg/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ const (
"pruner-enabled"
BlockStoreServiceAvailabilityWindow = blockStoreServiceRoot +
"availability-window"

// Node API Config.
nodeAPIRoot = beaconKitRoot + "node-api."
NodeAPIEnabled = nodeAPIRoot + "enabled"
NodeAPIAddress = nodeAPIRoot + "address"
)

// AddBeaconKitFlags implements servertypes.ModuleInitFlags interface.
Expand Down Expand Up @@ -142,4 +147,14 @@ func AddBeaconKitFlags(startCmd *cobra.Command) {
defaultCfg.BlockStoreService.AvailabilityWindow,
"block service availability window",
)
startCmd.Flags().Bool(
NodeAPIEnabled,
defaultCfg.NodeAPI.Enabled,
"node api enabled",
)
startCmd.Flags().String(
NodeAPIAddress,
defaultCfg.NodeAPI.Address,
"node api address",
)
}
4 changes: 4 additions & 0 deletions mod/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/berachain/beacon-kit/mod/errors"
engineclient "github.com/berachain/beacon-kit/mod/execution/pkg/client"
log "github.com/berachain/beacon-kit/mod/log/pkg/phuslu"
"github.com/berachain/beacon-kit/mod/node-api/server"
"github.com/berachain/beacon-kit/mod/payload/pkg/builder"
"github.com/mitchellh/mapstructure"
"github.com/spf13/viper"
Expand All @@ -48,6 +49,7 @@ func DefaultConfig() *Config {
PayloadBuilder: builder.DefaultConfig(),
Validator: validator.DefaultConfig(),
BlockStoreService: blockstore.DefaultConfig(),
NodeAPI: server.DefaultConfig(),
}
}

Expand All @@ -65,6 +67,8 @@ type Config struct {
Validator validator.Config `mapstructure:"validator"`
// BlockStoreService is the configuration for the block store service.
BlockStoreService blockstore.Config `mapstructure:"block-store-service"`
// NodeAPI is the configuration for the node API.
NodeAPI server.Config `mapstructure:"node-api"`
}

// GetEngine returns the execution client configuration.
Expand Down
20 changes: 17 additions & 3 deletions mod/config/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ module github.com/berachain/beacon-kit/mod/config

go 1.22.5

replace (
github.com/berachain/beacon-kit/mod/beacon => ../beacon
github.com/berachain/beacon-kit/mod/storage => ../storage
)

require (
github.com/berachain/beacon-kit/mod/beacon v0.0.0-20240718074353-1a991cfeed63
github.com/berachain/beacon-kit/mod/chain-spec v0.0.0-20240705193247-d464364483df
Expand All @@ -10,6 +15,7 @@ require (
github.com/berachain/beacon-kit/mod/execution v0.0.0-20240624003607-df94860f8eeb
github.com/berachain/beacon-kit/mod/geth-primitives v0.0.0-20240705193247-d464364483df
github.com/berachain/beacon-kit/mod/log v0.0.0-20240624033454-8f3451361f44
github.com/berachain/beacon-kit/mod/node-api v0.0.0-20240717210058-a144e074f6b2
github.com/berachain/beacon-kit/mod/payload v0.0.0-20240624003607-df94860f8eeb
github.com/berachain/beacon-kit/mod/primitives v0.0.0-20240710021622-37e8e3e7e155
github.com/cometbft/cometbft v1.0.0-rc1.0.20240711183925-948692fddcbe
Expand All @@ -18,16 +24,13 @@ require (
)

require (
cosmossdk.io/collections v0.4.0 // indirect
cosmossdk.io/core v0.12.1-0.20240623110059-dec2d5583e39 // indirect
github.com/DataDog/zstd v1.5.5 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/VictoriaMetrics/fastcache v1.12.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/berachain/beacon-kit/mod/async v0.0.0-20240624003607-df94860f8eeb // indirect
github.com/berachain/beacon-kit/mod/consensus-types v0.0.0-20240710022615-726645827bad // indirect
github.com/berachain/beacon-kit/mod/engine-primitives v0.0.0-20240710022615-726645827bad // indirect
github.com/berachain/beacon-kit/mod/storage v0.0.0-20240718074353-1a991cfeed63 // indirect
github.com/bits-and-blooms/bitset v1.13.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.3 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
Expand All @@ -53,10 +56,14 @@ require (
github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0 // indirect
github.com/ferranbt/fastssz v0.1.4-0.20240629094022-eac385e6ee79 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/getsentry/sentry-go v0.28.1 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.20.0 // indirect
github.com/gofrs/flock v0.12.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
Expand All @@ -72,7 +79,12 @@ require (
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/echo/v4 v4.12.0 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mitchellh/pointerstructure v1.2.1 // indirect
Expand Down Expand Up @@ -106,6 +118,8 @@ require (
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
github.com/tklauser/go-sysconf v0.3.14 // indirect
github.com/tklauser/numcpus v0.8.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect
Expand Down
Loading

0 comments on commit 201979a

Please sign in to comment.