Skip to content

Commit

Permalink
final refactoring and polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
kushti committed Dec 5, 2023
1 parent 5a5c472 commit 997b86a
Show file tree
Hide file tree
Showing 71 changed files with 109 additions and 113 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.ergoplatform

/** Exception that triggers proper system shutdown */
case class CriticalSystemException(message: String) extends Exception(message)
/** Exception that triggers system shutdown */
case class CriticalSystemException(message: String) extends Exception(message)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.ergoplatform._
import org.ergoplatform.http.api.ApiEncoderOption.Detalization
import org.ergoplatform.mining.{groupElemFromBytes, groupElemToBytes}
import org.ergoplatform.modifiers.mempool.{ErgoTransaction, UnsignedErgoTransaction}
import org.ergoplatform.nodeView.history.ErgoHistoryConstants.Difficulty
import org.ergoplatform.nodeView.history.ErgoHistoryUtils.Difficulty
import org.ergoplatform.sdk.wallet.secrets.{DhtSecretKey, DlogSecretKey}
import org.ergoplatform.settings.{Algos, ErgoAlgos}
import org.ergoplatform.wallet.Constants.ScanId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.ergoplatform.modifiers.history.extension.ExtensionCandidate
import org.ergoplatform.modifiers.history.header.Header.{Timestamp, Version}
import org.ergoplatform.modifiers.history.header.{Header, HeaderSerializer, HeaderWithoutPow}
import org.ergoplatform.modifiers.mempool.ErgoTransaction
import org.ergoplatform.nodeView.history.ErgoHistoryConstants.GenesisHeight
import org.ergoplatform.nodeView.history.ErgoHistoryUtils.GenesisHeight
import org.ergoplatform.nodeView.mempool.TransactionMembershipProof
import scorex.crypto.authds.{ADDigest, SerializedAdProof}
import scorex.crypto.hash.{Blake2b256, Digest32}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import org.ergoplatform.modifiers.history.{ADProofs, BlockTransactions}
import org.ergoplatform.modifiers.history.header.HeaderWithoutPow
import scorex.crypto.hash.Digest32

