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

feat: upgraded gradle and working on faster miner message lookup #108

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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
273 changes: 183 additions & 90 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,131 +1,162 @@
buildscript {
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
classpath 'nu.studer:gradle-jooq-plugin:3.0.3'
}

repositories {
mavenCentral()
jcenter()
maven { url 'https://plugins.gradle.org/m2/' }
maven { url 'https://jitpack.io' }
}
dependencies {
classpath("org.flywaydb:flyway-mysql:8.5.13")
}
}

plugins {
id "org.flywaydb.flyway" version "7.3.2"
id "distribution"
id 'com.github.johnrengelman.shadow' version '7.1.2'
id 'java'
id 'maven-publish'
id 'application'
id 'edu.sc.seis.launch4j' version '2.5.1'
id 'org.gradle.crypto.checksum' version '1.4.0'
id 'com.palantir.git-version' version '0.12.2'
id 'io.spring.dependency-management' version '1.0.1.RELEASE' //for logging - log4j
// latest version to run with JDK 11
// https://github.com/etiennestuder/gradle-jooq-plugin?tab=readme-ov-file#compatibility
id 'nu.studer.jooq' version '7.1.1'
id "org.flywaydb.flyway" version "8.5.13"
id "de.undercouch.download" version "5.5.0"
id 'jacoco'
id "com.github.node-gradle.node" version "7.0.1"
id 'org.kordamp.gradle.jdeps' version '0.20.0'
}

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

// In this section you declare where to find the dependencies of your project
repositories {
mavenCentral()
jcenter()
maven { url 'https://jitpack.io' }
}

apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'nu.studer.jooq'

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
implementation 'org.apache.poi:poi-ooxml:4.1.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.10'
implementation 'com.github.signum-network:signumj:v1.3.2'

implementation 'io.reactivex.rxjava2:rxjava:2.2.15'
implementation 'org.bouncycastle:bcprov-jdk18on:1.78.1'
implementation 'org.bouncycastle:bcpkix-jdk18on:1.78.1'
implementation 'org.ehcache:ehcache:3.9.9'
implementation 'com.google.code.gson:gson:2.8.9'
implementation 'commons-cli:commons-cli:1.4'
implementation 'com.zaxxer:HikariCP:5.0.1'
implementation 'org.jocl:jocl:2.0.1'
implementation 'org.nanohttpd:nanohttpd:2.3.1'
implementation "org.flywaydb:flyway-core:7.3.2"
implementation "com.h2database:h2:1.4.199"
implementation "org.jooq:jooq"
implementation "org.jooq:jooq-meta"
implementation "org.jooq:jooq-codegen"
implementation "org.apache.logging.log4j:log4j-api:2.16.0"
implementation "org.apache.logging.log4j:log4j-slf4j-impl:2.16.0"
implementation "org.slf4j:slf4j-api:1.7.26"
implementation 'com.zaxxer:HikariCP:3.3.1'
implementation 'com.google.code.gson:gson:2.8.5'
implementation group: 'org.ehcache', name: 'ehcache', version: '3.7.1'

// https://mvnrepository.com/artifact/javax.annotation/javax.annotation-api
implementation group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'

// Needed for build script so "compile" needed
compile "com.h2database:h2:1.4.197"
compile group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '2.4.1'
compile group: 'com.h2database', name: 'h2', version: '1.4.199'

//jooqRuntime "com.h2database:h2:1.4.199"
jooqRuntime group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '2.4.1'
}

def schema_dburl = "jdbc:mariadb://localhost:3306/pooldb"
def schema_dbusername = "user"
def schema_dbpassword = "pass"

//def schema_dburl = "jdbc:h2:file:./jooq-schema;AUTO_SERVER=TRUE"
flyway {
url = "${schema_dburl}"
user = "${schema_dbusername}"
password = "${schema_dbpassword}"
locations = ["filesystem:"+project.projectDir.toString()+"/src/main/resources/db/migration"]
//locations = ["filesystem:"+project.projectDir.toString()+"/src/main/resources/db/migration_h2"]
}
// db related deps
// as long as we use 3rd party code gen (nu.studer) we need to use jooq 3.16.23 (and also for JDK11)
// https://github.com/etiennestuder/gradle-jooq-plugin?tab=readme-ov-file#compatibility
implementation 'org.jooq:jooq:3.16.23'
implementation 'org.flywaydb:flyway-core:8.5.13'
// needed because of license issues since 8.2.0
// see https://documentation.red-gate.com/fd/release-notes-for-flyway-engine-179732572.html
implementation 'org.flywaydb:flyway-mysql:8.5.13'
implementation 'com.h2database:h2:2.2.224'
implementation 'org.postgresql:postgresql:42.7.3'
// unix socket support available - see https://github.com/kohlschutter/junixsocket
implementation 'com.kohlschutter.junixsocket:junixsocket-core:2.8.3'
implementation 'org.mariadb.jdbc:mariadb-java-client:2.4.1'
implementation 'org.xerial:sqlite-jdbc:3.45.2.0'
jooqGenerator 'com.h2database:h2:2.2.224'

