-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
344 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
#!/bin/bash | ||
# 2019 - Bismuth Foundation | ||
# Distributed under the MIT software license, see http://www.opensource.org/licenses/mit-license.php. | ||
|
||
# Usage: bash ./bis-node-alone-install.sh | ||
# or one liner : curl https://raw.githubusercontent.com/bismuthfoundation/Bismuth/master/auto-install/bis-node-alone-install.sh|bash | ||
# Setup a regular Bismuth node alone on a fresh Ubuntu 18 install. | ||
|
||
# BEWARE: check configure_firewall to activate. | ||
|
||
VERSION="0.1.1" | ||
|
||
create_swap() { | ||
if [ -d /swapfile ]; then | ||
echo "Swap file already there" | ||
else | ||
fallocate -l 3G /swapfile | ||
chmod 600 /swapfile | ||
mkswap /swapfile | ||
swapon /swapfile | ||
echo "/swapfile none swap sw 0 0" >> /etc/fstab | ||
echo "Swap file activated" | ||
fi | ||
} | ||
|
||
config_os() { | ||
if ! cat /etc/security/limits.conf | grep "root soft nofile 65535"; then | ||
echo "root soft nofile 65535" >> /etc/security/limits.conf | ||
echo "root hard nofile 65535" >> /etc/security/limits.conf | ||
fi | ||
if ! cat /etc/sysctl.conf | grep "fs.file-max = 100000"; then | ||
echo "fs.file-max = 100000" >> /etc/sysctl.conf | ||
fi | ||
if ! cat /etc/sysctl.conf | grep "vm.swappiness = 10"; then | ||
echo "vm.swappiness = 10" >> /etc/sysctl.conf | ||
fi | ||
if ! cat /etc/sysctl.conf | grep "vm.vfs_cache_pressure = 50"; then | ||
echo "vm.vfs_cache_pressure = 50" >> /etc/sysctl.conf | ||
fi | ||
sysctl -p | ||
echo 1 > /proc/sys/net/ipv4/tcp_low_latency | ||
} | ||
|
||
|
||
update_repos() { | ||
echo "Updating repos..." | ||
DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" update | ||
DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade | ||
} | ||
|
||
|
||
install_dependencies() { | ||
echo "Installing apt dependencies" | ||
# apt update -y | ||
# This may be enough, | ||
# apt install ufw unzip ntpdate python3-pip sqlite3 -y | ||
apt install ufw unzip ntpdate python3-pip sqlite3 build-essential python3-dev -y | ||
# ntpdate ntp.ubuntu.com | ||
# apt install ntp -y | ||
} | ||
|
||
|
||
configure_firewall() { | ||
echo "*NOT* Configuring Firewall" | ||
#ufw disable | ||
#ufw allow ssh/tcp | ||
#ufw limit ssh/tcp | ||
# node port | ||
#ufw allow 5658/tcp | ||
# HN port | ||
#ufw allow 6969/tcp | ||
# Wallet server | ||
#ufw allow 8150/tcp | ||
# Websocket server | ||
#ufw allow 8155/tcp | ||
#ufw logging on | ||
#ufw default deny incoming | ||
#ufw default allow outgoing | ||
#ufw --force enable | ||
} | ||
|
||
|
||
download_node() { | ||
echo "Fetching Node" | ||
cd | ||
if [ -f ./v4.3.0.1-beta.1.tar.gz ]; then | ||
rm v4.3.0.1-beta.1.tar.gz | ||
fi | ||
wget https://github.com/bismuthfoundation/Bismuth/archive/v4.3.0.1-beta.1.tar.gz | ||
tar -zxf v4.3.0.1-beta.1.tar.gz | ||
mv Bismuth-4.3.0.1-beta.1 Bismuth | ||
cd Bismuth | ||
echo "Configuring node" | ||
echo "ram=False" >> config_custom.txt | ||
echo "full_ledger=True" >> config_custom.txt | ||
echo "mempool_ram=False" >> config_custom.txt | ||
echo "Downloading bootstrap" | ||
cd static | ||
if [ -f ./ledger-verified.tar.gz ]; then | ||
rm ledger-verified.tar.gz | ||
fi | ||
wget https://snapshots.s3.nl-ams.scw.cloud/ledger-verified.tar.gz | ||
tar -zxf ledger-verified.tar.gz | ||
# Make some room | ||
rm ledger-verified.tar.gz | ||
echo "Getting node sentinel" | ||
cd /root/Bismuth | ||
wget https://gist.githubusercontent.com/EggPool/e7ad9baa2b32e4d7d3ba658a40b6d643/raw/934598c7ff815180b913d6549bd2d9688e016855/node_sentinel.py | ||
echo "Installing PIP requirements" | ||
pip3 install setuptools ipwhois | ||
pip3 install -r requirements-node.txt | ||
} | ||
|
||
install_plugin() { | ||
echo "Installing companion plugin" | ||
mkdir /root/Bismuth/plugins | ||
mkdir /root/Bismuth/plugins/500_hypernode | ||
cd /root/Bismuth/plugins/500_hypernode | ||
wget https://raw.githubusercontent.com/bismuthfoundation/hypernode/master/node_plugin/__init__.py | ||
} | ||
|
||
start_node() { | ||
echo "Starting node" | ||
cd | ||
screen -d -S node -m bash -c "cd Bismuth;python3 node.py" -X quit | ||
} | ||
|
||
wait_ledger() { | ||
echo "Waiting for ledger to download and extract" | ||
while true; do | ||
if [ ! -f /root/Bismuth/static/ledger.db ]; then | ||
echo "." | ||
sleep 10 | ||
else | ||
break | ||
fi | ||
done | ||
} | ||
|
||
|
||
add_cron_jobs() { | ||
# Node sentinel | ||
echo "Inserting example node sentinel cronjob, but not activated" | ||
if ! crontab -l | grep "node_sentinel"; then | ||
(crontab -l ; echo "#* * * * * cd /root/Bismuth;python3 node_sentinel.py") | crontab - | ||
fi | ||
} | ||
|
||
if [ "$(whoami)" != "root" ]; then | ||
echo "Script must be run as root" | ||
exit -1 | ||
fi | ||
|
||
while true; do | ||
if [ -d /root/Bismuth ]; then | ||
printf "/root/Bismuth/ already exists! The installer will delete this folder. Continue anyway?(Y/n)" | ||
pID=$(ps -ef | grep node.py | awk '{print $2}' | head -n 1) | ||
kill ${pID} | ||
rm -rf /root/Bismuth/ | ||
break | ||
else | ||
break | ||
fi | ||
done | ||
|
||
cd | ||
create_swap | ||
config_os | ||
update_repos | ||
install_dependencies | ||
configure_firewall | ||
download_node | ||
install_plugin | ||
|
||
# cron_jobs are what will launch at boot and auto-restart node - not acctivated by default. | ||
add_cron_jobs | ||
|
||
|
||
echo "Rebooting server." | ||
reboot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Auto install script | ||
|
||
**This is an auto install for NODE alone** | ||
To be used by devs, exchanges, service providers. | ||
If you want to host a Hypernode, please use the 2 in 1 auto installer at https://github.com/bismuthfoundation/hypernode/tree/master/auto-install | ||
|
||
- Tested on Ubuntu 18 Only | ||
- Needs login as root | ||
- will reboot the vps after install | ||
|
||
- Experimental, use at your own risks, may break your vps and need os reinstall | ||
- Does **not** set up the UFW firewall, to avoid conflicts with ssh port or other apps. see firewall sectino of the sccript if needed. | ||
|
||
- Works well for me :) | ||
|
||
A Docker images is now also available: | ||
https://github.com/bismuthfoundation/Bismuth-Docker/tree/master/node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# check_tx.py | ||
|
||
A Demo script that takes a transaction id as input, and sends back a json with it's status | ||
- Unknown | ||
- In mempool | ||
(shows timestamp, from, to, amount, first 50 chars of openfield) | ||
- In ledger | ||
(shows timestamp, from, to, amount, first 50 chars of openfield as well as number of confirmations) | ||
|
||
## How to run | ||
|
||
This script is supposed to be run in the node directory, it needs access to both `ledger.db` and `mempool.db`. | ||
It takes the ledger path from the default config.txt file. | ||
|
||
# Output examples | ||
|
||
Here are a few sample outputs. | ||
(Imaginary data) | ||
|
||
## Unknown Txid | ||
|
||
`python3 check_tx.py bZ8/XjQhKX4GmlVmettD8H1+Tdh+FG8zXfghfdgh` | ||
|
||
|
||
``` | ||
{"Status": "Unknown", "TxId": "bZ8/XjQhKX4GmlVmettD8H1+Tdh+FG8zXfghfdgh"} | ||
``` | ||
|
||
## Tx in Mempool | ||
|
||
`python3 check_tx.py anotheroneinthepool` | ||
|
||
``` | ||
{"Amount": 0, "Timestamp": 1517594747.07, "Address": "371a2a76a527d0a45aac441fc3170a9e609e59abd134aa4bca726211", "Recipient": "371a2a76a527d0a45aac441fc3170a9e609e59abd134aa4bca726211", "Block": 498059, "Openfield": "a9443a88b04834e8001ddc3569491d31a2b9c61765f99d1c62", "TxId": "bZ8/XjQhKX4GmlVmettD8H1+Tdh+FG8zX", "Status": "Mempool"} | ||
``` | ||
|
||
## Confirmed Tx, in ledger | ||
|
||
|
||
`python3 check_tx.py bZ8/XjQhKX4GmlVmettD8H1+Tdh+FG8zX` | ||
|
||
``` | ||
{"Amount": 0, "Confirmations": 2, "Timestamp": 1517594747.07, "Address": "371a2a76a527d0a45aac441fc3170a9e609e59abd134aa4bca726211", "Recipient": "371a2a76a527d0a45aac441fc3170a9e609e59abd134aa4bca726211", "Block": 498059, "Openfield": "a9443a88b04834e8001ddc3569491d31a2b9c61765f99d1c62", "TxId": "bZ8/XjQhKX4GmlVmettD8H1+Tdh+FG8zX", "Status": "Confirmed"} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
""" | ||
check_tx.py | ||
A Demo script that takes a transaction id as input, and sends back a json with it's status | ||
- unknown | ||
- in mempool (shows timestamp, from, to, amount, first 50 chars of openfield) | ||
- in ledger (shows timestamp, from, to, amount, first 50 chars of openfield as well as number of confirmations) | ||
This script is supposed to be run in the node directory, it needs access to both ledger.db and mempool.db | ||
""" | ||
|
||
import sqlite3, sys, json | ||
import options | ||
|
||
# Default ledger path | ||
ledger_path = "static/ledger.db" | ||
|
||
# Default mempool path | ||
mempool_path = "mempool.db" | ||
|
||
|
||
def list_to_tx(result): | ||
""" | ||
Converts the query result into a dict | ||
""" | ||
result[4] = result[4][:50] | ||
keys = ["Timestamp", "Address", "Recipient", "Amount", "Openfield", "Block"] | ||
return dict(zip(keys,result)) | ||
|
||
|
||
def is_in_mempool(txid): | ||
""" | ||
If txid is in mempool, sends back details of the tx | ||
""" | ||
mempool = sqlite3.connect(mempool_path) | ||
mempool.text_factory = str | ||
m = mempool.cursor() | ||
m.execute("SELECT timestamp, address, recipient, amount, openfield FROM transactions WHERE signature like ?;", (txid+"%",)) | ||
result = m.fetchone() | ||
if result: | ||
return (True, list_to_tx(list(result))) | ||
else: | ||
return (False, None) | ||
|
||
|
||
def is_in_ledger(txid): | ||
""" | ||
If txid is in ledger, sends back details of the tx and number of confirmations | ||
""" | ||
ledger = sqlite3.connect(ledger_path) | ||
ledger.text_factory = str | ||
m = ledger.cursor() | ||
m.execute("SELECT timestamp, address, recipient, amount, openfield, block_height FROM transactions WHERE signature like ?;", (txid+"%",)) | ||
result = m.fetchone() | ||
if result: | ||
m.execute("SELECT block_height FROM transactions ORDER BY block_height desc LIMIT 1") | ||
last = m.fetchone() | ||
return (True, list_to_tx(list(result)), last[0]) | ||
else: | ||
return (False, None, None) | ||
|
||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) != 2: | ||
txid = input("No argument detected, please insert command manually\n") | ||
else: | ||
txid = sys.argv[1] | ||
|
||
res = {"TxId":txid, "Status":"Unknown"} | ||
|
||
isit, details = is_in_mempool(txid) | ||
if isit: | ||
res["Status"] = "Mempool" | ||
res.update(details) | ||
|
||
isit, details, lastblock = is_in_ledger(txid) | ||
if isit: | ||
res["Status"] = "Confirmed" | ||
res.update(details) | ||
res["Confirmations"] = lastblock - res["Block"] | ||
|
||
print(json.dumps(res)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"127.0.0.1": "2829"} | ||
{"127.0.0.1": "2829", "51.15.97.143": "2829"} |