Skip to content

Commit 940adb9

Browse files
Ivansete-statusrichard-ramos
authored andcommittedOct 29, 2024
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 38043d3 commit 940adb9

40 files changed

+3660
-175
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 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) \
@@ -240,8 +245,19 @@ statusgo-library: ##@cross-compile Build status-go as static library for current
240245
@echo "Static library built:"
241246
@ls -la build/bin/libstatus.*
242247

243-
statusgo-shared-library: generate
244-
statusgo-shared-library: ##@cross-compile Build status-go as shared library for current platform
248+
249+
LIBWAKU := third_party/nwaku/build/libwaku.$(GOBIN_SHARED_LIB_EXT)
250+
$(LIBWAKU):
251+
@echo "Building libwaku"
252+
$(MAKE) -C third_party/nwaku update || { echo "nwaku make update failed"; exit 1; }
253+
$(MAKE) -C ./third_party/nwaku libwaku
254+
255+
build-libwaku: $(LIBWAKU)
256+
257+
statusgo-shared-library: generate ##@cross-compile Build status-go as shared library for current platform
258+
ifeq ($(USE_NWAKU),true)
259+
$(MAKE) $(LIBWAKU)
260+
endif
245261
## cmd/library/README.md explains the magic incantation behind this
246262
mkdir -p build/bin/statusgo-lib
247263
go run cmd/library/*.go > build/bin/statusgo-lib/main.go
@@ -362,9 +378,38 @@ lint-fix:
362378
-w {} \;
363379
$(MAKE) vendor
364380

381+
mock: ##@other Regenerate mocks
382+
mockgen -package=fake -destination=transactions/fake/mock.go -source=transactions/fake/txservice.go
383+
mockgen -package=status -destination=services/status/account_mock.go -source=services/status/service.go
384+
mockgen -package=peer -destination=services/peer/discoverer_mock.go -source=services/peer/service.go
385+
mockgen -package=mock_transactor -destination=transactions/mock_transactor/transactor.go -source=transactions/transactor.go
386+
mockgen -package=mock_pathprocessor -destination=services/wallet/router/pathprocessor/mock_pathprocessor/processor.go -source=services/wallet/router/pathprocessor/processor.go
387+
mockgen -package=mock_bridge -destination=services/wallet/bridge/mock_bridge/bridge.go -source=services/wallet/bridge/bridge.go
388+
mockgen -package=mock_client -destination=rpc/chain/mock/client/client.go -source=rpc/chain/client.go
389+
mockgen -package=mock_token -destination=services/wallet/token/mock/token/tokenmanager.go -source=services/wallet/token/token.go
390+
mockgen -package=mock_thirdparty -destination=services/wallet/thirdparty/mock/types.go -source=services/wallet/thirdparty/types.go
391+
mockgen -package=mock_balance_persistence -destination=services/wallet/token/mock/balance_persistence/balance_persistence.go -source=services/wallet/token/balance_persistence.go
392+
mockgen -package=mock_network -destination=rpc/network/mock/network.go -source=rpc/network/network.go
393+
mockgen -package=mock_rpcclient -destination=rpc/mock/client/client.go -source=rpc/client.go
394+
mockgen -package=mock_collectibles -destination=services/wallet/collectibles/mock/collection_data_db.go -source=services/wallet/collectibles/collection_data_db.go
395+
mockgen -package=mock_collectibles -destination=services/wallet/collectibles/mock/collectible_data_db.go -source=services/wallet/collectibles/collectible_data_db.go
396+
mockgen -package=mock_thirdparty -destination=services/wallet/thirdparty/mock/collectible_types.go -source=services/wallet/thirdparty/collectible_types.go
397+
mockgen -package=mock_paraswap -destination=services/wallet/thirdparty/paraswap/mock/types.go -source=services/wallet/thirdparty/paraswap/types.go
398+
mockgen -package=mock_onramp -destination=services/wallet/onramp/mock/types.go -source=services/wallet/onramp/types.go
399+
400+
365401
docker-test: ##@tests Run tests in a docker container with golang.
366402
docker run --privileged --rm -it -v "$(PWD):$(DOCKER_TEST_WORKDIR)" -w "$(DOCKER_TEST_WORKDIR)" $(DOCKER_TEST_IMAGE) go test ${ARGS}
367403

404+
test-libwaku: | $(LIBWAKU)
405+
go test -tags '$(BUILD_TAGS) use_nwaku' -run TestBasicWakuV2 ./wakuv2/... -count 1 -v -json | jq -r '.Output'
406+
407+
clean-libwaku:
408+
@echo "Removing libwaku"
409+
rm $(LIBWAKU)
410+
411+
rebuild-libwaku: | clean-libwaku $(LIBWAKU)
412+
368413
test: test-unit ##@tests Run basic, short tests during development
369414

370415
test-unit-prep: generate

‎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
@@ -227,7 +227,7 @@ func (w *gethWakuV2Wrapper) DialPeerByID(peerID peer.ID) error {
227227
}
228228

229229
func (w *gethWakuV2Wrapper) ListenAddresses() ([]multiaddr.Multiaddr, error) {
230-
return w.waku.ListenAddresses(), nil
230+
return w.waku.ListenAddresses()
231231
}
232232

233233
func (w *gethWakuV2Wrapper) RelayPeersByTopic(topic string) (*types.PeerList, 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 cc-test-reporter
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
@@ -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 {
@@ -740,8 +740,8 @@ func (m *Manager) All() ([]*Community, error) {
740740
}
741741

742742
type CommunityShard struct {
743-
CommunityID string `json:"communityID"`
744-
Shard *shard.Shard `json:"shard"`
743+
CommunityID string `json:"communityID"`
744+
Shard *wakuv2.Shard `json:"shard"`
745745
}
746746

747747
type CuratedCommunities struct {
@@ -1549,7 +1549,7 @@ func (m *Manager) DeleteCommunity(id types.HexBytes) error {
15491549
return m.persistence.DeleteCommunitySettings(id)
15501550
}
15511551

1552-
func (m *Manager) updateShard(community *Community, shard *shard.Shard, clock uint64) error {
1552+
func (m *Manager) updateShard(community *Community, shard *wakuv2.Shard, clock uint64) error {
15531553
community.config.Shard = shard
15541554
if shard == nil {
15551555
return m.persistence.DeleteCommunityShard(community.ID())
@@ -1558,15 +1558,15 @@ func (m *Manager) updateShard(community *Community, shard *shard.Shard, clock ui
15581558
return m.persistence.SaveCommunityShard(community.ID(), shard, clock)
15591559
}
15601560

1561-
func (m *Manager) UpdateShard(community *Community, shard *shard.Shard, clock uint64) error {
1561+
func (m *Manager) UpdateShard(community *Community, shard *wakuv2.Shard, clock uint64) error {
15621562
m.communityLock.Lock(community.ID())
15631563
defer m.communityLock.Unlock(community.ID())
15641564

15651565
return m.updateShard(community, shard, clock)
15661566
}
15671567

15681568
// SetShard assigns a shard to a community
1569-
func (m *Manager) SetShard(communityID types.HexBytes, shard *shard.Shard) (*Community, error) {
1569+
func (m *Manager) SetShard(communityID types.HexBytes, shard *wakuv2.Shard) (*Community, error) {
15701570
m.communityLock.Lock(communityID)
15711571
defer m.communityLock.Unlock(communityID)
15721572

@@ -2164,11 +2164,11 @@ func (m *Manager) HandleCommunityDescriptionMessage(signer *ecdsa.PublicKey, des
21642164
if err != nil {
21652165
return nil, err
21662166
}
2167-
var cShard *shard.Shard
2167+
var cShard *wakuv2.Shard
21682168
if communityShard == nil {
2169-
cShard = &shard.Shard{Cluster: shard.MainStatusShardCluster, Index: shard.DefaultShardIndex}
2169+
cShard = &wakuv2.Shard{Cluster: wakuv2.MainStatusShardCluster, Index: wakuv2.DefaultShardIndex}
21702170
} else {
2171-
cShard = shard.FromProtobuff(communityShard)
2171+
cShard = wakuv2.FromProtobuff(communityShard)
21722172
}
21732173
config := Config{
21742174
CommunityDescription: processedDescription,
@@ -3946,11 +3946,11 @@ func (m *Manager) GetByIDString(idString string) (*Community, error) {
39463946
return m.GetByID(id)
39473947
}
39483948

3949-
func (m *Manager) GetCommunityShard(communityID types.HexBytes) (*shard.Shard, error) {
3949+
func (m *Manager) GetCommunityShard(communityID types.HexBytes) (*wakuv2.Shard, error) {
39503950
return m.persistence.GetCommunityShard(communityID)
39513951
}
39523952

3953-
func (m *Manager) SaveCommunityShard(communityID types.HexBytes, shard *shard.Shard, clock uint64) error {
3953+
func (m *Manager) SaveCommunityShard(communityID types.HexBytes, shard *wakuv2.Shard, clock uint64) error {
39543954
m.communityLock.Lock(communityID)
39553955
defer m.communityLock.Unlock(communityID)
39563956

‎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
}

‎protocol/communities/persistence_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import (
1515
"github.com/status-im/status-go/eth-node/crypto"
1616
"github.com/status-im/status-go/eth-node/types"
1717
"github.com/status-im/status-go/protocol/common"
18-
"github.com/status-im/status-go/protocol/common/shard"
1918
"github.com/status-im/status-go/protocol/communities/token"
2019
"github.com/status-im/status-go/protocol/encryption"
2120
"github.com/status-im/status-go/protocol/protobuf"
2221
"github.com/status-im/status-go/protocol/sqlite"
2322
"github.com/status-im/status-go/services/wallet/bigint"
2423
"github.com/status-im/status-go/t/helpers"
24+
"github.com/status-im/status-go/wakuv2"
2525
)
2626

2727
func TestPersistenceSuite(t *testing.T) {
@@ -787,7 +787,7 @@ func (s *PersistenceSuite) TestSaveShardInfo() {
787787
s.Require().Nil(resultShard)
788788

789789
// not nil shard
790-
expectedShard := &shard.Shard{
790+
expectedShard := &wakuv2.Shard{
791791
Cluster: 1,
792792
Index: 2,
793793
}

0 commit comments

Comments
 (0)
Please sign in to comment.