Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
9097f1d
Changed gradle version.
MihaelBercic Aug 6, 2025
b710b76
Opted in.
MihaelBercic Aug 6, 2025
0f32d61
removed tests from gradle for now.
MihaelBercic Aug 6, 2025
56e7e91
removed tests from gradle for now.
MihaelBercic Aug 6, 2025
0f4e467
Build.
MihaelBercic Aug 6, 2025
3d2d574
Added jupiter.
MihaelBercic Aug 6, 2025
19ab710
Added jupiter.
MihaelBercic Aug 6, 2025
c3e1369
Added jupiter.
MihaelBercic Aug 6, 2025
c45b636
Solving.
MihaelBercic Aug 6, 2025
bf86880
Solving.
MihaelBercic Aug 6, 2025
298f75a
Moved configuration outside of the container. Made so that the jar is…
MihaelBercic Aug 6, 2025
d704126
Merge branch 'jungle-boogie' into rpc
MihaelBercic Oct 21, 2025
39fbadd
Merge pull request #40 from Nion-Network/rpc
MihaelBercic Oct 21, 2025
4d3174d
Fixed order of arguments to allow non-trusted ip
MihaelBercic Jan 6, 2026
02421d3
Fixed dockerfile.
MihaelBercic Jan 6, 2026
dc1d738
Fixed dockerfile.
MihaelBercic Jan 6, 2026
d875eb2
Issues with vdf-cli
MihaelBercic Jan 7, 2026
7cbe1c7
Added block storage.
MihaelBercic Jan 9, 2026
5c422e0
Added the sqlite jdbc
MihaelBercic Jan 9, 2026
faeb03d
Addd table creation.
MihaelBercic Jan 9, 2026
ca9c86f
Looking for websocket issues.
MihaelBercic Jan 12, 2026
43de024
Fixed ws.
MihaelBercic Jan 12, 2026
debd45b
Added stress test.
MihaelBercic Jan 13, 2026
8031276
Added reading stats.
MihaelBercic Jan 15, 2026
f2a3198
Adding parsing.
MihaelBercic Jan 15, 2026
03ffbca
Looking for issues with buffering.
MihaelBercic Jan 15, 2026
fe82851
Looking for issues with buffering.
MihaelBercic Jan 15, 2026
f34ed4b
Looking for issues with buffering.
MihaelBercic Jan 15, 2026
5409695
Looking for issues with buffering.
MihaelBercic Jan 15, 2026
a44e0c9
Looking for issues with buffering.
MihaelBercic Jan 15, 2026
3a4e633
Looking for issues with buffering.
MihaelBercic Jan 15, 2026
aeabd59
Looking for issues with buffering.
MihaelBercic Jan 15, 2026
edccd1c
Looking for issues with buffering.
MihaelBercic Jan 15, 2026
2a390e8
Looking for issues with buffering.
MihaelBercic Jan 15, 2026
20ca1ac
Looking for issues with buffering.
MihaelBercic Jan 15, 2026
9bb8dad
Looking for issues with buffering.
MihaelBercic Jan 15, 2026
59bcc2b
Added serialisation to circular lists
MihaelBercic Jan 15, 2026
aaceeb3
Added serialisation to circular lists
MihaelBercic Jan 15, 2026
2ea4b80
Removed logs.
MihaelBercic Jan 15, 2026
c008481
Added DHT node sharing via websocket.
MihaelBercic Jan 28, 2026
e7467a5
Added DHT node sharing via websocket.
MihaelBercic Jan 28, 2026
ca480b1
Added DHT node sharing via websocket.
MihaelBercic Jan 28, 2026
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
24 changes: 15 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
FROM docker:20-dind
FROM docker:dind
# RUN sed 's/http:\/\/fr\./http:\/\//' /etc/apt/sources.list

WORKDIR /root

RUN apk update
RUN apk add make \
bash \
openjdk21-jdk \
curl \
openssl-dev \
python3-dev \
gmp-dev \
tar

RUN apk add --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing criu-dev \
openjdk20-jre-headless
RUN apk add --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing/x86_64/criu-dev
RUN apk add tar

