Skip to content

Commit

Permalink
Merge branch 'master' into postfork
Browse files Browse the repository at this point in the history
  • Loading branch information
EggPool authored Nov 9, 2019
2 parents 0d689a3 + 51676e5 commit ad25d1d
Show file tree
Hide file tree
Showing 8 changed files with 344 additions and 14 deletions.
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,22 @@ Bismuth Readme
* https://github.com/EggPool
* https://github.com/hclivess

### License:
### Links:

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
Bismuth Foundation:
* https://github.com/bismuthfoundation

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Twitter:
* https://twitter.com/bismuthplatform
* https://twitter.com/bismuthdev
* https://twitter.com/EggPoolNet

Discord (main support and community place):
* https://discord.gg/dKVZd4z

Facebook:
* https://web.facebook.com/cryptobismuth

Reddit:
* https://www.reddit.com/r/cryptobismuth/

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2 changes: 1 addition & 1 deletion _MOST_USEFUL_FILES.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Web part of the zircodice casino.

## Bismuth Core API

https://github.com/EggPool/BismuthAPI
https://github.com/bismuthfoundation/BismuthAPI

## Bismuth plugins
https://github.com/bismuthfoundation/BismuthPlugins
Expand Down
180 changes: 180 additions & 0 deletions auto-install/bis-node-alone-install.sh
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
17 changes: 17 additions & 0 deletions auto-install/readme.md
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
44 changes: 44 additions & 0 deletions check_tx.md
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"}
```
83 changes: 83 additions & 0 deletions check_tx.py
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))

2 changes: 2 additions & 0 deletions node.py
Original file line number Diff line number Diff line change
Expand Up @@ -1966,6 +1966,7 @@ def verify(db_handler):
node.logger.app_log.warning("Error: {}".format(e))
raise


def add_indices(db_handler: dbhandler.DbHandler):
CREATE_TXID4_INDEX_IF_NOT_EXISTS = "CREATE INDEX IF NOT EXISTS TXID4_Index ON transactions(substr(signature,1,4))"
CREATE_MISC_BLOCK_HEIGHT_INDEX_IF_NOT_EXISTS = "CREATE INDEX IF NOT EXISTS 'Misc Block Height Index' on misc(block_height)"
Expand All @@ -1986,6 +1987,7 @@ def add_indices(db_handler: dbhandler.DbHandler):

node.logger.app_log.warning("Finished creating indices")


if __name__ == "__main__":
# classes
node = node.Node()
Expand Down
2 changes: 1 addition & 1 deletion peers_test.txt
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"}

0 comments on commit ad25d1d

Please sign in to comment.