Skip to content
Open
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
74 changes: 49 additions & 25 deletions monero-poc/verifier/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
cmake_minimum_required(VERSION 3.1)
project(OCVerifier CXX)
# Find GCC compiler
find_program(GCC_COMPILER NAMES gcc g++
DOC "Path to the GNU C/C++ compiler")

if(NOT GCC_COMPILER)
message(FATAL_ERROR "GCC/G++ compiler not found. Please install GCC or ensure it's in your PATH.")
endif()

set (CMAKE_CXX_STANDARD 17)
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
message(STATUS "Detected GCC/G++ compiler")
set(CXX_OCVERIFIER_FLAGS "-Wunused-variable")
else()
SET(CXX_OCVERIFIER_FLAGS "-Wunused-variable")
message(FATAL_ERROR "Must use GCC/G++ to compile")
endif()

message(STATUS "Using C compiler: ${CMAKE_C_COMPILER}")
message(STATUS "Using C++ compiler: ${CMAKE_CXX_COMPILER}")

if(CMAKE_C_COMPILER MATCHES "gcc")
#ok
else()
message(FATAL_ERROR "Must use gcc/g++ to compile")
option(TESTNET_ENABLE "Building with testnest." OFF)
if (TESTNET_ENABLE)
add_definitions(-DTESTNET_ENABLE)
endif()

set(XMR_ROOT "/root/monero/" CACHE PATH "Monero root folder")
Expand All @@ -36,19 +27,52 @@ message(WARNING "This project is using many precompiled libraries, it is recomme

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_OCVERIFIER_FLAGS}")
SET(FILES ${CMAKE_SOURCE_DIR}/connection.cpp
${CMAKE_SOURCE_DIR}/keyUtils.cpp
${CMAKE_SOURCE_DIR}/keyUtils.cpp
${CMAKE_SOURCE_DIR}/nodeVerifier.cpp
)
link_directories(${CMAKE_SOURCE_DIR}/precompiledMoneroLibraries/)
add_library(oc_verifier_lib STATIC verifierLib.cpp xmr.cpp)
ADD_EXECUTABLE(oc_verifier main.cpp ${FILES})
if (TESTNET_ENABLE)
add_executable(testnetDispatcher
testnetDispatcher.cpp
${CMAKE_SOURCE_DIR}/connection.cpp
${CMAKE_SOURCE_DIR}/keyUtils.cpp)
endif()

if (BOOST_ROOT)
message(STATUS "Look for Boost at: " ${BOOST_ROOT})
else()
message(STATUS "Look for Boost at default path")
endif()

target_link_libraries(oc_verifier pthread lmdb oc_verifier_lib cryptonote_basic cncrypto common ringct_basic device
cryptonote_format_utils_basic wallet-crypto epee easylogging version randomx boost_system boost_date_time
boost_chrono boost_filesystem boost_thread boost_regex boost_serialization boost_program_options sodium
unbound ssl crypto hidapi-libusb dl)
target_link_libraries(oc_verifier_lib cryptonote_basic cncrypto common ringct_basic device
cryptonote_format_utils_basic wallet-crypto epee easylogging version randomx boost_system boost_date_time
boost_chrono boost_filesystem boost_thread boost_regex boost_serialization boost_program_options sodium
unbound ssl crypto hidapi-libusb dl)
# This verion is required for precompiled libraries
find_package(Boost 1.71 EXACT REQUIRED COMPONENTS
filesystem system date_time chrono thread regex serialization program_options
)

target_include_directories(oc_verifier_lib PRIVATE ${Boost_INCLUDE_DIRS})
target_link_libraries(oc_verifier_lib PRIVATE
cryptonote_basic cncrypto common ringct_basic device cryptonote_format_utils_basic
wallet-crypto epee easylogging version randomx ${Boost_LIBRARIES} sodium unbound
ssl crypto hidapi-libusb dl)
target_compile_options(oc_verifier_lib PRIVATE -Ofast)

target_link_libraries(oc_verifier PRIVATE pthread lmdb oc_verifier_lib)
set_property(TARGET oc_verifier PROPERTY COMPILE_WARNING_AS_ERROR ON)

