Skip to content

DaoCasino/platform-action-monitor

Repository files navigation

Platform Action Monitor

The service is responsible for processing events from the blockchain and their delivery to various participants in the system. Provides interfaces for subscribing to events.

Stack

Golang, eos-go, pgx, gorilla/websocket

How it works

This service is a notification service tasked with delivering events from the blockchain to all DAOplatform operators. It supplies the interface for subscriptions. There are two types of interactions with the AM: initial: when connecting the client requests an offset topic starting from which the events are sent. current: after the finish of the initial stage AM pushes new events for the subscribed topic.

How to use

EOS

brew tap eosio/eosio
brew install eosio
brew tap eosio/eosio.cdt
brew install eosio.cdt

History tools

git clone --recursive https://github.com/EOSIO/history-tools.git environment/history-tools
docker-compose -f environment/docker-compose.yml build

Launch environments

The environment is configured so that every time the database and node is started, it is cleared and recreated.

History tools

Use ifconfig command to get the ip of the local interface en0 and paste it in docker-compose.yml

... --fill-connect-to 192.168.1.75:8080
docker-compose -f environment/docker-compose.yml up -d

Use docker ps, docker logs commands to check if history tools are working. The database starts for a long time and the history tools may fall with an error. Just repeat docker-compose up -d

EOS node

nodeos -e -p eosio --config-dir `pwd`environment/ --delete-all-blocks --disable-replay-opts

Option --disable-replay-opts is needed for state-history-plugin

Database Migrations

Install tool dbmate and run:

GO111MODULE=on go get -u github.com/amacneil/dbmate
dbmate up

Launch service

GO111MODULE=on go run cmd/monitor/main.go -config configs/config.yml

Dockerize

$ docker-compose build

Load testing

Use Artillery https://artillery.io/

config:
    target: "ws://localhost:8888/"
    phases:
        - duration: 60
          arrivalRate: 5
        # - duration: 120
        #   arrivalRate: 5
        #   rampTo: 50
        # - duration: 600
        #   arrivalRate: 50
scenarios:
    - engine: "ws"
      name: "Subscribe & Unsubscribe topic"
      flow:
        - send: '{"method":"subscribe","params":{"topic":"test","offset":0},"id":"0"}'
        - think: 0.5
        - send: '{"method":"unbscribe","params":{"topic":"test"},"id":"1"}'
$ artillery run loadtest.yml

Links

[]byte and JSON https://stackoverflow.com/questions/34089750/go-marshal-byte-to-json-giving-a-strange-string