ADD *.jar Node.jar
ADD config.json config.json
COPY . .
ADD vdf-cli vdf-cli
ADD Start.sh Start.sh
ADD SaveContainer.sh SaveContainer.sh
ADD RunContainer.sh RunContainer.sh
#ADD /
#ADD *.jar Node.jar
#ADD config.json config.json
#ADD vdf-cli vdf-cli
#ADD Start.sh Start.sh
#ADD SaveContainer.sh SaveContainer.sh
#ADD RunContainer.sh RunContainer.sh

# ADD stress.sh stress.sh
# COPY stress.tar stress.tar

RUN ./gradlew assemble jar
RUN chmod 777 Start.sh
RUN chmod 777 vdf-cli
RUN mv vdf-cli /usr/bin/vdf-cli
# RUN mv vdf-cli /usr/bin/vdf-cli
RUN chmod +x Start.sh
ENTRYPOINT ["./Start.sh"]
21 changes: 11 additions & 10 deletions Start.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
if [ "$#" -ne 1 ]; then
echo "Sleeping..."
# sleep $(shuf -i 1-120 -n 1)
fi
#if [ "$#" -ne 1 ]; then
#echo "Sleeping..."
#sleep $(shuf -i 1-120 -n 1)
#fi

dockerd --experimental &
while [ ! -f /var/run/docker.pid ]
Expand All @@ -11,10 +11,11 @@ echo "Waiting for docker daemon to initialize!"
sleep 5
done

# docker load -i stress.tar
# if [ "$1" -eq 5005 ]; then
# echo "We're trusted. Running stress test."
# bash stress.sh &
# fi
#docker load -i stress.tar

java -jar Node.jar $1
#if [ "$1" -eq 5005 ]; then
# echo "We're trusted. Running stress test."
# bash stress.sh &
#fi

java -jar build/libs/nion-core.jar $1 $2
41 changes: 24 additions & 17 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,43 +1,50 @@
plugins {
id 'java'
id("org.jetbrains.kotlin.jvm") version "1.9.0"
id("org.jetbrains.kotlin.plugin.serialization") version "1.9.0"
id("org.jetbrains.kotlin.jvm") version "2.2.0"
id("org.jetbrains.kotlin.plugin.serialization") version "2.2.0"
}

group 'nion.network'
version '0.1'

configurations.implementation.setCanBeResolved(true)
//version '0.1'
//configurations.implementation.setCanBeResolved(true)

repositories {
mavenCentral()
}

dependencies {
testImplementation('org.junit.jupiter:junit-jupiter-api:5.8.1')
testImplementation('org.junit.jupiter:junit-jupiter-engine:5.8.1')
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.2")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.10.2")


implementation('org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.0')
implementation('org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.2.0')
implementation('org.jetbrains.kotlinx:kotlinx-serialization-protobuf:1.3.0')
implementation('org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.0')
implementation("com.influxdb:influxdb-client-kotlin:4.0.0")
implementation("com.influxdb:influxdb-client-kotlin:7.3.0")
implementation('org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2-native-mt')
implementation("io.javalin:javalin:5.6.1")
implementation("org.slf4j:slf4j-simple:2.0.7")
}

tasks.withType(Test).configureEach {
it.scanForTestClasses = false
it.useJUnitPlatform()
implementation("org.jetbrains.exposed:exposed-core:1.0.0-rc-3")
implementation("org.jetbrains.exposed:exposed-jdbc:1.0.0-rc-3")
implementation("org.jetbrains.exposed:exposed-dao:1.0.0-rc-3")
implementation("org.xerial:sqlite-jdbc:3.49.1.0")
}