# Install related libs and executable
# Install executables
install(TARGETS oc_verifier
RUNTIME DESTINATION bin)
if (TESTNET_ENABLE)
install(TARGETS testnetDispatcher
RUNTIME DESTINATION bin)
endif()

# Install Boost libs
if(BOOST_ROOT)
install(DIRECTORY ${BOOST_ROOT}/lib/
DESTINATION lib/boost
FILES_MATCHING PATTERN "*.so*")
endif()
48 changes: 48 additions & 0 deletions monero-poc/verifier/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
ARG base_image="ubuntu:22.04"
ARG image_type="release"
ARG package_location=""

# Set environment variables to avoid user prompts during installation
ARG DEBIAN_FRONTEND=noninteractive

#********************Setup an runtime environment for running.
FROM ${base_image} AS build_image_runtime
ARG DEBIAN_FRONTEND
ARG package_location

# Install runtime environment
RUN apt-get update && \
apt-get install -y libsodium23 libunbound8 libhidapi-hidraw0 liblmdb0 libssl3 libhidapi-libusb0 libicu70 && \
apt-get clean

#********************Setup an develop environment for building.
FROM ${base_image} AS build_image_develop
ARG DEBIAN_FRONTEND
ARG package_location

# Install cmake, git and dev environments
RUN apt-get update && \
apt-get install -y cmake build-essential libsodium-dev libunbound-dev libhidapi-dev liblmdb-dev libssl-dev git && \
apt-get clean

#********************Package runtime into a Docker image
FROM ${base_image} AS build_image_release
ARG DEBIAN_FRONTEND
ARG APP_DEPENDENCIES
ARG package_location

# Create and set the working directory
WORKDIR /opt/qubic/oc_verifier

# Copy the requirements.txt file
COPY ${package_location}/ /opt/qubic/oc_verifier

#
ENV LD_LIBRARY_PATH="/opt/qubic/oc_verifier/lib/boost"

# Place holder to trigger above build
FROM build_image_${image_type}
ARG DEBIAN_FRONTEND
ARG APP_DEPENDENCIES
ARG CMD_BUILD
ARG package_location
41 changes: 37 additions & 4 deletions monero-poc/verifier/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
### REQUIREMENTS

The verifier will need monero repository set through `XMR_ROOT` variable when calling CMake, it also need some of libriaries that use by Monero

```
// Ubuntu
sudo apt-get install libsodium-dev ibunbound-dev libhidapi-dev liblmdb-dev libssl-dev
```

In case of using precompiledMoneroLibraries, you will need the `boost 1.71.0` otherwise you need to rebuild everything by your self.


Run this command after `git clone` to fetch RandomX library
```
git submodule update --init --recursive
Expand All @@ -7,14 +18,25 @@ git submodule update --init --recursive

On Linux, make sure `cmake` and `make` commands are installed and then run:
```
mkdir build;
mkdir build
cd build;
cmake ../;
make;
cmake .. -DXMR_ROOT=<path to Monero> -DBOOST_ROOT=<path to compiled boost 1.71>
make
```

On Windows, use the CMake GUI to create a Visual Studio project and then build the executable in Visual Studio.
## Testnet
Run belows command

```
mkdir build
cd build;
cmake .. -DXMR_ROOT=<path to Monero> -DBOOST_ROOT=<path to compiled boost 1.71> -DTESTNET_ENABLE=1
make
```


## Docker
Docker image can be built using `build_docker.sh`. Please run with `-h` for detail information

### USAGE

Expand Down Expand Up @@ -54,5 +76,16 @@ The verifier currently supports **three modes running in parallel**:
# Fetch from both peers and node, and submit results
./oc_verifier --peers [nodeip0],[nodeip1],...,[nodeipN] --seed [OPERATOR seed] --nodeip [OPERATOR IP]
```

