Hexa's Blog

Kaspa, Mining Script

15/01/2022 Mining Rig

  1. Download the latest kaspa-miner https://github.com/tmrlvi/kaspa-miner/releases and unzip.
  2. Create a bat file named run-kaspa-miner.bat at the directory which is unzip at previous step.
::run-kaspa-miner.bat
kaspa-miner-v0.2.1-GPU-0.2-win64-amd64.exe --mining-address=kaspa:qp30cee96qejpnz236fu8gn5yv9dkjdhp9s5hk8tfz8u7w068g7v7tlkvxn90 ^
                                           --threads 0 --devfund-percent 0 --cuda-workload 256 ^
                                           --kaspad-address IP_HERE --port 16110
  1. Execute run-kaspa-miner.bat to start mining. Good Luck!

Công thức tính số Alephium (ALPH) có để đào solo trong ngày

07/01/2022 Mining Rig

Trước khi đi vào công thức chi tiết, ta cần hiểu là trong một ngày số lượng block được đào tối đa là 21,600 blocks, hiện tại, khi đào mỗi blocks, miner được thưởng là 3.2 ALPH.

[1] Công thức
[1] Công thức

Như vậy giả sử như số hashrate của mình là 16 GH/s và tổng hashrate của network là 14 TH/s (14,000GH/s). Sau mỗi 24 giờ, miner sẽ nhận được xấp xỉ 79 ALPH.

[2] Ví dụ
[2] Ví dụ

ASDF, Dependencies Installation for Erlang

27/12/2021 Linux

This script should be run before asdf erlang installation.

#!/usr/bin/zsh
sudo yum groupinstall -y 'Development Tools' 'C Development Tools and Libraries';
sudo yum install -y autoconf;
sudo yum install -y ncurses-devel;
sudo yum install -y wxGTK3-devel wxBase3;
sudo yum install -y openssl-devel;
sudo yum install -y java-1.8.0-openjdk-devel;
sudo yum install -y libiodbc unixODBC-devel.x86_64 erlang-odbc.x86_64;
sudo yum install -y libxslt fop;

After executing the script above, you can run asdf install erlang YOUR_ERLANG_VERSION without a missing erlang features.

[1] Example, asdf install erlang 22.3
[1] Example, asdf install erlang 22.3

Cách khởi động nguồn máy tính tự động mỗi khi có điện?

18/12/2021 Mining Rig

Bài viết này tập trung giải quyết vấn đề khởi động máy tính tự động khi có điện dành cho bo mạch chủ không có cổng nhận jack 24-pin cấp điện từ nguồn (PSU), điện được lấy từ các jack 6 pin. Những bo mạch chủ này không hiếm gặp trên các dàn đào tiền mã hóa. Trên những bo mạch chủ này, không thể cài đặt chế độ tự khởi động trên BIOS được mà bạn sẽ cần chơi chiêu trên jack 24-pin.

Không dài dòng nữa, tất cả những gì bạn cần làm là chú ý đến dây 24-pin xuất ra từ bộ nguồn máy tính (PSU).

[1] Sơ đồ jack 24-pin từ PSU.
[1] Sơ đồ jack 24-pin từ PSU.

Hai cổng duy nhất cần chú ý đó là cổng số 1617, bạn sẽ cần phải làm chúng nối tiếp nhau. Lưu ý nhìn cái ngàm ngang nó nắm ở đâu nhé, cắm nhầm là căng thẳng đó. Trên hình bạn sẽ thấy cái ngàm ngang nằm ở vị trí cổng số 1819. Một lần nữa, chú ý đừng có nhầm, bạn mà cắn nhầm sang cổng số 45 là toang đó nhé, 5 volt chạy thẳng vào ground. Cực mạnh.

Anh em thầy thợ có rất nhiều cách thú vị. Đôi khi là đấu dây trực tiếp 2 cổng này, hoặc xịn xò hơn thì sẽ dùng một cái chấu chữ U để kết nối.

Dưới đây là hình ảnh ví dụ.

[2] Hình ảnh thực tế.
[2] Hình ảnh thực tế.

Trích Dẫn:

How to make executable jar with Gradle?

16/12/2021 Linux

