Skip to content

Commit

Permalink
refactor_: start using nwaku
Browse files Browse the repository at this point in the history
- some minor progress to add nwaku in status-go
- nwaku.go: GetNumConnectedPeers controls when passed pubsub is empty
- waku_test.go: adapt TestWakuV2Store
- add missing shard.go
- feat_: build nwaku with nix and use build tags to choose between go-waku and nwaku (#5896)
- chore_: update nwaku
- nwaku bump (#5911)
- bump: nwaku
- chore: add USE_NWAKU env flag
- fix: build libwaku only if needed
- feat: testing discovery and dialing with nwaku integration (#5940)
- message publisher and sent verifier (#5966)
- storenode requestor for missing message retrieval and result iterator impl (#5971)
- uncomment code that would allow status-go/go-waku to compile and libwaku test to run (#5986)
- supporting peer exchange with nwaku (#5983)
- store queries
- ping
- ping storenodes using AddrInfo (#6004)
- dial, drop and retrieve connected peers  (#6013)
- integrate on-demand DNS discovery and implement discoverAndConnectPeers (#6017)
- extract libwaku calls into WakuNode struct (#6027)
- async nwaku
- remove nwaku process loop
- receive messages via relay (#6185)
- extract timeout from context
- use correct port field, get free ports and uncomment some functions (#6200)
- enable filter/lightpush/px and setup rate limits
- add protected topics
  • Loading branch information
Ivansete-status authored and richard-ramos committed Dec 18, 2024
1 parent 38043d3 commit 77ba191
Show file tree
Hide file tree
Showing 80 changed files with 5,305 additions and 410 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ coverage.html
Session.vim
.undodir/*
/.idea/
/.vscode/
/cmd/*/.ethereum/
*.iml

Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "third_party/nwaku"]
path = third_party/nwaku
url = https://github.com/waku-org/nwaku
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@
"cSpell.words": [
"unmarshalling"
],
"gopls":{
"buildFlags": ["-tags=use_nwaku,gowaku_skip_migrations,gowaku_no_rln"]
}
}
49 changes: 47 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.PHONY: statusgo statusd-prune all test clean help
.PHONY: statusgo-android statusgo-ios
.PHONY: build-libwaku test-libwaku clean-libwaku rebuild-libwaku

# Clear any GOROOT set outside of the Nix shell
export GOROOT=
Expand Down Expand Up @@ -61,6 +62,10 @@ GIT_AUTHOR ?= $(shell git config user.email || echo $$USER)
ENABLE_METRICS ?= true
BUILD_TAGS ?= gowaku_no_rln

ifeq ($(USE_NWAKU), true)
BUILD_TAGS += use_nwaku
endif

BUILD_FLAGS ?= -ldflags="-X github.com/status-im/status-go/params.Version=$(RELEASE_TAG:v%=%) \
-X github.com/status-im/status-go/params.GitCommit=$(GIT_COMMIT) \
-X github.com/status-im/status-go/params.IpfsGatewayURL=$(IPFS_GATEWAY_URL) \
Expand Down Expand Up @@ -240,8 +245,19 @@ statusgo-library: ##@cross-compile Build status-go as static library for current
@echo "Static library built:"
@ls -la build/bin/libstatus.*

statusgo-shared-library: generate
statusgo-shared-library: ##@cross-compile Build status-go as shared library for current platform

LIBWAKU := third_party/nwaku/build/libwaku.$(GOBIN_SHARED_LIB_EXT)
$(LIBWAKU):
@echo "Building libwaku"
$(MAKE) -C third_party/nwaku update || { echo "nwaku make update failed"; exit 1; }
$(MAKE) -C ./third_party/nwaku libwaku

build-libwaku: $(LIBWAKU)

statusgo-shared-library: generate ##@cross-compile Build status-go as shared library for current platform
ifeq ($(USE_NWAKU),true)
$(MAKE) $(LIBWAKU)
endif
## cmd/library/README.md explains the magic incantation behind this
mkdir -p build/bin/statusgo-lib
go run cmd/library/*.go > build/bin/statusgo-lib/main.go
Expand Down Expand Up @@ -362,9 +378,38 @@ lint-fix:
-w {} \;
$(MAKE) vendor

mock: ##@other Regenerate mocks
mockgen -package=fake -destination=transactions/fake/mock.go -source=transactions/fake/txservice.go
mockgen -package=status -destination=services/status/account_mock.go -source=services/status/service.go
mockgen -package=peer -destination=services/peer/discoverer_mock.go -source=services/peer/service.go
mockgen -package=mock_transactor -destination=transactions/mock_transactor/transactor.go -source=transactions/transactor.go
mockgen -package=mock_pathprocessor -destination=services/wallet/router/pathprocessor/mock_pathprocessor/processor.go -source=services/wallet/router/pathprocessor/processor.go
mockgen -package=mock_bridge -destination=services/wallet/bridge/mock_bridge/bridge.go -source=services/wallet/bridge/bridge.go
mockgen -package=mock_client -destination=rpc/chain/mock/client/client.go -source=rpc/chain/client.go
mockgen -package=mock_token -destination=services/wallet/token/mock/token/tokenmanager.go -source=services/wallet/token/token.go
mockgen -package=mock_thirdparty -destination=services/wallet/thirdparty/mock/types.go -source=services/wallet/thirdparty/types.go
mockgen -package=mock_balance_persistence -destination=services/wallet/token/mock/balance_persistence/balance_persistence.go -source=services/wallet/token/balance_persistence.go
mockgen -package=mock_network -destination=rpc/network/mock/network.go -source=rpc/network/network.go
mockgen -package=mock_rpcclient -destination=rpc/mock/client/client.go -source=rpc/client.go
mockgen -package=mock_collectibles -destination=services/wallet/collectibles/mock/collection_data_db.go -source=services/wallet/collectibles/collection_data_db.go
mockgen -package=mock_collectibles -destination=services/wallet/collectibles/mock/collectible_data_db.go -source=services/wallet/collectibles/collectible_data_db.go
mockgen -package=mock_thirdparty -destination=services/wallet/thirdparty/mock/collectible_types.go -source=services/wallet/thirdparty/collectible_types.go
mockgen -package=mock_paraswap -destination=services/wallet/thirdparty/paraswap/mock/types.go -source=services/wallet/thirdparty/paraswap/types.go
mockgen -package=mock_onramp -destination=services/wallet/onramp/mock/types.go -source=services/wallet/onramp/types.go


docker-test: ##@tests Run tests in a docker container with golang.
docker run --privileged --rm -it -v "$(PWD):$(DOCKER_TEST_WORKDIR)" -w "$(DOCKER_TEST_WORKDIR)" $(DOCKER_TEST_IMAGE) go test ${ARGS}

test-libwaku: | $(LIBWAKU)
go test -tags '$(BUILD_TAGS) use_nwaku' -run TestBasicWakuV2 ./wakuv2/... -count 1 -v -json | jq -r '.Output'

clean-libwaku:
@echo "Removing libwaku"
rm $(LIBWAKU)

rebuild-libwaku: | clean-libwaku $(LIBWAKU)

test: test-unit ##@tests Run basic, short tests during development

test-unit-prep: generate
Expand Down
10 changes: 5 additions & 5 deletions cmd/ping-community/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ import (
"github.com/status-im/status-go/multiaccounts"
"github.com/status-im/status-go/multiaccounts/accounts"
"github.com/status-im/status-go/multiaccounts/settings"
"github.com/status-im/status-go/wakuv2"

"github.com/status-im/status-go/logutils"
"github.com/status-im/status-go/params"
"github.com/status-im/status-go/protocol"
"github.com/status-im/status-go/protocol/common"
"github.com/status-im/status-go/protocol/common/shard"
"github.com/status-im/status-go/protocol/identity/alias"
"github.com/status-im/status-go/protocol/protobuf"
wakuextn "github.com/status-im/status-go/services/wakuext"
Expand All @@ -48,8 +48,8 @@ var (
seedPhrase = flag.String("seed-phrase", "", "Seed phrase")
version = flag.Bool("version", false, "Print version and dump configuration")
communityID = flag.String("community-id", "", "The id of the community")
shardCluster = flag.Int("shard-cluster", shard.MainStatusShardCluster, "The shard cluster in which the of the community is published")
shardIndex = flag.Int("shard-index", shard.DefaultShardIndex, "The shard index in which the community is published")
shardCluster = flag.Int("shard-cluster", wakuv2.MainStatusShardCluster, "The shard cluster in which the of the community is published")
shardIndex = flag.Int("shard-index", wakuv2.DefaultShardIndex, "The shard index in which the community is published")
chatID = flag.String("chat-id", "", "The id of the chat")

dataDir = flag.String("dir", getDefaultDataDir(), "Directory used by node to store data")
Expand Down Expand Up @@ -148,9 +148,9 @@ func main() {

messenger := wakuextservice.Messenger()

var s *shard.Shard = nil
var s *wakuv2.Shard = nil
if shardCluster != nil && shardIndex != nil {
s = &shard.Shard{
s = &wakuv2.Shard{
Cluster: uint16(*shardCluster),
Index: uint16(*shardIndex),
}
Expand Down
5 changes: 0 additions & 5 deletions eth-node/bridge/geth/waku.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ func (w *GethWakuWrapper) StopDiscV5() error {
return errors.New("not available in WakuV1")
}

// PeerCount function only added for compatibility with waku V2
func (w *GethWakuWrapper) AddStorePeer(address multiaddr.Multiaddr) (peer.ID, error) {
return "", errors.New("not available in WakuV1")
}

// SubscribeToPubsubTopic function only added for compatibility with waku V2
func (w *GethWakuWrapper) SubscribeToPubsubTopic(topic string, optPublicKey *ecdsa.PublicKey) error {
// not available in WakuV1
Expand Down
10 changes: 4 additions & 6 deletions eth-node/bridge/geth/wakuv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,6 @@ func (w *gethWakuV2Wrapper) RemovePubsubTopicKey(topic string) error {
return w.waku.RemovePubsubTopicKey(topic)
}

func (w *gethWakuV2Wrapper) AddStorePeer(address multiaddr.Multiaddr) (peer.ID, error) {
return w.waku.AddStorePeer(address)
}

func (w *gethWakuV2Wrapper) AddRelayPeer(address multiaddr.Multiaddr) (peer.ID, error) {
return w.waku.AddRelayPeer(address)
}
Expand All @@ -227,7 +223,7 @@ func (w *gethWakuV2Wrapper) DialPeerByID(peerID peer.ID) error {
}

func (w *gethWakuV2Wrapper) ListenAddresses() ([]multiaddr.Multiaddr, error) {
return w.waku.ListenAddresses(), nil
return w.waku.ListenAddresses()
}

func (w *gethWakuV2Wrapper) RelayPeersByTopic(topic string) (*types.PeerList, error) {
Expand Down Expand Up @@ -331,7 +327,9 @@ func (w *gethWakuV2Wrapper) OnStorenodeAvailable() <-chan peer.ID {
}

func (w *gethWakuV2Wrapper) WaitForAvailableStoreNode(timeout time.Duration) bool {
return w.waku.StorenodeCycle.WaitForAvailableStoreNode(context.TODO(), timeout)
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
return w.waku.StorenodeCycle.WaitForAvailableStoreNode(ctx)
}

func (w *gethWakuV2Wrapper) SetStorenodeConfigProvider(c history.StorenodeConfigProvider) {
Expand Down
2 changes: 0 additions & 2 deletions eth-node/types/waku.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ type Waku interface {

RemovePubsubTopicKey(topic string) error

AddStorePeer(address multiaddr.Multiaddr) (peer.ID, error)

AddRelayPeer(address multiaddr.Multiaddr) (peer.ID, error)

DialPeer(address multiaddr.Multiaddr) error
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ require (
github.com/schollz/peerdiscovery v1.7.0
github.com/siphiuel/lc-proxy-wrapper v0.0.0-20230516150924-246507cee8c7
github.com/urfave/cli/v2 v2.27.2
github.com/waku-org/go-waku v0.8.1-0.20241015194815-37f936d74705
github.com/waku-org/go-waku v0.8.1-0.20241028194639-dd82c24e0057
github.com/wk8/go-ordered-map/v2 v2.1.7
github.com/yeqown/go-qrcode/v2 v2.2.1
github.com/yeqown/go-qrcode/writer/standard v1.2.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2140,8 +2140,8 @@ github.com/waku-org/go-libp2p-pubsub v0.12.0-gowaku.0.20240823143342-b0f2429ca27
github.com/waku-org/go-libp2p-pubsub v0.12.0-gowaku.0.20240823143342-b0f2429ca27f/go.mod h1:Oi0zw9aw8/Y5GC99zt+Ef2gYAl+0nZlwdJonDyOz/sE=
github.com/waku-org/go-libp2p-rendezvous v0.0.0-20240110193335-a67d1cc760a0 h1:R4YYx2QamhBRl/moIxkDCNW+OP7AHbyWLBygDc/xIMo=
github.com/waku-org/go-libp2p-rendezvous v0.0.0-20240110193335-a67d1cc760a0/go.mod h1:EhZP9fee0DYjKH/IOQvoNSy1tSHp2iZadsHGphcAJgY=
github.com/waku-org/go-waku v0.8.1-0.20241015194815-37f936d74705 h1:i1vIOgWIQn0jing5jxqO9rG676jPoShiTLknE/pRaWc=
github.com/waku-org/go-waku v0.8.1-0.20241015194815-37f936d74705/go.mod h1:1BRnyg2mQ2aBNLTBaPq6vEvobzywGykPOhGQFbHGf74=
github.com/waku-org/go-waku v0.8.1-0.20241028194639-dd82c24e0057 h1:C/UCg3Z4avOxvZEvY0JzYmeAoqZUBnSE6PK/SaxfEAM=
github.com/waku-org/go-waku v0.8.1-0.20241028194639-dd82c24e0057/go.mod h1:1BRnyg2mQ2aBNLTBaPq6vEvobzywGykPOhGQFbHGf74=
github.com/waku-org/go-zerokit-rln v0.1.14-0.20240102145250-fa738c0bdf59 h1:jisj+OCI6QydLtFq3Pyhu49wl9ytPN7oAHjMfepHDrA=
github.com/waku-org/go-zerokit-rln v0.1.14-0.20240102145250-fa738c0bdf59/go.mod h1:1PdBdPzyTaKt3VnpAHk3zj+r9dXPFOr3IHZP9nFle6E=
github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230916172309-ee0ee61dde2b h1:KgZVhsLkxsj5gb/FfndSCQu6VYwALrCOgYI3poR95yE=
Expand Down
2 changes: 1 addition & 1 deletion nix/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ in mkShell {

buildInputs = with pkgs; [
git jq which
go golangci-lint go-junit-report gopls go-bindata gomobileMod codecov-cli go-generate-fast
go golangci-lint go-junit-report gopls go-bindata gomobileMod codecov-cli go-generate-fast openssl
mockgen protobuf3_20 protoc-gen-go gotestsum go-modvendor openjdk cc-test-reporter
] ++ lib.optionals (stdenv.isDarwin) [ xcodeWrapper ];

Expand Down
3 changes: 1 addition & 2 deletions node/status_node_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"go.uber.org/zap"

"github.com/status-im/status-go/protocol/common/shard"
"github.com/status-im/status-go/server"
"github.com/status-im/status-go/signal"
"github.com/status-im/status-go/transactions"
Expand Down Expand Up @@ -338,7 +337,7 @@ func (b *StatusNode) wakuV2Service(nodeConfig *params.NodeConfig) (*wakuv2.Waku,
Nameserver: nodeConfig.WakuV2Config.Nameserver,
UDPPort: nodeConfig.WakuV2Config.UDPPort,
AutoUpdate: nodeConfig.WakuV2Config.AutoUpdate,
DefaultShardPubsubTopic: shard.DefaultShardPubsubTopic(),
DefaultShardPubsubTopic: wakuv2.DefaultShardPubsubTopic(),
TelemetryServerURL: nodeConfig.WakuV2Config.TelemetryServerURL,
ClusterID: nodeConfig.ClusterConfig.ClusterID,
EnableMissingMessageVerification: nodeConfig.WakuV2Config.EnableMissingMessageVerification,
Expand Down
10 changes: 5 additions & 5 deletions protocol/communities/community.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import (
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/images"
"github.com/status-im/status-go/protocol/common"
"github.com/status-im/status-go/protocol/common/shard"
community_token "github.com/status-im/status-go/protocol/communities/token"
"github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/protocol/requests"
"github.com/status-im/status-go/protocol/v1"
"github.com/status-im/status-go/server"
"github.com/status-im/status-go/wakuv2"
)

const signatureLength = 65
Expand All @@ -55,7 +55,7 @@ type Config struct {
RequestsToJoin []*RequestToJoin
MemberIdentity *ecdsa.PrivateKey
EventsData *EventsData
Shard *shard.Shard
Shard *wakuv2.Shard
PubsubTopicPrivateKey *ecdsa.PrivateKey
LastOpenedAt int64
}
Expand Down Expand Up @@ -172,7 +172,7 @@ func (o *Community) MarshalPublicAPIJSON() ([]byte, error) {
ActiveMembersCount uint64 `json:"activeMembersCount"`
PubsubTopic string `json:"pubsubTopic"`
PubsubTopicKey string `json:"pubsubTopicKey"`
Shard *shard.Shard `json:"shard"`
Shard *wakuv2.Shard `json:"shard"`
}{
ID: o.ID(),
Verified: o.config.Verified,
Expand Down Expand Up @@ -308,7 +308,7 @@ func (o *Community) MarshalJSON() ([]byte, error) {
ActiveMembersCount uint64 `json:"activeMembersCount"`
PubsubTopic string `json:"pubsubTopic"`
PubsubTopicKey string `json:"pubsubTopicKey"`
Shard *shard.Shard `json:"shard"`
Shard *wakuv2.Shard `json:"shard"`
LastOpenedAt int64 `json:"lastOpenedAt"`
Clock uint64 `json:"clock"`
}{
Expand Down Expand Up @@ -461,7 +461,7 @@ func (o *Community) DescriptionText() string {
return ""
}

func (o *Community) Shard() *shard.Shard {
func (o *Community) Shard() *wakuv2.Shard {
if o != nil && o.config != nil {
return o.config.Shard
}
Expand Down
22 changes: 11 additions & 11 deletions protocol/communities/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
multiaccountscommon "github.com/status-im/status-go/multiaccounts/common"
"github.com/status-im/status-go/params"
"github.com/status-im/status-go/protocol/common"
"github.com/status-im/status-go/protocol/common/shard"
community_token "github.com/status-im/status-go/protocol/communities/token"
"github.com/status-im/status-go/protocol/encryption"
"github.com/status-im/status-go/protocol/ens"
Expand All @@ -45,6 +44,7 @@ import (
"github.com/status-im/status-go/services/wallet/token"
"github.com/status-im/status-go/signal"
"github.com/status-im/status-go/transactions"
"github.com/status-im/status-go/wakuv2"
)

type Publisher interface {
Expand Down Expand Up @@ -740,8 +740,8 @@ func (m *Manager) All() ([]*Community, error) {
}

type CommunityShard struct {
CommunityID string `json:"communityID"`
Shard *shard.Shard `json:"shard"`
CommunityID string `json:"communityID"`
Shard *wakuv2.Shard `json:"shard"`
}

type CuratedCommunities struct {
Expand Down Expand Up @@ -1549,7 +1549,7 @@ func (m *Manager) DeleteCommunity(id types.HexBytes) error {
return m.persistence.DeleteCommunitySettings(id)
}

func (m *Manager) updateShard(community *Community, shard *shard.Shard, clock uint64) error {
func (m *Manager) updateShard(community *Community, shard *wakuv2.Shard, clock uint64) error {
community.config.Shard = shard
if shard == nil {
return m.persistence.DeleteCommunityShard(community.ID())
Expand All @@ -1558,15 +1558,15 @@ func (m *Manager) updateShard(community *Community, shard *shard.Shard, clock ui
return m.persistence.SaveCommunityShard(community.ID(), shard, clock)
}

func (m *Manager) UpdateShard(community *Community, shard *shard.Shard, clock uint64) error {
func (m *Manager) UpdateShard(community *Community, shard *wakuv2.Shard, clock uint64) error {
m.communityLock.Lock(community.ID())
defer m.communityLock.Unlock(community.ID())

return m.updateShard(community, shard, clock)
}

// SetShard assigns a shard to a community
func (m *Manager) SetShard(communityID types.HexBytes, shard *shard.Shard) (*Community, error) {
func (m *Manager) SetShard(communityID types.HexBytes, shard *wakuv2.Shard) (*Community, error) {
m.communityLock.Lock(communityID)
defer m.communityLock.Unlock(communityID)

Expand Down Expand Up @@ -2164,11 +2164,11 @@ func (m *Manager) HandleCommunityDescriptionMessage(signer *ecdsa.PublicKey, des
if err != nil {
return nil, err
}
var cShard *shard.Shard
var cShard *wakuv2.Shard
if communityShard == nil {
cShard = &shard.Shard{Cluster: shard.MainStatusShardCluster, Index: shard.DefaultShardIndex}
cShard = &wakuv2.Shard{Cluster: wakuv2.MainStatusShardCluster, Index: wakuv2.DefaultShardIndex}
} else {
cShard = shard.FromProtobuff(communityShard)
cShard = wakuv2.FromProtobuff(communityShard)
}
config := Config{
CommunityDescription: processedDescription,
Expand Down Expand Up @@ -3946,11 +3946,11 @@ func (m *Manager) GetByIDString(idString string) (*Community, error) {
return m.GetByID(id)
}

func (m *Manager) GetCommunityShard(communityID types.HexBytes) (*shard.Shard, error) {
func (m *Manager) GetCommunityShard(communityID types.HexBytes) (*wakuv2.Shard, error) {
return m.persistence.GetCommunityShard(communityID)
}

func (m *Manager) SaveCommunityShard(communityID types.HexBytes, shard *shard.Shard, clock uint64) error {
func (m *Manager) SaveCommunityShard(communityID types.HexBytes, shard *wakuv2.Shard, clock uint64) error {
m.communityLock.Lock(communityID)
defer m.communityLock.Unlock(communityID)

Expand Down
Loading

0 comments on commit 77ba191

Please sign in to comment.