Skip to content

Commit

Permalink
wip: moving to compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
abi87 committed Nov 23, 2024
1 parent f228b0a commit 617db4e
Show file tree
Hide file tree
Showing 13 changed files with 253 additions and 94 deletions.
2 changes: 1 addition & 1 deletion beacond/cmd/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
package main

import (
"cosmossdk.io/core/appmodule/v2"
appmodule "cosmossdk.io/core/appmodule/v2"
"github.com/berachain/beacon-kit/mod/beacon/blockchain"
"github.com/berachain/beacon-kit/mod/beacon/validator"
"github.com/berachain/beacon-kit/mod/consensus-types/pkg/types"
Expand Down
6 changes: 5 additions & 1 deletion mod/consensus/pkg/cometbft/cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,14 @@ func StatusCommand() *cobra.Command {
if err != nil {
return err
}
cometRPC, err := clientCtx.GetNode()
if err != nil {
return err
}

status, err := cmtservice.GetNodeStatus(
context.Background(),
clientCtx,
cometRPC,
)
if err != nil {
return err
Expand Down
14 changes: 10 additions & 4 deletions mod/consensus/pkg/cometbft/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,19 @@ func (s *Service[_]) Start(
return err
}

privVal, err := pvm.LoadOrGenFilePV(
cfg.PrivValidatorKeyFile(),
cfg.PrivValidatorStateFile(),
nil,
)
if err != nil {
return err
}

s.node, err = node.NewNode(
ctx,
cfg,
pvm.LoadOrGenFilePV(
cfg.PrivValidatorKeyFile(),
cfg.PrivValidatorStateFile(),
),
privVal,
nodeKey,
proxy.NewLocalClientCreator(s),
GetGenDocProvider(cfg),
Expand Down
14 changes: 14 additions & 0 deletions mod/node-core/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ replace (
cosmossdk.io/core/testing => ../../../cosmos-sdk/core/testing
cosmossdk.io/x/bank => ../../../cosmos-sdk/x/bank
cosmossdk.io/x/staking => ../../../cosmos-sdk/x/staking

github.com/berachain/beacon-kit/mod/cli => ../cli
github.com/berachain/beacon-kit/mod/config => ../config
github.com/berachain/beacon-kit/mod/consensus => ../consensus
github.com/berachain/beacon-kit/mod/node-api => ../node-api
github.com/berachain/beacon-kit/mod/observability => ../observability
github.com/berachain/beacon-kit/mod/storage => ../storage

github.com/cosmos/cosmos-sdk => ../../../cosmos-sdk
)

Expand Down Expand Up @@ -67,20 +69,32 @@ require (
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/cockroachdb/fifo v0.0.0-20240616162244-4768e80dfb9a // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.5 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/gabriel-vasile/mimetype v1.4.6 // 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.22.0 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/gorilla/handlers v1.5.2 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/hashicorp/go-hclog v1.6.3 // indirect
github.com/hashicorp/go-plugin v1.6.2 // indirect
github.com/hashicorp/yamux v0.1.2 // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/huandu/skiplist v1.2.1 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/karalabe/ssz v0.2.1-0.20240724074312-3d1ff7a6f7c4 // 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/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/phuslu/log v1.0.110 // indirect
github.com/prysmaticlabs/go-bitfield v0.0.0-20240618144021-706c95b2dd15 // indirect
github.com/stretchr/objx v0.5.2 // indirect
Expand Down
60 changes: 60 additions & 0 deletions mod/node-core/go.sum

Large diffs are not rendered by default.

87 changes: 6 additions & 81 deletions mod/node-core/pkg/components/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,93 +21,18 @@
package components

import (
"context"

"cosmossdk.io/core/store"
storetypes "cosmossdk.io/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/runtime"
)

//nolint:gochecknoglobals // storeKey is a singleton.
var storeKey = storetypes.NewKVStoreKey("beacon")
var storeKey = types.NewKVStoreKey("beacon")

func ProvideKVStoreKey() *storetypes.KVStoreKey {
func ProvideKVStoreKey() *types.KVStoreKey {
return storeKey
}

func ProvideKVStoreService(
storeKey *storetypes.KVStoreKey,
) store.KVStoreService {
// skips modules that have no store
return kvStoreService{key: storeKey}
}

func NewKVStoreService(storeKey *storetypes.KVStoreKey) store.KVStoreService {
return &kvStoreService{key: storeKey}
}

type kvStoreService struct {
key *storetypes.KVStoreKey
}

func (k kvStoreService) OpenKVStore(ctx context.Context) store.KVStore {
return NewKVStore(sdk.UnwrapSDKContext(ctx).KVStore(k.key))
}

// CoreKVStore is a wrapper of Core/Store kvstore interface
// Remove after https://github.com/cosmos/cosmos-sdk/issues/14714 is closed.
type coreKVStore struct {
kvStore storetypes.KVStore
}

// NewKVStore returns a wrapper of Core/Store kvstore interface
// Remove once store migrates to core/store kvstore interface.
func NewKVStore(store storetypes.KVStore) store.KVStore {
return coreKVStore{kvStore: store}
}

// Get returns nil iff key doesn't exist. Errors on nil key.
func (store coreKVStore) Get(key []byte) ([]byte, error) {
return store.kvStore.Get(key), nil
}

// Has checks if a key exists. Errors on nil key.
func (store coreKVStore) Has(key []byte) (bool, error) {
return store.kvStore.Has(key), nil
}

// Set sets the key. Errors on nil key or value.
func (store coreKVStore) Set(key, value []byte) error {
store.kvStore.Set(key, value)
return nil
}

// Delete deletes the key. Errors on nil key.
func (store coreKVStore) Delete(key []byte) error {
store.kvStore.Delete(key)
return nil
}

// Iterator iterates over a domain of keys in ascending order. End is exclusive.
// Start must be less than end, or the Iterator is invalid.
// Iterator must be closed by caller.
// To iterate over entire domain, use store.Iterator(nil, nil)
// CONTRACT: No writes may happen within a domain while an iterator exists over
// it.
// Exceptionally allowed for cachekv.Store, safe to write in the modules.
func (store coreKVStore) Iterator(start, end []byte) (store.Iterator, error) {
return store.kvStore.Iterator(start, end), nil
}

// ReverseIterator iterates over a domain of keys in descending order. End is
// exclusive.
// Start must be less than end, or the Iterator is invalid.
// Iterator must be closed by caller.
// CONTRACT: No writes may happen within a domain while an iterator exists over
// it.
// Exceptionally allowed for cachekv.Store, safe to write in the modules.
func (store coreKVStore) ReverseIterator(
start, end []byte,
) (store.Iterator, error) {
return store.kvStore.ReverseIterator(start, end), nil
func ProvideKVStoreService(storeKey *types.KVStoreKey) store.KVStoreService {
return runtime.NewKVStoreService(storeKey)
}
11 changes: 7 additions & 4 deletions mod/node-core/pkg/components/signer/legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

// LegacySigner is a BLS12-381 signer that uses a bls.PrivKey for signing.
type LegacySigner struct {
*bls12381.PrivKey
bls12381.PrivKey
}

// NewLegacySigner creates a new Signer instance given a secret key.
Expand All @@ -41,7 +41,7 @@ func NewLegacySigner(
if err != nil {
return nil, err
}
return &LegacySigner{PrivKey: &pk}, nil
return &LegacySigner{PrivKey: pk}, nil
}

// PublicKey returns the public key of the signer.
Expand All @@ -66,8 +66,11 @@ func (LegacySigner) VerifySignature(
msg []byte,
signature crypto.BLSSignature,
) error {
if ok := bls12381.PubKey(pubKey[:]).
VerifySignature(msg, signature[:]); !ok {
pk, err := bls12381.NewPublicKeyFromBytes(pubKey[:])
if err != nil {
return err
}
if !pk.VerifySignature(msg, signature[:]) {
return ErrInvalidSignature
}
return nil
Expand Down
7 changes: 5 additions & 2 deletions mod/node-core/pkg/components/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ func (f BLSSigner) VerifySignature(
msg []byte,
signature crypto.BLSSignature,
) error {
if ok := bls12381.PubKey(pubKey[:]).
VerifySignature(msg, signature[:]); !ok {
pk, err := bls12381.NewPublicKeyFromBytes(pubKey[:])
if err != nil {
return err
}
if !pk.VerifySignature(msg, signature[:]) {
return ErrInvalidSignature
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion mod/node-core/pkg/components/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
package components

import (
"cosmossdk.io/core/appmodule/v2"
appmodule "cosmossdk.io/core/appmodule/v2"
asynctypes "github.com/berachain/beacon-kit/mod/async/pkg/types"
"github.com/berachain/beacon-kit/mod/consensus-types/pkg/types"
consruntimetypes "github.com/berachain/beacon-kit/mod/consensus/pkg/types"
Expand Down
12 changes: 12 additions & 0 deletions mod/state-transition/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ require (
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.5 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/gogoproto v1.7.0 // indirect
github.com/cosmos/iavl v1.3.1 // indirect
github.com/cosmos/ics23/go v0.11.0 // indirect
Expand All @@ -90,6 +91,8 @@ require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/dvsekhvalnov/jose2go v1.7.0 // indirect
github.com/emicklei/dot v1.6.2 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.6 // indirect
github.com/go-kit/kit v0.13.0 // indirect
Expand All @@ -99,6 +102,7 @@ require (
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.22.0 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand All @@ -108,14 +112,21 @@ require (
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/orderedcode v0.0.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/handlers v1.5.2 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/hashicorp/go-hclog v1.6.3 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-metrics v0.5.3 // indirect
github.com/hashicorp/go-plugin v1.6.2 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/yamux v0.1.2 // indirect
github.com/hdevalence/ed25519consensus v0.2.0 // indirect
github.com/huandu/skiplist v1.2.1 // indirect
github.com/iancoleman/strcase v0.3.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
Expand All @@ -130,6 +141,7 @@ require (
github.com/minio/highwayhash v1.0.3 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7 // indirect
github.com/phuslu/log v1.0.110 // indirect
Expand Down
Loading

0 comments on commit 617db4e

Please sign in to comment.