jooq {
version = "3.11.9"
edition = "OSS"
burstPool(sourceSets.main) {
jdbc {
//driver = 'org.h2.Driver'
url = "${schema_dburl}"
user = "${schema_dbusername}"
password = "${schema_dbpassword}"
}
generator {
name = 'org.jooq.codegen.JavaGenerator'
database {
includes = ".*"
implementation 'org.owasp.encoder:encoder:1.2.3'
implementation 'org.bitlet:weupnp:0.1.4'

name = "org.jooq.meta.mariadb.MariaDBDatabase"
inputSchema = "pooldb"
implementation 'com.google.zxing:core:3.4.1'
implementation 'com.google.zxing:javase:3.4.1'

//name = "org.jooq.meta.h2.H2Database"
//inputSchema = 'PUBLIC'
implementation 'org.slf4j:slf4j-api:1.7.35'
implementation 'org.slf4j:slf4j-jdk14:1.7.35'

excludes = ''
outputSchemaToDefault = true
}
target {
packageName = "burst.pool.db"
directory = "src/main/java"
implementation 'org.eclipse.jetty:jetty-server:10.0.24'
implementation 'org.eclipse.jetty:jetty-servlet:10.0.24'
implementation 'org.eclipse.jetty:jetty-servlets:10.0.24'
implementation 'org.eclipse.jetty:jetty-rewrite:10.0.24'
implementation 'org.eclipse.jetty.websocket:websocket-jetty-server:10.0.24'

implementation 'javax.annotation:javax.annotation-api:1.3.2'

implementation 'com.github.jiconfont:jiconfont:1.0.0'
implementation 'com.github.jiconfont:jiconfont-swing:1.0.1'
implementation 'com.github.jiconfont:jiconfont-font_awesome:4.7.0.1'

//logging
implementation 'org.apache.logging.log4j:log4j-api:2.17.1'
implementation 'org.apache.logging.log4j:log4j-core:2.17.1'

// Use JUnit test framework
testImplementation("org.junit.platform:junit-platform-engine:1.5.1")
testImplementation("org.junit.platform:junit-platform-launcher:1.5.1")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.5.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.5.1")
testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.5.1")

testImplementation 'org.apache.httpcomponents:httpclient:4.5.13'

testImplementation 'org.mockito:mockito-core:3.0.0'

testImplementation 'org.powermock:powermock-module-junit4:2.0.2'
testImplementation 'org.powermock:powermock-api-mockito2:2.0.2'

}


test {
useJUnitPlatform()
testLogging {
exceptionFormat "full"
}
}

sourceSets {
main {
java {
srcDir "src"
}
resources {
srcDir "resources"
}
}
if (!project.hasProperty('skipTests')) {
test {
java {
srcDirs = ["test/java"]
}
}
}
}

// use the following to generate the schema tables:
// ./gradlew build -DgenerateSchema=true
generateBurstPoolJooqSchemaSource.dependsOn flywayMigrate
generateBurstPoolJooqSchemaSource.onlyIf {System.getProperty("generateSchema") == "true"}
flywayMigrate.onlyIf {System.getProperty("generateSchema") == "true"}
// Define the main class for the application
mainClassName = 'signum.Launcher'
description = 'Signum Node.'

jar {
// Needed by the logging library
manifest {
attributes 'Multi-Release': 'true'
}
}

def details = versionDetails()

task versionProp() {
tasks.register('versionProp') {
doFirst {
new File(sourceSets.main.output.resourcesDir, "/version.properties").text = "version:${details.lastTag}"
}
}

task buildJar(dependsOn: shadowJar)

jar {
manifest {
attributes 'Main-Class': 'burst.pool.Launcher'
}
shadowJar {
mergeServiceFiles()
}

shadowJar.dependsOn versionProp

distributions {
Expand All @@ -144,3 +175,65 @@ distributions {
}
}
}
// ==================== JOOQ Code Gen
// ./gradlew generateJooq

def schema_dburl = "jdbc:h2:${project.projectDir}/temp/generated/db/signum_jooq"
def schema_dbusername = ""
def schema_dbpassword = ""

flyway {
url = "${schema_dburl}"
user = "${schema_dbusername}"
password = "${schema_dbpassword}"
locations = ["filesystem:" + project.projectDir.toString() + "/resources/db/migration_h2_v2"]
}

import nu.studer.gradle.jooq.JooqEdition

jooq {
// last version to use with JDK 11
version = '3.16.23'
edition = JooqEdition.OSS

configurations {
main {
generateSchemaSourceOnCompilation = false
generationTool {
logging = org.jooq.meta.jaxb.Logging.DEBUG
jdbc {
driver = 'org.h2.Driver'
url = "${schema_dburl}"
user = "${schema_dbusername}"
password = "${schema_dbpassword}"
}
generator {
name = 'org.jooq.codegen.DefaultGenerator'
database {
name = 'org.jooq.meta.h2.H2Database'
includes = '.*'
excludes = ''
inputSchema = "PUBLIC"
outputSchema = "DB"

forcedTypes {
forcedType {
name = 'BOOLEAN'
expression = '.*\\.(.*\\.LATEST|MINTABLE|AT_STATE\\.FREEZE_WHEN_SAME_BALANCE|GOODS\\.DELISTED|TRANSACTION\\.(HAS_MESSAGE|HAS_ENCRYPTED_MESSAGE|HAS_PUBLIC_KEY_ANNOUNCEMENT|HAS_ENCRYPTTOSELF_MESSAGE)|PURCHASE\\.(PENDING|HAS_FEEDBACK_NOTES|HAS_PUBLIC_FEEDBACKS))'
types = '.*'
}
}
}
target {
packageName = 'brs.schema'
directory = 'temp/generated/jooq'
}
}
}
}
}
}

generateJooq.dependsOn(flywayMigrate)


4 changes: 3 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
#distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-all.zip

10 changes: 7 additions & 3 deletions src/main/java/burst/pool/pool/Pool.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
public class Pool {
private static final Logger logger = LoggerFactory.getLogger(Pool.class);

public static final double LN_FACTOR = 240.0/Math.log(240.0);
public static final double BLOCK_TIME_SECS = 240.0;
public static final double LN_FACTOR = BLOCK_TIME_SECS/Math.log(BLOCK_TIME_SECS);

private final NodeService nodeService;
private final SignumCrypto burstCrypto = SignumCrypto.getInstance();
Expand Down Expand Up @@ -188,9 +189,12 @@ private Completable processNextBlock() {

Block block = nodeService.getBlock(transactionalStorageService.getLastProcessedBlock() + 1).blockingGet();

// Check for commands from miners (always to the primary address)
SignumAddress poolAddress = burstCrypto.getAddressFromPassphrase(propertyService.getString(Props.passphrase));
// Having 100 should be enough to not get past it
int numberOfPastBlocks = 4;
int startLookupTimestamp = block.getTimestamp().getTimestamp() - (numberOfPastBlocks * (int)BLOCK_TIME_SECS);

// Check for commands from miners (always to the primary address)
// Having 100 should be enough to not get past it, using startLookupTime massively improves query execution time
Transaction []txs = nodeService.getAccountTransactions(poolAddress,0, 100, false).blockingGet();
for(Transaction tx : txs) {
if(tx.getBlockHeight() != block.getHeight())
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/burst/pool/pool/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private String handleBurstApiCall(IHTTPSession session, Map<String, String> para
if (submission.getNonce() == null) {
throw new SubmissionException("Nonce not set or invalid");
}

String blockheightParam = params.get("blockheight");
if(blockheightParam != null) {
try {
Expand Down Expand Up @@ -311,7 +311,7 @@ private String handleApiCall(IHTTPSession session, Map<String, String> params) {
return response.toString();
} else if (session.getUri().startsWith("/api/getWonBlocks")) {
JsonArray wonBlocks = new JsonArray();

// Get possible pending blocks
ArrayList<Block> recentlyForged = pool.getRecentlyForged();
if(recentlyForged != null) {
Expand All @@ -331,7 +331,7 @@ private String handleApiCall(IHTTPSession session, Map<String, String> params) {
wonBlocks.add(wonBlockJson);
}
}

storageService.getWonBlocks(100)
.forEach(wonBlock -> {

Expand Down Expand Up @@ -371,7 +371,7 @@ private Response handleCall(IHTTPSession session, Map<String, String> params) th
isPath = true;
mimeType = MIME_HTML;
}
else {
else {
for (String extension : mimeTypesAllowed.keySet()) {
if (uri.endsWith(extension)) {
mimeType = mimeTypesAllowed.get(extension);
Expand Down Expand Up @@ -473,7 +473,7 @@ private Response handleCall(IHTTPSession session, Map<String, String> params) th

return httpResponse;
}

private String getMinerName(Miner miner) {
if (miner != null && miner.getName() != null && miner.getName().length() > 0) {
String name = miner.getName();
Expand Down
Loading