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
34 changes: 34 additions & 0 deletions .github/workflows/build_and_publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Build and Release Artifacts

on: [push, pull_request]

defaults:
run:
working-directory: ./

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'adopt'
- name: Build And Test
run: ./gradlew clean build
- name: Publish Artifact
if : ${{contains(github.ref, 'master') }}
run: ./gradlew publish
env:
USERNAME: ${{ github.actor }}
TOKEN: ${{ secrets.GITHUB_TOKEN }}
42 changes: 42 additions & 0 deletions .github/workflows/manual.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Manual Release
on:
workflow_dispatch:
inputs:
publish_artifacts:
description: Publish artifact
type: boolean
default: false
required: true
artifacts_version:
description: Release artifact version
default: '0.0.1-test'
required: true
defaults:
run:
working-directory: ./

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- run: echo ${{github.event.inputs.publish_artifacts == 'true'}}
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'adopt'
- name: Build And Test
run: ./gradlew clean build
- name: Publish Artifact
if: ${{ github.event.inputs.publish_artifacts == 'true'}}
run: ./gradlew publish
env:
USERNAME: ${{ github.actor }}
TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: '${{ github.event.inputs.artifacts_version }}'
Binary file added Minima_wp_v9.pdf
Binary file not shown.
31 changes: 30 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,16 @@ plugins {
id 'com.github.johnrengelman.shadow' version '6.1.0'

id 'com.palantir.docker' version '0.28.0'

id 'maven-publish'
}

group 'org.minima'
version '0.100.33'

sourceCompatibility = '11'
targetCompatibility = '11'

repositories {
// Use jcenter for resolving dependencies.
// You can declare any Maven/Ivy/file repository here.
Expand Down Expand Up @@ -101,4 +109,25 @@ docker {
files tasks.shadowJar, "$rootDir/scripts/installDapps.sh", "$rootDir/dapps/"
copySpec.from("$buildDir/lib/minima-all.jar",).into(".")
//"./scripts/installDapps.sh", "./dapps/block.minidapp", "./dapps/wallet.minidapp", "dapps/terminal.minidapp", "dapps/emh.minidapp"
}
}