tasks.test {
useJUnitPlatform()
scanForTestClasses = false
failOnNoDiscoveredTests = false
}
tasks.jar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
setArchivesBaseName("Nion-Network")
archiveBaseName.set("nion-core")
manifest {
attributes.put("Main-Class", "LaunchKt")
}
from {
configurations.implementation.collect { it.isDirectory() ? it : zipTree(it) }
}
dependsOn(configurations.runtimeClasspath)
from({
configurations.runtimeClasspath
.collect { it.isDirectory() ? it : zipTree(it) }
})
}
4 changes: 2 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"influxUrl": "http://88.200.63.190:8086",
"influxToken": "LtudFFrFu_b91XO6bCr0mzJuKV-Ffzom2phPlbn9FqNgDiYYcFRmh0mt63sHwPTo7JUv3jCe9RQNmB4AHMpKbQ==",
"dashboardEnabled": false,
"loggingEnabled": false,
"loggingEnabled": true,
"trustedLoggingEnabled": false,
"historyMinuteClearance": 1,
"historyCleaningFrequency": 1,
Expand All @@ -21,4 +21,4 @@
"useCriu": true,
"useTreeBasedMessageRoutingProtocol": true,
"treeChildrenCount": 2
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
# Could be upgraded to 8.3, depending on the user needs.
8 changes: 5 additions & 3 deletions src/main/kotlin/Launch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import java.io.File
@ExperimentalSerializationApi
fun main(args: Array<String>) {
tryAndReport {
System.setProperty("kotlinx.coroutines.scheduler", "off") // Needed due to bugs with linux and docker containers. TODO: fix ASAP
val configuration = Json.decodeFromString<Configuration>(File("./config.json").readText())
System.setProperty("kotlinx.coroutines.scheduler", "off")

val passedConfiguration = args.getOrNull(0) ?: throw Exception("Configuration should be passed to the docker container.")
val configuration = Json.decodeFromString<Configuration>(passedConfiguration)
Logger.toggleLogging(configuration.loggingEnabled)
args.getOrNull(0)?.toInt()?.apply {
args.getOrNull(1)?.toInt()?.apply {
configuration.port = this
}
Nion(configuration).apply {
Expand Down
8 changes: 8 additions & 0 deletions src/main/kotlin/Nion.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import chain.ChainBuilder
import database.BlockTable
import kotlinx.serialization.ExperimentalSerializationApi
import logging.Dashboard
import logging.Logger
import network.data.Endpoint
import network.data.MessageProcessing
import network.data.messages.Message
import org.jetbrains.exposed.v1.jdbc.Database
import org.jetbrains.exposed.v1.jdbc.SchemaUtils
import org.jetbrains.exposed.v1.jdbc.transactions.transaction
import utils.asHex
import utils.launchCoroutine
import utils.runAfter
Expand Down Expand Up @@ -48,6 +52,10 @@ class Nion(configuration: Configuration) : ChainBuilder(configuration) {
Dashboard.reportException(Exception("Local address: $localAddress!"))
return
}
Database.connect("jdbc:sqlite:nion.db", "org.sqlite.JDBC")
transaction {
SchemaUtils.create(BlockTable)
}
attemptBootstrap()
attemptInclusion()
}
Expand Down
32 changes: 28 additions & 4 deletions src/main/kotlin/chain/Chain.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package chain

import chain.data.Block
import database.BlockTable
import logging.Logger
import org.jetbrains.exposed.v1.jdbc.insert
import org.jetbrains.exposed.v1.jdbc.transactions.transaction
import utils.CircularList
import utils.asHex
import utils.tryWithLock
Expand All @@ -13,19 +16,23 @@ import kotlin.concurrent.withLock
* on 16/11/2021 at 16:21
* using IntelliJ IDEA
*/
class Chain(private val verifiableDelay: VerifiableDelay, private val initialDifficulty: Int, private val committeeSize: Int) {
class Chain(
private val verifiableDelay: VerifiableDelay,
private val initialDifficulty: Int,
private val committeeSize: Int
) {

private val lock = ReentrantLock(true)
private val blocks = CircularList<Block>(50) // ToDo: Remove, do not use Circular List but use persistent storage!

/** Returns the last block in the chain. */
fun getLastBlock(): Block? {
return lock.withLock { blocks.lastOrNull() }
return lock.withLock { blocks.items.lastOrNull() }
}

/** Returns max 100 blocks [from slot][fromSlot].*/
fun getLastBlocks(fromSlot: Long): List<Block> {
return lock.withLock { blocks.takeLastWhile { it.slot > fromSlot } }.take(100)
return lock.withLock { blocks.items.takeLastWhile { it.slot > fromSlot } }.take(100)
}

/** Attempts to add each block one by one to the chain. */
Expand All @@ -34,7 +41,8 @@ class Chain(private val verifiableDelay: VerifiableDelay, private val initialDif
val lastBlock = getLastBlock()
val lastHash = lastBlock?.hash ?: "FFFF".toByteArray()
val difficulty = lastBlock?.difficulty ?: initialDifficulty
val isLegitimate = nextBlock.slot == (lastBlock?.slot ?: 0) + 1 // verifiableDelay.verifyProof(lastHash, difficulty, nextBlock.vdfProof)
val isLegitimate = nextBlock.slot == (lastBlock?.slot
?: 0) + 1 // verifiableDelay.verifyProof(lastHash, difficulty, nextBlock.vdfProof)
if (!isLegitimate) {
Logger.trace("Proof is not legitimate for block ${nextBlock.slot}!")
Logger.chain("Last hash: ${lastHash.asHex}")
Expand All @@ -45,9 +53,25 @@ class Chain(private val verifiableDelay: VerifiableDelay, private val initialDif
return false
}
lock.tryWithLock {

blocks.add(nextBlock)
// ToDo: Put chain history in some sort of storage instead of keeping in memory.
transaction {
BlockTable.insert {
it[BlockTable.slot] = nextBlock.slot
it[BlockTable.difficulty] = nextBlock.difficulty
it[BlockTable.blockProducer] = nextBlock.blockProducer
it[BlockTable.timestamp] = nextBlock.timestamp
it[BlockTable.precedentHash] = nextBlock.precedentHash.toHexString()
it[BlockTable.votes] = nextBlock.votes
it[BlockTable.committee] = nextBlock.committee.joinToString()
it[BlockTable.hash] = nextBlock.hash.toHexString()
it[BlockTable.votedMembers] = nextBlock.votedMembers.joinToString()

}
}
}

Logger.chain("Block[${nextBlock.votes}/$committeeSize] added [${nextBlock.slot}].")
}
return true
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/chain/VerifiableDelay.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class VerifiableDelay {

/** Runs a vdf-cli command and returns the output of vdf computation. */
fun computeProof(difficulty: Int, hash: ByteArray): String {
return "0000" // Issues with computing vdf-cli
val hexHash = hash.asHex
val needed = hexHash.length % 2
val processBuilder = ProcessBuilder()
Expand Down
18 changes: 18 additions & 0 deletions src/main/kotlin/database/Tables.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package database

import org.jetbrains.exposed.v1.core.dao.id.IntIdTable

/**
* @author Mihael Berčič on 9. 1. 26.
*/
object BlockTable : IntIdTable("blocks") {
val slot = long("slot")
val difficulty = integer("difficulty").default(0)
val blockProducer = text("block_producer")
val timestamp = long("timestamp")
val precedentHash = varchar("precendtHash", 255)
val votes = integer("votes").default(0)
val committee = text("committee")
val hash = text("hash")
val votedMembers = text("voted_members")
}
30 changes: 27 additions & 3 deletions src/main/kotlin/docker/DockerContainer.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package docker

import com.google.gson.annotations.SerializedName
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import utils.CircularList

Expand All @@ -25,6 +27,28 @@ data class DockerContainer(
var updated: Long = System.currentTimeMillis(),
var latestSnapshot: String? = null
) {
val averageCpuUsage get(): Double = cpuUsage.elements().average().takeIf { !it.isNaN() } ?: 0.0
val averageMemoryUsage get(): Double = memoryUsage.elements().average().takeIf { !it.isNaN() } ?: 0.0
}
val averageCpuUsage get(): Double = cpuUsage.items.average().takeIf { !it.isNaN() } ?: 0.0
val averageMemoryUsage get(): Double = memoryUsage.items.average().takeIf { !it.isNaN() } ?: 0.0
}

@Serializable
data class DockerStatsModel(
@SerialName("BlockIO")
val blockIo: String,
@SerialName("CPUPerc")
val cpuPercentage: String,
@SerialName("Container")
val container: String,
@SerialName("ID")
val id: String,
@SerialName("MemPerc")
val memoryPercentage: String,
@SerialName("MemUsage")
val memUsage: String,
@SerialName("Name")
val name: String,
@SerialName("NetIO")
val netIo: String,
@SerialName("PIDs")
val pids: String,
)
Loading
Loading