Skip to content

Commit

Permalink
Merge pull request #66 from bloxbean/ogmios_660
Browse files Browse the repository at this point in the history
Ogmios 6.6.0 and Conway era cost model changes (WIP)
  • Loading branch information
satran004 authored Aug 29, 2024
2 parents d3a4e3d + faace05 commit 456a3e6
Show file tree
Hide file tree
Showing 21 changed files with 715 additions and 694 deletions.
2 changes: 1 addition & 1 deletion applications/cli/config/download.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Please specify either the version or the full url for the following components
node.version=9.1.0
ogmios.version=6.5.0
ogmios.version=6.6.0
kupo.version=2.9.0
yaci.store.version=0.1.0-rc5

Expand Down
20 changes: 19 additions & 1 deletion applications/cli/config/node.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#protocolMagic=42
#maxKESEvolutions=60
#securityParam=300
#securityParam=80
#slotsPerKESPeriod=129600
#updateQuorum=1
#peerSharing=true
Expand Down Expand Up @@ -79,3 +79,21 @@
## CC Members
#ccMembers[0].hash=scriptHash-8fc13431159fdda66347a38c55105d50d77d67abc1c368b876d52ad1
#ccMembers[0].term=340

########################################################################################################
# Workaround for : https://github.com/bloxbean/yaci-devkit/issues/65
#
# The following parameters are enabled for a V2 cost model-related issue where there are 10 extra elements if the devnet
# is started with the Conway era at epoch 0. The following parameters are enabled to configure the Conway era hard fork (HF) at epoch 1.
# The network will start in the Babbage era and then hard fork (HF) to the Conway era at epoch 1.

# The shiftStartTimeBehind=true flag is enabled to shift the start time of the network to a time behind the current time by adjusting security parameter
# which changes the stability window. This is to speed up the process of reaching the Conway era.
#
# This should only be done in a development environment because if the stability window is larger than the epoch length, the reward/treasury calculations will be incorrect or ignored.
# Therefore, for a real multi-node network, you should start the network at the current time and allow it to reach the Conway era at epoch 1.
# So, the shiftStartTimeBehind flag should be "false" for non-development / multi-node networks.
#
#########################################################################################################
conwayHardForkAtEpoch=1
shiftStartTimeBehind=true
2 changes: 1 addition & 1 deletion applications/cli/docker/download-ogmios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ case $1 in
esac


