Skip to content

Commit

Permalink
Merge pull request #53 from bloxbean/feat/conway_8_12_0_pre
Browse files Browse the repository at this point in the history
Added support for node 8.12.1 - conway era
  • Loading branch information
satran004 committed Jun 29, 2024
2 parents 1c6520a + 464f818 commit a77377a
Show file tree
Hide file tree
Showing 18 changed files with 719 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ private void updateGenesis(Path clusterFolder, String clusterName, ClusterInfo c
} else if (era == Era.Conway) {
srcByronGenesisFile = clusterFolder.resolve("genesis-templates").resolve("byron-genesis.json");
srcShelleyGenesisFile = clusterFolder.resolve("genesis-templates").resolve("shelley-genesis.json");
srcAlonzoGenesisFile = clusterFolder.resolve("genesis-templates").resolve("alonzo-genesis.json.conway");
srcConwayGenesisFile = clusterFolder.resolve("genesis-templates").resolve("conway-genesis.json.conway");
srcAlonzoGenesisFile = clusterFolder.resolve("genesis-templates").resolve("alonzo-genesis.json");
srcConwayGenesisFile = clusterFolder.resolve("genesis-templates").resolve("conway-genesis.json");
}

Path destByronGenesisFile = clusterFolder.resolve("node").resolve("genesis").resolve("byron-genesis.json");
Expand All @@ -308,6 +308,12 @@ private void updateGenesis(Path clusterFolder, String clusterName, ClusterInfo c
values.put("activeSlotsCoeff", String.valueOf(activeSlotsCoeff));
values.put("epochLength", String.valueOf(epochLength));

//Check if protocol version should be minimun 10 and it's conway era
if (era == Era.Conway && genesisConfig.getProtocolMajorVer() < 10) {
values.put("protocolMajorVer", 10);
values.put("protocolMinorVer", 0);
}

//Update Genesis files
try {
templateEngineHelper.replaceValues(srcByronGenesisFile, destByronGenesisFile, values);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ public class GenesisConfig {
private BigInteger govActionDeposit = BigInteger.valueOf(1000000000);
private BigInteger dRepDeposit = BigInteger.valueOf(2000000);
private int dRepActivity = 20;
private BigDecimal minFeeRefScriptCostPerByte = BigDecimal.valueOf(44);

private String constitutionUrl = "https://devkit.yaci.xyz/constitution.json";
private String constitutionDataHash = "f89cc2469ce31c3dfda2f3e0b56c5c8b4ee4f0e5f66c30a3f12a95298b01179e";
private String constitutionScript;

private List<CCMember> ccMembers = new ArrayList<>();
private float ccThreshold = 0f;

private boolean disableFaucet = false;
private boolean disableShelleyInitialFunds = false;
Expand Down Expand Up @@ -310,6 +318,16 @@ public Map getConfigMap() {
map.put("govActionDeposit", govActionDeposit);
map.put("dRepDeposit", dRepDeposit);
map.put("dRepActivity", dRepActivity);
map.put("minFeeRefScriptCostPerByte", minFeeRefScriptCostPerByte);
map.put("constitutionUrl", constitutionUrl);
map.put("constitutionDataHash", constitutionDataHash);
if (constitutionScript != null)
map.put("constitutionScript", constitutionScript);

if (ccMembers != null && ccMembers.size() > 0)
ccMembers.getLast().setLast(true);
map.put("ccMembers", ccMembers);
map.put("ccThreshold", ccThreshold);

map.put("initialFunds", initialFundsList);

Expand Down Expand Up @@ -387,6 +405,12 @@ public GenesisConfig copy() {
genesisConfig.setGovActionDeposit(govActionDeposit);
genesisConfig.setDRepDeposit(dRepDeposit);
genesisConfig.setDRepActivity(dRepActivity);
genesisConfig.setMinFeeRefScriptCostPerByte(minFeeRefScriptCostPerByte);
genesisConfig.setConstitutionUrl(constitutionUrl);
genesisConfig.setConstitutionDataHash(constitutionDataHash);
genesisConfig.setConstitutionScript(constitutionScript);
genesisConfig.setCcMembers(ccMembers);
genesisConfig.setCcThreshold(ccThreshold);

genesisConfig.setFaucets(faucets);
genesisConfig.setInitialFunds(initialFunds);
Expand Down Expand Up @@ -443,4 +467,14 @@ public record GenesisDeleg(String delegator, String delegate, String vrf, boolea
public record NonAvvmBalances(String address, String balance, boolean last) {}

public record InitialAddress(String address, BigInteger balance, boolean staked, boolean last) {}

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public static class CCMember {
String hash;
int term;
boolean last;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public boolean addPeer(String adminUrl, String nodeName, int portShift, boolean
.p2pEnabled(true)
.isBlockProducer(isBlockProducer)
.adminNodeUrl(adminUrl)
.era(Era.Babbage) //TODO: Need to get from admin node
.era(bootstrapClusterInfo.getEra())
.build();

clusterInfo.setOgmiosPort(clusterInfo.getOgmiosPort() + portShift);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.bloxbean.cardano.yaci.core.util.HexUtil;
import com.bloxbean.cardano.yacicli.commands.localcluster.ClusterConfig;
import com.bloxbean.cardano.yacicli.commands.localcluster.ClusterInfo;
import com.bloxbean.cardano.yacicli.util.ProcessStream;
import com.bloxbean.cardano.yacicli.util.ProcessUtil;
import com.bloxbean.cardano.yacicli.util.TemplateEngine;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -22,8 +22,6 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.function.Consumer;

import static com.bloxbean.cardano.yacicli.util.ConsoleWriter.*;
Expand Down Expand Up @@ -54,13 +52,13 @@ public void updatePoolGenScript(Path destPath, ClusterInfo clusterInfo) throws I
}

@SneakyThrows
public void generatePoolKeys(String nodeName, boolean overwrite, Consumer<String> writer) {
public boolean generatePoolKeys(String nodeName, boolean overwrite, Consumer<String> writer) {
Path clusterPoolKeysFolder = clusterConfig.getPoolKeysFolder(nodeName);

if (clusterPoolKeysFolder.toFile().exists() && !overwrite) {
writer.accept(warn("Found existing pool keys for this node. Existing keys will be used." +
"Please use --overwrite-pool-keys option to overwrite pool keys"));
return;
return true;
}

if (!clusterPoolKeysFolder.toFile().exists()) {
Expand All @@ -70,23 +68,30 @@ public void generatePoolKeys(String nodeName, boolean overwrite, Consumer<String
try {
String genKeyFile = clusterConfig.getClusterFolder(nodeName).resolve("gen-pool-keys.sh").toFile()
.getAbsolutePath();

ProcessBuilder builder = new ProcessBuilder();
builder.command("sh", genKeyFile);

builder.directory(clusterPoolKeysFolder.toFile());
Process process = builder.start();

ProcessStream processStream =
new ProcessStream(process.getInputStream(), line -> {
if (line != null && !line.isEmpty())
writer.accept(successLabel("Pool Keys", line));
});
Future<?> future = Executors.newSingleThreadExecutor().submit(processStream);
future.get();

return ProcessUtil.executeAndFinish(builder, "Pool Keys", writer);
// ProcessBuilder builder = new ProcessBuilder();
// builder.command("sh", genKeyFile);
//
// builder.directory(clusterPoolKeysFolder.toFile());
// Process process = builder.start();
//
// ProcessStream processStream =
// new ProcessStream(process.getInputStream(), line -> {
// if (line != null && !line.isEmpty())
// writer.accept(successLabel("Pool Keys", line));
// });
// Future<?> future = Executors.newSingleThreadExecutor().submit(processStream);
// future.get();
} catch (Exception e) {
log.info(e.getMessage(), e);
}

return false;

//Generate Cold Keys and a Cold Counter

Expand Down Expand Up @@ -119,37 +124,42 @@ public void generateOperationalCert(String adminUrl, String nodeName, Consumer<S
generateOperationalCert(nodeName, kesPeriod, writer);
}

public void generateOperationalCert(String nodeName, int kesPeriod, Consumer<String> writer) throws IOException {
public boolean generateOperationalCert(String nodeName, int kesPeriod, Consumer<String> writer) throws IOException {
Path clusterPoolKeysFolder = clusterConfig.getPoolKeysFolder(nodeName);

if (!clusterPoolKeysFolder.toFile().exists()) {
Files.createDirectories(clusterPoolKeysFolder);
}

try {
String genCertFile = clusterConfig.getClusterFolder(nodeName).resolve("gen-pool-cert.sh").toFile()
.getAbsolutePath();
Path genPoolCertPath = clusterConfig.getClusterFolder(nodeName).resolve("gen-pool-cert.sh");
String genCertFile = genPoolCertPath.toFile().getAbsolutePath();

ProcessBuilder builder = new ProcessBuilder();
builder.command("sh", genCertFile, String.valueOf(kesPeriod));

builder.directory(clusterPoolKeysFolder.toFile());
Process process = builder.start();

ProcessStream processStream =
new ProcessStream(process.getInputStream(), line -> {
// //TODO -- Add logs
if (line != null && !line.isEmpty())
writer.accept(info(line));
});
Future<?> future = Executors.newSingleThreadExecutor().submit(processStream);
future.get();

return ProcessUtil.executeAndFinish(builder, "Operational Certificate", writer);
// Process process = builder.start();
//
// ProcessStream processStream =
// new ProcessStream(process.getInputStream(), line -> {
//// //TODO -- Add logs
// if (line != null && !line.isEmpty())
// writer.accept(info(line));
// });
// Future<?> future = Executors.newSingleThreadExecutor().submit(processStream);
// future.get();
} catch (Exception e) {
log.info(e.getMessage(), e);
}

return false;
}

@SneakyThrows
public void registerPool(String nodeName, PoolConfig poolConfig, Consumer<String> writer) {
public boolean registerPool(String nodeName, PoolConfig poolConfig, Consumer<String> writer) {
Path clusterPoolKeysFolder = clusterConfig.getPoolKeysFolder(nodeName);

try {
Expand All @@ -162,26 +172,29 @@ public void registerPool(String nodeName, PoolConfig poolConfig, Consumer<String
poolConfig.getRelayHost(), String.valueOf(poolConfig.getRelayPort()));

builder.directory(clusterPoolKeysFolder.toFile());
Process process = builder.start();

writer.accept("Running script : " + builder.command());

ProcessStream processStream =
new ProcessStream(process.getInputStream(), line -> {
// //TODO -- Add logs
if (line != null && !line.isEmpty())
writer.accept(successLabel("Pool Registration", line));
});
ProcessStream errorProcessStream =
new ProcessStream(process.getErrorStream(), line -> {
// //TODO -- Add logs
writer.accept(error(line));
});
Future<?> future = Executors.newSingleThreadExecutor().submit(processStream, errorProcessStream);
future.get();
return ProcessUtil.executeAndFinish(builder, "Pool Registration", writer);

// ProcessStream processStream =
// new ProcessStream(process.getInputStream(), line -> {
//// //TODO -- Add logs
// if (line != null && !line.isEmpty())
// writer.accept(successLabel("Pool Registration", line));
// });
// ProcessStream errorProcessStream =
// new ProcessStream(process.getErrorStream(), line -> {
//// //TODO -- Add logs
// writer.accept(error(line));
// });
// Future<?> future = Executors.newSingleThreadExecutor().submit(processStream, errorProcessStream);
// future.get();
} catch (Exception e) {
log.info(e.getMessage(), e);
}

return false;
}

@SneakyThrows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.bloxbean.cardano.yacicli.commands.localcluster.peer.PoolKeyGeneratorService;
import com.bloxbean.cardano.yacicli.commands.localcluster.profiles.GenesisProfile;
import com.bloxbean.cardano.yacicli.util.AdvancedTemplateEngine;
import com.bloxbean.cardano.yacicli.util.ProcessStream;
import com.bloxbean.cardano.yacicli.util.ProcessUtil;
import com.bloxbean.cardano.yacicli.util.TemplateEngine;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -23,8 +23,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.function.Consumer;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -52,8 +50,10 @@ public class PrivNetService {
public void setupNewKeysAndDefaultPool(Path clusterPath, String clusterName, ClusterInfo clusterInfo, GenesisConfig genesisConfig, Double activeCoeff, Consumer<String> writer) throws IOException {
updateGenesisScript(clusterPath, clusterName, clusterInfo, clusterInfo.getSlotLength(), activeCoeff,
clusterInfo.getEpochLength(), writer);
runGenesisScript(clusterPath, clusterName, true, writer);
writer.accept(success("New genesis keys generated successfully"));
boolean status = runGenesisScript(clusterPath, clusterName, true, writer);
if (status) {
writer.accept(success("New genesis keys generated successfully"));
}

updateByronAndShelleyDelegationKeys(clusterPath, clusterName, clusterInfo, writer);

Expand Down Expand Up @@ -91,21 +91,21 @@ private void updateGenesisScript(Path destPath, String clusterName, ClusterInfo
}
}

public void runGenesisScript(Path clusterPah, String clusterName, boolean overwrite, Consumer<String> writer) {
public boolean runGenesisScript(Path clusterPah, String clusterName, boolean overwrite, Consumer<String> writer) {
try {
Path genCreateScript = clusterPah.resolve("genesis-scripts").resolve("genesis-create.sh");

if (!genCreateScript.toFile().exists()) {
writer.accept(error("Genesis script file not found : %s", genCreateScript.toFile().getAbsolutePath()));
return;
return false;
}

Path clusterGenesisKeysFolder = clusterConfig.getGenesisKeysFolder(clusterName);

if (clusterGenesisKeysFolder.toFile().exists() && !overwrite) {
writer.accept(warn("Found existing genesis keys for this node. Existing keys will be used." +
"Please use --overwrite-genesis-keys option to overwrite genesis keys"));
return;
return true;
}

FileUtils.deleteDirectory(clusterGenesisKeysFolder.toFile());
Expand All @@ -120,24 +120,47 @@ public void runGenesisScript(Path clusterPah, String clusterName, boolean overwr
builder.command("sh", genCreateScriptFile);

builder.directory(genCreateScript.getParent().toFile());
Process process = builder.start();

ProcessStream processStream =
new ProcessStream(process.getInputStream(), line -> {
if (line != null && !line.isEmpty())
writer.accept(successLabel("Genesis Keys", line));
});

ProcessStream errorProcessStream =
new ProcessStream(process.getErrorStream(), line -> {
if (line != null && !line.isEmpty())
writer.accept(error("Genesis Keys", line));
});
Future<?> future = Executors.newSingleThreadExecutor().submit(processStream, errorProcessStream);
future.get();

return ProcessUtil.executeAndFinish(builder, "Genesis Keys", writer);
// String genCreateScriptFile = genCreateScript.toFile().getAbsolutePath();
//
// ProcessBuilder builder = new ProcessBuilder();
// builder.command("sh", genCreateScriptFile);
//
// builder.directory(genCreateScript.getParent().toFile());
// Process process = builder.start();
//
// ExecutorService executor = Executors.newSingleThreadExecutor();
// ProcessStream processStream =
// new ProcessStream(process.getInputStream(), line -> {
// if (line != null && !line.isEmpty())
// writer.accept(successLabel("Genesis Keys", line));
// });
//
// ProcessStream errorProcessStream =
// new ProcessStream(process.getErrorStream(), line -> {
// if (line != null && !line.isEmpty())
// writer.accept(error("Genesis Keys %s", line));
// });
//
// Future<?> inputFuture = executor.submit(processStream);
// Future<?> errorFuture = executor.submit(errorProcessStream);
//
// inputFuture.get();
// errorFuture.get();
//
// // Wait for process to complete
// int exitCode = process.waitFor();
// System.out.println("Process exited with code: " + exitCode);
//// Future<?> future = executor.submit(processStream, errorProcessStream);
//// future.get();
//
// executor.shutdown();
} catch (Exception e) {
log.info(e.getMessage(), e);
}

return false;
}

private void updateByronAndShelleyDelegationKeys(Path destPath, String clusterName, ClusterInfo clusterInfo, Consumer<String> writer) throws IOException {
Expand Down
Loading

0 comments on commit a77377a

Please sign in to comment.