Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4.1.1 #15

Merged
merged 8 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
280 changes: 150 additions & 130 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# android-termux-monero-node
Run a Full or Pruned Monero Node on Android using Termux
# Monerod-in-Termux
Run a Monero Node on Android using Termux

<center>
<figure>
Expand All @@ -9,154 +9,159 @@ Run a Full or Pruned Monero Node on Android using Termux
</center>

## Table of Contents
- [android-termux-monero-node](#android-termux-monero-node)
- [Table of Contents](#table-of-contents)
- [Why](#why)
- [Contributing to the Monero Network](#contributing-to-the-monero-network)
- [WARNING...](#warning)
- [Install](#install)
- [Controls Overview](#controls-overview)
- [Connecting to your Node / Seeding the Network](#connecting-to-your-node--seeding-the-network)
- [Wallet Connections](#wallet-connections)
- [P2P Seeding](#p2p-seeding)
- [Updates](#updates)
- [TODO's:](#todos)
- [Donate:](#donate)

# Why

The goal of this project is to give newbs a stupid-easy way to run an energy-efficient, full or pruned Monero node with decent defaults on an Android device.... ideally, this is a few year old device that's currently sitting in a drawer doing nothing. Why not set it up as a Monero node that sits at your house all day or you toss in a bag for making ultra-secure Monero transactions on the go? This code and install process isn't meant for power users, people with extreme use cases, etc. If you're already that smart, you should just hack up my code and use it however you like.

Battery Life-
I'm running this on a phone that's plugged in most of the time, so I can't speak for battery life; I would assume that once you're fully synced, the battery usage will drop quite a bit.
- [Background](#background)
- [TLDR / Install](#tldr--install)
- [Table of Contents](#table-of-contents)
- [⚠️ Warnings](#warnings)
- [Controls Overview](#controls-overview)
- [Connecting to your Node / Seeding the Network](#connecting-to-your-node--seeding-the-network)
- [Wallet Connections](#wallet-connections)
- [P2P Seeding](#p2p-seeding)
- [Updates](#updates)
- [TODO's](#todos)
- [Donate](#donate)

# Background

The goal of this project is to give newbs a stupid-easy way to run an energy-efficient, full or pruned Monero node on Android.

Ideally, this is an older device that's currently sitting in a drawer, doing nothing.
Why not set it up as a Monero node?

Battery Life
- Recommend leaving charger connected during initial sync, which can take a couple days.
- Battery usage after sync completion is quite low, but not 0 due to wake-lock being applied.
- While the node can be run on your main device, it is recommended to keep the device plugged in when running 24/7 or better, to run on a spare/old device.

Data Usage
- Over 100 gb initial download.
- After fully synced, and using config settings of: 1gb max up/down speeds; 32/100 out/in peers; averaging 25kb/s up/down:
- Approx 2gb/day (dl) as of Sunday, January 02, 2022.
- Slightly more than 4gb if P2P seeding is enabled.
- You can check your data usage using the **XMR Node Status** shortcut from the widget. It will show in the terminal that pops up.

Running a Monero node allows you to connect your wallet (Feather, CakeWallet, Monerujo etc) to your node.
While Monero is private, using a _remote_ node (one operated by a 3rd party) involves some level of trust.
A remote node receives certain information from you, such as the date, time of a tx and the IP that sent it to the node.
Running a node on Android is an easy and more decentralized way to both use and improve Monero and the Monero network.


# TLDR / Install

Prerequisites:

- Android 7.0+ with ARMv8/v7 architecture
- The script will check the architecture before running
- 50GB min free space (64GB+ Recommended) for Pruned node
- 150GB min free space (256GB+ Preferred) for Full Node
- External Storage is recommended.

Steps:

1. Install the [F-Droid App Store](https://f-droid.org/)

2. Install these Apps from F-Droid:

(Do **NOT** install from Play store. If any of these are already installed from gplay, uninstall them)
- [Termux](https://f-droid.org/packages/com.termux)
- [Termux:Widget](https://f-droid.org/packages/com.termux.widget)
- [Termux:API](https://f-droid.org/packages/com.termux.api)
- [Termux:Boot](https://f-droid.org/packages/com.termux.boot)

2. Set app permissions:

Go to:
1. Android Settings > search for ”Special Access"
2. Select "Battery Optimization" > All Apps
Then disable battery optimization for
- Termux
- Termux:Boot
3. Return to "Special Access" screen
4. Select "Draw over other apps"
Enable draw over apps aka draw on top for:
- Termux

3. In termux, issue the command
```bash
sh -c "$(curl -fsSL https://github.com/CryptoGrampy/android-termux-monero-node/raw/main/src/install-monerod-in-termux.sh)"
```
4. Follow the prompts.

Data Usage-
No idea how much data Monero uses- you'll almost certainly want to be on WiFi while it's initially syncing, and turn off the node while out and about. My node sits on a shelf next to my wifi router.
_**All Users:**_

Running a Monero node allows you to connect CakeWallet or Monerujo to the node running in the device itself, rather than connecting to a remote node; this is a safer way of using Monero, and it alleviates network strain on the remote nodes. You should also be able to connect from other devices in your LAN
Press Y when/if asked to use package maintainers version of sources.list

5. Add the 2x2 Termux widget to your home screen.

# Contributing to the Monero Network
6. SUCCESS

If you simply install and run this software without making any updates in your router, you are actually LEECHING from the rest of the users of the network. To truly contribute back to the network, open port 18080 in your router to seed (distribute) the Monero blockchain to the rest. To verify you're helping seed the network and that you've set up your router correctly, you will see 🌱 P2P: 5 (some number larger than 0) in your Android notifications.
NOTE: YOU WILL NOT BE ABLE TO TRANSACT UNTIL YOUR NODE IS 100% SYNCED.

While I DO recommend connecting to your Android node from within your local network using RPC, I DON'T recommend opening the RPC port in your router (yet).
**Extras**
1. Run on Boot: Open the "Termux:Boot" app (once).
2. Run in Fore/Background: "Stop" then "Start" the node from widget.
3. Connect to your Node: [Wallet Connections](#wallet-connections).
4. Enable P2P seeding (distributing) of the Blockchain [Forwarding P2P (seeding) port](#p2p-seeding).

More info on running a Monero Node:

https://www.reddit.com/r/Monero/comments/kkr04n/infographic_running_a_node_which_ports_should_i/
https://www.reddit.com/r/Monero/comments/kkgly6/message_to_all_monero_users_we_need_more_public/
https://www.reddit.com/r/Monero/comments/ko0xd1/i_put_together_a_new_guide_for_running_a_monero/

# WARNING...

1. DO NOT RUN THIS ON INTERNAL ANDROID STORAGE (use microSD ONLY) OR YOU IT WILL EVENTUALLY BURN OUT (Per Howard Chu) and Run this code AT YOUR OWN RISK and READ THE CODE (and feel free to reach out if you have any improvements 😜).

2. MicroSD cards have a limited lifespan in general, and it's possible the card will burn out after a couple years, though I don't have solid metrics on this. Monero is mostly writes and reads- not rewrites which are what kill storage the fastest.

3. You WILL (likely) lose data saved on your microSD card. Backup before running this code.

4. If things go awry, delete all of the Termux apps you're about to install, and all will be back to normal.


# Install

Video Install Guide (Use the code linked in this repo down below rather than the Pastebin shown in the video):

[![Monero Full Node Install](https://img.youtube.com/vi/z46zAy-LoHE/0.jpg)](https://www.youtube.com/watch?v=z46zAy-LoHE)

1. Hardware Prep:
- Android 7.0+ with ARMv8 CPU (Nearly all made in the last few years are fine)
- [Check your Android CPU 'Instruction Set' here](https://www.devicespecifications.com/en/model/f6cb274f)
- Freshly wiped 128GB (256GB+ Preferred) microSD set up in Android AS EXTERNAL STORAGE

<center>
<figure>
<img src="assets/cpu-architecture.png" width="300">
<figcaption>Example ARMv8 CPU Instruction Set</figcaption>
</figure>
</center>


1. Install Necessary Apps
- Install the Fdroid App Store (https://f-droid.org/)
- Install these Apps from Fdroid (Do NOT install from Play store. If any of these are already installed, uninstall them)
- Termux
- Termux:Boot
- Termux:Widget
- Termux:API

<center>
<figure>
<img src="assets/apps.jpeg" width="300">
<figcaption>Apps to Install from F-Droid Store </figcaption>
</figure>
</center>

3. Set Android Permissions (Go into Android settings and search for the permission names if you're having trouble locating them)
- Battery Optimization: Don't Optimize: Termux and Termux:Boot
- Display Over Other Apps: Termux

<center>
<img src="assets/android-permissions-1.png" width="300">
<img src="assets/android-permissions-2.png" width="300">
</center>

4. Add the 'Termux Widget 2x2' Widget to your Android home screen (press the refresh button after you've finished the install process)
# WARNINGS...

<center>
<img src="assets/termux-widget.jpeg" width="300">
</center>
1. Ideally you should store the blockchain on external storage (MicroSD etc).
Regardless of whether the blockchain is stored on SD or Internal..
You should run this AT YOUR OWN RISK and READ THE CODE. Feel free to make or suggest improvements.

5. Install
2. Monero is mostly writes and reads - not rewrites - which are what kill storage the fastest.

Quick Install- Copy and paste this into Termux, and press Enter
```bash
sh -c "$(curl -fsSL https://raw.githubusercontent.com/CryptoGrampy/android-termux-monero-node/main/src/install-monerod-in-termux.sh)"
```
3. You may risk your data or the lifespan of your microSD / Internal storage may be shortened.

Elaborate Install:

Copy the code (INCLUDING the parenthesis) from the links below based on the node type/storage available on your device.
It is recommended to backup before running, and preferably to run on a dedicated / spare / old device.

Make sure your screen stays 'on' throughout the install- give the screen a tap if necessary.
4. **Do _NOT_ forward port 18081 (the UNRESTRICTED RPC port)**

Open Termux, and paste the copied code into the terminal. Press the return button on the on-screen keyboard. You will likely need to give Termux permission to do various things (add repos, etc) during the install. Read what it's asking, type y and then press return.
# Controls Overview

6. SUCCESS!
Using the Termux Widget, you can 'Start XMR Node', 'Stop XMR Node', 'Update XMR Node', and check the 'XMR Node Status'.

# Controls Overview
The notification will be automatically be updated every 15 minutes. The first notification after starting your node may not appear until after 30 seconds have passed.

Using the Termux Widget, you can 'Start XMR Node', 'Stop XMR Node', 'Update XMR Node', and check the 'XMR Node Status'. Try them all- you're not going to break anything. Tap the arrow in the Android Termux notification in your swipe-down Android notifications to see detailed info on your Node. If a Monero update is available, it will be present in this notification.
The notification might not be 100% accurate on slower devices. You can force a refresh of the notification from notification itself, or by using the 'XMR Node Status' shortcut in the Termux widget.

The notifications will be automatically be updated every 15 minutes. The first notification after restarting your device or starting turning your node on might not be 100% accurate as the Monero node can take a while to start up. If you press the 'XMR Node Status' button in the Termux widget, you will briefly see the actual command line status of Monerod pop up in a Termux shell, and the Android notification will also update with the most recent node information (useful if you don't want to wait 15 minutes for an update)
Alternatively, you can "Stop" the node, and "Start" it in the foreground.

# Connecting to your Node / Seeding the Network

There are a few ip addresses and ports you need to know when running a wallet on the Android device itself, when you're pointing ANOTHER device in your LOCAL network at your new full or pruned node, or when you're opening up your router to seed the network.
Following are a few ip addresses and ports to make note of.

## Wallet Connections

NOTE: YOU WILL NOT BE ABLE TO TRANSACT UNTIL YOUR NODE IS 100% SYNCED. Continue using remote nodes/whatever you were using before in Cake or Monerujo until you're fully synced.
NOTE: YOU WILL NOT BE ABLE TO TRANSACT UNTIL YOUR NODE IS 100% SYNCED.

| Wallet Connection | IP (Why?) | Port (Why?) |
| ---------------------------- | ----------- | --------|
| Point CakeWallet/Monerujo Running on my Android at my XMR Node | 127.0.0.1 (This is Localhost!) | 18081 (Non-Remote RPC Port) |
| Point an XMR wallet on another device on my local network at my XMR node | VARIES (check router for your local Android device IP) | 18089 (REMOTE RPC Port) |
| Point an XMR wallet on another device OUTSIDE my local network at my node | Feature Not Available | Feature Not Available |
| Wallet relationship to node: | IP: | Port: (Why?) | Forward? |
| ---------------------------- | ------ | ------ | --- |
| The same device | 127.0.0.1 | 18081 (Unrestricted RPC Port) | Yes |
| Different devices on the same local network | Check Notification | 18089 (Restricted RPC Port) | No |
| Different devices on seperate networks | Public / Internet facing IP. [Search DuckDuckGo for ”my ip"](https://ddg.gg/?q=my+ip&ia=answer)| 18089 (Restricted RPC Port) | Yes |


If you're looking to go a little deeper, and understand why the above ip addresses/ports in the table are the way they are, this is the Monero startup command used in the script you ran. You can look up what each of these items means in [this nice Monerod reference guide]([src/full-monero-node-install](https://monerodocs.org/interacting/monerod-reference/))

```bash
./monerod --data-dir $NODE_DATA --db-sync-mode safe:sync --enable-dns-blocklist --in-peers 10 --rpc-restricted-bind-ip 0.0.0.0 --rpc-restricted-bind-port 18089 --rpc-bind-ip 127.0.0.1 --rpc-bind-port 18081 --no-igd --no-zmq --detach
```
These are the default ports set in the config file.
You can edit the config file (located at crypto/monero-cli).
[Here is a nice Monerod reference guide]([src/full-monero-node-install](https://monerodocs.org/interacting/monerod-reference/))

## P2P Seeding

If you want to seed the Monero network in the same way you would seed a torrent, and YES, I do encourage this, in your router, you need to forward port 18080 (NOT 18081 and NOT 18089) to your Android device. This process varies by router, but if you google 'port forwarding netgear (whatever your router brand is), you will find a guide.
If you want to seed (help distribute) the Monero network (Recommended)
| Port: (Why?) | Forward? |
| -------------- | --- |
| 18080 (P2P Port) | Yes |

The process for port forwarding may vary slightly depending on the router used.
If you [DuckDuckGo "port forwarding"](https://ddg.gg/port-forwarding) and add the name / brand of your router, you should find a guide.

For instance, this is how mine is setup:
Example:

<center>
<img src="assets/p2p-setup2.png" width="800">
Expand All @@ -166,32 +171,47 @@ For instance, this is how mine is setup:
<img src="assets/p2p-setup.png" width="800">
</center>


Once you've enabled port forwarding of 18080, like magic, the P2P value in the Monero node notifications on your Android device will begin to tick up in value. You're helping the network.

If you decide, for whatever reason, that you want to stop seeding the network, simply stop forwarding port 18080 in your router/remove the port forwarding rule.

Troubleshooting:
- If P2P suddenly stops working for you, it's possible your router changed the port of your Android device (this is normal behavior for a router). You will likely need to set up your Android device to use a 'static ip'... For this, Google 'static ip address android phone' or 'static ip address Netgear router' and figure out how to make your router always use the same ip internal ip address for your phone (Perhaps I'll add these instructions in the future)
- If P2P stops working for you, it's possible your router changed the IP of your Android device (this is normal behavior for a router).

You will likely need to set up your Android device to use a 'static ip'... For this..

Open Android Setting, and go to: wifi > tap & hold on current network > edit/modify > [show advanced] > ip settings

Change DHCP from "auto/dynamic" to "manual/static".

# Updates

- Termux Node Code: If you find out that I've added an amazing new feature, and you want to update your code, simply copy the newly updated install script from Github and paste it into a Termux shell- it's the same process as the initial install. I will do my best to take care of any cleanup activities that need to happen.
- (Stable) CryptoGrampy/main Install script:
Run
```bash
sh -c "$(curl -fsSL https://github.com/CryptoGrampy/android-termux-monero-node/raw/main/src/install-monerod-in-termux.sh)"
```
and follow the prompts.

- Monero: If you receive a notification that there is a new Monero version out (or perhaps you find out on Reddit, Twitter, etc), simply run the 'Update XMR Node' Termux shortcut through the Termux Widget.
- Updates to Monerod (node SW): Run the 'Update XMR Node' shortcut to install the new version.

# TODO's:

- [x] Turn off notifications and boot wake locks when user turns node off/add them back when node is turned on
- [x] Create Uninstaller
- [x] Custom Configs
- [x] Run as pruned
- [x] Check for external SD, if doesn't exist use different/symlinked install dir, check space before installing?
- [ ] Secure RPC defaults
- TBD

# Donate:

- If you enjoy this software, please feel free to send $XMR tips to [CryptoGrampy](https://twitter.com/CryptoGrampy)!
If you enjoy this software, please feel free to send a tip to:

- $XMR : 85HmFCiEvjg7eysKExQyqh5WgAbExUw6gF8osaE2pFrvUhQdf1HdD6XSTgAr4ECYMre6HjWutPJSdJftQcYEz3m2PYYTE6Y

- **[CryptoGrampy](https://twitter.com/CryptoGrampy)!** $XMR:
```
85HmFCiEvjg7eysKExQyqh5WgAbExUw6gF8osaE2pFrvUhQdf1HdD6XSTgAr4ECYMre6HjWutPJSdJftQcYEz3m2PYYTE6Y
```

- **[plowsof](https://github.com/plowsof)** $XMR:
```
86aSNJwDYC2AshDDvbGgtQ17RWspmKNwNXAqdFiFF2Db91v9PC26uDxffD9ZYfcMjvJpuKJepsQtELAdmXVk85E1DsuL6rG
```

- **[nahuhh](https://github.com/nahuhh)** ☠️ $XMR:
```
8343hzpypz2BR5ybAMNvvhaLtbXSMgCT7KqYSTfLBk3DF8Yayi5b7JGRWZc2GdqNu1EkALEFv1FHkCgeQ1zzkUFVMqtcTBy
```
Loading