Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A sidechain prototype #2107

Open
wants to merge 62 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
10362c9
WeakBlockAlgos
kushti Aug 22, 2023
76e2f60
Merge branch 'v5.0.15' of github.com:ergoplatform/ergo into weak-blocks
kushti Sep 12, 2023
c5d30d3
WeakBlockInfo, WeakBlockMessageSpec
kushti Sep 18, 2023
5c2eb29
impl steps
kushti Sep 28, 2023
d378942
Merge branch 'v5.0.16' of github.com:ergoplatform/ergo into weak-blocks
kushti Oct 25, 2023
8843114
initial weak blocks structures and algos
kushti Oct 30, 2023
5c4f9c2
compact block like messaging
kushti Oct 31, 2023
0dbfeb0
before structures
kushti Nov 1, 2023
1a68d0e
skeleton of processing algo
kushti Nov 4, 2023
1040926
weak blocks => sub blocks
kushti Nov 7, 2023
636f3d8
more weak=>sub renaming
kushti Nov 7, 2023
6293421
returning download plan
kushti Nov 7, 2023
23a5db0
better comments and todos, formatting
kushti Nov 9, 2023
2c5cf3c
motivation started in EIP, data structures refined
kushti Nov 10, 2023
4189783
Merge branch 'master' of github.com:ergoplatform/ergo into weak-blocks
kushti Nov 28, 2023
4962218
pow, superblocks
kushti Dec 1, 2023
514e6fb
subblocks section finished
kushti Dec 2, 2023
564ad05
propagation text started, prevSubBlockId made optional (comp fails)
kushti Dec 6, 2023
346e1a7
commitment
kushti Dec 21, 2023
a068545
styling fixes
kushti Dec 28, 2023
c0709f2
key spaces for sub-blocks and sidechains
kushti Dec 29, 2023
85de7a4
eip update
kushti Jan 3, 2024
a248ccf
dag note, new subsections added
kushti Jan 4, 2024
58327f9
Merge branch 'v5.0.20' of github.com:ergoplatform/ergo into sb-sidechain
kushti Jan 25, 2024
a45ee11
fixing sb comp issues
kushti Jan 25, 2024
5894eb7
plan
kushti Jan 29, 2024
e5c3712
link to prev added, sidechain header id
kushti Feb 1, 2024
3c05b1a
sidechainStateDigest added, generate stub
kushti Feb 1, 2024
2c143a6
sidechain block
kushti Feb 5, 2024
1d251d5
5.0.21 version set
kushti Feb 5, 2024
874bda0
more checks, introducing SideChainNFT
kushti Feb 5, 2024
1f3a87d
sidechain digest
kushti Feb 5, 2024
c55fdef
Refactor Message class
ccellado Feb 8, 2024
810d708
Refactor Message class
ccellado Feb 8, 2024
c81b8b1
checkSidechainData started
kushti Feb 8, 2024
eb56887
Merge branch 'master' of github.com:ergoplatform/ergo into sb-sidechain
kushti Feb 14, 2024
a4c6c89
verify for a block, checkSidechainData WIP 1
kushti Feb 14, 2024
07b8d9d
SidechainDataValidationResult hierarchy
kushti Feb 19, 2024
735a7b2
txsDigest generation
kushti Feb 19, 2024
4823d92
checkSidechainData stub finished
kushti Feb 21, 2024
5dd405b
SidechainHeaderModifierTypeId, SidechainValidationSettings, verify re…
kushti Feb 21, 2024
df0ac3b
Better wallet unlock error
ccellado Feb 23, 2024
ce95bc2
Better wallet unlock error
ccellado Feb 23, 2024
aa8cf53
Better wallet unlock error
ccellado Feb 23, 2024
c19b7dd
Merge pull request #2119 from ccellado/better-wallet-unlock-error
kushti Feb 25, 2024
ace7016
add burn tokens form to ergo-node-interface
deadit Feb 25, 2024
e0c383a
Merge pull request #2125 from ergoplatform/add_burn_tokens_to_ergo_panel
kushti Feb 26, 2024
d739f5d
Merge branch 'master' of github.com:ergoplatform/ergo into v5.0.21
kushti Feb 26, 2024
e7dbd1c
Merge pull request #2113 from ccellado/refactor_message
kushti Feb 26, 2024
b2e312a
SidechainInterpreter
kushti Feb 26, 2024
1340843
Move tests to ergo-core
ccellado Mar 1, 2024
c56614b
Move tests to ergo-core
ccellado Mar 1, 2024
d9b9af9
SidechainBlockValidationResult hierarchy
kushti Mar 1, 2024
85336b7
Merge pull request #2132 from ccellado/ergo-core-tests
kushti Mar 4, 2024
d37d0f9
fix ErgoStateContextSpec sporadic failure
stenolog Feb 22, 2024
46f7f98
provide alternate test-generators
stenolog Mar 4, 2024
bd9db19
Merge pull request #2116 from stenolog/i2114-repro
kushti Mar 5, 2024
b7dcf24
Fix ergo-core publishing in build.sbt
ccellado Mar 7, 2024
11ec4f3
Fix ergo-core multiversion tests
ccellado Mar 7, 2024
26f7271
Merge pull request #2135 from ccellado/improve-ci
kushti Mar 9, 2024
d6dccaf
Merge branch 'v5.0.21' of github.com:ergoplatform/ergo into sb-sidechain
kushti Mar 14, 2024
9927fd0
checkSidechainData in nextCheck
kushti Mar 18, 2024
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
43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,49 @@ jobs:
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}