Gradle is a build automation tool for multi-language software development. It controls the development process in the tasks of compilation and packaging to testing, deployment, and publishing. Supported languages include Java (as well as Kotlin, Groovy, Scala), C/C++, and JavaScript. The other, if not the major function of Gradle is to collect statistical data about the usage of software libraries around the globe.

In this post, I would like to introduce a solution to create an executable jar with Gradle. All modification related to a file named build.gradle. This file located at /project-root/app/build.gradle. By default, this file will be generated with Gradle init task.

There are three part concerned:

  • Add a plugin named application to plugins block.
plugins {
    // Apply the application plugin to add support for building a CLI application in Java.
    id 'application'
}
  • Define mainClass in application block.
application {
    // Define the main class for the application.
    mainClass = 'JekyllPostGenerator.App'              # MODIFY IT
}
  • Define jar block.
jar {
    archiveBaseName = 'jekyll-post-generator'          # MODIFY IT
    archiveVersion =  '2.0.0'                          # MODIFY IT
    manifest {
        attributes(
               'Main-Class': 'JekyllPostGenerator.App' # MODIFY IT
        )
    }
}

Last but not least, you need to run gradle task named jar to created an executable jar file which would be created in /root-project/app/build/libs. Regarding above configuration, my executable file will be jekyll-post-generator-2.0.0.jar. This file now can be executed with java -jar jekyll-post-generator-2.0.0.jar. And this is a command to create jar file.


# In the project-root
./gradlew jar

[1] `gradlew jar` task output example.
[1] `gradlew jar` task output example.

How to install GTX 1060 on Fedora with Secure Boot enabled?

15/12/2021 Linux

In this post, I would like to introduce solution to install VGA drivers for 1060 on Fedora with enabled SECURE BOOT.

Step 1: Determine vga installed on the motherboard.

On terminal, use the following command to see avaialble installed VGA.

lspci |grep -E "VGA|3D"

Example output:

02:00.0 VGA compatible controller: NVIDIA Corporation GP106 [GeForce GTX 1060 6GB] (rev a1)
04:00.0 VGA compatible controller: ASPEED Technology, Inc. ASPEED Graphics Family (rev 30)

Step 2: Download nvidia driver from Nvidia Official Website

[1] NVIDIA Driver Downloads
[1] NVIDIA Driver Downloads

In this post, I would like to pick the latest stable version 470.94 which was released on December 13, 2021. After your downloading finished, remember to make the file executable with chmod +x NVIDIA-Linux-x86_64-470.94.run, and copy it to $HOME/Software/VGA-1060-key, you will need to execute this file each time your update your kernels.

mkdir -p $HOME/Software/VGA-1060-key;
cd $HOME/Software/VGA-1060-key;
wget https://us.download.nvidia.com/XFree86/Linux-x86_64/470.94/NVIDIA-Linux-x86_64-470.94.run;
chmod +x NVIDIA-Linux-x86_64-470.94.run;

Step 3: Generate new pair private-key and public-key

mkdir -p $HOME/Software/VGA-1060-key/key;
cd $HOME/Software/VGA-1060-key/key;
openssl req -new -x509 -newkey rsa:2048 -keyout vga-1060.key -outform DER -out vga-1060.der -nodes -days 365000 -subj "/CN=Graphics Drivers";

Your directory tree should look like:

[2] Directory Tree
[2] Directory Tree

Step 4: Enroll new public key with mokutil

You need to run this command to import your new public key with mokutil, this program will ask you a password for enrolling, which then be asked in the next reboot.

sudo mokutil --import $HOME/Software/VGA-1060-key/key/vga-1060.der;

Step 5: Make install.sh in VGA-1060-key directory

This is install.sh content:

#!/bin/bash
./NVIDIA-Linux-x86_64-470.94.run --module-signing-secret-key=/home/YOUR_USERNAME/Software/VGA-1060-key/key/vga-1060.key \
                                 --module-signing-public-key=/home/YOUR_USERNAME/Software/VGA-1060-key/key/vga-1060.der

Each time you update your kernel, you need to go boots OS with level 3 and run this script install.sh.

[3] Directory Tree
[3] Directory Tree

Step 5: Install package dependencies & update OS

This step ensure you got the lastest kernel & all dependent packages.

