Skip to content

Commit

Permalink
feat: Make application stable (#3)
Browse files Browse the repository at this point in the history
* feat: start light client

* chore: remove logs, fetch more info

* chore: remove implements in js and won't implement protocols

* chore: remove polkaj and tuples, and copy to project

* fix hex decoding

* chore: remove unused files

* chore: use bootnodes from chainspec

* chore: stop infinite loop for now

* chore: remove unused sout

* chore: remove sysout

* chore: remove unused dependency

* chore: add debug messages

* chore: remove unused dependency

* chore: remove double line
  • Loading branch information
ablax authored Aug 8, 2024
1 parent 9a5520e commit 227faf1
Show file tree
Hide file tree
Showing 124 changed files with 1,520 additions and 423 deletions.
20 changes: 0 additions & 20 deletions Dockerfile

This file was deleted.

32 changes: 11 additions & 21 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
plugins {
id("java")
id("war")
id("org.teavm") version "0.9.2"
id("io.freefair.lombok") version "8.6"
id("org.teavm") version "0.10.0"
id("io.freefair.lombok") version "8.7.1"
}

group = "com.limechain"
Expand All @@ -20,31 +20,21 @@ dependencies {
compileOnly("org.projectlombok:lombok:1.18.34")
implementation("org.projectlombok:lombok:1.18.34")

implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))

implementation("org.javatuples:javatuples:1.2")

// implementation("com.github.LimeChain:nabu:0.7.8")
// implementation("com.fasterxml.jackson.core:jackson-databind:2.17.2")

implementation("org.teavm:teavm-jso-apis:0.9.2")
implementation("org.teavm:teavm-jso-apis:0.10.0")

}

tasks.getByName<Test>("test") {
useJUnitPlatform()
jvmArgs("-Dnet.bytebuddy.experimental=true")
}

teavm.js {
addedToWebApp = true
mainClass = "com.limechain.Main"
targetFileName = "fruzhin.js"
}

//teavm {
// js {
// sourceMap.set(true)
// debugInformation.set(true)
// }
//}

//TODO: Debug only. Remove when doing release build
teavm {
js {
sourceMap.set(true)
debugInformation.set(true)
}
}
Binary file removed libs/polkaj-common-types-0.5.0-SNAPSHOT.jar
Binary file not shown.
Binary file removed libs/polkaj-scale-0.5.0-SNAPSHOT.jar
Binary file not shown.
Binary file removed libs/polkaj-scale-types-0.5.0-SNAPSHOT.jar
Binary file not shown.
15 changes: 0 additions & 15 deletions local_dev.sh

This file was deleted.

26 changes: 6 additions & 20 deletions src/main/java/com/limechain/Main.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.limechain;

import com.limechain.client.HostNode;
import com.limechain.client.LightClient;
import com.limechain.config.HostConfig;
import com.limechain.rpc.server.AppBean;
import com.limechain.rpc.server.RpcApp;
import com.limechain.utils.DivLogger;

import java.util.logging.Level;