test_core:
name: Run ergo-core tests and publish a ergo-core snapshot
env:
HAS_SECRETS: ${{ secrets.SONATYPE_PASSWORD != '' }}
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.12, 2.12.18, 2.11.12]
java: [[email protected]]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup Java and Scala
uses: olafurpg/setup-scala@v10
with:
java-version: ${{ matrix.java }}

- name: Cache sbt
uses: actions/cache@v2
with:
path: |
~/.sbt
~/.ivy2/cache
~/.coursier/cache/v1
~/.cache/coursier/v1
~/AppData/Local/Coursier/Cache/v1
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Runs ergo-core tests
run: sbt ++${{ matrix.scala }} ergoCore/test

- name: Publish a wallet snapshot ${{ github.ref }}
if: env.HAS_SECRETS == 'true'
run: sbt ++${{ matrix.scala }} ergoCore/publish
env:
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}

test_node:
name: Run node tests
strategy:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ import scorex.crypto.hash.{Blake2b256, Digest32}
import scorex.db.{ByteArrayWrapper, LDBVersionedStore}

import scala.collection.immutable.SortedMap
import scala.math.Ordering.Implicits._

object OOMTest extends App {

implicit val ordering: Ordering[Array[Byte]] =
new Ordering[Array[Byte]] {
override def compare(o1: Array[Byte], o2: Array[Byte]): Int =
implicitly[Ordering[Seq[Int]]].compare(o1.toSeq.map(_ & 0xFF), o2.toSeq.map(_ & 0xFF))
}

type Box = (ADKey, ADValue)

type HF = Blake2b256.type
Expand Down
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ lazy val ergoCore = (project in file("ergo-core"))
),
scalacOptions in(Compile, compile) ++= (if (scalaBinaryVersion.value == "2.11") Seq() else Seq("-release", "8")),
scalacOptions in(Compile, compile) --= scalacOpts,
parallelExecution in Test := false,
)

lazy val ergoWallet = (project in file("ergo-wallet"))
Expand Down
4 changes: 3 additions & 1 deletion ergo-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ val handshakeMessageSerialized = HandshakeSerializer.toBytes(handshakeMessage)
Serialize the message and send it.
If the message arrived successfully, start communicating with the peer node.

