mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-04 23:13:09 +00:00
lightpush with config and metrics
This commit is contained in:
parent
a094e1dc2d
commit
6da2c53e00
57
Dockerfile.lightpushWithMix.compile
Normal file
57
Dockerfile.lightpushWithMix.compile
Normal file
@ -0,0 +1,57 @@
|
||||
# BUILD NIM APP ----------------------------------------------------------------
|
||||
FROM rust:1.77.1-alpine3.18 AS nim-build
|
||||
|
||||
ARG NIMFLAGS
|
||||
ARG MAKE_TARGET=lightpushwithmix
|
||||
ARG NIM_COMMIT
|
||||
ARG LOG_LEVEL=TRACE
|
||||
|
||||
# Get build tools and required header files
|
||||
RUN apk add --no-cache bash git build-base openssl-dev pcre-dev linux-headers curl jq
|
||||
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
|
||||
# workaround for alpine issue: https://github.com/alpinelinux/docker-alpine/issues/383
|
||||
RUN apk update && apk upgrade
|
||||
|
||||
# Ran separately from 'make' to avoid re-doing
|
||||
RUN git submodule update --init --recursive
|
||||
|
||||
# Slowest build step for the sake of caching layers
|
||||
RUN make -j$(nproc) deps QUICK_AND_DIRTY_COMPILER=1 ${NIM_COMMIT}
|
||||
|
||||
# Build the final node binary
|
||||
RUN make -j$(nproc) ${NIM_COMMIT} $MAKE_TARGET LOG_LEVEL=${LOG_LEVEL} NIMFLAGS="${NIMFLAGS}"
|
||||
|
||||
|
||||
# REFERENCE IMAGE as BASE for specialized PRODUCTION IMAGES----------------------------------------
|
||||
FROM alpine:3.18 AS base_lpt
|
||||
|
||||
ARG MAKE_TARGET=lightpushwithmix
|
||||
|
||||
LABEL maintainer="prem@waku.org"
|
||||
LABEL source="https://github.com/waku-org/nwaku"
|
||||
LABEL description="Lite Push With Mix: Waku light-client"
|
||||
LABEL commit="unknown"
|
||||
LABEL version="unknown"
|
||||
|
||||
# DevP2P, LibP2P, and JSON RPC ports
|
||||
EXPOSE 30303 60000 8545
|
||||
|
||||
# Referenced in the binary
|
||||
RUN apk add --no-cache libgcc pcre-dev libpq-dev \
|
||||
wget \
|
||||
iproute2 \
|
||||
python3
|
||||
|
||||
# Fix for 'Error loading shared library libpcre.so.3: No such file or directory'
|
||||
RUN ln -s /usr/lib/libpcre.so /usr/lib/libpcre.so.3
|
||||
|
||||
COPY --from=nim-build /app/build/lightpush_publisher_mix /usr/bin/
|
||||
RUN chmod +x /usr/bin/lightpush_publisher_mix
|
||||
|
||||
# Standalone image to be used manually and in lpt-runner -------------------------------------------
|
||||
FROM base_lpt AS standalone_lpt
|
||||
|
||||
ENTRYPOINT ["/usr/bin/lightpush_publisher_mix"]
|
||||
@ -10,7 +10,8 @@ import
|
||||
libp2p/crypto/curve25519,
|
||||
libp2p/multiaddress,
|
||||
eth/keys,
|
||||
eth/p2p/discoveryv5/enr
|
||||
eth/p2p/discoveryv5/enr,
|
||||
metrics
|
||||
|
||||
import mix/entry_connection, mix/protocol
|
||||
|
||||
@ -26,7 +27,8 @@ import
|
||||
factory/builder,
|
||||
waku_lightpush/client
|
||||
],
|
||||
./lightpush_publisher_mix_config
|
||||
./lightpush_publisher_mix_config,
|
||||
./lightpush_publisher_mix_metrics
|
||||
|
||||
|
||||
proc now*(): Timestamp =
|
||||
@ -88,12 +90,7 @@ proc setupAndPublish(rng: ref HmacDrbgContext, conf: LPMixConf) {.async.} =
|
||||
@[MultiAddress.init(conf.destPeerAddr).get()],
|
||||
)
|
||||
node.peerManager.addServicePeer(pxPeerInfo, WakuPeerExchangeCodec)
|
||||
#[ let pxPeerInfo2 = RemotePeerInfo.init(
|
||||
"16Uiu2HAmRhxmCHBYdXt1RibXrjAUNJbduAhzaTHwFCZT4qWnqZAu",
|
||||
@[MultiAddress.init("/ip4/127.0.0.1/tcp/60005").get()],
|
||||
)
|
||||
node.peerManager.addServicePeer(pxPeerInfo2, WakuPeerExchangeCodec)
|
||||
]#
|
||||
|
||||
(
|
||||
await node.mountMix(
|
||||
intoCurve25519Key(
|
||||
@ -105,7 +102,6 @@ proc setupAndPublish(rng: ref HmacDrbgContext, conf: LPMixConf) {.async.} =
|
||||
).isOkOr:
|
||||
error "failed to mount waku mix protocol: ", error = $error
|
||||
return
|
||||
#discard node.setMixBootStrapNodes()
|
||||
|
||||
let destPeerId = PeerId.init(conf.destPeerId).valueOr:
|
||||
error "Failed to initialize PeerId", err = error
|
||||
@ -125,15 +121,14 @@ proc setupAndPublish(rng: ref HmacDrbgContext, conf: LPMixConf) {.async.} =
|
||||
(await node.fetchPeerExchangePeers()).isOkOr:
|
||||
warn "Cannot fetch peers from peer exchange", cause = error
|
||||
|
||||
while node.getMixNodePoolSize() < 3:
|
||||
while node.getMixNodePoolSize() < conf.minMixPoolSize:
|
||||
info "waiting for mix nodes to be discovered",
|
||||
currentpoolSize = node.getMixNodePoolSize()
|
||||
await sleepAsync(1000)
|
||||
|
||||
notice "publisher service started"
|
||||
var numMsgs = 4
|
||||
notice "publisher service started with mix node pool size ", currentpoolSize = node.getMixNodePoolSize()
|
||||
var i = 0
|
||||
while i < numMsgs:
|
||||
while i < conf.numMsgs:
|
||||
i = i + 1
|
||||
let text = "hi there i'm a publisher using mix, this is msg number " & $i
|
||||
let message = WakuMessage(
|
||||
@ -148,6 +143,7 @@ proc setupAndPublish(rng: ref HmacDrbgContext, conf: LPMixConf) {.async.} =
|
||||
)
|
||||
|
||||
if res.isOk:
|
||||
lp_mix_success.inc()
|
||||
notice "published message",
|
||||
text = text,
|
||||
timestamp = message.timestamp,
|
||||
@ -155,6 +151,7 @@ proc setupAndPublish(rng: ref HmacDrbgContext, conf: LPMixConf) {.async.} =
|
||||
contentTopic = LightpushContentTopic
|
||||
else:
|
||||
error "failed to publish message", error = res.error
|
||||
lp_mix_failed.inc(labelValues = ["publish_error"])
|
||||
|
||||
await sleepAsync(1000)
|
||||
|
||||
|
||||
@ -19,4 +19,16 @@ type
|
||||
desc: "Port to listen on.",
|
||||
defaultValue: 50000,
|
||||
name: "port",
|
||||
}: int
|
||||
|
||||
numMsgs* {.
|
||||
desc: "Number of messages to send.",
|
||||
defaultValue: 1,
|
||||
name: "num-msgs",
|
||||
}: int
|
||||
|
||||
minMixPoolSize* {.
|
||||
desc: "Number of messages to wait for before sending.",
|
||||
defaultValue: 3,
|
||||
name: "mix-mix-pool-size",
|
||||
}: int
|
||||
7
examples/lightpush_publisher_mix_metrics.nim
Normal file
7
examples/lightpush_publisher_mix_metrics.nim
Normal file
@ -0,0 +1,7 @@
|
||||
{.push raises: [].}
|
||||
|
||||
import metrics
|
||||
|
||||
declarePublicGauge lp_mix_success, "number of lightpush messages sent via mix"
|
||||
|
||||
declarePublicGauge lp_mix_failed, "number of lightpush messages failed via mix", labels = ["error"]
|
||||
Loading…
x
Reference in New Issue
Block a user