### Docker run
```bash
docker run -it --rm --init [docker image] bash -c "./bin/oc_verifier --peers [nodeip0],[nodeip1],...,[nodeipN]"

docker run -it --rm --init [docker image] bash -c "./bin/oc_verifier --seed [OPERATOR seed] --nodeip [OPERATOR IP]"

docker run -it --rm --init [docker image] bash -c "./bin/oc_verifier --peers [nodeip0],[nodeip1],...,[nodeipN] --seed [OPERATOR seed] --nodeip [OPERATOR IP]"

```

Screenshot:
![image](https://github.com/user-attachments/assets/c629abc8-afb9-4d05-97c5-487456946774)
92 changes: 92 additions & 0 deletions monero-poc/verifier/build_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/bash

# Parse arguments
XMR_ROOT_LOCATION=""
BOOST_ROOT_LOCATION=""
BUILD_ALL=0
VERSION=latest
TESTNET=0

# Parse args
while [[ $# -gt 0 ]]; do
case "$1" in
--xmr-root)
XMR_ROOT_LOCATION="$2"
shift 2
;;
--boost-root)
BOOST_ROOT_LOCATION="$2"
shift 2
;;
--build-all)
BUILD_ALL="$2"
shift 2
;;
--version)
VERSION="$2"
shift 2
;;
--testnet)
TESTNET_ENABLE="$2"
shift 2
;;
--help|-h)
echo "Usage: $0 [options]"
echo
echo "Options:"
echo " --xmr-root PATH Path to Monero root folder"
echo " --boost-root PATH Path to Boost root folder"
echo " --build-all 0|1 Rebuild both runtime and dev image (default: 0)"
echo " --version VERSION Specify build version"
echo " --testnet 0|1 Enable dummy test net mode"
echo " --help, -h Show this help message"
exit 0
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done

# Location to thirdparty
echo "XMR_ROOT_LOCATION=$XMR_ROOT_LOCATION"
echo "BOOST_ROOT_LOCATION=$BOOST_ROOT_LOCATION"

# If this is enabled both runtime and develop image will be re-built
echo "BUILD_ALL=$BUILD_ALL"
echo "VERSION=$VERSION"

echo "TESTNET_ENABLE=$TESTNET_ENABLE"

# Build the environment Docker image
DEV_IMAGE="oc-verifier-dev"
RUNTIME_IMAGE="oc-verifier-rt"
RELEASE_IMAGE="oc-verifier"
DOCKER_SRC_DIR="/opt/qubic/oc_verifier_src"

if [ "$BUILD_ALL" == 1 ]; then
# Trigger build the runtime image
echo "Building the runtime Docker image"
docker build -f Dockerfile --build-arg image_type=runtime -t ${RUNTIME_IMAGE} .

# Build the dev image with tool for compilation
echo "Building the develop Docker image"
docker build -f Dockerfile --build-arg base_image=${RUNTIME_IMAGE} --build-arg image_type=develop -t ${DEV_IMAGE} .
fi


# Compile the code if neccessary
package_location=build_docker
build_cmd="rm -rf ${package_location} || true && \
mkdir ${package_location} && \
cd ${package_location} && \
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=./redist -DTESTNET_ENABLE=${TESTNET_ENABLE} -DXMR_ROOT=/xmr_root -DBOOST_ROOT=/boost_root && \
make install"
install_cmd="echo "
echo $build_cmd
docker run --rm -v ./:${DOCKER_SRC_DIR} -v ${XMR_ROOT_LOCATION}:/xmr_root -v ${BOOST_ROOT_LOCATION}:/boost_root -u $(id -u) ${DEV_IMAGE} bash -c "cd $DOCKER_SRC_DIR && $build_cmd && $install_cmd"

# Package into a new release image base on runtime time
echo "Packaging..."
docker build --build-arg base_image=${RUNTIME_IMAGE} --build-arg image_type=release --build-arg package_location=${package_location}/redist -t ${RELEASE_IMAGE}:${VERSION} .
1 change: 1 addition & 0 deletions monero-poc/verifier/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ void QubicConnection::getHandshakeData(std::vector<uint8_t>& buffer)

QubicConnection::~QubicConnection()
{
shutdown(mSocket, SHUT_RDWR);
close(mSocket);
}

Expand Down
Loading