All communication is wrapped with Message headers, format described [here](https://docs.ergoplatform.com/dev/p2p/network/#message-format).
All communication is wrapped with message headers.
Format described [here](https://docs.ergoplatform.com/dev/p2p/network/#message-format).
[MessageBase](src/main/scala/org/ergoplatform/network/message/MessageBase.scala) interface to implement.

## Syncing with the node

Expand Down
3 changes: 3 additions & 0 deletions ergo-core/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ val deps212 = Seq(
"io.circe" %% "circe-generic" % "0.13.0",
"io.circe" %% "circe-parser" % "0.13.0")

publishMavenStyle := true
publishArtifact in Test := false

libraryDependencies ++= Seq() ++
(if (scalaVersion.value == scala211) deps211 else deps212)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,3 +425,5 @@ object AutolykosPowScheme {
}

}

object MainnetPoWVerifier extends AutolykosPowScheme(k = 32, n = 26)
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.circe.syntax._
import io.circe.{Decoder, Encoder, HCursor}
import org.bouncycastle.util.BigIntegers
import org.ergoplatform.http.api.ApiCodecs
import org.ergoplatform.mining.AutolykosSolution.pkForV2
import org.ergoplatform.modifiers.history.header.Header.Version
import org.ergoplatform.settings.Algos
import org.ergoplatform.serialization.ErgoSerializer
Expand Down Expand Up @@ -59,6 +60,30 @@ object AutolykosSolution extends ApiCodecs {

}

case class WeakAutolykosSolution(pk: EcPointType, n: Array[Byte]) {
val encodedPk: Array[Byte] = groupElemToBytes(pk)
}

object WeakAutolykosSolution extends ApiCodecs {
implicit val jsonEncoder: Encoder[WeakAutolykosSolution] = { s: WeakAutolykosSolution =>
Map(
"pk" -> s.pk.asJson,
"n" -> Algos.encode(s.n).asJson
).asJson
}

implicit val jsonDecoder: Decoder[WeakAutolykosSolution] = { c: HCursor =>
for {
pkOpt <- c.downField("pk").as[Option[EcPointType]]
n <- c.downField("n").as[Array[Byte]]
} yield {
WeakAutolykosSolution(pkOpt.getOrElse(pkForV2), n)
}
}

}



/**
* Binary serializer for Autolykos v1 solution,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ object Extension extends ApiCodecs {
*/
val ValidationRulesPrefix: Byte = 0x02

/**
* Prefix for keys related to sub-blocks related data.
*/
val SubBlocksDataPrefix: Byte = 0x03

/**
* Prefix for keys related to sidechains data.
*/
val SidechainsDataPrefix: Byte = 0x04

/**
* Id a type of network object encoding extension
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.ergoplatform.network.message

import org.ergoplatform.network.message.MessageConstants._

import scala.util.{Success, Try}

/**
* Trait for a ergo network message
*
* @param spec - message specification
* @param input - message being wrapped, whether in byte-array form (if from outside),
* or structured data (if formed locally)
* @tparam Content - message data type
*/
trait MessageBase[Content] {
val spec: MessageSpec[Content]
val input: Either[Array[Byte], Content]

/**
* Message data bytes
*/
lazy val dataBytes: Array[Byte] = input match {
case Left(db) => db
case Right(d) => spec.toBytes(d)
}

/**
* Structured message content
*/
lazy val data: Try[Content] = input match {
case Left(db) => spec.parseBytesTry(db)
case Right(d) => Success(d)
}

lazy val dataLength: Int = dataBytes.length

/**
* @return serialized message length in bytes
*/
def messageLength: Int = {
if (dataLength > 0) {
HeaderLength + ChecksumLength + dataLength
} else {
HeaderLength
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import io.circe.{Encoder, Json}
import org.ergoplatform.sdk.JsonCodecs
import org.ergoplatform.settings.Algos
import scorex.crypto.authds.merkle.MerkleProof
import scorex.crypto.hash.Digest32
import scorex.crypto.hash.{Digest, Digest32}
import scorex.util.ModifierId
import io.circe.syntax._

Expand All @@ -15,7 +15,11 @@ import io.circe.syntax._
* @param txId - transaction identifier
* @param proof - Merkle proof of transaction membership
*/
case class TransactionMembershipProof(txId: ModifierId, proof: MerkleProof[Digest32])
case class TransactionMembershipProof(txId: ModifierId, proof: MerkleProof[Digest32]) {
def valid(expectedRootHash: Digest): Boolean = {
proof.valid(expectedRootHash)
}
}

object TransactionMembershipProof extends JsonCodecs {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.ergoplatform.settings

import com.typesafe.config.ConfigFactory
import net.ceedubs.ficus.Ficus._
import net.ceedubs.ficus.readers.ArbitraryTypeReader._
import java.io.File

object ChainSettingsReader extends PowSchemeReaders with ModifierIdReader with SettingsReaders{
def read(path: String): Option[ChainSettings] = {
val file = new File(path)
if (file.exists) {
val cfg = ConfigFactory.parseFile(file)
val fallback = ConfigFactory.parseFile(new File("src/main/resources/application.conf"))
val network = ConfigFactory.parseFile(new File("src/main/resources/testnet.conf"))
val fullConfig = ConfigFactory
.defaultOverrides()
.withFallback(cfg) //order
.withFallback(network) //matters
.withFallback(fallback) //here
.resolve()

val chainSettings = fullConfig.as[ChainSettings]("ergo.chain")
Some(chainSettings)
} else None
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.ergoplatform.settings

import com.typesafe.config.Config
import net.ceedubs.ficus.readers.ValueReader
import scorex.util.ModifierId

trait ModifierIdReader {

implicit val modifierIdReader: ValueReader[ModifierId] = new ValueReader[ModifierId] {
override def read(cfg: Config, path: String): ModifierId = {
ModifierId @@ cfg.getString(path)
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.ergoplatform.settings

import com.typesafe.config.{Config, ConfigException}
import net.ceedubs.ficus.Ficus._
import net.ceedubs.ficus.readers.ValueReader
import org.ergoplatform.mining._

trait PowSchemeReaders {

implicit val powSchemeReader: ValueReader[AutolykosPowScheme] = new ValueReader[AutolykosPowScheme] {
override def read(cfg: Config, path: String): AutolykosPowScheme = {
val schemeNameKey = s"$path.powType"
val schemeName = cfg.getString(schemeNameKey)
val n = cfg.as[Int](s"$path.n")
val k = cfg.as[Int](s"$path.k")
if (schemeName == "autolykos") {
new AutolykosPowScheme(k, n)
} else if (schemeName == "fake") {
new DefaultFakePowScheme(k, n)
} else {
throw new ConfigException.BadValue(schemeNameKey, schemeName)
}
}
}
}

Loading
Loading