/**
*
*/
object CandidateUtils {
/**
* Derives header without pow from [[CandidateBlock]].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.ergoplatform.mining
import io.circe.syntax._
import io.circe.{Encoder, Json}
import org.ergoplatform.http.api.ApiCodecs
import org.ergoplatform.nodeView.history.ErgoHistoryConstants.Height
import org.ergoplatform.nodeView.history.ErgoHistoryUtils.Height
import sigmastate.crypto.DLogProtocol.ProveDlog


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.ergoplatform.mining.difficulty

import org.ergoplatform.modifiers.history.header.Header
import org.ergoplatform.nodeView.history.ErgoHistoryConstants.{Difficulty, Height}
import org.ergoplatform.nodeView.history.ErgoHistoryUtils.{Difficulty, Height}
import org.ergoplatform.settings.ChainSettings
import scorex.util.ScorexLogging
import scala.concurrent.duration.FiniteDuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.ergoplatform.mining.difficulty

import java.math.BigInteger

import org.ergoplatform.nodeView.history.ErgoHistoryConstants._
import org.ergoplatform.nodeView.history.ErgoHistoryUtils._
import org.ergoplatform.serialization.ErgoSerializer
import scorex.util.serialization.{Reader, Writer}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.ergoplatform.modifiers.history
import org.ergoplatform.mining.AutolykosPowScheme
import org.ergoplatform.modifiers.history.header.Header
import org.ergoplatform.modifiers.history.header.Header._
import org.ergoplatform.nodeView.history.ErgoHistoryConstants._
import org.ergoplatform.nodeView.history.ErgoHistoryUtils._
import org.ergoplatform.settings.Constants
import scorex.util._
import sigmastate.crypto.CryptoConstants.EcPointType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.ergoplatform.mining.difficulty.DifficultySerializer
import org.ergoplatform.modifiers.history.extension.Extension
import org.ergoplatform.modifiers.history.{ADProofs, BlockTransactions, PreHeader}
import org.ergoplatform.modifiers.{BlockSection, HeaderTypeId, NetworkObjectTypeId, NonHeaderBlockSection}
import org.ergoplatform.nodeView.history.ErgoHistoryConstants._
import org.ergoplatform.nodeView.history.ErgoHistoryUtils._
import org.ergoplatform.settings.{Algos, Constants}
import org.ergoplatform.wallet.interpreter.ErgoInterpreter
import org.ergoplatform.serialization.ErgoSerializer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.ergoplatform.modifiers.history.header

import org.ergoplatform.core.idToBytes
import org.ergoplatform.nodeView.history.ErgoHistoryConstants.EmptyHistoryHeight
import org.ergoplatform.nodeView.history.ErgoHistoryUtils.EmptyHistoryHeight

/**
* A fake header that is used to fill the chain that starts from the beginning
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.ergoplatform.modifiers.NetworkObjectTypeId
import scorex.util.ModifierId

/**
* P2P network message which is encoding "inventory",
* P2P network message which is encoding "inventory", transactions or block sections the node has
*
* @param typeId
* @param ids
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.ergoplatform.nodeView

import org.ergoplatform.modifiers.BlockSection

/**
* Wrapper for locally generated block section
*/
case class LocallyGeneratedModifier(pmod: BlockSection)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
package org.ergoplatform.nodeView.history

import org.ergoplatform.ErgoLikeContext
import org.ergoplatform.modifiers.history.header.Header
import org.ergoplatform.nodeView.history.ErgoHistoryConstants.EmptyHistoryHeight

/**
* Repository for types, constants and functions related to blockchain database (ErgoHistory)
*/
object ErgoHistoryUtils {
/**
* Type for time, represents machine-specific timestamp of a transaction
* or block section, as milliseconds passed since beginning of UNIX
* epoch on the machine
*/
type Time = Long

type Height = ErgoLikeContext.Height // Int
type Score = BigInt
type Difficulty = BigInt
type NBits = Long

val CharsetName = "UTF-8"

val EmptyHistoryHeight: Int = 0
val GenesisHeight: Int = EmptyHistoryHeight + 1 // first block has height == 1

def heightOf(headerOpt: Option[Header]): Int = headerOpt.map(_.height).getOrElse(EmptyHistoryHeight)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.ergoplatform.settings

import org.ergoplatform.mining.difficulty.DifficultySerializer
import org.ergoplatform.nodeView.history.ErgoHistoryConstants.Difficulty
import org.ergoplatform.nodeView.history.ErgoHistoryUtils.Difficulty
import scorex.crypto.authds.avltree.batch.AvlTreeParameters
import sigmastate.Values
import sigmastate.Values.ErgoTree
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.ergoplatform.settings
import com.google.common.primitives.Ints
import io.circe.Encoder
import io.circe.syntax._
import org.ergoplatform.nodeView.history.ErgoHistoryConstants.Height
import org.ergoplatform.nodeView.history.ErgoHistoryUtils.Height
import org.ergoplatform.serialization.ErgoSerializer
import scorex.util.serialization.{Reader, Writer}
import scorex.util.Extensions._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.ergoplatform.modifiers.history.extension.Extension
import org.ergoplatform.modifiers.history.header.Header
import org.ergoplatform.modifiers.history.{ADProofs, BlockTransactions}
import org.ergoplatform.modifiers.mempool.ErgoTransaction
import org.ergoplatform.nodeView.history.ErgoHistoryConstants._
import org.ergoplatform.nodeView.history.ErgoHistoryUtils._
import org.ergoplatform.wallet.boxes.ErgoBoxAssetExtractor
import org.ergoplatform.validation.{InvalidModifier, ModifierValidator}
import org.ergoplatform.validation.ValidationResult.Invalid
Expand Down
6 changes: 3 additions & 3 deletions src/it/scala/org/ergoplatform/it/DeepRollBackSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.ergoplatform.it
import java.io.File
import com.typesafe.config.Config
import org.ergoplatform.it.container.{IntegrationSuite, Node}
import org.ergoplatform.nodeView.history.ErgoHistoryConstants
import org.ergoplatform.nodeView.history.ErgoHistoryUtils
import org.scalatest.freespec.AnyFreeSpec

import scala.async.Async
Expand Down Expand Up @@ -50,15 +50,15 @@ class DeepRollBackSpec extends AnyFreeSpec with IntegrationSuite {
// 1. Let the first node mine `chainLength + delta` blocks
Async.await(minerAIsolated.waitForHeight(chainLength + delta))

val genesisA = Async.await(minerAIsolated.headerIdsByHeight(ErgoHistoryConstants.GenesisHeight)).head
val genesisA = Async.await(minerAIsolated.headerIdsByHeight(ErgoHistoryUtils.GenesisHeight)).head

val minerBIsolated: Node = docker.startDevNetNode(minerBConfig, isolatedPeersConfig,
specialVolumeOpt = Some((localVolumeB, remoteVolumeB))).get

// 2. Let another node mine `chainLength` blocks
Async.await(minerBIsolated.waitForHeight(chainLength))

val genesisB = Async.await(minerBIsolated.headerIdsByHeight(ErgoHistoryConstants.GenesisHeight)).head
val genesisB = Async.await(minerBIsolated.headerIdsByHeight(ErgoHistoryUtils.GenesisHeight)).head

genesisA should not equal genesisB

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import org.ergoplatform.modifiers.{BlockSection, ErgoFullBlock, NonHeaderBlockSe
import org.ergoplatform.nodeView.ErgoReadersHolder.GetDataFromHistory
import org.ergoplatform.nodeView.history.ErgoHistoryReader
import org.ergoplatform.settings.{Algos, ErgoSettings, RESTApiSettings}
import org.ergoplatform.nodeView.ErgoNodeViewHolderLocallyGeneratedModifier._
import org.ergoplatform.http.api.ApiError.BadRequest
import scorex.core.api.http.ApiResponse
import scorex.crypto.authds.merkle.MerkleProof
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.ergoplatform.modifiers.ErgoFullBlock
import org.ergoplatform.modifiers.history.header.Header
import org.ergoplatform.nodeView.ErgoReadersHolder.{GetReaders, Readers}
import org.ergoplatform.nodeView.history.ErgoHistory
import org.ergoplatform.nodeView.history.ErgoHistoryConstants._
import org.ergoplatform.nodeView.history.ErgoHistoryUtils._
import org.ergoplatform.nodeView.state.{ErgoStateReader, StateType}
import org.ergoplatform.settings.{Algos, ErgoSettings, LaunchParameters, Parameters}
import scorex.core.network.ConnectedPeer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import org.ergoplatform.modifiers.history.popow.NipopowAlgos
import org.ergoplatform.modifiers.mempool.{ErgoTransaction, UnconfirmedTransaction}
import org.ergoplatform.network.ErgoNodeViewSynchronizerMessages._
import org.ergoplatform.nodeView.ErgoNodeViewHolder.ReceivableMessages.EliminateTransactions
import org.ergoplatform.nodeView.ErgoNodeViewHolderLocallyGeneratedModifier._
import org.ergoplatform.nodeView.ErgoReadersHolder.{GetReaders, Readers}
import org.ergoplatform.nodeView.history.ErgoHistoryConstants.Height
import org.ergoplatform.nodeView.history.ErgoHistoryUtils.Height
import org.ergoplatform.nodeView.history.{ErgoHistoryReader, ErgoHistoryUtils}
import org.ergoplatform.nodeView.mempool.ErgoMemPoolReader
import org.ergoplatform.nodeView.state.{ErgoState, ErgoStateContext, StateType, UtxoStateReader}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import scorex.core.network.ModifiersStatus.Requested
import org.ergoplatform.core.idsToString
import scorex.core.network.NetworkController.ReceivableMessages.{PenalizePeer, SendToNetwork}
import org.ergoplatform.network.ErgoNodeViewSynchronizerMessages._
import org.ergoplatform.network.ErgoNodeViewSynchronizerProcessNipopow.ProcessNipopow
import org.ergoplatform.nodeView.state.{ErgoStateReader, SnapshotsInfo, UtxoSetSnapshotPersistence, UtxoStateReader}
import org.ergoplatform.network.message._
import org.ergoplatform.network.message.{InvSpec, MessageSpec, ModifiersSpec, RequestModifierSpec}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.ergoplatform.nodeView.wallet.ErgoWalletReader
import scorex.core.network.ConnectedPeer
import scorex.util.ModifierId
import org.ergoplatform.ErgoLikeContext.Height
import org.ergoplatform.modifiers.history.popow.NipopowProof

/**
* Repository of messages processed ErgoNodeViewSynchronizer actor
Expand Down Expand Up @@ -133,4 +134,12 @@ object ErgoNodeViewSynchronizerMessages {
* @param blockId - id of a block corresponding to the UTXO set snapshot
*/
case class InitStateFromSnapshot(blockHeight: Height, blockId: ModifierId)

/**
* Command for a central node view holder component to process NiPoPoW proof,
* and possibly initialize headers chain from a best NiPoPoW proof known, when enough proofs collected
*
* @param nipopowProof - proof to initialize history from
*/
case class ProcessNipopow(nipopowProof: NipopowProof)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.ergoplatform.network

import io.circe.{Encoder, Json}
import org.ergoplatform.consensus.PeerChainStatus
import org.ergoplatform.nodeView.history.ErgoHistoryConstants._
import org.ergoplatform.nodeView.history.ErgoHistoryUtils._
import scorex.core.network.ConnectedPeer

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.ergoplatform.network

import org.ergoplatform.consensus.{Fork, Older, PeerChainStatus, Unknown}
import org.ergoplatform.nodeView.history.{ErgoHistoryReader, ErgoSyncInfo, ErgoSyncInfoV1, ErgoSyncInfoV2}
import org.ergoplatform.nodeView.history.ErgoHistoryConstants._
import org.ergoplatform.nodeView.history.ErgoHistoryUtils._
import org.ergoplatform.settings.NetworkSettings
import scorex.core.network.ConnectedPeer
import scorex.util.ScorexLogging
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.ergoplatform.network.peer

import org.ergoplatform.nodeView.history.ErgoHistoryConstants._
import org.ergoplatform.nodeView.history.ErgoHistoryUtils._
import java.io.{ByteArrayInputStream, ByteArrayOutputStream, ObjectInputStream, ObjectOutputStream}
import java.net.{InetAddress, InetSocketAddress}
import org.ergoplatform.settings.ErgoSettings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ import org.ergoplatform.wallet.utils.FileUtils
import org.ergoplatform.settings.{Algos, Constants, ErgoSettings, LaunchParameters, NetworkType, ScorexSettings}
import org.ergoplatform.core._
import org.ergoplatform.network.ErgoNodeViewSynchronizerMessages._
import org.ergoplatform.network.ErgoNodeViewSynchronizerProcessNipopow.ProcessNipopow
import org.ergoplatform.nodeView.ErgoNodeViewHolder.{BlockAppliedTransactions, CurrentView, DownloadRequest}
import org.ergoplatform.nodeView.ErgoNodeViewHolder.ReceivableMessages._
import org.ergoplatform.nodeView.ErgoNodeViewHolderLocallyGeneratedModifier._
import org.ergoplatform.modifiers.history.{ADProofs, HistoryModifierSerializer}
import org.ergoplatform.utils.ScorexEncoding
import org.ergoplatform.validation.RecoverableModifierError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.ergoplatform.modifiers.history._
import org.ergoplatform.modifiers.history.extension.Extension
import org.ergoplatform.modifiers.history.header.{Header, PreGenesisHeader}
import org.ergoplatform.modifiers.{BlockSection, ErgoFullBlock, NetworkObjectTypeId, NonHeaderBlockSection}
import org.ergoplatform.nodeView.history.ErgoHistoryConstants.{EmptyHistoryHeight, GenesisHeight, Height}
import org.ergoplatform.nodeView.history.ErgoHistoryUtils.{EmptyHistoryHeight, GenesisHeight, Height}
import org.ergoplatform.nodeView.history.extra.ExtraIndex
import org.ergoplatform.nodeView.history.storage._
import org.ergoplatform.nodeView.history.storage.modifierprocessors.{BlockSectionProcessor, HeadersProcessor}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import org.ergoplatform.consensus.ProgressInfo
import org.ergoplatform.modifiers.history._
import org.ergoplatform.modifiers.history.header.Header
import org.ergoplatform.modifiers.{BlockSection, ErgoFullBlock}
import org.ergoplatform.nodeView.history.ErgoHistoryConstants._
import org.ergoplatform.nodeView.history.ErgoHistoryUtils
import org.ergoplatform.nodeView.history.ErgoHistoryUtils._
import org.ergoplatform.settings.Algos
import scorex.db.ByteArrayWrapper
import scorex.util.{ModifierId, bytesToId, idToBytes}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.ergoplatform.nodeView.history.storage.modifierprocessors

import org.ergoplatform.modifiers.history.header.Header
import org.ergoplatform.nodeView.history.ErgoHistoryConstants._
import org.ergoplatform.nodeView.history.ErgoHistoryUtils._
import org.ergoplatform.settings.ErgoSettings

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.ergoplatform.mining.difficulty.DifficultyAdjustment
import org.ergoplatform.modifiers.BlockSection
import org.ergoplatform.modifiers.history._
import org.ergoplatform.modifiers.history.header.Header
import org.ergoplatform.nodeView.history.ErgoHistoryConstants._
import org.ergoplatform.nodeView.history.ErgoHistoryUtils._
import org.ergoplatform.nodeView.history.storage.HistoryStorage
import org.ergoplatform.settings.Constants.HashLength
import org.ergoplatform.settings.ValidationRules._
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.ergoplatform.nodeView.history.storage.modifierprocessors

import org.ergoplatform.nodeView.history.ErgoHistoryConstants.Height
import org.ergoplatform.nodeView.history.ErgoHistoryUtils.Height

/**
* Interface to methods providing updating and reading height of first full block stored in local database
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.ergoplatform.modifiers.BlockSection
import org.ergoplatform.modifiers.history.extension.Extension
import org.ergoplatform.modifiers.history.header.Header
import org.ergoplatform.modifiers.history.popow.{NipopowAlgos, NipopowProverWithDbAlgs, NipopowProof, NipopowProofSerializer, PoPowHeader, PoPowParams}
import org.ergoplatform.nodeView.history.ErgoHistoryConstants.GenesisHeight
import org.ergoplatform.nodeView.history.ErgoHistoryUtils.GenesisHeight
import org.ergoplatform.nodeView.history.ErgoHistoryReader
import org.ergoplatform.settings.{ChainSettings, NipopowSettings}
import org.ergoplatform.settings.Constants.HashLength
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.ergoplatform.nodeView.history.storage.modifierprocessors
import com.google.common.primitives.Ints
import org.ergoplatform.ErgoLikeContext.Height
import org.ergoplatform.nodeView.history.ErgoHistoryReader
import org.ergoplatform.nodeView.history.ErgoHistoryConstants._
import org.ergoplatform.nodeView.history.ErgoHistoryUtils._
import org.ergoplatform.nodeView.history.storage.HistoryStorage
import org.ergoplatform.nodeView.state.{ErgoStateReader, UtxoState}
import org.ergoplatform.nodeView.state.UtxoState.SubtreeId
Expand Down
Loading

0 comments on commit 997b86a

Please sign in to comment.