public class Main {

private static final DivLogger log = new DivLogger();
Expand All @@ -15,28 +18,11 @@ public static void main(String[] args) {
RpcApp rpcApp = new RpcApp();
rpcApp.start();

HostConfig hostConfig = AppBean.getBean(HostConfig.class);

// Figure out what client role we want to start
// final NodeRole nodeRole = hostConfig.getNodeRole();
HostNode client;

// switch (nodeRole) {
// case LIGHT -> client = new LightClient();
// case NONE -> {
// // This shouldn't happen.
// return;
// }
// default -> {
// log.log(Level.SEVERE, "Node role {0} not yet implemented.", nodeRole);
// return;
// }
// }
HostNode client = new LightClient();

// Start the client
// NOTE: This starts the beans the client would need - mutates the global context
// client.start();
// log.log(Level.INFO, "\uD83D\uDE80Started {0} client!", nodeRole);

client.start();
log.log(Level.INFO, "\uD83D\uDE80Started light client!");
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.limechain.chain.lightsyncstate;

import io.emeraldpay.polkaj.types.Hash256;
import com.limechain.polkaj.Hash256;
import lombok.Getter;
import lombok.Setter;
import org.javatuples.Pair;
import com.limechain.tuple.Pair;

import java.math.BigInteger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import lombok.Getter;
import lombok.Setter;
import org.javatuples.Pair;
import com.limechain.tuple.Pair;

import java.math.BigInteger;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.limechain.chain.lightsyncstate;

import io.emeraldpay.polkaj.types.Hash256;
import com.limechain.polkaj.Hash256;
import lombok.Getter;
import lombok.Setter;
import org.javatuples.Pair;
import com.limechain.tuple.Pair;

import java.math.BigInteger;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.limechain.chain.lightsyncstate;

import io.emeraldpay.polkaj.types.Hash256;
import com.limechain.polkaj.Hash256;
import lombok.Getter;
import lombok.Setter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

import com.limechain.chain.lightsyncstate.scale.AuthoritySetReader;
import com.limechain.chain.lightsyncstate.scale.EpochChangesReader;
import com.limechain.network.protocol.warp.dto.BlockHeader;
import com.limechain.network.protocol.warp.scale.reader.BlockHeaderReader;
import com.limechain.polkaj.reader.ScaleCodecReader;
import com.limechain.utils.StringUtils;
import io.emeraldpay.polkaj.scale.ScaleCodecReader;
import lombok.Getter;
import lombok.ToString;

import java.util.Arrays;
import java.util.Map;

@Getter
public class LightSyncState {
// private BlockHeader finalizedBlockHeader;
private BlockHeader finalizedBlockHeader;
private EpochChanges epochChanges;
private AuthoritySet grandpaAuthoritySet;

Expand All @@ -29,12 +33,15 @@ public static LightSyncState decode(Map<String, String> lightSyncState) {
throw new IllegalStateException("grandpaAuthoritySet is null");
}


var state = new LightSyncState();
// state.finalizedBlockHeader = new BlockHeaderReader()
// .read(new ScaleCodecReader(StringUtils.hexToBytes(header)));
byte[] bytes = StringUtils.hexToBytes(header);
state.finalizedBlockHeader = new BlockHeaderReader()
.read(new ScaleCodecReader(bytes));

byte[] bytes1 = StringUtils.hexToBytes(epochChanges);
state.epochChanges = new EpochChangesReader()
.read(new ScaleCodecReader(StringUtils.hexToBytes(epochChanges)));
.read(new ScaleCodecReader(bytes1));

state.grandpaAuthoritySet = new AuthoritySetReader()
.read(new ScaleCodecReader(StringUtils.hexToBytes(grandpaAuthoritySet)));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.limechain.chain.lightsyncstate;

import io.emeraldpay.polkaj.types.Hash256;
import com.limechain.polkaj.Hash256;
import lombok.Getter;
import lombok.Setter;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.limechain.chain.lightsyncstate.scale;

import com.limechain.chain.lightsyncstate.Authority;
import io.emeraldpay.polkaj.scale.ScaleCodecReader;
import io.emeraldpay.polkaj.scale.ScaleReader;
import io.emeraldpay.polkaj.scale.reader.UInt64Reader;
import com.limechain.polkaj.reader.ScaleCodecReader;
import com.limechain.polkaj.reader.ScaleReader;
import com.limechain.polkaj.reader.UInt64Reader;

public class AuthorityReader implements ScaleReader<Authority> {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.limechain.chain.lightsyncstate.scale;

import io.emeraldpay.polkaj.scale.ScaleCodecReader;
import io.emeraldpay.polkaj.scale.ScaleReader;
import io.emeraldpay.polkaj.scale.reader.UInt64Reader;
import org.javatuples.Pair;
import com.limechain.polkaj.reader.ScaleCodecReader;
import com.limechain.polkaj.reader.ScaleReader;
import com.limechain.polkaj.reader.UInt64Reader;
import com.limechain.tuple.Pair;

import java.math.BigInteger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import com.limechain.chain.lightsyncstate.AuthoritySet;
import com.limechain.chain.lightsyncstate.ForkTree;
import com.limechain.chain.lightsyncstate.PendingChange;
import io.emeraldpay.polkaj.scale.ScaleCodecReader;
import io.emeraldpay.polkaj.scale.ScaleReader;
import io.emeraldpay.polkaj.scale.reader.ListReader;
import io.emeraldpay.polkaj.scale.reader.UInt32Reader;
import io.emeraldpay.polkaj.scale.reader.UInt64Reader;
import org.javatuples.Pair;
import com.limechain.polkaj.reader.ListReader;
import com.limechain.polkaj.reader.ScaleCodecReader;
import com.limechain.polkaj.reader.ScaleReader;
import com.limechain.polkaj.reader.UInt32Reader;
import com.limechain.polkaj.reader.UInt64Reader;
import com.limechain.tuple.Pair;

public class AuthoritySetReader implements ScaleReader<AuthoritySet> {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.limechain.chain.lightsyncstate.scale;

import com.limechain.chain.lightsyncstate.BabeEpoch;
import io.emeraldpay.polkaj.scale.ScaleCodecReader;
import io.emeraldpay.polkaj.scale.ScaleReader;
import io.emeraldpay.polkaj.scale.reader.UInt64Reader;
import org.javatuples.Pair;
import com.limechain.polkaj.reader.ScaleCodecReader;
import com.limechain.polkaj.reader.ScaleReader;
import com.limechain.polkaj.reader.UInt64Reader;
import com.limechain.tuple.Pair;

public class BabeConfigReader implements ScaleReader<BabeEpoch.NextBabeConfig> {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.limechain.chain.lightsyncstate.scale;

import com.limechain.chain.lightsyncstate.BabeEpoch;
import io.emeraldpay.polkaj.scale.ScaleCodecReader;
import io.emeraldpay.polkaj.scale.ScaleReader;
import io.emeraldpay.polkaj.scale.reader.ListReader;
import io.emeraldpay.polkaj.scale.reader.UInt64Reader;
import com.limechain.polkaj.reader.ListReader;
import com.limechain.polkaj.reader.ScaleCodecReader;
import com.limechain.polkaj.reader.ScaleReader;
import com.limechain.polkaj.reader.UInt64Reader;

public class BabeEpochReader implements ScaleReader<BabeEpoch> {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.limechain.chain.lightsyncstate.scale;

import com.limechain.chain.lightsyncstate.PendingChange;
import io.emeraldpay.polkaj.scale.ScaleCodecReader;
import io.emeraldpay.polkaj.scale.ScaleReader;
import io.emeraldpay.polkaj.scale.reader.UInt32Reader;
import com.limechain.polkaj.reader.ScaleCodecReader;
import com.limechain.polkaj.reader.ScaleReader;
import com.limechain.polkaj.reader.UInt32Reader;

import java.math.BigInteger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,41 @@
import com.limechain.chain.lightsyncstate.EpochChanges;
import com.limechain.chain.lightsyncstate.ForkTree;
import com.limechain.chain.lightsyncstate.PersistedEpoch;
import io.emeraldpay.polkaj.scale.ScaleCodecReader;
import io.emeraldpay.polkaj.scale.ScaleReader;
import io.emeraldpay.polkaj.scale.reader.ListReader;
import io.emeraldpay.polkaj.scale.reader.UInt32Reader;
import io.emeraldpay.polkaj.types.Hash256;
import org.javatuples.Pair;
import com.limechain.chain.lightsyncstate.PersistedEpochHeader;
import com.limechain.polkaj.Hash256;
import com.limechain.polkaj.reader.ListReader;
import com.limechain.polkaj.reader.ScaleCodecReader;
import com.limechain.polkaj.reader.ScaleReader;
import com.limechain.polkaj.reader.UInt32Reader;
import com.limechain.tuple.Pair;

import java.math.BigInteger;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

public class EpochChangesReader implements ScaleReader<EpochChanges> {
@Override
public EpochChanges read(ScaleCodecReader reader) {
EpochChanges changes = new EpochChanges();

var forkTree = new ForkTree<>();
forkTree.setRoots(reader.read(new ListReader<>(
new ForkTreeNodeReader<>(
new PersistedEpochHeaderReader()
)))
.toArray(ForkTree.ForkTreeNode[]::new));
PersistedEpochHeaderReader epochHeaderReader = new PersistedEpochHeaderReader();
ForkTreeNodeReader<PersistedEpochHeader> forkTreeReader = new ForkTreeNodeReader<>(epochHeaderReader);
ListReader<ForkTree.ForkTreeNode<PersistedEpochHeader>> listReader = new ListReader<>(forkTreeReader);
List<ForkTree.ForkTreeNode<PersistedEpochHeader>> roots = reader.read(listReader);
forkTree.setRoots(roots.toArray(ForkTree.ForkTreeNode[]::new));
forkTree.setBestFinalizedNumber(reader.readOptional(new UInt32Reader()));

Map<Pair<Hash256, BigInteger>, PersistedEpoch> epochs = new TreeMap<>();
PersistedEpochReader scaleReader = new PersistedEpochReader();

Map<Pair<Hash256, BigInteger>, PersistedEpoch> epochs = new HashMap<>();
int epochsCount = reader.readCompactInt();
for (int i = 0; i < epochsCount; i++) {
Pair<Hash256, BigInteger> key = new Pair<>(
new Hash256(reader.readUint256()),
BigInteger.valueOf(reader.readUint32())
);
var value = reader.read(new PersistedEpochReader());
Hash256 hash256 = new Hash256(reader.readUint256());
BigInteger bigInteger = BigInteger.valueOf(reader.readUint32());
Pair<Hash256, BigInteger> key = new Pair<>(hash256, bigInteger);
var value = reader.read(scaleReader);
epochs.put(key, value);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.limechain.chain.lightsyncstate.scale;

import com.limechain.chain.lightsyncstate.EpochHeader;
import io.emeraldpay.polkaj.scale.ScaleCodecReader;
import io.emeraldpay.polkaj.scale.ScaleReader;
import io.emeraldpay.polkaj.scale.reader.UInt64Reader;
import com.limechain.polkaj.reader.ScaleCodecReader;
import com.limechain.polkaj.reader.ScaleReader;
import com.limechain.polkaj.reader.UInt64Reader;

public class EpochHeaderReader implements ScaleReader<EpochHeader> {
@Override
Expand Down
Loading

0 comments on commit 227faf1

Please sign in to comment.