Skip to content

Commit ac519a1

Browse files
Ivansete-statusrichard-ramos
authored andcommitted
refactor_: start using nwaku
- 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)
1 parent 97f4c6e commit ac519a1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3663
-190
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ coverage.html
6464
Session.vim
6565
.undodir/*
6666
/.idea/
67-
/.vscode/
6867
/cmd/*/.ethereum/
6968
*.iml
7069

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "third_party/nwaku"]
2+
path = third_party/nwaku
3+
url = https://github.com/waku-org/nwaku

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@
88
"cSpell.words": [
99
"unmarshalling"
1010
],
11+
"gopls":{
12+
"buildFlags": ["-tags=use_nwaku,gowaku_skip_migrations,gowaku_no_rln"]
13+
}
1114
}

Makefile

+27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.PHONY: statusgo statusd-prune all test clean help
22
.PHONY: statusgo-android statusgo-ios
3+
.PHONY: build-libwaku test-libwaku clean-libwaku rebuild-libwaku
34

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

65+
ifeq ($(USE_NWAKU), true)
66+
BUILD_TAGS += use_nwaku
67+
endif
68+
6469
BUILD_FLAGS ?= -ldflags="-X github.com/status-im/status-go/params.Version=$(RELEASE_TAG:v%=%) \
6570
-X github.com/status-im/status-go/params.GitCommit=$(GIT_COMMIT) \
6671
-X github.com/status-im/status-go/params.IpfsGatewayURL=$(IPFS_GATEWAY_URL) \
@@ -221,7 +226,19 @@ statusgo-library: ##@cross-compile Build status-go as static library for current
221226
@echo "Static library built:"
222227
@ls -la build/bin/libstatus.*
223228

