Nano-SpeedTest
Nano-SpeedTest copied to clipboard
Webapp to test speed of Nano Transactions
Nano-SpeedTest
Table of Contents
- Front End
- Front End: Getting Started
- Front End: Testing
- Front End: Other Information
- Back End
- Back End: Installing Dependencies
- Back End: Testing
- Back End: Setting Up Node
This website is able to time nano transactions from between nodes in distinct places. In order to run the project on your own computer, there are two disctinct parts you must setup: front end and back end.
Nano SpeedTest Front End
This front end is created using React. Below are instructions on how to get started and other useful resources.
Getting Started
- Clone this repo by running
git clone https://github.com/silverstar194/Nano-SpeedTest.git
- Install node in order to use
npm
commands -brew install node
(install here for windows: https://nodejs.org/en/) - Navigate to
Nano-SpeedTest/app/frontend
- Install all node dependencies -
npm install
- While it is installing, inside the
frontend
folder create a file called.env
. Inside place:REACT_APP_GOOGLE_MAPS_KEY=<KEY>
andREACT_APP_API_PREFIX=http://api.nanospeed.live/
andNODE_PATH=src/
on separate lines. This will allow you to use the Google Maps and keep the local structure of the project working correctly. - Finally, run app in development mode -
npm start
Open http://localhost:3000 to view it in the browser.
The page will reload if you make edits.
You will also see any lint errors in the console.
Front End Testing
Currently basic unit testing of redux actions and reducers exists. Running npm test
triggers tests to run and continue to run on file changes.
In addition, npm test -- --coverage
(yes there are two --) will show the coverage report. Currently only .js
files are being tested and it is specifically set to ignore additional files such as index.js
and serviceWorker.js
. These options can be changed in the package.json
.
Other Information
For the project to build, these files must exist with exact filenames:
-
public/index.html
is the page template; -
src/index.js
is the JavaScript entry point.
You can delete or rename the other files.
You may create subdirectories inside src
. For faster rebuilds, only files inside src
are processed by Webpack.
You need to put any JS and CSS files inside src
, otherwise Webpack won’t see them.
Only files inside public
can be used from public/index.html
.
Read instructions below for using assets from JavaScript and HTML.
You can, however, create more top-level directories.
They will not be included in the production build so you can use them for things like documentation.
Using Process.env
Using process.env.<VARIABLE>
requires placing the variable you wish to use in the .env
file prefixed with REACT_APP_<YOUR_NAME>
which can then be used in the code as process.env.REACT_APP_<YOUR_NAME>
. If you want to use the variable in the index.html file it must be wrapped "%<VARIABLE_NAME>%"
.
Some Notes on the Frontend
Structure
Components/
holds all the React Elements. It also holds most of the other pages such as the Homepage
, MoreInfo Page
, and Advertisements
.
Components/CurrentTransactions/
is the Your Results
tab
Components/HistoricalData
is the Global Statistics
tab
The structure and naming of the components could definitely use some work as we did not originally plan to have as many pages and the project never got refactored based on our timeline. There are also a number of components that really should have the logic simplified and broken out into smaller subsections.
Testing
The tests on UI components are basically worthless - they just perform checking that the component actually renders.
Tests on .js
files are better but some of the more complicated areas such as requests and middleware we did not cover.
Nano SpeedTest Back End
Installing Dependencies
Python 3
Make sure you have installed the latest version of Python 3 and pip from the official Python website.
Verify the installation with the follwing command:
$ python --version
Django
These are the Django packages installed by following this tutorial.
$ pip3 install djangorestframework
$ pip3 install markdown
$ pip3 install django-filter
Other Python Dependencies
$ pip3 install requests # Used for sending HTTP Requests
$ pip3 install nano-python # RPC wrapper for Nano
$ pip3 install mysqlclient # We are using a MySQL database
$ pip3 install django-ipware # Used for getting IP from REST request
$ pip3 install django-ratelimit # Puts a limit on the transaction endpoints to prevent spamming
$ pip3 install django-crontab # Runs task to periodically balance accounts
$ pip3 install django-cors-headers
$ pip3 install numpy
Environment Variable Setup
dPoW API
In order to run the Django server, the following environment variables need to exist (the server will not start without them). They are not provided here for security.
-
NANO_ST__DPOW__ENDPOINT
endpoint of the dPoW service -
NANO_ST__DPOW__API_KEY
API key for the dPoW service -
NANO_ST__DB__NAME
-
NANO_ST__DB__USER
-
NANO_ST__DB__PASSWORD
-
NANO_ST__DB__HOST
Running the Server
Execute the following to host the web API locally.
$ python manage.py runserver <IP:Port (Optional)>
Executing a Django Project Python Shell
One can execute a Django Python shell (similar to a standard Python shell but imports project) using the following command:
$ python manage.py shell
This provides a nice sandbox to interact with the API while coding.
Calling management commands
These commands and code can be found in ./speedtest_api/management/commands/
The following runs the account balancer (attach this to a cron job):
$ python manage.py balance_accounts
The following generates wallets and accounts on available nodes and adds them to the database:
$ python manage.py populate_nodes
The following calculates the Proof of Work for all accounts (unless they have a valid POW):
$ python manage.py regen_pow
The following synchronizes the balance of all accounts from the Nano network to our database balance:
$ python manage.py sync_accounts
Back End Testing
Currently backend tests can be run as follows:
$ python manage.py test
In order to do this you need to have a node set up. We have included a link on setup in the next section.
Setting Up Node
https://github.com/nanocurrency/raiblocks/wiki/Docker-node
Spam prevention
There are several layers of spam protection.
Firstly, each IP is limited at the Django app layer to 15 requests per thread. The backend client is running on 3 threads for a total of 45 requests per day per IP.
Secondly, total number of requests are limited to Nginx at 80/min with 20 burst limit.
Lastly, using Fail2Ban any requests that are over the 80/min with 20 burst are counted up. Any IP with more than 3 violations are banned for a 24 hour period.