Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
477 commits
Select commit Hold shift + click to select a range
c603a73
Merge branch 'master' of github.com:ergoplatform/ergo into weak-blocks
kushti Jun 18, 2025
675a349
condition for better logging
kushti Jun 19, 2025
8c973c5
merging w. 6.0 master
kushti Jun 25, 2025
be30289
filter out transactions included in previous input block in candidate…
kushti Jun 30, 2025
fe929e5
optional arg for NewBestInputBlock
kushti Jul 2, 2025
2d221c8
publishing NewBestInputBlock(None) when block transactions assembled …
kushti Jul 2, 2025
7846bdd
merging w. master
kushti Jul 3, 2025
5675cc8
optimizations in ErgoTransaction
kushti Jul 3, 2025
30cd96b
publishing NewBestInputBlock(None) in all cases
kushti Jul 3, 2025
5a60ed9
send ordering ann only to equal or forked peers
kushti Jul 5, 2025
1ab0ade
resolving todos WIP1
kushti Jul 7, 2025
d91cdaa
extractOrderingId
kushti Jul 23, 2025
de82f24
revisiting todos, more comments
kushti Jul 23, 2025
801c082
improving comments and style in ENVH
kushti Jul 24, 2025
1dea334
all transactions downloaded check
kushti Jul 24, 2025
36f4a38
Merge branch 'master' of github.com:ergoplatform/ergo into refactorin…
kushti Jul 25, 2025
6403761
requestDownloads simplified
kushti Jul 25, 2025
1125229
inputBlock API method
kushti Jul 28, 2025
0d557df
removing unused code from SubBlockAlgos
kushti Jul 28, 2025
a69e05b
inputBlockTransactionIds
kushti Jul 29, 2025
cb47a9e
better place for input/ordering related API methods
kushti Jul 29, 2025
87b5c4b
Merge branch 'v6.0.1' of github.com:ergoplatform/ergo into refactorin…
kushti Jul 29, 2025
102c020
reset _bestInputBlock on new best block
kushti Aug 1, 2025
5f75241
resolving couple of todos
kushti Aug 1, 2025
756d163
cache with expiration for transactionsCache
kushti Aug 4, 2025
01b4906
applyInputBlock audit wip1
kushti Aug 4, 2025
29dc541
applyInputBlock audit wip2
kushti Aug 4, 2025
bff25a6
Merge branch 'master' of github.com:ergoplatform/ergo into weak-blocks
kushti Aug 5, 2025
0075a93
mergin w. 6.0.1
kushti Aug 5, 2025
1a3a4d1
Merge branch 'master' of github.com:ergoplatform/ergo into refactorin…
kushti Aug 10, 2025
b4595f1
merging w. master
kushti Aug 10, 2025
8d4e43d
stylistic improvements
kushti Aug 11, 2025
43bc09a
merging w. refactoring-presub
kushti Aug 11, 2025
1bc4c30
check pow for input block
kushti Aug 12, 2025
0ce3c32
inputBlockTransactions dos vector todo
kushti Aug 12, 2025
edeb030
InputBlockMessageSpec scaladoc improved, transactionCache timeout red…
kushti Aug 15, 2025
ec5e382
weakId
kushti Aug 15, 2025
3714ba8
InputBlockTransactionIdsMessageSpec, ErgoTransaction.WeakId
kushti Aug 19, 2025
0311251
optional weakTxIds field in inputblockinfo
kushti Aug 19, 2025
055838a
subblocks p2p rework
kushti Aug 21, 2025
8c88a53
processInputBlockTransactions
kushti Aug 21, 2025
3405251
pow check fix, validation related logging
kushti Aug 25, 2025
65353b6
fixing NewBestInputBlock input in ErgoReadersHolder
kushti Aug 25, 2025
b61f6c2
debug output in p2p
kushti Aug 26, 2025
db904e1
downloading new ordering block immediately on getting its input block
kushti Aug 26, 2025
29a4a05
check if a peer is supporting subblocks before sending one to it
kushti Aug 27, 2025
e46794d
utxo set filter fix
kushti Aug 27, 2025
b4a641b
isTypeKnown, NetworkObjectTypeIdSpec
kushti Aug 28, 2025
465d0a7
fix for inv with unknown mod type id
kushti Aug 28, 2025
ef46938
unused DeliveryTracker,getSource removed
kushti Aug 28, 2025
de23199
eliminate InputBlockRequestMessageSpec && InputBlockTransactionIdsReq…
kushti Aug 29, 2025
23b89dd
requestInputBlockTransactionIds, requestInputBlock
kushti Aug 29, 2025
27c82e8
retrying logic
kushti Aug 29, 2025
546eee9
local flag added, input block sending only if local
kushti Sep 1, 2025
9d8f402
avoid processing ordering block announcement if it is already processed
kushti Sep 1, 2025
12937a0
request input block only once
kushti Sep 2, 2025
4b5c342
OrderingBlockAnnouncementTypeId
kushti Sep 2, 2025
ae51ffc
announce locally generated announcement block immediately after gener…
kushti Sep 2, 2025
eb1ae43
send inv for ordering block announcement if not generated locally
kushti Sep 4, 2025
599da78
processOrderingBlockAnnouncementRequest
kushti Sep 4, 2025
3fe0fec
checking ordering block pow on retrieval
kushti Sep 10, 2025
452dcf6
SubBlockAlgos.powScheme removed
kushti Sep 11, 2025
fce884a
todo cleanup
kushti Sep 11, 2025
8892149
do not put input block tx ids into tracker (due to duplicate id)
kushti Sep 12, 2025
9edd6c4
access modifiers and log messages improved
kushti Sep 16, 2025
389c9f5
double application fix
kushti Sep 16, 2025
e043458
CRUSH.md
kushti Sep 16, 2025
c9a6698
agent generated wp draft
kushti Sep 16, 2025
990b271
crush data; latex stub for the wp
kushti Sep 16, 2025
75fcc0c
InputBlockTransactionsRequestMessageSpec fix
kushti Sep 17, 2025
98c6759
merging w origin
kushti Sep 18, 2025
740d652
penalize peer for sending ordering block announcement with improper PoW
kushti Sep 18, 2025
3a7ade4
first ENVSS tests
kushti Sep 18, 2025
2bc5cce
improving ENVSS tests
kushti Sep 18, 2025
3d366ff
Merge branch 'weak-blocks' of github.com:ergoplatform/ergo into weak-…
kushti Sep 18, 2025
9695003
OBAMSS test
kushti Sep 18, 2025
5ba8e76
InputBlockMessageSpecsSpec
kushti Sep 18, 2025
001c788
more tests
kushti Sep 18, 2025
b78bbbc
agent generated tests
kushti Sep 18, 2025
80e3356
more logging
kushti Sep 18, 2025
fa29a2f
fixing LocallyGeneratedOrderingBlock subscription being missed
kushti Sep 19, 2025
17512ca
p2p messages tests & ProtocolVersionCompatibilitySpec
kushti Sep 19, 2025
6123d66
Merge branch 'weak-blocks' of github.com:ergoplatform/ergo into weak-…
kushti Sep 19, 2025
a2eb595
NetworkComponentSpec
kushti Sep 19, 2025
7dd1827
more p2p layer tests
kushti Sep 19, 2025
fc7d827
PeerManagerSpec
kushti Sep 19, 2025
d0bf559
Merge branch 'weak-blocks' of github.com:ergoplatform/ergo into weak-…
kushti Sep 19, 2025
dd0204d
more p2p tests
kushti Sep 19, 2025
be9cbcd
fix for nosuchkeyexception
kushti Sep 22, 2025
af44316
clear mempool for locally generated input blocks
kushti Sep 22, 2025
f390109
ScanInputBlock
kushti Sep 25, 2025
5c8d300
Merge branch 'weak-blocks' of github.com:ergoplatform/ergo into weak-…
kushti Sep 26, 2025
4c6fd01
more tests in InputBlockProcessorSpecification
kushti Sep 26, 2025
8bcd784
more tests in IBP, clearing mempool when ib from remote, wp abstract
kushti Sep 29, 2025
deca1d2
more todos, intro started
kushti Sep 30, 2025
6247fd0
mempool clearance test
kushti Oct 2, 2025
57fe335
merging w. origin
kushti Oct 2, 2025
34a4c61
intro
kushti Oct 2, 2025
8f70593
InputBlockWalletSpec
kushti Oct 3, 2025
6631d55
Merge branch 'weak-blocks' of github.com:ergoplatform/ergo into weak-…
kushti Oct 3, 2025
91cb85d
initial fix for wallet not using input block boxes
kushti Oct 6, 2025
89a3bd3
OutputsHolder
kushti Oct 7, 2025
b1014ac
structure in wp
kushti Oct 7, 2025
3bed637
tests for invalid input blocks application
kushti Oct 8, 2025
b0b281d
Merge branch 'weak-blocks' of github.com:ergoplatform/ergo into weak-…
kushti Oct 8, 2025
17272a3
pruning note
kushti Oct 9, 2025
ffecf67
Merge branch 'weak-blocks' of github.com:ergoplatform/ergo into weak-…
kushti Oct 9, 2025
00798fb
pruning pic
kushti Oct 12, 2025
72a1a90
intro improvs
kushti Oct 13, 2025
85e5351
sec2 improvs
kushti Oct 14, 2025
4cc58d7
input block definition fixes
kushti Oct 14, 2025
bfdb9d5
duplicate code in LocallyGeneratedInputBlock processing removed
kushti Oct 16, 2025
d175f58
wrapper for applyInputBlockTransactions call
kushti Oct 16, 2025
0cf81c3
rolled back input blocks added to applyInputBlockTransactions signature
kushti Oct 16, 2025
e16cdd5
linking structure, ext fields
kushti Oct 21, 2025
468a3a2
processing forks in the mempool
kushti Oct 21, 2025
9430143
extension fields details
kushti Oct 21, 2025
97ebaa8
pow inequality
kushti Oct 23, 2025
2fb971c
put tree version into Ergo tree in /script/p2s
kushti Oct 26, 2025
e026b6c
stylistic improvements in InputBlocksProcessor
kushti Oct 29, 2025
a9a44cc
forking tests, more comments in InputBlocksProcessor, wp improvements
kushti Oct 29, 2025
10c5f49
improving tests and wp
kushti Oct 29, 2025
3680a60
initial version of reworked forks
kushti Nov 11, 2025
d02c893
applicationStep
kushti Nov 11, 2025
0cc0508
polishing rework and fixing tests #1'
kushti Nov 11, 2025
e807f14
applyDisconnected
kushti Nov 13, 2025
503f529
scaladoc for interface methods
kushti Nov 13, 2025
6a128ce
forking processing
kushti Nov 14, 2025
91aa805
testnet60 settings
kushti Nov 16, 2025
e6a6b57
Tests synthetic network type
kushti Nov 17, 2025
a125269
fork processing fixes #1
kushti Nov 17, 2025
469e1d3
fork processing fixes #2
kushti Nov 17, 2025
503b45a
bestChain fix
kushti Nov 17, 2025
81871a6
updating all the forks
kushti Nov 18, 2025
9fa4ec9
code cleanup
kushti Nov 20, 2025
6802f3f
try/catch
kushti Nov 21, 2025
1a09fb4
Added new route to create mining candidate with transactions under a …
K-Singh Nov 22, 2025
0692cb7
rollback processing
kushti Nov 25, 2025
fdf39b7
outdated todos removed, WP restructuring
kushti Nov 25, 2025
c6cfaa1
empty log messages fixed, removed unneeded sections from the WP
kushti Nov 25, 2025
42be1a4
processedBlocks instead of processedIndex/costCollected
kushti Nov 26, 2025
506b21b
sigma dep update
kushti Nov 28, 2025
17b4da8
double spending test, light clients section stub
kushti Dec 3, 2025
eb008f0
fees section in the WP, new test: forks spanning across multiple orde…
kushti Dec 4, 2025
6c420d1
pruning test
kushti Dec 9, 2025
62c9116
improving fees / tx classes
kushti Dec 10, 2025
e48d180
deployment
kushti Dec 11, 2025
f3f691c
cleaning conclusion
kushti Dec 11, 2025
84ce581
citations fixed
kushti Dec 11, 2025
d9794df
Fixed small bugs related to GenerateCandidate params
K-Singh Dec 15, 2025
e33d565
Fig 1&2
kushti Dec 20, 2025
c63ec7a
section labels
kushti Dec 22, 2025
72f5107
Sec 3.2 update
kushti Dec 22, 2025
0bcc3ae
light clients made subsection, security section cleared
kushti Dec 22, 2025
7b94684
fixing citations
kushti Dec 22, 2025
e8dec37
authnote fixes
kushti Dec 23, 2025
95d23c5
Network Protocol Extensions improvements
kushti Dec 24, 2025
d95d6af
chain selection rule
kushti Dec 27, 2025
9876fae
finalized stucture
kushti Dec 31, 2025
d756536
sec 3 update
kushti Jan 2, 2026
f1c5986
main.pdf
kushti Jan 2, 2026
38c54a2
input blocks API methods description in openapi.yaml
kushti Jan 10, 2026
300c11e
minor improvements in ErgoNodeViewSynchronizer
kushti Jan 11, 2026
fb47e05
.get fixed in CandidateGenerator
kushti Jan 12, 2026
0ef7c7a
first input block related test in CandidateGeneratorSpec
kushti Jan 14, 2026
e9e77ca
more logging
kushti Jan 16, 2026
dd4aee2
forks explosion test
kushti Jan 19, 2026
0f21194
improving comments
kushti Jan 21, 2026
291c400
fork switching fix
kushti Jan 21, 2026
436df03
chained txs tests
kushti Jan 22, 2026
f7e5381
making InputBlockProcessorSpecification failing again
kushti Jan 22, 2026
2f58743
6.0.3 version set
kushti Jan 22, 2026
9c64a57
merging with master
kushti Jan 26, 2026
8e00909
crush.md removed
kushti Jan 26, 2026
be4efdc
preRestart
kushti Jan 27, 2026
b1739cb
jdk in dockerfile updated
kushti Jan 28, 2026
8529c67
Merge pull request #2294 from ergoplatform/ittest
kushti Jan 28, 2026
9689f4d
forks explosion fix
kushti Jan 29, 2026
3aaf59a
scaladoc in InputBlocksProcessor
kushti Jan 30, 2026
9a799c6
comments in IBP
kushti Jan 30, 2026
d6134ff
ENVS scaladoc
kushti Jan 30, 2026
1a10daa
Merge branch 'v6.0.3' of github.com:ergoplatform/ergo into testnet60
kushti Feb 2, 2026
dc41142
removing outdated test on mining after v2activationheight (which is w…
kushti Feb 4, 2026
9dc5145
Merge branch 'v6.0.3' of github.com:ergoplatform/ergo into p2stv
kushti Feb 4, 2026
de5b2ee
peridic localInputBlockChunks clean-up
kushti Feb 23, 2026
df74bd2
wrapping getIfPresent result
kushti Feb 25, 2026
3b13707
cfor
kushti Feb 25, 2026
b35b5c9
sending FullBlock applied, sending ordering and input block to seemin…
kushti Feb 26, 2026
b0a5f61
Merge pull request #2287 from Lithos-Protocol/master
kushti Feb 26, 2026
2ebaddf
Merge pull request #2252 from ergoplatform/testnet60
kushti Feb 26, 2026
39f8011
Merge pull request #2247 from ergoplatform/p2stv
kushti Feb 26, 2026
e746c25
OrderingBlockSyncSpec
kushti Feb 26, 2026
00ee8e1
OrderingBlockMessageFlowSpec
kushti Feb 27, 2026
f4cddfd
new tests fixed
kushti Feb 27, 2026
0b519ba
InputBlockWalletSpec improved
kushti Feb 27, 2026
a6c0fb0
new tests in MempoolBlockClearingSpec
kushti Mar 2, 2026
d935117
Do not try to mine when the blockchain is not synced - initial approach
kushti Mar 4, 2026
a6c2955
Merge branch 'master' of github.com:ergoplatform/ergo into v6.0.3
kushti Mar 4, 2026
dfe6903
Merge branch 'v6.0.3' of github.com:ergoplatform/ergo into v6.0.3
kushti Mar 4, 2026
247cfeb
new tests
kushti Mar 4, 2026
1bd7226
inputblockinfo.valid and pow tests
kushti Mar 11, 2026
9e74160
readjustable number of sub-blocks per block
kushti Mar 11, 2026
771fb49
download parent header if it is not available in ordering block annou…
kushti Mar 12, 2026
11671a2
fix for recursive loop in collectTxs
kushti Mar 13, 2026
01fe310
unit tests for collectTxs
kushti Mar 16, 2026
3b3726f
cfor in InputBlockTransactionsData
kushti Mar 16, 2026
9323f2a
more cfor
kushti Mar 16, 2026
80bb70e
spam-check todos in OrderingBlockAnnouncementMessageSpec
kushti Mar 16, 2026
359d7b7
better control flow todos resolved
kushti Mar 17, 2026
53e384c
more antispam checks in OrderingBlockAnnouncementMessageSpec
kushti Mar 17, 2026
df8323a
versioning for OrderingBlockAnnouncement msg
kushti Mar 17, 2026
5223260
SubblocksVersion set to 6.5.0
kushti Mar 17, 2026
f39878f
chained txs in the same block - todo and tests
kushti Mar 18, 2026
87f1d08
HeightThreshold
kushti Mar 19, 2026
07aa3ba
cfor optimization in InputBlockTransactionsMessageSpec
kushti Mar 19, 2026
b48c676
outdated todo removed in ESC
kushti Mar 19, 2026
6fb65db
unneeded inheritance from BlockSection removed from InputBlockTransac…
kushti Mar 20, 2026
60d9fe5
new CandidateBlock fields
kushti Mar 23, 2026
9ce1d30
maxSize limit raised in OrderingBlockAnnouncementMessageSpec
kushti Mar 24, 2026
0f19ccd
ordering block announcements pruning
kushti Mar 24, 2026
c0f69d1
OBA pruning tests in InputBlockProcessorSpecification
kushti Mar 24, 2026
01ed40a
log on null in getIfPresent for tx cache, todo removed
kushti Mar 24, 2026
ff3d6ae
proper type matcching in ErgoSanity
kushti Mar 25, 2026
b8a7b20
proper pattern matching in ErgoMinerSpec
kushti Mar 25, 2026
e098322
extract header/fullblock from ProveResult
kushti Mar 27, 2026
ca358f6
Merge branch 'v6.0.3' of github.com:ergoplatform/ergo into i2238
kushti Mar 28, 2026
4cfe14e
persistentProver.synchronized in proofsForTransactions
kushti Mar 28, 2026
47b4464
logging tx parsing failure reason
kushti Mar 28, 2026
be984aa
Merge branch 'v6.0.3' of github.com:ergoplatform/ergo into i2238
kushti Mar 28, 2026
124f61e
6 blocks diff, nicer log messages
kushti Apr 3, 2026
0258110
NewBestInputBlock tests in ENVSS
kushti Apr 3, 2026
392c2f4
more tests in ErgoNodeViewSynchronizerSpecification
kushti Apr 4, 2026
31614b7
more ErgoNodeViewSynchronizerSpecification test
kushti Apr 5, 2026
b301d47
tests for >3 weakTxIds
kushti Apr 6, 2026
9efaca6
more ErgoNodeViewSynchronizerSpecification tests
kushti Apr 6, 2026
b494c23
more candidate generation tests
kushti Apr 7, 2026
a5129d4
more ErgoNodeViewSynchronizerSpecification tests
kushti Apr 9, 2026
1c90af8
remove outdated test
kushti Apr 9, 2026
af0f343
Merge pull request #2295 from ergoplatform/i2238
kushti Apr 9, 2026
591634e
outdated test removed
kushti Apr 10, 2026
e334bc9
Merge branch 'v6.0.3' of github.com:ergoplatform/ergo into v6.0.3
kushti Apr 10, 2026
c4ef8c2
ProtocolVersionCompatibilitySpec fix
kushti Apr 12, 2026
844027d
sigmastate dependency update
kushti Apr 15, 2026
3b22769
testing logic in CandidateGeneratorSpec improved
kushti Apr 17, 2026
af368f8
checking diff in InputBlockInfo.valid
kushti Apr 17, 2026
7ed40be
merging w. 6.0.3
kushti Apr 22, 2026
438817f
valid() complete for ordering blocks
kushti Apr 24, 2026
99acc22
weakSolution API route
kushti Apr 27, 2026
f855dd7
broadcast input blocks to peers having utxo set only
kushti Apr 27, 2026
6dad080
digest mode related todo in processInputBlock removed
kushti Apr 27, 2026
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ devnet
.ensime_cache/
scorex.yaml

# LLM reports on code analysis etc
llm_generated

# scala build folders
target

Expand Down
3 changes: 2 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@
## Development Restrictions
- **Code Changes**: Only modify code in `src/test/` folders
- **Production Code**: Do not touch production code in `src/main/` directories
- **Test Focus**: All development work should be test-related only
- **Test Focus**: All development work should be test-related only
- **Generated Specs**: All LLM-generated specifications should be placed in the `llm_generated/` folder
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ val circeVersion = "0.13.0"
val akkaVersion = "2.6.10"
val akkaHttpVersion = "10.2.4"

val sigmaStateVersion = "6.0.2"
val sigmaStateVersion = "6.0.2-30-59782d92-SNAPSHOT"
val ficusVersion = "1.4.7"

// for testing current sigmastate build (see sigmastate-ergo-it jenkins job)
Expand Down Expand Up @@ -185,7 +185,7 @@ docker / dockerfile := {
val configMainNet = (IntegrationTest / resourceDirectory).value / "mainnetTemplate.conf"

new Dockerfile {
from("openjdk:11-jre-slim")
from("eclipse-temurin:11-jre-jammy")
label("ergo-integration-tests", "ergo-integration-tests")
add(assembly.value, "/opt/ergo/ergo.jar")
add(Seq(configDevNet), "/opt/ergo")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@ import scorex.util.ModifierId
case class ProgressInfo[PM <: BlockSection](branchPoint: Option[ModifierId],
toRemove: Seq[PM],
toApply: Seq[PM],
toDownload: Seq[(NetworkObjectTypeId.Value, ModifierId)])
(implicit encoder: ScorexEncoder) {
toDownload: Map[NetworkObjectTypeId.Value, ModifierId]) {

if (toRemove.nonEmpty)
if (toRemove.nonEmpty) {
require(branchPoint.isDefined, s"Branch point should be defined for non-empty `toRemove`")
}

lazy val chainSwitchingNeeded: Boolean = toRemove.nonEmpty

override def toString: String = {
s"ProgressInfo(BranchPoint: ${branchPoint.map(encoder.encodeId)}, " +
s"ProgressInfo(BranchPoint: ${branchPoint.map(ScorexEncoder.encodeId)}, " +
s" to remove: ${toRemove.map(_.encodedId)}, to apply: ${toApply.map(_.encodedId)})"
}
}

object ProgressInfo {
val empty: ProgressInfo[BlockSection] = ProgressInfo[BlockSection](None, Seq.empty, Seq.empty, Map.empty)
}
8 changes: 4 additions & 4 deletions ergo-core/src/main/scala/org/ergoplatform/core/core.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ package object core {

type VersionTag = VersionTag.Type

def idsToString(ids: Seq[(NetworkObjectTypeId.Value, util.ModifierId)])(implicit enc: ScorexEncoder): String = {
def idsToString(ids: Seq[(NetworkObjectTypeId.Value, util.ModifierId)]): String = {
List(ids.headOption, ids.lastOption)
.flatten
.map { case (typeId, id) => s"($typeId,${enc.encodeId(id)})" }
.map { case (typeId, id) => s"($typeId,${ScorexEncoder.encodeId(id)})" }
.mkString("[", "..", "]")
}

def idsToString(modifierType: NetworkObjectTypeId.Value, ids: Seq[util.ModifierId])(implicit encoder: ScorexEncoder): String = {
def idsToString(modifierType: NetworkObjectTypeId.Value, ids: Seq[util.ModifierId]): String = {
idsToString(ids.map(id => (modifierType, id)))
}

def idsToString(invData: InvData)(implicit encoder: ScorexEncoder): String = idsToString(invData.typeId, invData.ids)
def idsToString(invData: InvData): String = idsToString(invData.typeId, invData.ids)

def bytesToId: Array[Byte] => util.ModifierId = scorex.util.bytesToId

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.ergoplatform.http.api

import cats.syntax.either._
import cats.syntax.either._ // needed for Scala 2.11
import io.circe._ // needed for Scala 2.11
import sigmastate.utils.Helpers._

import io.circe._
import io.circe.syntax._
import org.bouncycastle.util.BigIntegers
import org.ergoplatform.ErgoBox.RegisterId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package org.ergoplatform.mining
import com.google.common.primitives.{Bytes, Ints, Longs}
import org.bouncycastle.util.BigIntegers
import org.ergoplatform.ErgoLikeContext.Height
import org.ergoplatform.settings.Parameters
import org.ergoplatform.{AutolykosSolution, BlockSolutionSearchResult, InputBlockFound, InputBlockHeaderFound, InputSolutionFound, NoSolutionFound, NothingFound, OrderingBlockFound, OrderingBlockHeaderFound, OrderingSolutionFound, ProveBlockResult}
import org.ergoplatform.mining.difficulty.DifficultySerializer
import org.ergoplatform.modifiers.ErgoFullBlock
import org.ergoplatform.modifiers.history._
Expand All @@ -12,6 +14,7 @@ import org.ergoplatform.modifiers.history.header.{Header, HeaderSerializer, Head
import org.ergoplatform.modifiers.mempool.ErgoTransaction
import org.ergoplatform.nodeView.history.ErgoHistoryUtils.GenesisHeight
import org.ergoplatform.nodeView.mempool.TransactionMembershipProof
import org.ergoplatform.settings.Parameters
import scorex.crypto.authds.{ADDigest, SerializedAdProof}
import scorex.crypto.hash.{Blake2b256, Digest32}
import scorex.util.{ModifierId, ScorexLogging}
Expand Down Expand Up @@ -106,7 +109,7 @@ class AutolykosPowScheme(val k: Int, val n: Int) extends ScorexLogging {
// for version 1, we check equality of left and right sides of the equation
require(checkPoWForVersion1(header), "Incorrect points")
} else {
require(checkPoWForVersion2(header), "h(f) < b condition not met")
require(checkOrderingBlockPoW(header), "h(f) < b condition not met")
}
}

Expand All @@ -116,13 +119,21 @@ class AutolykosPowScheme(val k: Int, val n: Int) extends ScorexLogging {
* @param header - header to check PoW for
* @return whether PoW is valid or not
*/
def checkPoWForVersion2(header: Header): Boolean = {
val b = getB(header.nBits)
def checkOrderingBlockPoW(header: Header): Boolean = {
// for version 2, we're calculating hit and compare it with target
val hit = hitForVersion2(header)

val b = getB(header.nBits)
hit < b
}

def checkInputBlockPoW(header: Header, parameters: Parameters): Boolean = {
val hit = hitForVersion2(header) // todo: cache hit in header

val orderingTarget = getB(header.nBits)
val inputTarget = orderingTarget * parameters.subBlocksPerBlock
hit < inputTarget
}
/**
* Check PoW for Autolykos v1 header
*
Expand Down Expand Up @@ -241,7 +252,7 @@ class AutolykosPowScheme(val k: Int, val n: Int) extends ScorexLogging {
/**
* Get target `b` from encoded difficulty `nBits`
*/
private[mining] def getB(nBits: Long): BigInt = {
def getB(nBits: Long): BigInt = {
q / DifficultySerializer.decodeCompactBits(nBits)
}

Expand Down Expand Up @@ -278,6 +289,7 @@ class AutolykosPowScheme(val k: Int, val n: Int) extends ScorexLogging {

//Proving-related code which is not critical for consensus below


/**
* Autolykos solver suitable for CPU-mining in testnet and devnets.
*
Expand All @@ -295,7 +307,8 @@ class AutolykosPowScheme(val k: Int, val n: Int) extends ScorexLogging {
votes: Array[Byte],
sk: PrivateKey,
minNonce: Long = Long.MinValue,
maxNonce: Long = Long.MaxValue): Option[Header] = {
maxNonce: Long = Long.MaxValue,
parameters: Parameters): ProveBlockResult = {
val (parentId, height) = AutolykosPowScheme.derivedHeaderFields(parentOpt)

val h = HeaderWithoutPow(version, parentId, adProofsRoot, stateRoot, transactionsRoot, timestamp,
Expand All @@ -305,7 +318,11 @@ class AutolykosPowScheme(val k: Int, val n: Int) extends ScorexLogging {
val x = randomSecret()
val hbs = Ints.toByteArray(h.height)
val N = calcN(h)
checkNonces(version, hbs, msg, sk, x, b, N, minNonce, maxNonce).map(solution => h.toHeader(solution))
checkNonces(version, hbs, msg, sk, x, b, N, minNonce, maxNonce, parameters) match {
case NoSolutionFound => NothingFound
case InputSolutionFound(as) => InputBlockHeaderFound(h.toHeader(as))
case OrderingSolutionFound(as) => OrderingBlockHeaderFound(h.toHeader(as))
}
}

/**
Expand All @@ -323,18 +340,25 @@ class AutolykosPowScheme(val k: Int, val n: Int) extends ScorexLogging {
votes: Array[Byte],
sk: PrivateKey,
minNonce: Long = Long.MinValue,
maxNonce: Long = Long.MaxValue): Option[ErgoFullBlock] = {
maxNonce: Long = Long.MaxValue,
parameters: Parameters): ProveBlockResult = {

val transactionsRoot = BlockTransactions.transactionsRoot(transactions, version)
val adProofsRoot = ADProofs.proofDigest(adProofBytes)

prove(parentOpt, version, nBits, stateRoot, adProofsRoot, transactionsRoot,
timestamp, extensionCandidate.digest, votes, sk, minNonce, maxNonce).map { h =>
def constructBlockFromHeader(h: Header) = {
val adProofs = ADProofs(h.id, adProofBytes)
val blockTransactions = BlockTransactions(h.id, version, transactions)
val extension = extensionCandidate.toExtension(h.id)
new ErgoFullBlock(h, blockTransactions, extension, Some(adProofs))
}

prove(parentOpt, version, nBits, stateRoot, adProofsRoot, transactionsRoot,
timestamp, extensionCandidate.digest, votes, sk, minNonce, maxNonce, parameters) match {
case NothingFound => NothingFound
case InputBlockHeaderFound(h) => InputBlockFound(constructBlockFromHeader(h))
case OrderingBlockHeaderFound(h) => OrderingBlockFound(constructBlockFromHeader(h))
}
}

/**
Expand All @@ -344,7 +368,8 @@ class AutolykosPowScheme(val k: Int, val n: Int) extends ScorexLogging {
def proveCandidate(candidateBlock: CandidateBlock,
sk: PrivateKey,
minNonce: Long = Long.MinValue,
maxNonce: Long = Long.MaxValue): Option[ErgoFullBlock] = {
maxNonce: Long = Long.MaxValue,
parameters: Parameters): ProveBlockResult = {
proveBlock(candidateBlock.parentOpt,
candidateBlock.version,
candidateBlock.nBits,
Expand All @@ -356,13 +381,14 @@ class AutolykosPowScheme(val k: Int, val n: Int) extends ScorexLogging {
candidateBlock.votes,
sk,
minNonce,
maxNonce
maxNonce,
parameters
)
}

/**
* Check nonces from `startNonce` to `endNonce` for message `m`, secrets `sk` and `x`, difficulty `b`.
* Return AutolykosSolution if there is any valid nonce in this interval.
* Return BlockSolutionSearchResult if there is any valid nonce in this interval, for ordering or input block.
*/
private[mining] def checkNonces(version: Header.Version,
h: Array[Byte],
Expand All @@ -372,14 +398,18 @@ class AutolykosPowScheme(val k: Int, val n: Int) extends ScorexLogging {
b: BigInt,
N: Int,
startNonce: Long,
endNonce: Long): Option[AutolykosSolution] = {
endNonce: Long,
parameters: Parameters): BlockSolutionSearchResult = {

val subblocksPerBlock = parameters.subBlocksPerBlock

log.debug(s"Going to check nonces from $startNonce to $endNonce")
val p1 = groupElemToBytes(genPk(sk))
val p2 = groupElemToBytes(genPk(x))

@tailrec
def loop(i: Long): Option[AutolykosSolution] = if (i == endNonce) {
None
def loop(i: Long): BlockSolutionSearchResult = if (i == endNonce) {
NoSolutionFound
} else {
if (i % 1000000 == 0 && i > 0) println(s"$i nonce tested")
val nonce = Longs.toByteArray(i)
Expand All @@ -397,8 +427,11 @@ class AutolykosPowScheme(val k: Int, val n: Int) extends ScorexLogging {
toBigInt(hash(indexes.map(i => genElement(version, m, p1, p2, Ints.toByteArray(i), h)).sum.toByteArray))
}
if (d <= b) {
log.debug(s"Solution found at $i")
Some(AutolykosSolution(genPk(sk), genPk(x), nonce, d))
log.debug(s"Ordering block solution found at $i")
OrderingSolutionFound(new AutolykosSolution(genPk(sk), genPk(x), nonce, d))
} else if (d <= b * subblocksPerBlock) {
log.debug(s"Input block solution found at $i")
InputSolutionFound(new AutolykosSolution(genPk(sk), genPk(x), nonce, d))
} else {
loop(i + 1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,19 @@ import sigmastate.utils.Helpers._
import io.circe.syntax._
import io.circe.{Decoder, Encoder, HCursor}
import org.bouncycastle.util.BigIntegers
import org.ergoplatform.AutolykosSolution
import org.ergoplatform.AutolykosSolution.pkForV2
import org.ergoplatform.http.api.ApiCodecs
import org.ergoplatform.modifiers.history.header.Header.Version
import org.ergoplatform.settings.Algos
import org.ergoplatform.serialization.ErgoSerializer
import scorex.util.serialization.{Reader, Writer}
import sigma.crypto.{CryptoConstants, EcPointType}
import org.ergoplatform.AutolykosSolution.pkForV2

/**
* Solution for an Autolykos PoW puzzle.
*
* In Autolykos v.1 all the four fields are used, in Autolykos v.2 only pk and n fields are used.
*
* @param pk - miner public key. Should be used to collect block rewards
* @param w - one-time public key. Prevents revealing of miners secret
* @param n - nonce (8 bytes)
* @param d - distance between pseudo-random number, corresponding to nonce `n` and a secret,
* corresponding to `pk`. The lower `d` is, the harder it was to find this solution.
*/
case class AutolykosSolution(pk: EcPointType,
w: EcPointType,
n: Array[Byte],
d: BigInt) {
val encodedPk: Array[Byte] = groupElemToBytes(pk)
}

object AutolykosSolution extends ApiCodecs {
// "pk", "w" and "d" values for Autolykos v2 solution, where they not passed from outside
val pkForV2: EcPointType = CryptoConstants.dlogGroup.identity
object AutolykosSolutionJsonCodecs extends ApiCodecs {
// "w" and "d" values for Autolykos v2 solution, where they not passed from outside
val wForV2: EcPointType = CryptoConstants.dlogGroup.generator
val dForV2: BigInt = 0

Expand All @@ -52,12 +37,37 @@ object AutolykosSolution extends ApiCodecs {
n <- c.downField("n").as[Array[Byte]]
dOpt <- c.downField("d").as[Option[BigInt]]
} yield {
AutolykosSolution(pkOpt.getOrElse(pkForV2), wOpt.getOrElse(wForV2), n, dOpt.getOrElse(dForV2))
new AutolykosSolution(pkOpt.getOrElse(pkForV2), wOpt.getOrElse(wForV2), n, dOpt.getOrElse(dForV2))
}
}

}

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 All @@ -81,7 +91,7 @@ class AutolykosV1SolutionSerializer extends ErgoSerializer[AutolykosSolution] {
val nonce = r.getBytes(8)
val dBytesLength = r.getUByte()
val d = BigInt(BigIntegers.fromUnsignedByteArray(r.getBytes(dBytesLength)))
AutolykosSolution(pk, w, nonce, d)
new AutolykosSolution(pk, w, nonce, d)
}

}
Expand All @@ -102,7 +112,7 @@ class AutolykosV2SolutionSerializer extends ErgoSerializer[AutolykosSolution] {
override def parse(r: Reader): AutolykosSolution = {
val pk = groupElemFromBytes(r.getBytes(PublicKeyLength))
val nonce = r.getBytes(8)
AutolykosSolution(pk, wForV2, nonce, dForV2)
new AutolykosSolution(pk, wForV2, nonce, dForV2)
}

}
Expand Down
Loading
Loading