sudo dnf install kernel-devel kernel-headers gcc make dkms acpid libglvnd-glx libglvnd-opengl libglvnd-devel pkgconfig;
sudo dnf update;

Step 6: Disable nouveau

  • Create or edit /etc/modprobe.d/blacklist-nouveau.conf
sudo echo "blacklist nouveau" >> /etc/modprobe.d/blacklist-nouveau.conf
  • Edit /etc/default/grub Append following flag to the end of GRUB_CMDLINE_LINUX
    • rd.driver.blacklist=nouveau
    • modprobe.blacklist=nouveau
    • nvidia-drm.modeset=1

For example:

[4] /etc/default/grub
[4] /etc/default/grub

Step 7: Update grub2 config & generate new initramfs

grub2-mkconfig -o /boot/grub2/grub.cfg;

## Backup old initramfs nouveau image ##
mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r)-with-nouveau.img;

## Generate new initramfs image ##
dracut /boot/initramfs-$(uname -r).img $(uname -r);

Step 8: Boots OS on level 3 and execute the install.sh

Boots OS on level 3 and reboot

sudo systemctl set-default multi-user.target;
sudo systemctl -r now;

After login, go to VGA-1060-key directory and execute install.sh. At this step, just keep accepting and the driver will be installed.

cd /home/nguyenvinhlinh/Software/VGA-1060-key;
sudo ./install.sh;

After installing vga driver, you will need reboot OS on level 5 - graphical

systemctl set-default multi-user.target;
systemctl -r now;

Next time, if you update your kernel, you can run this step (Step 8) again, it should be fine. In addition, you should encrypt your private-key with gpg, it’s not a good practice leave it unencrypted. You can check this guide Mã hóa và giải mã file trên linux sử dụng GPG

Reference

PhoenixMiner - config.txt Template

08/12/2021 Mining Rig

# PhoenixMiner configuration file config.txt

-pool   asia1.ethermine.org:4444
-pool2  asia2.ethermine.org:4444
-wal    miner_address_here
-worker huyen-vu

Personal Note: Installing a Monero full node

I. Monero Node Config - monerod.conf

# /opt/monero-gui-v0.17.2.3/monerod.conf

# Data directory (blockchain db and indices)
data-dir=/mnt/disk_2/Monero/  # Remember to create the monero user first

# Log file
log-file=/mnt/disk_2/Monero/log/monerod.log
max-log-file-size=0            # Prevent monerod from managing the log files; we want logrotate to take care of that

# P2P full node
p2p-bind-ip=0.0.0.0            # Bind to all interfaces (the default)
p2p-bind-port=18080            # Bind to default port

# RPC open node
rpc-bind-ip=0.0.0.0            # Bind to all interfaces
rpc-bind-port=18081            # Bind on default port
confirm-external-bind=1        # Open node (confirm)
restricted-rpc=1               # Prevent unsafe RPC calls
no-igd=1                       # Disable UPnP port mapping

# Slow but reliable db writes
db-sync-mode=safe:sync
block-sync-size=100

# Emergency checkpoints set by MoneroPulse operators will be enforced to workaround potential consensus bugs
# Check https://monerodocs.org/infrastructure/monero-pulse/ for explanation and trade-offs
enforce-dns-checkpointing=1

out-peers=64              # This will enable much faster sync and tx awareness; the default 8 is suboptimal nowadays
in-peers=1024             # The default is unlimited; we prefer to put a cap on this

limit-rate-up=1048576     # 1048576 kB/s == 1GB/s; a raise from default 2048 kB/s; contribute more to p2p network
limit-rate-down=1048576   # 1048576 kB/s == 1GB/s; a raise from default 8192 kB/s; allow for faster initial sync

II. Systemctl service - /etc/systemd/system/monero.service

[Unit]
Description=Monero Full Node
After=network.target  mnt-disk_2.mount

[Service]
WorkingDirectory=/opt/monero-gui-v0.17.2.3
ExecStart=/opt/monero-gui-v0.17.2.3/monerod --config-file /opt/monero-gui-v0.17.2.3/monerod.conf --detach
User=nguyenvinhlinh
RemainAfterExit=yes
Restart=on-failure
RestartSec=10
TimeoutStopSec=infinity

[Install]
WantedBy=multi-user.target