229+
230+
LIBWAKU := third_party/nwaku/build/libwaku.$(GOBIN_SHARED_LIB_EXT)
231+
$(LIBWAKU):
232+
@echo "Building libwaku"
233+
$(MAKE) -C third_party/nwaku update || { echo "nwaku make update failed"; exit 1; }
234+
$(MAKE) -C ./third_party/nwaku libwaku
235+
236+
build-libwaku: $(LIBWAKU)
237+
224238
statusgo-shared-library: ##@cross-compile Build status-go as shared library for current platform
239+
ifeq ($(USE_NWAKU),true)
240+
$(MAKE) $(LIBWAKU)
241+
endif
225242
## cmd/library/README.md explains the magic incantation behind this
226243
mkdir -p build/bin/statusgo-lib
227244
go run cmd/library/*.go > build/bin/statusgo-lib/main.go
@@ -355,9 +372,19 @@ mock: ##@other Regenerate mocks
355372
mockgen -package=mock_paraswap -destination=services/wallet/thirdparty/paraswap/mock/types.go -source=services/wallet/thirdparty/paraswap/types.go
356373
mockgen -package=mock_onramp -destination=services/wallet/onramp/mock/types.go -source=services/wallet/onramp/types.go
357374

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

379+
test-libwaku: | $(LIBWAKU)
380+
go test -tags '$(BUILD_TAGS) use_nwaku' -run TestBasicWakuV2 ./wakuv2/... -count 1 -v -json | jq -r '.Output'
381+
382+
clean-libwaku:
383+
@echo "Removing libwaku"
384+
rm $(LIBWAKU)
385+
386+
rebuild-libwaku: | clean-libwaku $(LIBWAKU)
387+
361388
test: test-unit ##@tests Run basic, short tests during development
362389

363390
test-unit: export BUILD_TAGS ?=

cmd/ping-community/main.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ import (
2424
"github.com/status-im/status-go/multiaccounts"
2525
"github.com/status-im/status-go/multiaccounts/accounts"
2626
"github.com/status-im/status-go/multiaccounts/settings"
27+
"github.com/status-im/status-go/wakuv2"
2728

2829
"github.com/status-im/status-go/logutils"
2930
"github.com/status-im/status-go/params"
3031
"github.com/status-im/status-go/protocol"
3132
"github.com/status-im/status-go/protocol/common"
32-
"github.com/status-im/status-go/protocol/common/shard"
3333
"github.com/status-im/status-go/protocol/identity/alias"
3434
"github.com/status-im/status-go/protocol/protobuf"
3535
wakuextn "github.com/status-im/status-go/services/wakuext"
@@ -48,8 +48,8 @@ var (
4848
seedPhrase = flag.String("seed-phrase", "", "Seed phrase")
4949
version = flag.Bool("version", false, "Print version and dump configuration")
5050
communityID = flag.String("community-id", "", "The id of the community")
51-
shardCluster = flag.Int("shard-cluster", shard.MainStatusShardCluster, "The shard cluster in which the of the community is published")
52-
shardIndex = flag.Int("shard-index", shard.DefaultShardIndex, "The shard index in which the community is published")
51+
shardCluster = flag.Int("shard-cluster", wakuv2.MainStatusShardCluster, "The shard cluster in which the of the community is published")
52+
shardIndex = flag.Int("shard-index", wakuv2.DefaultShardIndex, "The shard index in which the community is published")
5353
chatID = flag.String("chat-id", "", "The id of the chat")
5454

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

149149
messenger := wakuextservice.Messenger()
150150

151-
var s *shard.Shard = nil
151+
var s *wakuv2.Shard = nil
152152
if shardCluster != nil && shardIndex != nil {
153-
s = &shard.Shard{
153+
s = &wakuv2.Shard{
154154
Cluster: uint16(*shardCluster),
155155
Index: uint16(*shardIndex),
156156
}

eth-node/bridge/geth/wakuv2.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ func (w *gethWakuV2Wrapper) DialPeerByID(peerID peer.ID) error {
275275
}
276276

277277
func (w *gethWakuV2Wrapper) ListenAddresses() ([]multiaddr.Multiaddr, error) {
278-
return w.waku.ListenAddresses(), nil
278+
return w.waku.ListenAddresses()
279279
}
280280

281281
func (w *gethWakuV2Wrapper) RelayPeersByTopic(topic string) (*types.PeerList, error) {

nix/shell.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ in pkgs.mkShell {
2121

2222
buildInputs = with pkgs; [
2323
git jq which
24-
go golangci-lint go-junit-report gopls go-bindata gomobileMod
24+
go golangci-lint go-junit-report gopls go-bindata gomobileMod openssl
2525
mockgen protobuf3_20 protoc-gen-go gotestsum go-modvendor openjdk cc-test-reporter
2626
] ++ lib.optionals (stdenv.isDarwin) [ xcodeWrapper ];
2727

node/get_status_node.go

+13-12
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,19 @@ type StatusNode struct {
119119
localNotificationsSrvc *localnotifications.Service
120120
personalSrvc *personal.Service
121121
timeSourceSrvc *timesource.NTPTimeSource
122-
wakuSrvc *waku.Waku
123-
wakuExtSrvc *wakuext.Service
124-
wakuV2Srvc *wakuv2.Waku
125-
wakuV2ExtSrvc *wakuv2ext.Service
126-
ensSrvc *ens.Service
127-
communityTokensSrvc *communitytokens.Service
128-
gifSrvc *gif.Service
129-
stickersSrvc *stickers.Service
130-
chatSrvc *chat.Service
131-
updatesSrvc *updates.Service
132-
pendingTracker *transactions.PendingTxTracker
133-
connectorSrvc *connector.Service
122+
// nwakuSrvc *
123+
wakuSrvc *waku.Waku
124+
wakuExtSrvc *wakuext.Service
125+
wakuV2Srvc *wakuv2.Waku
126+
wakuV2ExtSrvc *wakuv2ext.Service
127+
ensSrvc *ens.Service
128+
communityTokensSrvc *communitytokens.Service
129+
gifSrvc *gif.Service
130+
stickersSrvc *stickers.Service
131+
chatSrvc *chat.Service
132+
updatesSrvc *updates.Service
133+
pendingTracker *transactions.PendingTxTracker
134+
connectorSrvc *connector.Service
134135

135136
walletFeed event.Feed
136137
}

node/status_node_services.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"reflect"
1111
"time"
1212

13-
"github.com/status-im/status-go/protocol/common/shard"
1413
"github.com/status-im/status-go/server"
1514
"github.com/status-im/status-go/signal"
1615
"github.com/status-im/status-go/transactions"
@@ -333,7 +332,7 @@ func (b *StatusNode) wakuV2Service(nodeConfig *params.NodeConfig) (*wakuv2.Waku,
333332
Nameserver: nodeConfig.WakuV2Config.Nameserver,
334333
UDPPort: nodeConfig.WakuV2Config.UDPPort,
335334
AutoUpdate: nodeConfig.WakuV2Config.AutoUpdate,
336-
DefaultShardPubsubTopic: shard.DefaultShardPubsubTopic(),
335+
DefaultShardPubsubTopic: wakuv2.DefaultShardPubsubTopic(),
337336
TelemetryServerURL: nodeConfig.WakuV2Config.TelemetryServerURL,
338337
ClusterID: nodeConfig.ClusterConfig.ClusterID,
339338
EnableMissingMessageVerification: nodeConfig.WakuV2Config.EnableMissingMessageVerification,

protocol/communities/community.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ import (
2323
"github.com/status-im/status-go/eth-node/types"
2424
"github.com/status-im/status-go/images"
2525
"github.com/status-im/status-go/protocol/common"
26-
"github.com/status-im/status-go/protocol/common/shard"
2726
community_token "github.com/status-im/status-go/protocol/communities/token"
2827
"github.com/status-im/status-go/protocol/protobuf"
2928
"github.com/status-im/status-go/protocol/requests"
3029
"github.com/status-im/status-go/protocol/v1"
3130
"github.com/status-im/status-go/server"
31+
"github.com/status-im/status-go/wakuv2"
3232
)
3333

3434
const signatureLength = 65
@@ -55,7 +55,7 @@ type Config struct {
5555
RequestsToJoin []*RequestToJoin
5656
MemberIdentity *ecdsa.PrivateKey
5757
EventsData *EventsData
58-
Shard *shard.Shard
58+
Shard *wakuv2.Shard
5959
PubsubTopicPrivateKey *ecdsa.PrivateKey
6060
LastOpenedAt int64
6161
}
@@ -172,7 +172,7 @@ func (o *Community) MarshalPublicAPIJSON() ([]byte, error) {
172172
ActiveMembersCount uint64 `json:"activeMembersCount"`
173173
PubsubTopic string `json:"pubsubTopic"`
174174
PubsubTopicKey string `json:"pubsubTopicKey"`
175-
Shard *shard.Shard `json:"shard"`
175+
Shard *wakuv2.Shard `json:"shard"`
176176
}{
177177
ID: o.ID(),
178178
Verified: o.config.Verified,
@@ -308,7 +308,7 @@ func (o *Community) MarshalJSON() ([]byte, error) {
308308
ActiveMembersCount uint64 `json:"activeMembersCount"`
309309
PubsubTopic string `json:"pubsubTopic"`
310310
PubsubTopicKey string `json:"pubsubTopicKey"`
311-
Shard *shard.Shard `json:"shard"`
311+
Shard *wakuv2.Shard `json:"shard"`
312312
LastOpenedAt int64 `json:"lastOpenedAt"`
313313
Clock uint64 `json:"clock"`
314314
}{
@@ -461,7 +461,7 @@ func (o *Community) DescriptionText() string {
461461
return ""
462462
}
463463

464-
func (o *Community) Shard() *shard.Shard {
464+
func (o *Community) Shard() *wakuv2.Shard {
465465
if o != nil && o.config != nil {
466466
return o.config.Shard
467467
}

protocol/communities/manager.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
multiaccountscommon "github.com/status-im/status-go/multiaccounts/common"
3131
"github.com/status-im/status-go/params"
3232
"github.com/status-im/status-go/protocol/common"
33-
"github.com/status-im/status-go/protocol/common/shard"
3433
community_token "github.com/status-im/status-go/protocol/communities/token"
3534
"github.com/status-im/status-go/protocol/encryption"
3635
"github.com/status-im/status-go/protocol/ens"
@@ -45,6 +44,7 @@ import (
4544
"github.com/status-im/status-go/services/wallet/token"
4645
"github.com/status-im/status-go/signal"
4746
"github.com/status-im/status-go/transactions"
47+
"github.com/status-im/status-go/wakuv2"
4848
)
4949

5050
type Publisher interface {
@@ -737,8 +737,8 @@ func (m *Manager) All() ([]*Community, error) {
737737
}
738738

739739
type CommunityShard struct {
740-
CommunityID string `json:"communityID"`
741-
Shard *shard.Shard `json:"shard"`
740+
CommunityID string `json:"communityID"`
741+
Shard *wakuv2.Shard `json:"shard"`
742742
}
743743

744744
type CuratedCommunities struct {
@@ -1546,7 +1546,7 @@ func (m *Manager) DeleteCommunity(id types.HexBytes) error {
15461546
return m.persistence.DeleteCommunitySettings(id)
15471547
}
15481548

1549-
func (m *Manager) updateShard(community *Community, shard *shard.Shard, clock uint64) error {
1549+
func (m *Manager) updateShard(community *Community, shard *wakuv2.Shard, clock uint64) error {
15501550
community.config.Shard = shard
15511551
if shard == nil {
15521552
return m.persistence.DeleteCommunityShard(community.ID())
@@ -1555,15 +1555,15 @@ func (m *Manager) updateShard(community *Community, shard *shard.Shard, clock ui
15551555
return m.persistence.SaveCommunityShard(community.ID(), shard, clock)
15561556
}
15571557

1558-
func (m *Manager) UpdateShard(community *Community, shard *shard.Shard, clock uint64) error {
1558+
func (m *Manager) UpdateShard(community *Community, shard *wakuv2.Shard, clock uint64) error {
15591559
m.communityLock.Lock(community.ID())
15601560
defer m.communityLock.Unlock(community.ID())
15611561

15621562
return m.updateShard(community, shard, clock)
15631563
}
15641564

15651565
// SetShard assigns a shard to a community
1566-
func (m *Manager) SetShard(communityID types.HexBytes, shard *shard.Shard) (*Community, error) {
1566+
func (m *Manager) SetShard(communityID types.HexBytes, shard *wakuv2.Shard) (*Community, error) {
15671567
m.communityLock.Lock(communityID)
15681568
defer m.communityLock.Unlock(communityID)
15691569

@@ -2155,11 +2155,11 @@ func (m *Manager) HandleCommunityDescriptionMessage(signer *ecdsa.PublicKey, des
21552155
if err != nil {
21562156
return nil, err
21572157
}
2158-
var cShard *shard.Shard
2158+
var cShard *wakuv2.Shard
21592159
if communityShard == nil {
2160-
cShard = &shard.Shard{Cluster: shard.MainStatusShardCluster, Index: shard.DefaultShardIndex}
2160+
cShard = &wakuv2.Shard{Cluster: wakuv2.MainStatusShardCluster, Index: wakuv2.DefaultShardIndex}
21612161
} else {
2162-
cShard = shard.FromProtobuff(communityShard)
2162+
cShard = wakuv2.FromProtobuff(communityShard)
21632163
}
21642164
config := Config{
21652165
CommunityDescription: processedDescription,
@@ -3972,11 +3972,11 @@ func (m *Manager) GetByIDString(idString string) (*Community, error) {
39723972
return m.GetByID(id)
39733973
}
39743974

3975-
func (m *Manager) GetCommunityShard(communityID types.HexBytes) (*shard.Shard, error) {
3975+
func (m *Manager) GetCommunityShard(communityID types.HexBytes) (*wakuv2.Shard, error) {
39763976
return m.persistence.GetCommunityShard(communityID)
39773977
}
39783978

3979-
func (m *Manager) SaveCommunityShard(communityID types.HexBytes, shard *shard.Shard, clock uint64) error {
3979+
func (m *Manager) SaveCommunityShard(communityID types.HexBytes, shard *wakuv2.Shard, clock uint64) error {
39803980
m.communityLock.Lock(communityID)
39813981
defer m.communityLock.Unlock(communityID)
39823982

protocol/communities/persistence.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import (
1616
"github.com/status-im/status-go/eth-node/crypto"
1717
"github.com/status-im/status-go/eth-node/types"
1818
"github.com/status-im/status-go/protocol/common"
19-
"github.com/status-im/status-go/protocol/common/shard"
2019
"github.com/status-im/status-go/protocol/communities/token"
2120
"github.com/status-im/status-go/protocol/encryption"
2221
"github.com/status-im/status-go/protocol/protobuf"
2322
"github.com/status-im/status-go/services/wallet/bigint"
23+
"github.com/status-im/status-go/wakuv2"
2424
)
2525

2626
type Persistence struct {
@@ -1766,7 +1766,7 @@ func (p *Persistence) AllNonApprovedCommunitiesRequestsToJoin() ([]*RequestToJoi
17661766
return nonApprovedRequestsToJoin, nil
17671767
}
17681768

1769-
func (p *Persistence) SaveCommunityShard(communityID types.HexBytes, shard *shard.Shard, clock uint64) error {
1769+
func (p *Persistence) SaveCommunityShard(communityID types.HexBytes, shard *wakuv2.Shard, clock uint64) error {
17701770
var cluster, index *uint16
17711771

17721772
if shard != nil {
@@ -1801,7 +1801,7 @@ func (p *Persistence) SaveCommunityShard(communityID types.HexBytes, shard *shar
18011801
}
18021802

18031803
// if data will not be found, will return sql.ErrNoRows. Must be handled on the caller side
1804-
func (p *Persistence) GetCommunityShard(communityID types.HexBytes) (*shard.Shard, error) {
1804+
func (p *Persistence) GetCommunityShard(communityID types.HexBytes) (*wakuv2.Shard, error) {
18051805
var cluster sql.NullInt64
18061806
var index sql.NullInt64
18071807
err := p.db.QueryRow(`SELECT shard_cluster, shard_index FROM communities_shards WHERE community_id = ?`,
@@ -1815,7 +1815,7 @@ func (p *Persistence) GetCommunityShard(communityID types.HexBytes) (*shard.Shar
18151815
return nil, nil
18161816
}
18171817

1818-
return &shard.Shard{
1818+
return &wakuv2.Shard{
18191819
Cluster: uint16(cluster.Int64),
18201820
Index: uint16(index.Int64),
18211821
}, nil

protocol/communities/persistence_mapping.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77

88
"github.com/status-im/status-go/eth-node/crypto"
99
"github.com/status-im/status-go/protocol/common"
10-
"github.com/status-im/status-go/protocol/common/shard"
1110
"github.com/status-im/status-go/server"
11+
"github.com/status-im/status-go/wakuv2"
1212
)
1313

1414
func communityToRecord(community *Community) (*CommunityRecord, error) {
@@ -118,9 +118,9 @@ func recordBundleToCommunity(
118118
}
119119
}
120120

121-
var s *shard.Shard = nil
121+
var s *wakuv2.Shard = nil
122122
if r.community.shardCluster != nil && r.community.shardIndex != nil {
123-
s = &shard.Shard{
123+
s = &wakuv2.Shard{
124124
Cluster: uint16(*r.community.shardCluster),
125125
Index: uint16(*r.community.shardIndex),
126126
}

0 commit comments

Comments
 (0)