feat(waku)_: allow client to set store confirmations

This commit is contained in:
Prem Chaitanya Prathi 2024-07-11 15:27:56 +05:30 committed by Andrea Maria Piana
parent 6c0c267c3c
commit 58a3cc1127
19 changed files with 105 additions and 27 deletions

View File

@ -834,13 +834,16 @@ func TestLoginAccount(t *testing.T) {
RootDataDir: tmpdir,
LogFilePath: tmpdir + "/log",
WakuV2Nameserver: &nameserver,
WakuV2Fleet: "status.staging",
}
c := make(chan interface{}, 10)
signal.SetMobileSignalHandler(func(data []byte) {
if strings.Contains(string(data), signal.EventLoggedIn) {
require.Contains(t, string(data), "status.staging")
c <- struct{}{}
}
})
defer signal.SetMobileSignalHandler(nil)
waitForLogin := func(chan interface{}) {
select {
case <-c:

View File

@ -139,8 +139,9 @@ func SetFleet(fleet string, nodeConfig *params.NodeConfig) error {
Host: "0.0.0.0",
AutoUpdate: true,
// mobile may need override following options
LightClient: specifiedWakuV2Config.LightClient,
Nameserver: specifiedWakuV2Config.Nameserver,
LightClient: specifiedWakuV2Config.LightClient,
EnableStoreConfirmationForMessagesSent: specifiedWakuV2Config.EnableStoreConfirmationForMessagesSent,
Nameserver: specifiedWakuV2Config.Nameserver,
}
clusterConfig, err := params.LoadClusterConfigFromFleet(fleet)
@ -289,7 +290,12 @@ func defaultNodeConfig(installationID string, request *requests.CreateAccount, o
nodeConfig.ListenAddr = DefaultListenAddr
err := SetDefaultFleet(nodeConfig)
fleet := request.WakuV2Fleet
if fleet == "" {
fleet = DefaultFleet
}
err := SetFleet(fleet, nodeConfig)
if err != nil {
return nil, err
}
@ -298,6 +304,10 @@ func defaultNodeConfig(installationID string, request *requests.CreateAccount, o
nodeConfig.WakuV2Config.LightClient = true
}
if request.WakuV2EnableStoreConfirmationForMessagesSent {
nodeConfig.WakuV2Config.EnableStoreConfirmationForMessagesSent = true
}
if request.WakuV2Nameserver != nil {
nodeConfig.WakuV2Config.Nameserver = *request.WakuV2Nameserver
}

View File

@ -1613,7 +1613,6 @@ func (b *GethStatusBackend) prepareSettings(request *requests.CreateAccount, inp
settings.PreviewPrivacy = request.PreviewPrivacy
settings.CurrentNetwork = request.CurrentNetwork
settings.TestNetworksEnabled = request.TestNetworksEnabled
if !input.restoringAccount {
settings.Mnemonic = &input.mnemonic
settings.OmitTransfersHistoryScan = true
@ -1622,6 +1621,10 @@ func (b *GethStatusBackend) prepareSettings(request *requests.CreateAccount, inp
//settings.MnemonicWasNotShown = true
}
if request.WakuV2Fleet != "" {
settings.Fleet = &request.WakuV2Fleet
}
return settings, nil
}

View File

@ -116,7 +116,7 @@
// 1718978062_nodeconfig_add_connector.up.sql (76B)
// 1720466921_missing_message_verification.up.sql (167B)
// 1720557751_rename_staging.up.sql (3.258kB)
// 1720606449_enable_store_confirmation_for_messages_sent.up.sql (183B)
// 1720606449_enable_store_confirmation_for_messages_sent.up.sql (191B)
// doc.go (94B)
package migrations
@ -2505,7 +2505,7 @@ func _1720557751_rename_stagingUpSql() (*asset, error) {
return a, nil
}
var __1720606449_enable_store_confirmation_for_messages_sentUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x94\xcd\xb1\x0a\xc2\x30\x10\x80\xe1\xbd\x4f\x71\xcf\xe0\x2a\x0e\x57\x13\xa7\xd8\x88\x26\xf3\x71\xca\xa5\x14\xdb\x04\x72\xa9\xbe\xbe\x88\x9b\x5b\xe7\x1f\xbe\x1f\x5d\xb0\x57\x08\xd8\x3b\x0b\x6f\x7e\xae\xaf\x1d\x3d\x4a\x4e\xd3\x08\x68\x0c\x1c\xbd\x8b\xe7\x01\x24\xf3\x7d\x16\xd2\x56\xaa\xfc\x72\x5d\xb8\x4d\x25\x53\x2a\x95\x16\x51\xe5\x51\x94\x54\x72\x83\xde\x7b\x67\x71\x00\x63\x4f\x18\x5d\x80\xc4\xb3\xca\xbe\xeb\xe2\xc5\x60\xf8\x7f\xdc\x6c\xd8\x84\x1f\xa0\xd5\xf5\xab\x7d\x02\x00\x00\xff\xff\x43\x0d\xea\x40\xb7\x00\x00\x00")
var __1720606449_enable_store_confirmation_for_messages_sentUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x94\xcd\xb1\x0e\xc2\x20\x10\x80\xe1\x9d\xa7\xb8\x67\x70\x6d\x1c\xae\x82\x13\xb6\x46\xe9\x7c\xc1\xe6\x40\x22\x85\x84\x43\x7d\x7d\x07\x37\x37\xe7\x3f\xf9\x3f\xb4\xce\x5c\xc0\xe1\x68\x0d\xbc\xfd\xe3\xf9\xda\xd1\x5a\x4b\x48\x11\x50\x6b\x38\xcc\x76\x39\x4d\xc0\xc5\xdf\x32\x93\xf4\xda\xf8\x9b\xdb\xe6\x7b\xaa\x85\x42\x6d\xb4\xb1\x88\x8f\x2c\x24\x5c\x3a\x8c\xf3\x6c\x0d\x4e\xa0\xcd\x11\x17\xeb\x20\xf8\x2c\x3c\x28\xb5\x9c\x35\xba\x5f\xe3\x6a\xdc\x5f\xf3\x3d\xe4\x14\xef\x9d\xd6\x9c\xb8\xf4\x41\xa9\x4f\x00\x00\x00\xff\xff\xcf\x1d\x1b\x7f\xbf\x00\x00\x00")
func _1720606449_enable_store_confirmation_for_messages_sentUpSqlBytes() ([]byte, error) {
return bindataRead(
@ -2520,8 +2520,8 @@ func _1720606449_enable_store_confirmation_for_messages_sentUpSql() (*asset, err
return nil, err
}
info := bindataFileInfo{name: "1720606449_enable_store_confirmation_for_messages_sent.up.sql", size: 183, mode: os.FileMode(0644), modTime: time.Unix(1700000000, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x18, 0xd6, 0xa8, 0x6d, 0xf2, 0xd8, 0x5, 0xff, 0x17, 0x42, 0xae, 0xe5, 0x2c, 0xb6, 0xe7, 0xcd, 0xa8, 0xf9, 0xe8, 0x59, 0x8d, 0xd8, 0xf7, 0x10, 0xcd, 0x62, 0xf8, 0x74, 0x33, 0xd6, 0xc7, 0x7b}}
info := bindataFileInfo{name: "1720606449_enable_store_confirmation_for_messages_sent.up.sql", size: 191, mode: os.FileMode(0644), modTime: time.Unix(1700000000, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xfd, 0x7a, 0x1f, 0x26, 0xef, 0x64, 0x9, 0x96, 0x10, 0x6b, 0x9e, 0x96, 0x37, 0x8, 0x38, 0x17, 0xa3, 0xd3, 0x34, 0xf6, 0x72, 0xa0, 0x67, 0x68, 0xed, 0xd7, 0xc5, 0x1e, 0xea, 0xdd, 0xe1, 0x4e}}
return a, nil
}

View File

@ -1,4 +1,4 @@
ALTER TABLE wakuv2_config ADD COLUMN enable_store_confirmation_for_messages_sent BOOLEAN DEFAULT false;
UPDATE wakuv2_config SET enable_store_confirmation_for_messages_sent = true;
UPDATE wakuv2_config SET enable_store_confirmation_for_messages_sent = light_client;

2
go.mod
View File

@ -96,7 +96,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.20240712043904-2f333c1e1c13
github.com/waku-org/go-waku v0.8.1-0.20240713051642-554e93791529
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

4
go.sum
View File

@ -2143,8 +2143,8 @@ github.com/waku-org/go-libp2p-pubsub v0.0.0-20240703191659-2cbb09eac9b5 h1:9u16E
github.com/waku-org/go-libp2p-pubsub v0.0.0-20240703191659-2cbb09eac9b5/go.mod h1:QEb+hEV9WL9wCiUAnpY29FZR6W3zK8qYlaml8R4q6gQ=
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.20240712043904-2f333c1e1c13 h1:2OCOlUdH4Vvt26Gj6EXnZpzgrHjWty9vUfm+6ZXvCxo=
github.com/waku-org/go-waku v0.8.1-0.20240712043904-2f333c1e1c13/go.mod h1:ugDTCvcP6oJ9mTtINeo4EIsnC3oQCU3RsctNKu4MsRw=
github.com/waku-org/go-waku v0.8.1-0.20240713051642-554e93791529 h1:iP8SuT74PV+jOtWHuzlBYGjsyw9RrY/V8o2Y71zshsw=
github.com/waku-org/go-waku v0.8.1-0.20240713051642-554e93791529/go.mod h1:ugDTCvcP6oJ9mTtINeo4EIsnC3oQCU3RsctNKu4MsRw=
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=

View File

@ -147,10 +147,11 @@ INSERT INTO settings (
wallet_token_preferences_group_by_community,
wallet_collectible_preferences_group_by_collection,
wallet_collectible_preferences_group_by_community,
test_networks_enabled
test_networks_enabled,
fleet
) VALUES (
?,?,?,?,?,?,?,?,?,?,?,?,?,?,
?,?,?,?,?,?,?,?,?,'id',?,?,?,?,?,?,?,?,?,?)`,
?,?,?,?,?,?,?,?,?,'id',?,?,?,?,?,?,?,?,?,?,?)`,
s.Address,
s.Currency,
s.CurrentNetwork,
@ -184,6 +185,7 @@ INSERT INTO settings (
s.CollectibleGroupByCollection,
s.CollectibleGroupByCommunity,
s.TestNetworksEnabled,
s.Fleet,
)
if err != nil {
return err

View File

@ -797,6 +797,11 @@ func SetLightClient(db *sql.DB, enabled bool) error {
return err
}
func SetStoreConfirmationForMessagesSent(db *sql.DB, enabled bool) error {
_, err := db.Exec(`UPDATE wakuv2_config SET enable_store_confirmation_for_messages_sent = ?`, enabled)
return err
}
func SetLogLevel(db *sql.DB, logLevel string) error {
_, err := db.Exec(`UPDATE log_config SET log_level = ?`, logLevel)
return err

View File

@ -12,6 +12,10 @@ func (m *Messenger) SetLightClient(request *requests.SetLightClient) error {
return nodecfg.SetLightClient(m.database, request.Enabled)
}
func (m *Messenger) SetStoreConfirmationForMessagesSent(request *requests.SetStoreConfirmationForMessagesSent) error {
return nodecfg.SetStoreConfirmationForMessagesSent(m.database, request.Enabled)
}
func (m *Messenger) SetLogLevel(request *requests.SetLogLevel) error {
if err := request.Validate(); err != nil {
return err

View File

@ -49,8 +49,10 @@ type CreateAccount struct {
CustomizationColor string `json:"customizationColor"`
Emoji string `json:"emoji"`
WakuV2Nameserver *string `json:"wakuV2Nameserver"`
WakuV2LightClient bool `json:"wakuV2LightClient"`
WakuV2Nameserver *string `json:"wakuV2Nameserver"`
WakuV2LightClient bool `json:"wakuV2LightClient"`
WakuV2EnableStoreConfirmationForMessagesSent bool `json:"wakuV2EnableStoreConfirmationForMessagesSent"`
WakuV2Fleet string `json:"wakuV2Fleet"`
LogLevel *string `json:"logLevel"`
LogFilePath string `json:"logFilePath"` // absolute path

View File

@ -0,0 +1,5 @@
package requests
type SetStoreConfirmationForMessagesSent struct {
Enabled bool `json:"enabled"`
}

View File

@ -1782,6 +1782,10 @@ func (api *PublicAPI) SetLightClient(request *requests.SetLightClient) error {
return api.service.messenger.SetLightClient(request)
}
func (api *PublicAPI) SetStoreConfirmationForMessagesSent(request *requests.SetStoreConfirmationForMessagesSent) error {
return api.service.messenger.SetStoreConfirmationForMessagesSent(request)
}
func (api *PublicAPI) SetLogLevel(request *requests.SetLogLevel) error {
return api.service.messenger.SetLogLevel(request)
}

View File

@ -338,6 +338,14 @@ func (w *WakuNode) setupENR(ctx context.Context, addrs []ma.Multiaddr) error {
}
func (w *WakuNode) SetRelayShards(rs protocol.RelayShards) error {
err := wenr.Update(w.log, w.localNode, wenr.WithWakuRelaySharding(rs))
if err != nil {
return err
}
return nil
}
func (w *WakuNode) watchTopicShards(ctx context.Context) error {
evtRelaySubscribed, err := w.Relay().Events().Subscribe(new(relay.EvtRelaySubscribed))
if err != nil {

View File

@ -457,16 +457,25 @@ func (w *WakuNode) Start(ctx context.Context) error {
}
w.filterLightNode.SetHost(host)
err = w.setupENR(ctx, w.ListenAddresses())
if err != nil {
return err
}
if w.opts.enableFilterLightNode {
err := w.filterLightNode.Start(ctx)
if err != nil {
return err
}
}
err = w.setupENR(ctx, w.ListenAddresses())
if err != nil {
return err
//TODO: setting this up temporarily to improve connectivity success for lightNode in status.
//This will have to be removed or changed with community sharding will be implemented.
if w.opts.shards != nil {
err = w.SetRelayShards(*w.opts.shards)
if err != nil {
return err
}
}
}
w.peerExchange.SetHost(host)

View File

@ -27,6 +27,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/waku-org/go-waku/waku/v2/onlinechecker"
"github.com/waku-org/go-waku/waku/v2/peermanager"
"github.com/waku-org/go-waku/waku/v2/protocol"
"github.com/waku-org/go-waku/waku/v2/protocol/filter"
"github.com/waku-org/go-waku/waku/v2/protocol/legacy_store"
"github.com/waku-org/go-waku/waku/v2/protocol/lightpush"
@ -53,6 +54,7 @@ type WakuNodeParameters struct {
hostAddr *net.TCPAddr
maxConnectionsPerIP int
clusterID uint16
shards *protocol.RelayShards
dns4Domain string
advertiseAddrs []multiaddr.Multiaddr
multiAddr []multiaddr.Multiaddr
@ -317,6 +319,23 @@ func WithClusterID(clusterID uint16) WakuNodeOption {
}
}
func WithPubSubTopics(topics []string) WakuNodeOption {
return func(params *WakuNodeParameters) error {
rs, err := protocol.TopicsToRelayShards(topics...)
if err != nil {
return err
}
if len(rs) == 0 {
return nil
}
if rs[0].ClusterID != params.clusterID {
return errors.New("pubsubtopics have different clusterID than configured clusterID")
}
params.shards = &rs[0] //Only consider 0 as a node can only support 1 cluster as of now
return nil
}
}
// WithMaxConnectionsPerIP sets the max number of allowed peers from the same IP
func WithMaxConnectionsPerIP(limit int) WakuNodeOption {
return func(params *WakuNodeParameters) error {

View File

@ -328,9 +328,9 @@ func (wakuLP *WakuLightPush) Publish(ctx context.Context, message *wpb.WakuMessa
req.Message = message
req.PubsubTopic = params.pubsubTopic
logger := message.Logger(wakuLP.log, params.pubsubTopic).With(zap.Stringers("peerIDs", params.selectedPeers))
logger := message.Logger(wakuLP.log, params.pubsubTopic)
logger.Debug("publishing message")
logger.Debug("publishing message", zap.Stringers("peers", params.selectedPeers))
var wg sync.WaitGroup
var responses []*pb.PushResponse
for _, peerID := range params.selectedPeers {

2
vendor/modules.txt vendored
View File

@ -1018,7 +1018,7 @@ github.com/waku-org/go-discover/discover/v5wire
github.com/waku-org/go-libp2p-rendezvous
github.com/waku-org/go-libp2p-rendezvous/db
github.com/waku-org/go-libp2p-rendezvous/pb
# github.com/waku-org/go-waku v0.8.1-0.20240712043904-2f333c1e1c13
# github.com/waku-org/go-waku v0.8.1-0.20240713051642-554e93791529
## explicit; go 1.21
github.com/waku-org/go-waku/logging
github.com/waku-org/go-waku/tests

View File

@ -91,6 +91,7 @@ const messageExpiredPerid = 10 // in seconds
const maxRelayPeers = 300
const randomPeersKeepAliveInterval = 5 * time.Second
const allPeersKeepAliveInterval = 5 * time.Minute
const PeersToPublishForLightpush = 2
type SentEnvelope struct {
Envelope *protocol.Envelope
@ -304,6 +305,8 @@ func New(nodeKey *ecdsa.PrivateKey, fleet string, cfg *Config, logger *zap.Logge
waku.defaultShardInfo = shards[0]
opts = append(opts, node.WithMaxPeerConnections(cfg.DiscoveryLimit))
cfg.EnableStoreConfirmationForMessagesSent = false
//TODO: temporary work-around to improve lightClient connectivity, need to be removed once community sharding is implemented
opts = append(opts, node.WithPubSubTopics(cfg.DefaultShardedPubsubTopics))
} else {
relayOpts := []pubsub.Option{
pubsub.WithMaxMessageSize(int(waku.cfg.MaxMessageSize)),
@ -1014,7 +1017,7 @@ func (w *Waku) broadcast() {
publishMethod = LightPush
fn = func(env *protocol.Envelope, logger *zap.Logger) error {
logger.Info("publishing message via lightpush")
_, err := w.node.Lightpush().Publish(w.ctx, env.Message(), lightpush.WithPubSubTopic(env.PubsubTopic()))
_, err := w.node.Lightpush().Publish(w.ctx, env.Message(), lightpush.WithPubSubTopic(env.PubsubTopic()), lightpush.WithMaxPeers(PeersToPublishForLightpush))
return err
}
} else {
@ -1050,11 +1053,12 @@ func (w *Waku) broadcast() {
}
func (w *Waku) checkIfMessagesStored() {
ticker := time.NewTicker(hashQueryInterval)
defer ticker.Stop()
if !w.cfg.EnableStoreConfirmationForMessagesSent {
return
}
ticker := time.NewTicker(hashQueryInterval)
defer ticker.Stop()
for {
select {
case <-w.ctx.Done():