version=v6.5.0
version=v6.6.0
file=ogmios-${version}-${SUFFIX}-linux.zip
wget https://github.com/CardanoSolutions/ogmios/releases/download/${version}/$file

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void createCluster(@ShellOption(value = {"-n", "--name"}, defaultValue =
@ShellOption(value = {"--submit-api-port"}, help = "Submit Api Port", defaultValue = "8090") int submitApiPort,
@ShellOption(value = {"-s", "--slot-length"}, help = "Slot Length in sec. (0.1 to ..)", defaultValue = "1") double slotLength,
@ShellOption(value = {"-b", "--block-time"}, help = "Block time in sec. (1 - 20)", defaultValue = "1") double blockTime,
@ShellOption(value = {"-e", "--epoch-length"}, help = "No of slots in an epoch", defaultValue = "500") int epochLength,
@ShellOption(value = {"-e", "--epoch-length"}, help = "No of slots in an epoch", defaultValue = "600") int epochLength,
@ShellOption(value = {"-o", "--overwrite"}, defaultValue = "false", help = "Overwrite existing node directory. default: false") boolean overwrite,
@ShellOption(value = {"--start"}, defaultValue = "false", help = "Automatically start the node after create. default: false") boolean start,
@ShellOption(value = {"--era"}, defaultValue = "conway", help = "Era (babbage, conway)") String era,
Expand All @@ -118,11 +118,15 @@ public void createCluster(@ShellOption(value = {"-n", "--name"}, defaultValue =
return;
}

if (epochLength < 20) {
writeLn(error("Epoch length should be 20 or more"));
if (epochLength < 5) {
writeLn(error("Epoch length below 5 is not allowed."));
return;
}

if (epochLength < 20) {
writeLn(warn("Epoch length is too small. The node may behave unexpectedly if the epoch length is too small. Keep it at least 20 or more."));
}

//Era check
Era nodeEra;
if (era == null || era.isEmpty())
Expand All @@ -137,6 +141,7 @@ else if (era.equalsIgnoreCase("conway"))
}

long protocolMagic = genesisConfig.getProtocolMagic();
long slotsPerKESPeriod = genesisConfig.getSlotsPerKESPeriod();

//stop any cluster if running
localClusterService.stopCluster(msg -> writeLn(msg));
Expand All @@ -148,6 +153,7 @@ else if (era.equalsIgnoreCase("conway"))
.slotLength(slotLength)
.blockTime(blockTime)
.epochLength(epochLength)
.slotsPerKESPeriod(slotsPerKESPeriod)
.protocolMagic(protocolMagic)
.p2pEnabled(true)
.masterNode(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public class ClusterInfo {
private double slotLength;
private double blockTime;
private int epochLength;
private long slotsPerKESPeriod;
private long securityParam;
private double activeSlotsCoeff;
private boolean p2pEnabled;
private long startTime;
private boolean masterNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,43 @@ public void printUrls(String clusteName, ClusterInfo clusterInfo) {
if (isDocker) {
writeLn(header(AnsiColors.CYAN_BOLD, "###### Node Details (Container) ######"));
} else {
writeLn(successLabel("Admin Port", String.valueOf(applicationConfig.getAdminPort())));
writeLn(infoLabel("Admin Port", String.valueOf(applicationConfig.getAdminPort())));
writeLn(header(AnsiColors.CYAN_BOLD, "###### Node Details ######"));
}
writeLn(successLabel("Node port", String.valueOf(clusterInfo.getNodePort())));
writeLn(successLabel("Node Socket Paths", ""));
writeLn(infoLabel("Node port", String.valueOf(clusterInfo.getNodePort())));
writeLn(infoLabel("Node Socket Paths", ""));
writeLn(clusterInfo.getSocketPath());
writeLn(successLabel("Submit Api Port", String.valueOf(clusterInfo.getSubmitApiPort())));
writeLn(successLabel("Protocol Magic", String.valueOf(clusterInfo.getProtocolMagic())));
writeLn(successLabel("Block Time", String.valueOf(clusterInfo.getBlockTime())) + " sec");
writeLn(successLabel("Slot Length", String.valueOf(clusterInfo.getSlotLength())) + " sec");
writeLn(successLabel("Start Time", String.valueOf(clusterInfo.getStartTime())));
writeLn(infoLabel("Submit Api Port", String.valueOf(clusterInfo.getSubmitApiPort())));
writeLn(infoLabel("Protocol Magic", String.valueOf(clusterInfo.getProtocolMagic())));
writeLn(infoLabel("Block Time", String.valueOf(clusterInfo.getBlockTime())) + " sec");
writeLn(infoLabel("Slot Length", String.valueOf(clusterInfo.getSlotLength())) + " sec");
writeLn(infoLabel("Start Time", String.valueOf(clusterInfo.getStartTime())));
writeLn(infoLabel("Epoch Length", String.valueOf(clusterInfo.getEpochLength())));
writeLn(infoLabel("Security Param", String.valueOf(clusterInfo.getSecurityParam())));
writeLn(infoLabel("SlotsPerKESPeriod", String.valueOf(clusterInfo.getSlotsPerKESPeriod())));

if (clusteName == null || !"default".equals(clusteName))
return;

if (isDocker) {
writeLn("\n");
writeLn(header(AnsiColors.CYAN_BOLD, "#################### URLS (Host) ####################"));
writeLn(successLabel("Yaci Viewer", String.format("http://localhost:%s", getViewerPort())));
writeLn(successLabel("Yaci Store Swagger UI", String.format("http://localhost:%s/swagger-ui.html", getStorePort(clusterInfo))));
writeLn(successLabel("Yaci Store Api URL", String.format("http://localhost:%s/api/v1/", getStorePort(clusterInfo))));
writeLn(successLabel("Pool Id", "pool1wvqhvyrgwch4jq9aa84hc8q4kzvyq2z3xr6mpafkqmx9wce39zy"));
writeLn(infoLabel("Yaci Viewer", String.format("http://localhost:%s", getViewerPort())));
writeLn(infoLabel("Yaci Store Swagger UI", String.format("http://localhost:%s/swagger-ui.html", getStorePort(clusterInfo))));
writeLn(infoLabel("Yaci Store Api URL", String.format("http://localhost:%s/api/v1/", getStorePort(clusterInfo))));
writeLn(infoLabel("Pool Id", "pool1wvqhvyrgwch4jq9aa84hc8q4kzvyq2z3xr6mpafkqmx9wce39zy"));

if (enableOgmios) {
writeLn("\n");
writeLn(header(AnsiColors.CYAN_BOLD, "#################### Other URLS ####################"));
writeLn(successLabel("Ogmios Url (Optional)", "ws://localhost:" + getOgmiosPort(clusterInfo)));
writeLn(successLabel("Kupo Url (Optional)", "http://localhost:" + getKupoPort(clusterInfo)));
writeLn(infoLabel("Ogmios Url (Optional)", "ws://localhost:" + getOgmiosPort(clusterInfo)));
writeLn(infoLabel("Kupo Url (Optional)", "http://localhost:" + getKupoPort(clusterInfo)));
}

writeLn("\n");
writeLn(header(AnsiColors.CYAN_BOLD, "#################### Node Ports ####################"));
writeLn(successLabel("n2n port", "localhost:" + getN2NPort(clusterInfo)));
writeLn(successLabel("n2c port (socat)", "localhost:" + getN2cSocatPort(clusterInfo)));
writeLn(infoLabel("n2n port", "localhost:" + getN2NPort(clusterInfo)));
writeLn(infoLabel("n2c port (socat)", "localhost:" + getN2cSocatPort(clusterInfo)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ private void updateGenesis(Path clusterFolder, String clusterName, ClusterInfo c
if (era == Era.Babbage) {
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");
srcAlonzoGenesisFile = clusterFolder.resolve("genesis-templates").resolve("alonzo-genesis.json.babbage");
srcConwayGenesisFile = clusterFolder.resolve("genesis-templates").resolve("conway-genesis.json");
} else if (era == Era.Conway) {
srcByronGenesisFile = clusterFolder.resolve("genesis-templates").resolve("byron-genesis.json");
Expand Down Expand Up @@ -313,12 +313,32 @@ 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);
//Check if protocol version should be minimun 9 and it's conway era
if (era == Era.Conway && genesisConfig.getProtocolMajorVer() < 9) {
values.put("protocolMajorVer", 9);
values.put("protocolMinorVer", 0);
}

//Derive security param
long securityParam = genesisConfigCopy.getSecurityParam();

if (genesisConfig.getConwayHardForkAtEpoch() > 0 && genesisConfig.isShiftStartTimeBehind()) {
//Workaround for https://github.com/bloxbean/yaci-devkit/issues/65
//Calculate required securityParam to jump directly to epoch = 1
long expectedStabilityWindow = Math.round(epochLength * 1.5);
securityParam = Math.round(expectedStabilityWindow * activeSlotsCoeff) / 3;
} else {
if (securityParam == 0) {
//For stabilityWindow = epochLength * stabilityWindowFactory (0-1) , k = (epochLength * coefficient) / (3 * 2)
securityParam = Math.round(((epochLength * activeSlotsCoeff) / 3) * genesisConfig.getStabilityWindowFactor());
}
}

values.put("securityParam", securityParam);
clusterInfo.setSecurityParam(securityParam);
clusterInfo.setActiveSlotsCoeff(activeSlotsCoeff);
writer.accept(info("Security parameter : %s", securityParam));

//Update Genesis files
try {
templateEngineHelper.replaceValues(srcByronGenesisFile, destByronGenesisFile, values);
Expand All @@ -329,6 +349,15 @@ private void updateGenesis(Path clusterFolder, String clusterName, ClusterInfo c
throw new IOException(e);
}

//Check security Parameter
long stabilityWindow = Math.round((3 * securityParam) / activeSlotsCoeff);
if (stabilityWindow > epochLength) {
writer.accept(warn("Stability window is greater than epoch length. Stability window : %s, Epoch length : %s", stabilityWindow, epochLength));
writer.accept(warn("You may want to adjust the security parameter to make sure stability window is less than epoch length. " +
"\nThe features like rewards calculation which depends on stability window may not work as expected" +
"\nIf you are using default configuration, you can ignore this warning. The transaction processing will work fine"));
}

writer.accept(success("Slot length updated in genesis.json"));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bloxbean.cardano.yacicli.localcluster;

import com.bloxbean.cardano.yaci.core.util.OSUtil;
import com.bloxbean.cardano.yacicli.localcluster.config.GenesisConfig;
import com.bloxbean.cardano.yacicli.localcluster.model.RunStatus;
import com.bloxbean.cardano.yacicli.util.PortUtil;
import com.bloxbean.cardano.yacicli.util.ProcessUtil;
Expand All @@ -24,7 +25,6 @@
import java.util.List;
import java.util.Queue;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;

import static com.bloxbean.cardano.yacicli.util.ConsoleWriter.*;
Expand All @@ -36,6 +36,7 @@ public class ClusterStartService {
private final ClusterConfig clusterConfig;
private final ClusterPortInfoHelper clusterPortInfoHelper;
private final ProcessUtil processUtil;
private final GenesisConfig genesisConfig;

private ObjectMapper objectMapper = new ObjectMapper();
private List<Process> processes = new ArrayList<>();
Expand Down Expand Up @@ -252,6 +253,18 @@ private boolean setupFirstRun(ClusterInfo clusterInfo, Path clusterFolder, Consu
//Update Byron Genesis file
ObjectNode jsonNode = (ObjectNode) objectMapper.readTree(byronGenesis.toFile());
long byronStartTime = Instant.now().getEpochSecond();

if (genesisConfig.getConwayHardForkAtEpoch() > 0 && genesisConfig.isShiftStartTimeBehind()) {
long stabilityWindow = (long) Math.floor((3 * clusterInfo.getSecurityParam()) / clusterInfo.getActiveSlotsCoeff());

long maxBehindBySecond = stabilityWindow - 5;
if (stabilityWindow > clusterInfo.getEpochLength()) {
maxBehindBySecond = clusterInfo.getEpochLength();
}

byronStartTime = byronStartTime - maxBehindBySecond;
writer.accept(success("Updating Start time to current time - " + maxBehindBySecond + " in byron-genesis.json"));
}
jsonNode.set("startTime", new LongNode(byronStartTime));
objectMapper.writer(new DefaultPrettyPrinter()).writeValue(byronGenesis.toFile(), jsonNode);

Expand All @@ -265,7 +278,7 @@ private boolean setupFirstRun(ClusterInfo clusterInfo, Path clusterFolder, Consu
clusterInfo.setStartTime(byronStartTime);
saveClusterInfo(clusterFolder, clusterInfo);

writer.accept(success("Update Start time"));
writer.accept(success("Updated Start time"));
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public class GenesisConfig {
private String networkId = "Testnet";
private long protocolMagic = 42;
private int maxKESEvolutions = 60;
private int securityParam = 300;
private double stabilityWindowFactor = 0.5; //This is used to automatically derive the security parameter from epoch length
private int securityParam = 0;
private long slotsPerKESPeriod = 129600;
private int updateQuorum = 1;
private boolean peerSharing = true;
Expand Down Expand Up @@ -157,6 +158,11 @@ public class GenesisConfig {
// new NonAvvmBalances("2657WMsDfac6if177KSAP7hosuDveRHN3ZsyP2EQNgTaQ5tqFTnmw1EMZcGreMHva", "3340000000", true)
);


//Introduced for the issue https://github.com/bloxbean/yaci-devkit/issues/65
private int conwayHardForkAtEpoch = 0;
private boolean shiftStartTimeBehind = false;

@PostConstruct
public void postInit() {
if (faucets.size() == 0 && !disableFaucet) {
Expand Down Expand Up @@ -250,6 +256,7 @@ public Map getConfigMap() {
}
map.put("protocolMagic", protocolMagic);
map.put("maxKESEvolutions", maxKESEvolutions);
map.put("stabilityWindowFactor", stabilityWindowFactor);
map.put("securityParam", securityParam);
map.put("slotsPerKESPeriod", slotsPerKESPeriod);
map.put("updateQuorum", updateQuorum);
Expand Down Expand Up @@ -337,6 +344,9 @@ public Map getConfigMap() {
map.put("genesisDelegs", genesisDelegs);
map.put("nonAvvmBalances", nonAvvmBalances);

map.put("conwayHardForkAtEpoch", conwayHardForkAtEpoch);
map.put("shiftStartTimeBehind", shiftStartTimeBehind);

return map;
}

Expand All @@ -345,6 +355,7 @@ public GenesisConfig copy() {
genesisConfig.setNetworkId(networkId);
genesisConfig.setProtocolMagic(protocolMagic);
genesisConfig.setMaxKESEvolutions(maxKESEvolutions);
genesisConfig.setStabilityWindowFactor(stabilityWindowFactor);
genesisConfig.setSecurityParam(securityParam);
genesisConfig.setSlotsPerKESPeriod(slotsPerKESPeriod);
genesisConfig.setUpdateQuorum(updateQuorum);
Expand Down Expand Up @@ -423,6 +434,9 @@ public GenesisConfig copy() {
genesisConfig.setGenesisDelegs(new ArrayList<>(genesisDelegs));
genesisConfig.setNonAvvmBalances(new ArrayList<>(nonAvvmBalances));

genesisConfig.setConwayHardForkAtEpoch(conwayHardForkAtEpoch);
genesisConfig.setShiftStartTimeBehind(shiftStartTimeBehind);

return genesisConfig;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,17 @@ private void printClusterInfo(String clusterName) throws IOException {
ClusterInfo clusterInfo = clusterService.getClusterInfo(clusterName);
writeLn("");
writeLn(header(AnsiColors.CYAN_BOLD, "###### Node Details ######"));
writeLn(successLabel("Node port", String.valueOf(clusterInfo.getNodePort())));
writeLn(successLabel("Node Socket Paths", ""));
writeLn(infoLabel("Node port", String.valueOf(clusterInfo.getNodePort())));
writeLn(infoLabel("Node Socket Paths", ""));
writeLn(clusterInfo.getSocketPath());
writeLn(successLabel("Submit Api Port", String.valueOf(clusterInfo.getSubmitApiPort())));
writeLn(successLabel("Protocol Magic", String.valueOf(clusterInfo.getProtocolMagic())));
writeLn(successLabel("Block Time", String.valueOf(clusterInfo.getBlockTime())) + " sec");
writeLn(successLabel("Slot Length", String.valueOf(clusterInfo.getSlotLength())) + " sec");
writeLn(successLabel("Start Time", String.valueOf(clusterInfo.getStartTime())));
writeLn(infoLabel("Submit Api Port", String.valueOf(clusterInfo.getSubmitApiPort())));
writeLn(infoLabel("Protocol Magic", String.valueOf(clusterInfo.getProtocolMagic())));
writeLn(infoLabel("Block Time", String.valueOf(clusterInfo.getBlockTime())) + " sec");
writeLn(infoLabel("Slot Length", String.valueOf(clusterInfo.getSlotLength())) + " sec");
writeLn(infoLabel("Start Time", String.valueOf(clusterInfo.getStartTime())));
writeLn(infoLabel("Epoch Length", String.valueOf(clusterInfo.getEpochLength())));
writeLn(infoLabel("Security Param", String.valueOf(clusterInfo.getSecurityParam())));
writeLn(infoLabel("SlotsPerKESPeriod", String.valueOf(clusterInfo.getSlotsPerKESPeriod())));
}

public Availability peerCommandAvailability() {
Expand Down
Loading

0 comments on commit 456a3e6

Please sign in to comment.