Skip to content

Commit

Permalink
Merge pull request #2084 from ergoplatform/v5.0.18
Browse files Browse the repository at this point in the history
Candidate for 5.0.18
  • Loading branch information
kushti authored Dec 22, 2023
2 parents f48d3d5 + ae6e442 commit 48239ef
Show file tree
Hide file tree
Showing 28 changed files with 220 additions and 166 deletions.
65 changes: 65 additions & 0 deletions do-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash

set -euo pipefail

required_java_version="1.8"
java_version=$(java -version 2>&1 | awk -F '"' '/version/ {print $2}')

if [[ $java_version != $required_java_version* ]]; then
echo "Incompatible Java version: $java_version. Requires 1.8.x."
exit 1
fi

rm -rf target
sbt clean assembly

jar=$(find "target/scala-2.12" -name 'ergo-*.jar' -print -quit)

if [[ -z $jar ]]; then
echo "Ergo jar not found."
exit 1
fi

jar_version=$(echo "$jar" | sed 's/^.*ergo-\(.*\)\.jar$/\1/')
conf_file="src/main/resources/application.conf"
conf_version=$(grep "appVersion =" "$conf_file" | cut -d '=' -f2 | tr -d '[:space:]')

if [[ -z $conf_version ]]; then
echo "Version not found in application.conf."
exit 1
fi

if [[ $conf_version != $jar_version ]]; then
echo "Version mismatch: application.conf ($conf_version) != jar ($jar_version)."
echo "Removing jar $jar"
rm "$jar"
exit 1
fi

openapi_files=("openapi.yaml" "openapi-ai.yaml")

for file in "${openapi_files[@]}"; do
openapi_path="src/main/resources/api/$file"
version_line=$(grep 'version:' "$openapi_path")

if [[ -z $version_line ]]; then
echo "Error: Version line not found in $openapi_path"
exit 1
fi

actual_version=$(echo $version_line | awk -F '"' '{print $2}')

if [[ -z $actual_version ]]; then
echo "Error: Version not found in $openapi_path"
exit 1
fi

if [[ $actual_version != $jar_version ]]; then
echo "Version mismatch in $openapi_path: ($actual_version) != jar ($jar_version)."
echo "Removing jar $jar"
rm "$jar"
exit 1
fi
done

echo "do-release completed successfully"
55 changes: 0 additions & 55 deletions ergo-core/src/main/scala/org/ergoplatform/NodeViewModifier.scala

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.ergoplatform.consensus

import org.ergoplatform.PersistentNodeViewModifier
import org.ergoplatform.modifiers.NetworkObjectTypeId
import org.ergoplatform.modifiers.{BlockSection, NetworkObjectTypeId}
import org.ergoplatform.utils.ScorexEncoder
import scorex.util.ModifierId

