Skip to content

Commit

Permalink
chore_: move waku interface out of eth-node
Browse files Browse the repository at this point in the history
Waku interface does not belong to eth-node. It has been moved to newly
created `wakuinterface` package.
  • Loading branch information
osmaczko committed Jan 10, 2025
1 parent 4faaa3e commit 5c78c3a
Show file tree
Hide file tree
Showing 81 changed files with 453 additions and 397 deletions.
3 changes: 2 additions & 1 deletion api/geth_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import (
"github.com/status-im/status-go/signal"
"github.com/status-im/status-go/sqlite"
"github.com/status-im/status-go/transactions"
"github.com/status-im/status-go/wakuinterface"
"github.com/status-im/status-go/walletdatabase"
)

Expand Down Expand Up @@ -2669,7 +2670,7 @@ func (b *GethStatusBackend) LocalPairingStarted() error {
return accountDB.MnemonicWasShown()
}

func (b *GethStatusBackend) injectAccountsIntoWakuService(w types.WakuKeyManager, st *ext.Service) error {
func (b *GethStatusBackend) injectAccountsIntoWakuService(w wakuinterface.WakuKeyManager, st *ext.Service) error {
chatAccount, err := b.accountManager.SelectedChatAccount()
if err != nil {
return err
Expand Down
9 changes: 5 additions & 4 deletions eth-node/bridge/geth/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import (
"go.uber.org/zap"

"github.com/status-im/status-go/waku"
"github.com/status-im/status-go/wakuinterface"
"github.com/status-im/status-go/wakuv2"

"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p/enode"

gethens "github.com/status-im/status-go/eth-node/bridge/geth/ens"
"github.com/status-im/status-go/eth-node/types"
gethnode "github.com/status-im/status-go/eth-node/node"
enstypes "github.com/status-im/status-go/eth-node/types/ens"
)

Expand All @@ -22,7 +23,7 @@ type gethNodeWrapper struct {
waku2 *wakuv2.Waku
}

func NewNodeBridge(stack *node.Node, waku1 *waku.Waku, waku2 *wakuv2.Waku) types.Node {
func NewNodeBridge(stack *node.Node, waku1 *waku.Waku, waku2 *wakuv2.Waku) gethnode.Node {
return &gethNodeWrapper{stack: stack, waku1: waku1, waku2: waku2}
}

Expand All @@ -42,15 +43,15 @@ func (w *gethNodeWrapper) SetWaku2(waku *wakuv2.Waku) {
w.waku2 = waku
}

func (w *gethNodeWrapper) GetWaku(ctx interface{}) (types.Waku, error) {
func (w *gethNodeWrapper) GetWaku(ctx interface{}) (wakuinterface.Waku, error) {
if w.waku1 == nil {
return nil, errors.New("waku service is not available")
}

return NewGethWakuWrapper(w.waku1), nil
}

func (w *gethNodeWrapper) GetWakuV2(ctx interface{}) (types.Waku, error) {
func (w *gethNodeWrapper) GetWakuV2(ctx interface{}) (wakuinterface.Waku, error) {
if w.waku2 == nil {
return nil, errors.New("waku service is not available")
}
Expand Down
13 changes: 7 additions & 6 deletions eth-node/bridge/geth/public_waku_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import (
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/waku"
wakucommon "github.com/status-im/status-go/waku/common"
"github.com/status-im/status-go/wakuinterface"
)

type GethPublicWakuAPIWrapper struct {
api *waku.PublicWakuAPI
}

// NewGethPublicWakuAPIWrapper returns an object that wraps Geth's PublicWakuAPI in a types interface
func NewGethPublicWakuAPIWrapper(api *waku.PublicWakuAPI) types.PublicWakuAPI {
func NewGethPublicWakuAPIWrapper(api *waku.PublicWakuAPI) wakuinterface.API {
if api == nil {
panic("PublicWakuAPI cannot be nil")
}
Expand All @@ -42,7 +43,7 @@ func (w *GethPublicWakuAPIWrapper) DeleteKeyPair(ctx context.Context, key string

// NewMessageFilter creates a new filter that can be used to poll for
// (new) messages that satisfy the given criteria.
func (w *GethPublicWakuAPIWrapper) NewMessageFilter(req types.Criteria) (string, error) {
func (w *GethPublicWakuAPIWrapper) NewMessageFilter(req wakuinterface.Criteria) (string, error) {
topics := make([]wakucommon.TopicType, len(req.Topics))
for index, tt := range req.Topics {
topics[index] = wakucommon.TopicType(tt)
Expand All @@ -65,15 +66,15 @@ func (w *GethPublicWakuAPIWrapper) BloomFilter() []byte {

// GetFilterMessages returns the messages that match the filter criteria and
// are received between the last poll and now.
func (w *GethPublicWakuAPIWrapper) GetFilterMessages(id string) ([]*types.Message, error) {
func (w *GethPublicWakuAPIWrapper) GetFilterMessages(id string) ([]*wakuinterface.Message, error) {
msgs, err := w.api.GetFilterMessages(id)
if err != nil {
return nil, err
}

wrappedMsgs := make([]*types.Message, len(msgs))
wrappedMsgs := make([]*wakuinterface.Message, len(msgs))
for index, msg := range msgs {
wrappedMsgs[index] = &types.Message{
wrappedMsgs[index] = &wakuinterface.Message{
Sig: msg.Sig,
TTL: msg.TTL,
Timestamp: msg.Timestamp,
Expand All @@ -91,7 +92,7 @@ func (w *GethPublicWakuAPIWrapper) GetFilterMessages(id string) ([]*types.Messag

// Post posts a message on the network.
// returns the hash of the message in case of success.
func (w *GethPublicWakuAPIWrapper) Post(ctx context.Context, req types.NewMessage) ([]byte, error) {
func (w *GethPublicWakuAPIWrapper) Post(ctx context.Context, req wakuinterface.NewMessage) ([]byte, error) {
msg := waku.NewMessage{
SymKeyID: req.SymKeyID,
PublicKey: req.PublicKey,
Expand Down
13 changes: 7 additions & 6 deletions eth-node/bridge/geth/public_wakuv2_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"

"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/wakuinterface"
"github.com/status-im/status-go/wakuv2"
wakucommon "github.com/status-im/status-go/wakuv2/common"
)
Expand All @@ -15,7 +16,7 @@ type gethPublicWakuV2APIWrapper struct {
}

// NewGethPublicWakuAPIWrapper returns an object that wraps Geth's PublicWakuAPI in a types interface
func NewGethPublicWakuV2APIWrapper(api *wakuv2.PublicWakuAPI) types.PublicWakuAPI {
func NewGethPublicWakuV2APIWrapper(api *wakuv2.PublicWakuAPI) wakuinterface.API {
if api == nil {
panic("PublicWakuV2API cannot be nil")
}
Expand Down Expand Up @@ -46,7 +47,7 @@ func (w *gethPublicWakuV2APIWrapper) BloomFilter() []byte {

// NewMessageFilter creates a new filter that can be used to poll for
// (new) messages that satisfy the given criteria.
func (w *gethPublicWakuV2APIWrapper) NewMessageFilter(req types.Criteria) (string, error) {
func (w *gethPublicWakuV2APIWrapper) NewMessageFilter(req wakuinterface.Criteria) (string, error) {
topics := make([]wakucommon.TopicType, len(req.Topics))
for index, tt := range req.Topics {
topics[index] = wakucommon.TopicType(tt)
Expand All @@ -64,15 +65,15 @@ func (w *gethPublicWakuV2APIWrapper) NewMessageFilter(req types.Criteria) (strin

// GetFilterMessages returns the messages that match the filter criteria and
// are received between the last poll and now.
func (w *gethPublicWakuV2APIWrapper) GetFilterMessages(id string) ([]*types.Message, error) {
func (w *gethPublicWakuV2APIWrapper) GetFilterMessages(id string) ([]*wakuinterface.Message, error) {
msgs, err := w.api.GetFilterMessages(id)
if err != nil {
return nil, err
}

wrappedMsgs := make([]*types.Message, len(msgs))
wrappedMsgs := make([]*wakuinterface.Message, len(msgs))
for index, msg := range msgs {
wrappedMsgs[index] = &types.Message{
wrappedMsgs[index] = &wakuinterface.Message{
Sig: msg.Sig,
Timestamp: msg.Timestamp,
PubsubTopic: msg.PubsubTopic,
Expand All @@ -88,7 +89,7 @@ func (w *gethPublicWakuV2APIWrapper) GetFilterMessages(id string) ([]*types.Mess

// Post posts a message on the network.
// returns the hash of the message in case of success.
func (w *gethPublicWakuV2APIWrapper) Post(ctx context.Context, req types.NewMessage) ([]byte, error) {
func (w *gethPublicWakuV2APIWrapper) Post(ctx context.Context, req wakuinterface.NewMessage) ([]byte, error) {
msg := wakuv2.NewMessage{
SymKeyID: req.SymKeyID,
PublicKey: req.PublicKey,
Expand Down
17 changes: 9 additions & 8 deletions eth-node/bridge/geth/waku.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ import (
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/waku"
wakucommon "github.com/status-im/status-go/waku/common"
"github.com/status-im/status-go/wakuinterface"
)

type GethWakuWrapper struct {
waku *waku.Waku
}

// NewGethWakuWrapper returns an object that wraps Geth's Waku in a types interface
func NewGethWakuWrapper(w *waku.Waku) types.Waku {
func NewGethWakuWrapper(w *waku.Waku) wakuinterface.Waku {
if w == nil {
panic("waku cannot be nil")
}
Expand All @@ -36,11 +37,11 @@ func NewGethWakuWrapper(w *waku.Waku) types.Waku {
}

// GetGethWhisperFrom retrieves the underlying whisper Whisper struct from a wrapped Whisper interface
func GetGethWakuFrom(m types.Waku) *waku.Waku {
func GetGethWakuFrom(m wakuinterface.Waku) *waku.Waku {
return m.(*GethWakuWrapper).waku
}

func (w *GethWakuWrapper) PublicWakuAPI() types.PublicWakuAPI {
func (w *GethWakuWrapper) PublicWakuAPI() wakuinterface.API {
return NewGethPublicWakuAPIWrapper(waku.NewPublicWakuAPI(w.waku))
}

Expand Down Expand Up @@ -114,7 +115,7 @@ func (w *GethWakuWrapper) ListenAddresses() ([]multiaddr.Multiaddr, error) {
return nil, errors.New("not available in WakuV1")
}

func (w *GethWakuWrapper) RelayPeersByTopic(topic string) (*types.PeerList, error) {
func (w *GethWakuWrapper) RelayPeersByTopic(topic string) (*wakuinterface.PeerList, error) {
return nil, errors.New("not available in WakuV1")
}

Expand All @@ -128,7 +129,7 @@ func (w *GethWakuWrapper) DropPeer(peerID peer.ID) error {
return errors.New("not available in WakuV1")
}

func (w *GethWakuWrapper) SubscribeToConnStatusChanges() (*types.ConnStatusSubscription, error) {
func (w *GethWakuWrapper) SubscribeToConnStatusChanges() (*wakuinterface.ConnStatusSubscription, error) {
return nil, errors.New("not available in WakuV1")
}

Expand All @@ -137,8 +138,8 @@ func (w *GethWakuWrapper) SetCriteriaForMissingMessageVerification(peerID peer.I
}

// Peers function only added for compatibility with waku V2
func (w *GethWakuWrapper) Peers() types.PeerStats {
p := make(types.PeerStats)
func (w *GethWakuWrapper) Peers() wakuinterface.PeerStats {
p := make(wakuinterface.PeerStats)
return p
}

Expand Down Expand Up @@ -342,7 +343,7 @@ func (w *GethWakuWrapper) SetStorenodeConfigProvider(c history.StorenodeConfigPr

func (w *GethWakuWrapper) ProcessMailserverBatch(
ctx context.Context,
batch types.MailserverBatch,
batch wakuinterface.MailserverBatch,
storenodeID peer.ID,
pageLimit uint64,
shouldProcessNextPage func(int) (bool, uint64),
Expand Down
15 changes: 8 additions & 7 deletions eth-node/bridge/geth/wakuv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
gocommon "github.com/status-im/status-go/common"
"github.com/status-im/status-go/connection"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/wakuinterface"
"github.com/status-im/status-go/wakuv2"
wakucommon "github.com/status-im/status-go/wakuv2/common"
)
Expand All @@ -28,7 +29,7 @@ type gethWakuV2Wrapper struct {
}

// NewGethWakuWrapper returns an object that wraps Geth's Waku in a types interface
func NewGethWakuV2Wrapper(w *wakuv2.Waku) types.Waku {
func NewGethWakuV2Wrapper(w *wakuv2.Waku) wakuinterface.Waku {
if w == nil {
panic("waku cannot be nil")
}
Expand All @@ -39,11 +40,11 @@ func NewGethWakuV2Wrapper(w *wakuv2.Waku) types.Waku {
}

// GetGethWhisperFrom retrieves the underlying whisper Whisper struct from a wrapped Whisper interface
func GetGethWakuV2From(m types.Waku) *wakuv2.Waku {
func GetGethWakuV2From(m wakuinterface.Waku) *wakuv2.Waku {
return m.(*gethWakuV2Wrapper).waku
}

func (w *gethWakuV2Wrapper) PublicWakuAPI() types.PublicWakuAPI {
func (w *gethWakuV2Wrapper) PublicWakuAPI() wakuinterface.API {
return NewGethPublicWakuV2APIWrapper(wakuv2.NewPublicWakuAPI(w.waku))
}

Expand Down Expand Up @@ -214,7 +215,7 @@ func (w *gethWakuV2Wrapper) AddRelayPeer(address multiaddr.Multiaddr) (peer.ID,
return w.waku.AddRelayPeer(address)
}

func (w *gethWakuV2Wrapper) Peers() types.PeerStats {
func (w *gethWakuV2Wrapper) Peers() wakuinterface.PeerStats {
return w.waku.Peers()
}

Expand All @@ -230,7 +231,7 @@ func (w *gethWakuV2Wrapper) ListenAddresses() ([]multiaddr.Multiaddr, error) {
return w.waku.ListenAddresses(), nil
}

func (w *gethWakuV2Wrapper) RelayPeersByTopic(topic string) (*types.PeerList, error) {
func (w *gethWakuV2Wrapper) RelayPeersByTopic(topic string) (*wakuinterface.PeerList, error) {
return w.waku.RelayPeersByTopic(topic)
}

Expand All @@ -250,7 +251,7 @@ func (w *gethWakuV2Wrapper) MarkP2PMessageAsProcessed(hash common.Hash) {
w.waku.MarkP2PMessageAsProcessed(hash)
}

func (w *gethWakuV2Wrapper) SubscribeToConnStatusChanges() (*types.ConnStatusSubscription, error) {
func (w *gethWakuV2Wrapper) SubscribeToConnStatusChanges() (*wakuinterface.ConnStatusSubscription, error) {
return w.waku.SubscribeToConnStatusChanges(), nil
}

Expand Down Expand Up @@ -336,7 +337,7 @@ func (w *gethWakuV2Wrapper) SetStorenodeConfigProvider(c history.StorenodeConfig

func (w *gethWakuV2Wrapper) ProcessMailserverBatch(
ctx context.Context,
batch types.MailserverBatch,
batch wakuinterface.MailserverBatch,
storenodeID peer.ID,
pageLimit uint64,
shouldProcessNextPage func(int) (bool, uint64),
Expand Down
17 changes: 17 additions & 0 deletions eth-node/node/node.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package gethnode

import (
"go.uber.org/zap"

enstypes "github.com/status-im/status-go/eth-node/types/ens"
"github.com/status-im/status-go/wakuinterface"
)

type Node interface {
NewENSVerifier(logger *zap.Logger) enstypes.ENSVerifier
GetWaku(ctx interface{}) (wakuinterface.Waku, error)
GetWakuV2(ctx interface{}) (wakuinterface.Waku, error)
AddPeer(url string) error
RemovePeer(url string) error
PeersCount() int
}
13 changes: 0 additions & 13 deletions eth-node/types/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ package types

import (
"fmt"

"go.uber.org/zap"

enstypes "github.com/status-im/status-go/eth-node/types/ens"
)

// EnodeID is a unique identifier for each node.
Expand All @@ -15,12 +11,3 @@ type EnodeID [32]byte
func (n EnodeID) String() string {
return fmt.Sprintf("%x", n[:])
}

type Node interface {
NewENSVerifier(logger *zap.Logger) enstypes.ENSVerifier
GetWaku(ctx interface{}) (Waku, error)
GetWakuV2(ctx interface{}) (Waku, error)
AddPeer(url string) error
RemovePeer(url string) error
PeersCount() int
}
Loading

0 comments on commit 5c78c3a

Please sign in to comment.