publishing {
repositories {
maven {
name = "GitHubPackages"
url = "https://maven.pkg.github.com/minima-global/Minima"
if (System.getenv("VERSION") != '') {
version = System.getenv("VERSION")
}
credentials {
username = System.getenv("USERNAME")
password = System.getenv("TOKEN")
}
}
}
publications {
gpr(MavenPublication) {
from(components.java)
}
}
}
Binary file modified jar/minima-all.jar
Binary file not shown.
Binary file modified jar/minima.jar
Binary file not shown.
Binary file removed minima_whitepaper_v6.pdf
Binary file not shown.
18 changes: 15 additions & 3 deletions src/org/minima/database/MinimaDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,6 @@ public void saveSQL() {
readLock(true);

try {
//Get the base Database folder
File basedb = getBaseDBFolder();

//Clean shutdown of SQL DBs
mTxPoWDB.saveDB();
mArchive.saveDB();
Expand All @@ -250,6 +247,21 @@ public void saveSQL() {
readLock(false);
}

public void saveWalletSQL() {
//We need read lock
readLock(true);

try {
mWallet.saveDB();

}catch(Exception exc) {
MinimaLogger.log("ERROR saveWalletSQL "+exc);
}

//Release the krakken
readLock(false);
}

public void saveState() {

//We need read lock
Expand Down
170 changes: 119 additions & 51 deletions src/org/minima/database/mmr/MMR.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Random;

import org.minima.objects.base.MiniData;
import org.minima.objects.base.MiniNumber;
Expand Down Expand Up @@ -222,6 +223,11 @@ private void addHashTableEntry(MMREntry zEntry) {
mSetEntries.put(name, zEntry);
}

private void removeHashTableEntry(MMREntry zEntry) {
String name = getHashTableEntry(zEntry.getRow(), zEntry.getEntryNumber());
mSetEntries.remove(name);
}

/**
* Sets the Entry value in THIS SET ONLY. Does not affect parents.
* @param zRow
Expand Down Expand Up @@ -698,68 +704,83 @@ public static MMR ReadFromStream(DataInputStream zIn) throws IOException {
}

/**
* TEST STUFF
* PRUNE
*
* Recursive Remove subtrees below a ZERO SUM Value
*/
public static void main(String[] zArgs) {
public void pruneTree() {
//Get the Peaks..
ArrayList<MMREntry> peaks = getPeaks();
for(MMREntry peak : peaks) {
prune(peak);
}
}

MMR mmr = new MMR();

//First bit of data
MMRData one = new MMRData(new MiniData("0x01"), new MiniNumber(1));
MMRData two = new MMRData(new MiniData("0x02"), new MiniNumber(2));
MMRData three = new MMRData(new MiniData("0x03"), new MiniNumber(3));
MMRData four = new MMRData(new MiniData("0x04"), new MiniNumber(4));

//Add to the tree
mmr.addEntry(one);
printinfo(mmr);

mmr.addEntry(two);
printinfo(mmr);
private void prune(MMREntry zStartNode) {

mmr.addEntry(one);
printinfo(mmr);

mmr.addEntry(one);
printinfo(mmr);
//Is this a valid MMRENtry
if(zStartNode.isEmpty()) {
//Already pruned..
return;
}

//Now get a a proof..
MMRProof proof = mmr.getProofToPeak(MMREntryNumber.ZERO);
MMRData peak = proof.calculateProof(one);
System.out.println("Peak Proof : "+proof);
System.out.println("Proof : "+peak);
//Which row are the children on..
int childrow = zStartNode.getChildRow();
if(childrow<0) {
//We are at the base leaf nodes.. leave it..
return;
}

boolean check = mmr.checkProof(one, proof);
System.out.println("isValid : "+check);
//The children..
MMREntry leftchild = getEntry(childrow, zStartNode.getLeftChildEntry());
MMREntry rightchild = getEntry(childrow, zStartNode.getRightChildEntry());

//Now get a a proof..
MMRProof fullproof = mmr.getProof(MMREntryNumber.ZERO);
MMRData fpeak = fullproof.calculateProof(one);
System.out.println("Full Proof : "+fullproof);
System.out.println("Proof : "+fpeak);
//Prune the children if they exist
prune(leftchild);
prune(rightchild);

check = mmr.checkProof(one, fullproof);
System.out.println("isValid : "+check);
//Is this a ZERO node.. if so remove the children
if(zStartNode.getMMRData().getValue().isEqual(MiniNumber.ZERO)) {
removeHashTableEntry(leftchild);
removeHashTableEntry(rightchild);
}

//Now update something..
mmr.updateEntry(MMREntryNumber.ZERO, proof, three);
printinfo(mmr);
}

/**
* TEST STUFF
*/
public static void main(String[] zArgs) {

System.out.println("** MMR Tree Prune POC **");

//Get the new proof..
proof = mmr.getProofToPeak(MMREntryNumber.ZERO);
MMR mmr = new MMR();

//Now create a child MMR.. with the parent
MMR child = new MMR(mmr);
printinfo(child);
child.updateEntry(MMREntryNumber.ZERO, proof, four);
printinfo(child);
//First bit of data
MMRData zero = new MMRData(new MiniData("0x00"), new MiniNumber(0));
MMRData one = new MMRData(new MiniData("0x01"), new MiniNumber(1));

//Now create a child MMR.. with the parent
MMR child2 = new MMR(mmr);
printinfo(child2);
child2.clearParent();
child2.updateEntry(MMREntryNumber.ZERO, proof, four);
printinfo(child2);
//Add 16 entries..
for(int loop=0;loop<16;loop++) {
mmr.addEntry(one);
}
printmmrtree(mmr);

//Set random values to Zero..
for(int zz=0;zz<24;zz++) {
int rand = new Random().nextInt(16);
MMREntryNumber entry = new MMREntryNumber(rand);
MMREntry ent = mmr.getEntry(0, entry);
if(ent.isEmpty() || ent.getMMRData().getValue().isEqual(MiniNumber.ZERO)) {
continue;
}

System.out.println("\nSet entry "+rand+" to 0");
MMRProof proof = mmr.getProofToPeak(entry);
mmr.updateEntry(entry, proof, zero);
mmr.pruneTree();
printmmrtree(mmr);
}
}

public static void printinfo(MMR zTree) {
Expand All @@ -777,5 +798,52 @@ public static void printinfo(MMR zTree) {
System.out.println("Root : "+root);
}

public static void printmmrtree(MMR zTree) {
//Start from the max row..
int toprow = zTree.mMaxRow;
for(int i=toprow;i>=0;i--) {

//The start gap
int startgap = (int) (Math.pow(2, i) -1) * 2;
int gap = (int) (Math.pow(2, i+1)) * 2;

//Get the row..
ArrayList<MMREntry> row = new ArrayList<>();
Enumeration<MMREntry> entries = zTree.mSetEntries.elements();
while(entries.hasMoreElements()) {
MMREntry entry = entries.nextElement();
if(entry.getRow() == i) {
row.add(entry);
}
}

//The final char buffrer for the row
char[] str = new char[128];
for(int c=0;c<128;c++) {
str[c] = ' ';
}

StringBuffer strow = new StringBuffer(" ");
for(MMREntry entry : row) {

//Add the entry to the correct spot..
int xpos = entry.getEntryNumber().getBigDecimal().intValue();
int finalpos = startgap+(xpos*gap);
int value = entry.getMMRData().getValue().getAsInt();
String valstr = ""+value;
char[] cc = valstr.toCharArray();

System.arraycopy(cc, 0, str, finalpos, cc.length);
}

System.out.println(str);
}

//Print the peak value..
System.out.println("Total Entries : "+zTree.mSetEntries.size());
System.out.println("Tree Peak Sum Value : "+zTree.getRoot().getValue());

}

}

13 changes: 12 additions & 1 deletion src/org/minima/database/txpowtree/TxPoWTreeNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private void constructMMR(boolean zFindRelevant) {
//Are we checking for relevant data
ArrayList<KeyRow> allrel = new ArrayList<>();
if(zFindRelevant) {
allrel = wallet.getAllRelevant();
allrel = wallet.getAllRelevant(false);
}

//Add all the peaks..
Expand Down Expand Up @@ -333,6 +333,17 @@ public TxPoWTreeNode getParent() {
return mParent;
}

public TxPoWTreeNode getParent(int zBlocks) {
TxPoWTreeNode parent = this;
int counter = 0;
while(counter<zBlocks && parent.getParent()!=null) {
parent = parent.getParent();
counter++;
}

return parent;
}

public TxPoWTreeNode getPastNode(MiniNumber zBlockNumber) {
TxPoWTreeNode parent = this;
while(parent != null) {
Expand Down
Loading