Skip to content

Commit a3bff47

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) - 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
1 parent d291204 commit a3bff47

File tree

73 files changed

+5150
-321
lines changed

Some content is hidden

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

73 files changed

+5150
-321
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

+47-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.PHONY: statusgo 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=
@@ -60,6 +61,10 @@ GIT_AUTHOR ?= $(shell git config user.email || echo $$USER)
6061
ENABLE_METRICS ?= true
6162
BUILD_TAGS ?= gowaku_no_rln
6263

64+
ifeq ($(USE_NWAKU), true)
65+
BUILD_TAGS += use_nwaku
66+
endif
67+
6368
BUILD_FLAGS ?= -ldflags="-X github.com/status-im/status-go/vendor/github.com/ethereum/go-ethereum/metrics.EnabledStr=$(ENABLE_METRICS)"
6469
BUILD_FLAGS_MOBILE ?=
6570

@@ -207,8 +212,19 @@ statusgo-library: ##@cross-compile Build status-go as static library for current
207212
@echo "Static library built:"
208213
@ls -la build/bin/libstatus.*
209214

210-
statusgo-shared-library: generate
211-
statusgo-shared-library: ##@cross-compile Build status-go as shared library for current platform
215+
216+
LIBWAKU := third_party/nwaku/build/libwaku.$(GOBIN_SHARED_LIB_EXT)
217+
$(LIBWAKU):
218+
@echo "Building libwaku"
219+
$(MAKE) -C third_party/nwaku update || { echo "nwaku make update failed"; exit 1; }
220+
$(MAKE) -C ./third_party/nwaku libwaku
221+
222+
build-libwaku: $(LIBWAKU)
223+
224+
statusgo-shared-library: generate ##@cross-compile Build status-go as shared library for current platform
225+
ifeq ($(USE_NWAKU),true)
226+
$(MAKE) $(LIBWAKU)
227+
endif
212228
## cmd/library/README.md explains the magic incantation behind this
213229
mkdir -p build/bin/statusgo-lib
214230
go run cmd/library/*.go > build/bin/statusgo-lib/main.go
@@ -291,9 +307,38 @@ lint-fix:
291307
-w {} \;
292308
$(MAKE) vendor
293309

310+
mock: ##@other Regenerate mocks
311+
mockgen -package=fake -destination=transactions/fake/mock.go -source=transactions/fake/txservice.go
312+
mockgen -package=status -destination=services/status/account_mock.go -source=services/status/service.go
313+
mockgen -package=peer -destination=services/peer/discoverer_mock.go -source=services/peer/service.go
314+
mockgen -package=mock_transactor -destination=transactions/mock_transactor/transactor.go -source=transactions/transactor.go
315+
mockgen -package=mock_pathprocessor -destination=services/wallet/router/pathprocessor/mock_pathprocessor/processor.go -source=services/wallet/router/pathprocessor/processor.go
316+
mockgen -package=mock_bridge -destination=services/wallet/bridge/mock_bridge/bridge.go -source=services/wallet/bridge/bridge.go
317+
mockgen -package=mock_client -destination=rpc/chain/mock/client/client.go -source=rpc/chain/client.go
318+
mockgen -package=mock_token -destination=services/wallet/token/mock/token/tokenmanager.go -source=services/wallet/token/token.go
319+
mockgen -package=mock_thirdparty -destination=services/wallet/thirdparty/mock/types.go -source=services/wallet/thirdparty/types.go
320+
mockgen -package=mock_balance_persistence -destination=services/wallet/token/mock/balance_persistence/balance_persistence.go -source=services/wallet/token/balance_persistence.go
321+
mockgen -package=mock_network -destination=rpc/network/mock/network.go -source=rpc/network/network.go
322+
mockgen -package=mock_rpcclient -destination=rpc/mock/client/client.go -source=rpc/client.go
323+
mockgen -package=mock_collectibles -destination=services/wallet/collectibles/mock/collection_data_db.go -source=services/wallet/collectibles/collection_data_db.go
324+
mockgen -package=mock_collectibles -destination=services/wallet/collectibles/mock/collectible_data_db.go -source=services/wallet/collectibles/collectible_data_db.go
325+
mockgen -package=mock_thirdparty -destination=services/wallet/thirdparty/mock/collectible_types.go -source=services/wallet/thirdparty/collectible_types.go
326+
mockgen -package=mock_paraswap -destination=services/wallet/thirdparty/paraswap/mock/types.go -source=services/wallet/thirdparty/paraswap/types.go
327+
mockgen -package=mock_onramp -destination=services/wallet/onramp/mock/types.go -source=services/wallet/onramp/types.go
328+
329+
294330
docker-test: ##@tests Run tests in a docker container with golang.
295331
docker run --privileged --rm -it -v "$(PWD):$(DOCKER_TEST_WORKDIR)" -w "$(DOCKER_TEST_WORKDIR)" $(DOCKER_TEST_IMAGE) go test ${ARGS}
296332

333+
test-libwaku: | $(LIBWAKU)
334+
go test -tags '$(BUILD_TAGS) use_nwaku' -run TestBasicWakuV2 ./wakuv2/... -count 1 -v -json | jq -r '.Output'
335+
336+
clean-libwaku:
337+
@echo "Removing libwaku"
338+
rm $(LIBWAKU)
339+
340+
rebuild-libwaku: | clean-libwaku $(LIBWAKU)
341+
297342
test: test-unit ##@tests Run basic, short tests during development
298343

299344
test-unit-prep: generate

cmd/ping-community/main.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ 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/cmd/utils"
2930
"github.com/status-im/status-go/logutils"
3031
"github.com/status-im/status-go/params"
3132
"github.com/status-im/status-go/protocol"
3233
"github.com/status-im/status-go/protocol/common"
33-
"github.com/status-im/status-go/protocol/common/shard"
3434
"github.com/status-im/status-go/protocol/identity/alias"
3535
"github.com/status-im/status-go/protocol/protobuf"
3636
wakuextn "github.com/status-im/status-go/services/wakuext"
@@ -49,8 +49,8 @@ var (
4949
seedPhrase = flag.String("seed-phrase", "", "Seed phrase")
5050
version = flag.Bool("version", false, "Print version and dump configuration")
5151
communityID = flag.String("community-id", "", "The id of the community")
52-
shardCluster = flag.Int("shard-cluster", shard.MainStatusShardCluster, "The shard cluster in which the of the community is published")
53-
shardIndex = flag.Int("shard-index", shard.DefaultShardIndex, "The shard index in which the community is published")
52+
shardCluster = flag.Int("shard-cluster", wakuv2.MainStatusShardCluster, "The shard cluster in which the of the community is published")
53+
shardIndex = flag.Int("shard-index", wakuv2.DefaultShardIndex, "The shard index in which the community is published")
5454
chatID = flag.String("chat-id", "", "The id of the chat")
5555

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

153153
messenger := wakuextservice.Messenger()
154154

155-
var s *shard.Shard = nil
155+
var s *wakuv2.Shard = nil
156156
if shardCluster != nil && shardIndex != nil {
157-
s = &shard.Shard{
157+
s = &wakuv2.Shard{
158158
Cluster: uint16(*shardCluster),
159159
Index: uint16(*shardIndex),
160160
}

eth-node/bridge/geth/waku.go

-5
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,6 @@ func (w *GethWakuWrapper) StopDiscV5() error {
6363
return errors.New("not available in WakuV1")
6464
}
6565

66-
// PeerCount function only added for compatibility with waku V2
67-
func (w *GethWakuWrapper) AddStorePeer(address multiaddr.Multiaddr) (peer.ID, error) {
68-
return "", errors.New("not available in WakuV1")
69-
}
70-
7166
// SubscribeToPubsubTopic function only added for compatibility with waku V2
7267
func (w *GethWakuWrapper) SubscribeToPubsubTopic(topic string, optPublicKey *ecdsa.PublicKey) error {
7368
// not available in WakuV1

eth-node/bridge/geth/wakuv2.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,6 @@ func (w *gethWakuV2Wrapper) RemovePubsubTopicKey(topic string) error {
206206
return w.waku.RemovePubsubTopicKey(topic)
207207
}
208208

209-
func (w *gethWakuV2Wrapper) AddStorePeer(address multiaddr.Multiaddr) (peer.ID, error) {
210-
return w.waku.AddStorePeer(address)
211-
}
212-
213209
func (w *gethWakuV2Wrapper) AddRelayPeer(address multiaddr.Multiaddr) (peer.ID, error) {
214210
return w.waku.AddRelayPeer(address)
215211
}
@@ -227,7 +223,7 @@ func (w *gethWakuV2Wrapper) DialPeerByID(peerID peer.ID) error {
227223
}
228224

229225
func (w *gethWakuV2Wrapper) ListenAddresses() ([]multiaddr.Multiaddr, error) {
230-
return w.waku.ListenAddresses(), nil
226+
return w.waku.ListenAddresses()
231227
}
232228

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

eth-node/types/waku.go

-2
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,6 @@ type Waku interface {
134134

135135
RemovePubsubTopicKey(topic string) error
136136

137-
AddStorePeer(address multiaddr.Multiaddr) (peer.ID, error)
138-
139137
AddRelayPeer(address multiaddr.Multiaddr) (peer.ID, error)
140138

141139
DialPeer(address multiaddr.Multiaddr) error

nix/shell.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ in mkShell {
2626

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

node/status_node_services.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212

1313
"go.uber.org/zap"
1414

15-
"github.com/status-im/status-go/protocol/common/shard"
1615
"github.com/status-im/status-go/server"
1716
"github.com/status-im/status-go/signal"
1817
"github.com/status-im/status-go/transactions"
@@ -338,7 +337,7 @@ func (b *StatusNode) wakuV2Service(nodeConfig *params.NodeConfig) (*wakuv2.Waku,
338337
Nameserver: nodeConfig.WakuV2Config.Nameserver,
339338
UDPPort: nodeConfig.WakuV2Config.UDPPort,
340339
AutoUpdate: nodeConfig.WakuV2Config.AutoUpdate,
341-
DefaultShardPubsubTopic: shard.DefaultShardPubsubTopic(),
340+
DefaultShardPubsubTopic: wakuv2.DefaultShardPubsubTopic(),
342341
TelemetryServerURL: nodeConfig.WakuV2Config.TelemetryServerURL,
343342
ClusterID: nodeConfig.ClusterConfig.ClusterID,
344343
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
@@ -31,7 +31,6 @@ import (
3131
multiaccountscommon "github.com/status-im/status-go/multiaccounts/common"
3232
"github.com/status-im/status-go/params"
3333
"github.com/status-im/status-go/protocol/common"
34-
"github.com/status-im/status-go/protocol/common/shard"
3534
community_token "github.com/status-im/status-go/protocol/communities/token"
3635
"github.com/status-im/status-go/protocol/encryption"
3736
"github.com/status-im/status-go/protocol/ens"
@@ -46,6 +45,7 @@ import (
4645
"github.com/status-im/status-go/services/wallet/token"
4746
"github.com/status-im/status-go/services/wallet/wallettypes"
4847
"github.com/status-im/status-go/signal"
48+
"github.com/status-im/status-go/wakuv2"
4949
)
5050

5151
type Publisher interface {
@@ -768,8 +768,8 @@ func (m *Manager) All() ([]*Community, error) {
768768
}
769769

770770
type CommunityShard struct {
771-
CommunityID string `json:"communityID"`
772-
Shard *shard.Shard `json:"shard"`
771+
CommunityID string `json:"communityID"`
772+
Shard *wakuv2.Shard `json:"shard"`
773773
}
774774

775775
type CuratedCommunities struct {
@@ -1577,7 +1577,7 @@ func (m *Manager) DeleteCommunity(id types.HexBytes) error {
15771577
return m.persistence.DeleteCommunitySettings(id)
15781578
}
15791579

1580-
func (m *Manager) updateShard(community *Community, shard *shard.Shard, clock uint64) error {
1580+
func (m *Manager) updateShard(community *Community, shard *wakuv2.Shard, clock uint64) error {
15811581
community.config.Shard = shard
15821582
if shard == nil {
15831583
return m.persistence.DeleteCommunityShard(community.ID())
@@ -1586,15 +1586,15 @@ func (m *Manager) updateShard(community *Community, shard *shard.Shard, clock ui
15861586
return m.persistence.SaveCommunityShard(community.ID(), shard, clock)
15871587
}
15881588

1589-
func (m *Manager) UpdateShard(community *Community, shard *shard.Shard, clock uint64) error {
1589+
func (m *Manager) UpdateShard(community *Community, shard *wakuv2.Shard, clock uint64) error {
15901590
m.communityLock.Lock(community.ID())
15911591
defer m.communityLock.Unlock(community.ID())
15921592

15931593
return m.updateShard(community, shard, clock)
15941594
}
15951595

15961596
// SetShard assigns a shard to a community
1597-
func (m *Manager) SetShard(communityID types.HexBytes, shard *shard.Shard) (*Community, error) {
1597+
func (m *Manager) SetShard(communityID types.HexBytes, shard *wakuv2.Shard) (*Community, error) {
15981598
m.communityLock.Lock(communityID)
15991599
defer m.communityLock.Unlock(communityID)
16001600

@@ -2207,11 +2207,11 @@ func (m *Manager) HandleCommunityDescriptionMessage(signer *ecdsa.PublicKey, des
22072207
if err != nil {
22082208
return nil, err
22092209
}
2210-
var cShard *shard.Shard
2210+
var cShard *wakuv2.Shard
22112211
if communityShard == nil {
2212-
cShard = &shard.Shard{Cluster: shard.MainStatusShardCluster, Index: shard.DefaultShardIndex}
2212+
cShard = &wakuv2.Shard{Cluster: wakuv2.MainStatusShardCluster, Index: wakuv2.DefaultShardIndex}
22132213
} else {
2214-
cShard = shard.FromProtobuff(communityShard)
2214+
cShard = wakuv2.FromProtobuff(communityShard)
22152215
}
22162216
config := Config{
22172217
CommunityDescription: processedDescription,
@@ -3996,11 +3996,11 @@ func (m *Manager) GetByIDString(idString string) (*Community, error) {
39963996
return m.GetByID(id)
39973997
}
39983998

3999-
func (m *Manager) GetCommunityShard(communityID types.HexBytes) (*shard.Shard, error) {
3999+
func (m *Manager) GetCommunityShard(communityID types.HexBytes) (*wakuv2.Shard, error) {
40004000
return m.persistence.GetCommunityShard(communityID)
40014001
}
40024002

4003-
func (m *Manager) SaveCommunityShard(communityID types.HexBytes, shard *shard.Shard, clock uint64) error {
4003+
func (m *Manager) SaveCommunityShard(communityID types.HexBytes, shard *wakuv2.Shard, clock uint64) error {
40044004
m.communityLock.Lock(communityID)
40054005
defer m.communityLock.Unlock(communityID)
40064006

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)