Expand All @@ -14,11 +13,11 @@ import scorex.util.ModifierId
* @param toDownload - modifiers to download from other nodes
* @tparam PM - type of used modifier
*/
case class ProgressInfo[PM <: PersistentNodeViewModifier](branchPoint: Option[ModifierId],
toRemove: Seq[PM],
toApply: Seq[PM],
toDownload: Seq[(NetworkObjectTypeId.Value, ModifierId)])
(implicit encoder: ScorexEncoder) {
case class ProgressInfo[PM <: BlockSection](branchPoint: Option[ModifierId],
toRemove: Seq[PM],
toApply: Seq[PM],
toDownload: Seq[(NetworkObjectTypeId.Value, ModifierId)])
(implicit encoder: ScorexEncoder) {

if (toRemove.nonEmpty)
require(branchPoint.isDefined, s"Branch point should be defined for non-empty `toRemove`")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package org.ergoplatform.modifiers

import io.circe.Encoder
import org.ergoplatform.PersistentNodeViewModifier
import org.ergoplatform.modifiers.history.extension.Extension
import org.ergoplatform.modifiers.history.header.Header
import org.ergoplatform.modifiers.history.{ADProofs, BlockTransactions}


/**
* Block section, so a header, or block transactions, or extension, or ADProofs.
*/
trait BlockSection extends PersistentNodeViewModifier with ErgoNodeViewModifier
trait BlockSection extends ErgoNodeViewModifier {
/**
* Id of another block section of the same type, which should be applied to the node view before this modifier
*/
def parentId: scorex.util.ModifierId

}

object BlockSection {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.ergoplatform.modifiers

import io.circe.syntax._
import io.circe.{Decoder, Encoder, HCursor, Json}
import org.ergoplatform.TransactionsCarryingPersistentNodeViewModifier
import org.ergoplatform.http.api.ApiCodecs
import org.ergoplatform.modifiers.history.extension.Extension
import org.ergoplatform.modifiers.history.header.Header
Expand All @@ -15,8 +14,7 @@ case class ErgoFullBlock(header: Header,
blockTransactions: BlockTransactions,
extension: Extension,
adProofs: Option[ADProofs])
extends BlockSection
with TransactionsCarryingPersistentNodeViewModifier {
extends TransactionsCarryingBlockSection {

override type M = ErgoFullBlock

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,61 @@
package org.ergoplatform.modifiers

import org.ergoplatform.core.BytesSerializable
import org.ergoplatform.utils.ScorexEncoding
import scorex.util.{ModifierId, bytesToId}
import scorex.utils.Ints

trait ErgoNodeViewModifier { self: BytesSerializable =>
/**
* Basic trait for entities which are modifying internal blockchain view of the node, such as
* unconfirmed transactions, block sections
*/
trait ErgoNodeViewModifier extends BytesSerializable with ScorexEncoding {

/**
* @return cryptographically strong unique identifier of an object
*/
def serializedId: Array[Byte]

/**
* identifier which can is friendly to data structures such as maps etc
*/
lazy val id: ModifierId = bytesToId(serializedId)

/**
* Type of node view modifier (transaction, header etc)
*/
val modifierTypeId: NetworkObjectTypeId.Value

/**
* Size of binary representation provided during object construction (to avoid serialization just to get the value)
*/
val sizeOpt: Option[Int]

/**
* Cached size of binary representation
*/
lazy val size: Int = sizeOpt.getOrElse(bytes.length)

def serializedId: Array[Byte]
/**
* @return readable representation of `id`, as `id` is a hex-encoded string now, just identity functions is used
*/
def encodedId: String = id

override def equals(obj: scala.Any): Boolean = obj match {
case that: ErgoNodeViewModifier => (that.id == id) && (that.modifierTypeId == modifierTypeId)
case _ => false
}

override def hashCode(): Int = {
Ints.fromByteArray(serializedId)
}

}

object ErgoNodeViewModifier {
/**
* It is assumed that all the modifiers (offchain transactions, blocks, blockheaders etc)
* have identifiers of the some length fixed with the ModifierIdSize constant
*/
val ModifierIdSize: Int = 32 // in bytes
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.ergoplatform.modifiers

import org.ergoplatform.modifiers.mempool.ErgoTransaction

/**
* Block section which contains transactions
*/
trait TransactionsCarryingBlockSection extends BlockSection {

def transactions: Seq[ErgoTransaction]

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package org.ergoplatform.modifiers.history

import io.circe.syntax._
import io.circe.{Decoder, Encoder, HCursor}
import org.ergoplatform.TransactionsCarryingPersistentNodeViewModifier
import org.ergoplatform.http.api.ApiCodecs
import org.ergoplatform.modifiers.{BlockTransactionsTypeId, NetworkObjectTypeId, NonHeaderBlockSection}
import org.ergoplatform.modifiers.{BlockTransactionsTypeId, NetworkObjectTypeId, NonHeaderBlockSection, TransactionsCarryingBlockSection}
import org.ergoplatform.modifiers.history.header.Header
import org.ergoplatform.modifiers.mempool.{ErgoTransaction, ErgoTransactionSerializer}
import org.ergoplatform.nodeView.mempool.TransactionMembershipProof
Expand Down Expand Up @@ -33,7 +32,7 @@ case class BlockTransactions(headerId: ModifierId,
blockVersion: Version,
txs: Seq[ErgoTransaction],
override val sizeOpt: Option[Int] = None)
extends NonHeaderBlockSection with TransactionsCarryingPersistentNodeViewModifier {
extends NonHeaderBlockSection with TransactionsCarryingBlockSection {

assert(txs.nonEmpty, "Block should always contain at least 1 coinbase-like transaction")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.ergoplatform.modifiers.history.header.{Header, HeaderSerializer}
import org.ergoplatform.serialization.ErgoSerializer
import scorex.util.serialization.{Reader, Writer}
import scorex.util.Extensions.LongOps
import scorex.util.ScorexLogging

/**
* A structure representing NiPoPow proof as a persistent modifier.
Expand All @@ -28,7 +29,7 @@ case class NipopowProof(popowAlgos: NipopowAlgos,
prefix: Seq[PoPowHeader],
suffixHead: PoPowHeader,
suffixTail: Seq[Header],
continuous: Boolean) {
continuous: Boolean) extends ScorexLogging {

lazy val serializer: ErgoSerializer[NipopowProof] = new NipopowProofSerializer(popowAlgos)

Expand All @@ -47,13 +48,20 @@ case class NipopowProof(popowAlgos: NipopowAlgos,
* @return whether this PoPoW proof is better than "that"
*/
def isBetterThan(that: NipopowProof): Boolean = {
if (this.isValid && that.isValid) {
popowAlgos.lowestCommonAncestor(headersChain, that.headersChain)
.map(h => headersChain.filter(_.height > h.height) -> that.headersChain.filter(_.height > h.height))
.exists({ case (thisDivergingChain, thatDivergingChain) =>
popowAlgos.bestArg(thisDivergingChain)(m) > popowAlgos.bestArg(thatDivergingChain)(m) })
} else {
this.isValid
try {
if (this.isValid && that.isValid) {
popowAlgos.lowestCommonAncestor(headersChain, that.headersChain)
.map(h => headersChain.filter(_.height > h.height) -> that.headersChain.filter(_.height > h.height))
.exists({ case (thisDivergingChain, thatDivergingChain) =>
popowAlgos.bestArg(thisDivergingChain)(m) > popowAlgos.bestArg(thatDivergingChain)(m)
})
} else {
this.isValid
}
} catch {
case t: Throwable =>
log.error(s"Nipopow proofs comparison (isBetter) failed due to ${t.getMessage}: ", t)
false
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.ergoplatform.modifiers.mempool

import io.circe.syntax._
import org.ergoplatform.{DataInput, ErgoBox, ErgoBoxCandidate, ErgoLikeTransaction, ErgoLikeTransactionSerializer, Input}
import org.ergoplatform.ErgoBox.BoxId
import org.ergoplatform.SigmaConstants.{MaxBoxSize, MaxPropositionBytes}
import org.ergoplatform.{EphemerealNodeViewModifier, _}
import org.ergoplatform.http.api.ApiCodecs
import org.ergoplatform.mining.emission.EmissionRules
import org.ergoplatform.modifiers.history.header.Header
import org.ergoplatform.modifiers.mempool.ErgoTransaction.unresolvedIndices
import org.ergoplatform.modifiers.transaction.Transaction
import org.ergoplatform.modifiers.transaction.Signable
import org.ergoplatform.modifiers.{ErgoNodeViewModifier, NetworkObjectTypeId, TransactionTypeId}
import org.ergoplatform.nodeView.ErgoContext
import org.ergoplatform.nodeView.state.ErgoStateContext
Expand Down Expand Up @@ -57,11 +57,12 @@ case class ErgoTransaction(override val inputs: IndexedSeq[Input],
override val outputCandidates: IndexedSeq[ErgoBoxCandidate],
override val sizeOpt: Option[Int] = None)
extends ErgoLikeTransaction(inputs, dataInputs, outputCandidates)
with Transaction
with EphemerealNodeViewModifier
with Signable
with ErgoNodeViewModifier
with ScorexLogging {

override val modifierTypeId: NetworkObjectTypeId.Value = TransactionTypeId.value

override val serializedId: Array[Byte] = Algos.hash(messageToSign)

override lazy val id: ModifierId = bytesToId(serializedId)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.ergoplatform.modifiers.transaction


/**
* A basic trait for entities which can be signed
*/
trait Signable {

/**
* Bytes to be signed
*/
val messageToSign: Array[Byte]

}

This file was deleted.

Loading

0 comments on commit 48239ef

Please sign in to comment.