mirror of https://github.com/waku-org/nwaku.git
Enables perssist-message flag in the store protocol for wakunode2 (#519)
* enables perssistmessage flag * disables in memory storage when persist-messages is false * adds the persistMessages input to the mountStore * defaults the store flag to true * adds the missing argument * persists messages in memory conditioned to the persistMessages flag * adds persistmessages flag to the config_bridge * defaults persistmessages to true * defaults the store flag to true and persist-messages to false * updates store.md * updates chat2 instructions about --store flag * removes --store flag from chat2 command execution Co-authored-by: Oskar Thorén <ot@oskarthoren.com>
This commit is contained in:
parent
7b6d93d13b
commit
c0d858af1d
|
@ -44,10 +44,10 @@ The `chat2` application can retrieve historical chat messages from a node suppor
|
||||||
./build/chat2 --storenode:/ip4/134.209.139.210/tcp/30303/p2p/16Uiu2HAmPLe7Mzm8TsYUubgCAW1aJoeFScxrLj8ppHFivPo97bUZ
|
./build/chat2 --storenode:/ip4/134.209.139.210/tcp/30303/p2p/16Uiu2HAmPLe7Mzm8TsYUubgCAW1aJoeFScxrLj8ppHFivPo97bUZ
|
||||||
```
|
```
|
||||||
|
|
||||||
Alternatively, the `chat2` application will select a random `storenode` for you from the test fleet if the `store` option is set to `true` and `storenode` left unspecified.
|
Alternatively, the `chat2` application will select a random `storenode` for you from the test fleet if `storenode` left unspecified.
|
||||||
|
|
||||||
```
|
```
|
||||||
./build/chat2 --store:true
|
./build/chat2
|
||||||
```
|
```
|
||||||
|
|
||||||
> *NOTE: Currently (Mar 3, 2021) the only node in the test fleet that provides reliable store functionality is `/ip4/134.209.139.210/tcp/30303/p2p/16Uiu2HAmPLe7Mzm8TsYUubgCAW1aJoeFScxrLj8ppHFivPo97bUZ`. We're working on fixing this.*
|
> *NOTE: Currently (Mar 3, 2021) the only node in the test fleet that provides reliable store functionality is `/ip4/134.209.139.210/tcp/30303/p2p/16Uiu2HAmPLe7Mzm8TsYUubgCAW1aJoeFScxrLj8ppHFivPo97bUZ`. We're working on fixing this.*
|
||||||
|
|
|
@ -20,8 +20,11 @@ Run two nodes and connect them:
|
||||||
./build/wakunode2 --ports-shift:1 --staticnode:/ip4/0.0.0.0/tcp/60000/p2p/16Uiu2HAmF4tuht6fmna6uDqoSMgFqhUrdaVR6VQRyGr6sCpfS2jp --storenode:/ip4/0.0.0.0/tcp/60000/p2p/16Uiu2HAmF4tuht6fmna6uDqoSMgFqhUrdaVR6VQRyGr6sCpfS2jp
|
./build/wakunode2 --ports-shift:1 --staticnode:/ip4/0.0.0.0/tcp/60000/p2p/16Uiu2HAmF4tuht6fmna6uDqoSMgFqhUrdaVR6VQRyGr6sCpfS2jp --storenode:/ip4/0.0.0.0/tcp/60000/p2p/16Uiu2HAmF4tuht6fmna6uDqoSMgFqhUrdaVR6VQRyGr6sCpfS2jp
|
||||||
```
|
```
|
||||||
|
|
||||||
When passing the flag `dbpath` with a path, messages are persisted and stored in a database called `store` under the specified path.
|
When flag `persist-messages` is passed messages are going to be persisted in-memory.
|
||||||
When none is passed, messages are not persisted and are only stored in-memory.
|
If additionally flag `dbpath` is passed with a path, messages are persisted and stored in a database called `store` under the specified path.
|
||||||
|
If flag `persist-messages` is not passed, messages are not persisted and stored at all.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
You should see your nodes connecting.
|
You should see your nodes connecting.
|
||||||
|
|
||||||
|
|
|
@ -278,7 +278,7 @@ proc processInput(rfd: AsyncFD, rng: ref BrHmacDrbgContext) {.async.} =
|
||||||
node.mountSwap()
|
node.mountSwap()
|
||||||
|
|
||||||
if (conf.storenode != "") or (conf.store == true):
|
if (conf.storenode != "") or (conf.store == true):
|
||||||
node.mountStore()
|
node.mountStore(persistMessages = conf.persistmessages)
|
||||||
|
|
||||||
var storenode: string
|
var storenode: string
|
||||||
|
|
||||||
|
|
|
@ -225,7 +225,7 @@ procSuite "Waku v2 JSON-RPC API":
|
||||||
key = wakunode2.PrivateKey.random(ECDSA, rng[]).get()
|
key = wakunode2.PrivateKey.random(ECDSA, rng[]).get()
|
||||||
peer = PeerInfo.init(key)
|
peer = PeerInfo.init(key)
|
||||||
|
|
||||||
node.mountStore()
|
node.mountStore(persistMessages = true)
|
||||||
let
|
let
|
||||||
subscription = node.wakuStore.subscription()
|
subscription = node.wakuStore.subscription()
|
||||||
|
|
||||||
|
@ -518,7 +518,7 @@ procSuite "Waku v2 JSON-RPC API":
|
||||||
|
|
||||||
node.mountFilter()
|
node.mountFilter()
|
||||||
node.mountSwap()
|
node.mountSwap()
|
||||||
node.mountStore()
|
node.mountStore(persistMessages = true)
|
||||||
|
|
||||||
# Create and set some peers
|
# Create and set some peers
|
||||||
let
|
let
|
||||||
|
|
|
@ -101,7 +101,7 @@ procSuite "Peer Manager":
|
||||||
|
|
||||||
node.mountFilter()
|
node.mountFilter()
|
||||||
node.mountSwap()
|
node.mountSwap()
|
||||||
node.mountStore()
|
node.mountStore(persistMessages = true)
|
||||||
|
|
||||||
node.wakuFilter.setPeer(filterPeer)
|
node.wakuFilter.setPeer(filterPeer)
|
||||||
node.wakuSwap.setPeer(swapPeer)
|
node.wakuSwap.setPeer(swapPeer)
|
||||||
|
|
|
@ -62,10 +62,10 @@ procSuite "Waku SWAP Accounting":
|
||||||
# Start nodes and mount protocols
|
# Start nodes and mount protocols
|
||||||
await node1.start()
|
await node1.start()
|
||||||
node1.mountSwap()
|
node1.mountSwap()
|
||||||
node1.mountStore()
|
node1.mountStore(persistMessages = true)
|
||||||
await node2.start()
|
await node2.start()
|
||||||
node2.mountSwap()
|
node2.mountSwap()
|
||||||
node2.mountStore()
|
node2.mountStore(persistMessages = true)
|
||||||
|
|
||||||
await node2.subscriptions.notify("/waku/2/default-waku/proto", message)
|
await node2.subscriptions.notify("/waku/2/default-waku/proto", message)
|
||||||
|
|
||||||
|
@ -108,10 +108,10 @@ procSuite "Waku SWAP Accounting":
|
||||||
# Start nodes and mount protocols
|
# Start nodes and mount protocols
|
||||||
await node1.start()
|
await node1.start()
|
||||||
node1.mountSwap()
|
node1.mountSwap()
|
||||||
node1.mountStore()
|
node1.mountStore(persistMessages = true)
|
||||||
await node2.start()
|
await node2.start()
|
||||||
node2.mountSwap()
|
node2.mountSwap()
|
||||||
node2.mountStore()
|
node2.mountStore(persistMessages = true)
|
||||||
|
|
||||||
await node2.subscriptions.notify("/waku/2/default-waku/proto", message)
|
await node2.subscriptions.notify("/waku/2/default-waku/proto", message)
|
||||||
|
|
||||||
|
|
|
@ -225,9 +225,9 @@ procSuite "WakuNode":
|
||||||
var completionFut = newFuture[bool]()
|
var completionFut = newFuture[bool]()
|
||||||
|
|
||||||
await node1.start()
|
await node1.start()
|
||||||
node1.mountStore()
|
node1.mountStore(persistMessages = true)
|
||||||
await node2.start()
|
await node2.start()
|
||||||
node2.mountStore()
|
node2.mountStore(persistMessages = true)
|
||||||
|
|
||||||
await node2.subscriptions.notify("/waku/2/default-waku/proto", message)
|
await node2.subscriptions.notify("/waku/2/default-waku/proto", message)
|
||||||
|
|
||||||
|
|
|
@ -114,9 +114,14 @@ type
|
||||||
|
|
||||||
store* {.
|
store* {.
|
||||||
desc: "Flag whether to start store protocol",
|
desc: "Flag whether to start store protocol",
|
||||||
defaultValue: false
|
defaultValue: true
|
||||||
name: "store" }: bool
|
name: "store" }: bool
|
||||||
|
|
||||||
|
persistmessages* {.
|
||||||
|
desc: "Enable message persistence: true|false",
|
||||||
|
defaultValue: false
|
||||||
|
name: "persist-messages" }: bool
|
||||||
|
|
||||||
filter* {.
|
filter* {.
|
||||||
desc: "Flag whether to start filter protocol",
|
desc: "Flag whether to start filter protocol",
|
||||||
defaultValue: false
|
defaultValue: false
|
||||||
|
|
|
@ -219,7 +219,7 @@ when isMainModule:
|
||||||
|
|
||||||
# Mount configured Waku v2 protocols
|
# Mount configured Waku v2 protocols
|
||||||
if conf.store:
|
if conf.store:
|
||||||
mountStore(bridge.nodev2)
|
mountStore(bridge.nodev2, persistMessages = conf.persistmessages)
|
||||||
|
|
||||||
if conf.filter:
|
if conf.filter:
|
||||||
mountFilter(bridge.nodev2)
|
mountFilter(bridge.nodev2)
|
||||||
|
|
|
@ -53,9 +53,14 @@ type
|
||||||
defaultValue: ""
|
defaultValue: ""
|
||||||
name: "storenode" }: string
|
name: "storenode" }: string
|
||||||
|
|
||||||
|
persistmessages* {.
|
||||||
|
desc: "Enable message persistence: true|false",
|
||||||
|
defaultValue: false
|
||||||
|
name: "persist-messages" }: bool
|
||||||
|
|
||||||
store* {.
|
store* {.
|
||||||
desc: "Enable store protocol: true|false",
|
desc: "Enable store protocol: true|false",
|
||||||
defaultValue: false
|
defaultValue: true
|
||||||
name: "store" }: bool
|
name: "store" }: bool
|
||||||
|
|
||||||
filter* {.
|
filter* {.
|
||||||
|
|
|
@ -394,7 +394,7 @@ proc mountSwap*(node: WakuNode) =
|
||||||
# NYI - Do we need this?
|
# NYI - Do we need this?
|
||||||
#node.subscriptions.subscribe(WakuSwapCodec, node.wakuSwap.subscription())
|
#node.subscriptions.subscribe(WakuSwapCodec, node.wakuSwap.subscription())
|
||||||
|
|
||||||
proc mountStore*(node: WakuNode, store: MessageStore = nil) =
|
proc mountStore*(node: WakuNode, store: MessageStore = nil, persistMessages: bool) =
|
||||||
info "mounting store"
|
info "mounting store"
|
||||||
|
|
||||||
if node.wakuSwap.isNil:
|
if node.wakuSwap.isNil:
|
||||||
|
@ -405,7 +405,8 @@ proc mountStore*(node: WakuNode, store: MessageStore = nil) =
|
||||||
node.wakuStore = WakuStore.init(node.peerManager, node.rng, store, node.wakuSwap)
|
node.wakuStore = WakuStore.init(node.peerManager, node.rng, store, node.wakuSwap)
|
||||||
|
|
||||||
node.switch.mount(node.wakuStore)
|
node.switch.mount(node.wakuStore)
|
||||||
node.subscriptions.subscribe(WakuStoreCodec, node.wakuStore.subscription())
|
if persistMessages:
|
||||||
|
node.subscriptions.subscribe(WakuStoreCodec, node.wakuStore.subscription())
|
||||||
|
|
||||||
proc mountRlnRelay*(node: WakuNode, ethClientAddress: Option[string] = none(string), ethAccountAddress: Option[Address] = none(Address), membershipContractAddress: Option[Address] = none(Address)) {.async.} =
|
proc mountRlnRelay*(node: WakuNode, ethClientAddress: Option[string] = none(string), ethAccountAddress: Option[Address] = none(Address), membershipContractAddress: Option[Address] = none(Address)) {.async.} =
|
||||||
# TODO return a bool value to indicate the success of the call
|
# TODO return a bool value to indicate the success of the call
|
||||||
|
@ -678,7 +679,7 @@ when isMainModule:
|
||||||
if (conf.storenode != "") or (conf.store):
|
if (conf.storenode != "") or (conf.store):
|
||||||
var store: WakuMessageStore
|
var store: WakuMessageStore
|
||||||
|
|
||||||
if not sqliteDatabase.isNil:
|
if (not sqliteDatabase.isNil) and conf.persistmessages:
|
||||||
let res = WakuMessageStore.init(sqliteDatabase)
|
let res = WakuMessageStore.init(sqliteDatabase)
|
||||||
if res.isErr:
|
if res.isErr:
|
||||||
warn "failed to init WakuMessageStore", err = res.error
|
warn "failed to init WakuMessageStore", err = res.error
|
||||||
|
@ -686,7 +687,7 @@ when isMainModule:
|
||||||
else:
|
else:
|
||||||
store = res.value
|
store = res.value
|
||||||
|
|
||||||
mountStore(node, store)
|
mountStore(node, store, conf.persistmessages)
|
||||||
|
|
||||||
if conf.storenode != "":
|
if conf.storenode != "":
|
||||||
setStorePeer(node, conf.storenode)
|
setStorePeer(node, conf.storenode)
|
||||||
|
|
Loading…
Reference in New Issue