Giter VIP home page Giter VIP logo

betsy-middleware's Introduction

NANO/BANANO Work/Callback/Distributed POW Middleware (Betsy) v2.0

What is Betsy?

Middleware for banano/nano applications and nodes.

Why would I use this?

Here's some of the possible use cases

  • You want to use distributed pow v3, but you don't want to change any application code.
  • You want to use distributed pow v3, but you also want to use other work peers at the same time
  • You want to precache work for accounts without using distributed pow
  • You want to forward the nano/banano node callback to multiple services
  • You want to use any combination of distributed pow and work peers, but you don't want things to collapse when they are unavailable

Setup and Dependencies

Betsy requires python 3.6 or newer. Recommended operation is to use a virtualenv for all of the project dependencies.

# git clone https://github.com/bbedward/betsy-middleware.git
# cd betsy-middleware
# virtualenv -p python3.6 venv
# ./venv/bin/pip install -r requirements.txt

Usage

You can run ./venv/bin/python main.py --help for all options.

Betsy is configured using arguments.

Argument Description
--host Host for betsy to listen on (default: 127.0.0.1)
--port Port for betsy to listen on (default: 5555)
--node-url URL of the local node for work_generate fallback If not specified, then will disable local node fallback. (optional, example: [::1]:7072)
--log-file Where betsy will output logging data to (default: /tmp/betsy.log)
--work-urls Work peer list, separated by spaces (NOT distributed pow) (optional, example: 'http://peer.com/api http://peer2.com/api`
--callbacks APIs to forward the node callback to (optional, example: 'http://myapi.cc/api http://myapi2.cc/api`
--precache Enable work precaching for work peers, excludes BoomPoW
--debug Enable debug mode (more verbose logging)

If I wanted to:

  • Run on port 4545
  • Enable work fallback to my nano node which has RPC on [::1]:7076
  • Use the work peers https://workpeerone.com and 123.45.67.89:7176
  • Forward callbacks to 127.0.0.1:6000/callback
  • And enable work precaching

I would use the arguments as:

main.py --port 4545 --node-url [::1]:7076 --work-urls https://workpeerone.com 123.45.67.89:7176 --callbacks 127.0.0.1:6000/callback --precache

Setting up with BoomPow v2 (BPoW)

You can use betsy with BANANO's PoW service as well (BoomPow). You just need to add the key to the environment.

BPOW_KEY=124567

You can also add it to a file .env

If you intend to use BoomPow with a NANO service!

You need to also start betsy with the option --bpow-nano-difficulty

Setting the node callback to point to betsy

If you want to use precaching or callback forwarding, betsy needs to receive callbacks. You can do this by editing the NanoData/config.json file as follows:

"callback_address": "127.0.0.1",
"callback_port": "5555",
"callback_target": "/callback",

callback_address and callback_port are the same as the --host and --port options you choose when you run betsy.

Getting work from Betsy

Betsy does all the complicated stuff behind the scenes, all you need to do is post a standard work_generate request.

curl -g -d '{"action":"work_generate", "hash":"ECCB8CB65CD3106EDA8CE9AA893FEAD497A91BCA903890CBD7A5C59F06AB9113"}' '127.0.0.1:5555'

You can also use betsy as a work_peer in the NanoData/config.json

work_peers: [
  "::ffff:127.0.0.1:5555"
]

Running as systemd service

1.) Create file /etc/systemd/system/betsy.service

[Unit]
Description=Betsy - Nano Middleware
After=network.target

[Service]
Type=simple
User=<your_user>
WorkingDirectory=/path/to/betsy
EnvironmentFile=/path/to/betsy/.env
ExecStart=/path/to/betsy/venv/bin/python main.py --host 127.0.0.1 --port 5555 --work-urls 123.45.67.89:6000/work --callbacks 123.45.67.89/callback --precache

[Install]
WantedBy=multi-user.target

2.) Enable and start

sudo systemctl enable betsy
sudo systemctl start betsy

betsy-middleware's People

Contributors

bbedward avatar gbl08ma avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

betsy-middleware's Issues

Error feedback when the redis connection fails

It can be difficult to understand that it's redis missing:

(! 2034)-> ./venv/bin/python main.py --node-url [::1]:55000 --debug
INFO:aiohttp.server:Opening redis connection
DEBUG:aioredis:Creating tcp connection to ('localhost', 6379)
DEBUG:aioredis:Closed 0 connection(s)
Traceback (most recent call last):
  File "main.py", line 364, in <module>
    main()
  File "main.py", line 351, in main
    asyncio.get_event_loop().run_until_complete(start())
  File "uvloop/loop.pyx", line 1451, in uvloop.loop.Loop.run_until_complete
  File "main.py", line 344, in start
    await runner.setup()
  File "/home/glawless/nano_ws/betsy-middleware/venv/lib/python3.6/site-packages/aiohttp/web_runner.py", line 203, in setup
    self._server = await self._make_server()
  File "/home/glawless/nano_ws/betsy-middleware/venv/lib/python3.6/site-packages/aiohttp/web_runner.py", line 302, in _make_server
    await self._app.startup()
  File "/home/glawless/nano_ws/betsy-middleware/venv/lib/python3.6/site-packages/aiohttp/web_app.py", line 389, in startup
    await self.on_startup.send(self)
  File "/home/glawless/nano_ws/betsy-middleware/venv/lib/python3.6/site-packages/aiohttp/signals.py", line 34, in send
    await receiver(*args, **kwargs)  # type: ignore
  File "main.py", line 301, in open_redis
    db=1, encoding='utf-8', minsize=2, maxsize=50)
  File "/home/glawless/nano_ws/betsy-middleware/venv/lib/python3.6/site-packages/aioredis/commands/__init__.py", line 201, in create_redis_pool
    loop=loop)
  File "/home/glawless/nano_ws/betsy-middleware/venv/lib/python3.6/site-packages/aioredis/pool.py", line 56, in create_pool
    await pool._fill_free(override_min=False)
  File "/home/glawless/nano_ws/betsy-middleware/venv/lib/python3.6/site-packages/aioredis/pool.py", line 388, in _fill_free
    conn = await self._create_new_connection(self._address)
  File "/home/glawless/nano_ws/betsy-middleware/venv/lib/python3.6/site-packages/aioredis/connection.py", line 108, in create_connection
    timeout, loop=loop)
  File "/usr/lib/python3.6/asyncio/tasks.py", line 339, in wait_for
    return (yield from fut)
  File "/home/glawless/nano_ws/betsy-middleware/venv/lib/python3.6/site-packages/aioredis/stream.py", line 19, in open_connection
    lambda: protocol, host, port, **kwds)
  File "uvloop/loop.pyx", line 1904, in create_connection
  File "uvloop/loop.pyx", line 1883, in uvloop.loop.Loop.create_connection
ConnectionRefusedError: [Errno 111] Connection refused

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.