III. Firewall-cmd service - /etc/firewalld/services/monero.xml

<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>Monero node</short>
  <description>
    This option allows Monero node to use tcp port:
    - 18080: p2p network
    - 18081: JSON-RPC server
  </description>
  <port protocol="tcp" port="18080"/>
  <port protocol="tcp" port="18081"/>
</service>

Personal Note: Installing an Alephium full node

I. Alephium node config - $ALEPHIUM_HOME/user.conf

alephium.network.external-address="x.x.x.x:9973"
alephium.api.network-interface = "0.0.0.0"
alephium.mining.api-interface="0.0.0.0"

alephium.mining.miner-addresses=[
 "miner_address_1",
 "miner_address_2",
 "miner_address_3",
 "miner_address_4",
]

II. Systemctl EnvironmentFile - /opt/alephium/alephium.env

ALEPHIUM_HOME=/mnt/CaHeoNas/disk_3/Alephium

III. Systemctl service - /etc/systemd/system/alephium.service

[Unit]
Description=Alphelium Full Node
After=network.target mnt-CaHeoNas-disk_3.mount

[Service]
WorkingDirectory=/opt/alephium
EnvironmentFile=/opt/alephium/alephium.env
ExecStart=java -jar -Xms512m -Xmx1028m alephium-1.0.0.jar
User=nguyenvinhlinh
RemainAfterExit=yes
Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target

IV. Firewall-cmd service - /etc/firewalld/services/alephium.xml

<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>Alephium node</short>
  <description>
    This option allows Alephium node to use tcp port 9973, 10973, 12973
  </description>
  <port protocol="tcp" port="9973"/>
  <port protocol="tcp" port="10973"/>
  <port protocol="tcp" port="12973"/>
</service>

IV. Balance checking script

All Credit goes this guy Mark Rahmani (diomark#8272) https://www.facebook.com/diomark/

#!/bin/zsh

#first need to unlock wallet. not putting password in here

#check wallet
curlResult=`curl -X 'GET'   'http://127.0.0.1:12973/wallets/MINER_WALLET_NAME/balances'   -H 'accept: application/json' 2>/dev/null | json_pp | grep totalBalanceHint| cut -f1 -d","`
lastdate=`date +%s`


if echo $curlResult | grep -q ALPH; then
  datestr=`date +"%x %R"`
  echo -n "$datestr "
  echo Wallet unlocked - $curlResult;
else
  echo Please unlock wallet first
  exit
fi

while true; do
 oldResult=$curlResult

 datestr=`date +"%x %R"`; echo -n "."; curlResult=`curl -X 'GET'   'http://127.0.0.1:12973/wallets/MINER_WALLET_NAME/balances'   -H 'accept: application/json' 2>/dev/null | json_pp | grep totalBalanceHint| cut -f1 -d","`
 if [ "$oldResult" != "" ]; then
    if [ "$curlResult" != "$oldResult" ]; then
       echo
       echo -n "$datestr "
       newdate=`date +%s`
       secs=`expr $newdate - $lastdate`
       mins=`expr $secs / 60`
       echo  -n "Won a block after $mins minutes! "
       echo $curlResult
       lastdate=$newdate
    fi
 fi

 sleep 30
done

Balance Checking Script Output.
Balance Checking Script Output.

Personal Note: Installing a Bitcoin full node

I. Systemctl service - /etc/systemd/system/bitcoin.service

[Unit]
Description=Bitcoin Full Node
After=network.target  mnt-disk_2.mount

[Service]
WorkingDirectory=/opt/bitcoin-0.21.1/
ExecStart=/opt/bitcoin-0.21.1/bin/bitcoind -datadir=/mnt/disk_2/Bitcoin -daemon
ExecStop=/opt/bitcoin-0.21.1/bin/bitcoin-cli -datadir=/mnt/disk_2/Bitcoin stop
User=nguyenvinhlinh
RemainAfterExit=yes
Restart=on-failure
RestartSec=10
TimeoutStopSec=infinity

[Install]
WantedBy=multi-user.target

II. Firewall-cmd service - /etc/firewalld/services/bitcoin.xml

<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>Bitcoin node</short>
  <description>This option allows Bitcoin node to use tcp port 8333</description>
  <port protocol="tcp" port="8333"/>
</service>