Skip to content

Commit 52f09ea

Browse files
authored
Merge branch 'version-1.5.x' into reduce-locking-in-updater
2 parents 3ae3758 + 663db56 commit 52f09ea

17 files changed

Lines changed: 66 additions & 315 deletions

docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG baseImage=eclipse-temurin:11-jre-noble
1+
ARG baseImage=eclipse-temurin:21-jre-noble
22
FROM $baseImage
33

44
ENV WAVES_LOG_LEVEL=INFO

docker/entrypoint.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
JAVA_OPTS="-XX:+ExitOnOutOfMemoryError
44
-Xmx${WAVES_HEAP_SIZE}
55
--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED
6+
--add-opens=java.base/sun.nio.ch=ALL-UNNAMED
67
-Dlogback.stdout.level=${WAVES_LOG_LEVEL}
78
-Dlogback.file.directory=${WVLOG}
89
-Dwaves.config.directory=/etc/waves

node/src/main/scala/com/wavesplatform/Application.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,6 @@ class Application(val actorSystem: ActorSystem, val settings: WavesSettings, con
435435
scoreStatsReporter,
436436
configRoot,
437437
rocksDB,
438-
() => utxStorage.getPriorityPool.map(_.compositeBlockchain),
439438
routeTimeout,
440439
heavyRequestScheduler
441440
),

node/src/main/scala/com/wavesplatform/api/http/DebugApiRoute.scala

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ case class DebugApiRoute(
5555
scoreReporter: Coeval[RxScoreObserver.Stats],
5656
configRoot: ConfigObject,
5757
db: RocksDBWriter,
58-
priorityPoolBlockchain: () => Option[Blockchain],
5958
routeTimeout: RouteTimeout,
6059
heavyRequestScheduler: Scheduler
6160
) extends ApiRoute
@@ -197,14 +196,13 @@ case class DebugApiRoute(
197196

198197
def validate: Route =
199198
path("validate")(jsonPost[JsObject] { jsv =>
200-
val resBlockchain = priorityPoolBlockchain().getOrElse(blockchain)
201199
val startTime = System.nanoTime()
202200

203201
val parsedTransaction = TransactionFactory.fromSignedRequest(jsv)
204202

205203
val tracedSnapshot = for {
206204
tx <- TracedResult(parsedTransaction)
207-
diff <- TransactionDiffer.forceValidate(resBlockchain.lastBlockTimestamp, time.correctedTime(), enableExecutionLog = true)(resBlockchain, tx)
205+
diff <- TransactionDiffer.forceValidate(blockchain.lastBlockTimestamp, time.correctedTime(), enableExecutionLog = true)(blockchain, tx)
208206
} yield (tx, diff)
209207

210208
val error = tracedSnapshot.resultE match {
@@ -218,7 +216,7 @@ case class DebugApiRoute(
218216
.fold(
219217
_ => this.serializer,
220218
{ case (_, snapshot) =>
221-
val snapshotBlockchain = SnapshotBlockchain(resBlockchain, snapshot)
219+
val snapshotBlockchain = SnapshotBlockchain(blockchain, snapshot)
222220
this.serializer.copy(blockchain = snapshotBlockchain)
223221
}
224222
)
@@ -230,8 +228,8 @@ case class DebugApiRoute(
230228
val meta = tx match {
231229
case ist: InvokeScriptTransaction =>
232230
val result = diff.scriptResults.get(ist.id())
233-
TransactionMeta.Invoke(Height(resBlockchain.height), ist, TxMeta.Status.Succeeded, diff.scriptsComplexity, result)
234-
case tx => TransactionMeta.Default(Height(resBlockchain.height), tx, TxMeta.Status.Succeeded, diff.scriptsComplexity)
231+
TransactionMeta.Invoke(Height(blockchain.height), ist, TxMeta.Status.Succeeded, diff.scriptsComplexity, result)
232+
case tx => TransactionMeta.Default(Height(blockchain.height), tx, TxMeta.Status.Succeeded, diff.scriptsComplexity)
235233
}
236234
serializer.transactionWithMetaJson(meta)
237235
}
@@ -244,7 +242,7 @@ case class DebugApiRoute(
244242
case ist: InvokeScriptTrace => ist.maybeLoggedJson(logged = true)(serializer.invokeScriptResultWrites)
245243
case trace => trace.loggedJson
246244
},
247-
"height" -> resBlockchain.height
245+
"height" -> blockchain.height
248246
)
249247

250248
error.fold(response ++ extendedJson)(err =>

node/src/main/scala/com/wavesplatform/mining/Miner.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ class MinerImpl(
8484
settings.minerSettings,
8585
minerScheduler,
8686
appenderScheduler,
87-
transactionAdded,
88-
utx.getPriorityPool.map(p => p.nextMicroBlockSize(_)).getOrElse(identity)
87+
transactionAdded
8988
)
9089

9190
def getNextBlockGenerationOffset(account: KeyPair): Either[String, FiniteDuration] =

node/src/main/scala/com/wavesplatform/mining/microblocks/MicroBlockMiner.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ object MicroBlockMiner {
3030
settings: MinerSettings,
3131
minerScheduler: SchedulerService,
3232
appenderScheduler: SchedulerService,
33-
transactionAdded: Observable[Unit],
34-
nextMicroBlockSize: Int => Int = identity
33+
transactionAdded: Observable[Unit]
3534
): MicroBlockMiner =
3635
new MicroBlockMinerImpl(
3736
setDebugState,
@@ -41,7 +40,6 @@ object MicroBlockMiner {
4140
settings,
4241
minerScheduler,
4342
appenderScheduler,
44-
transactionAdded,
45-
nextMicroBlockSize
43+
transactionAdded
4644
)
4745
}

node/src/main/scala/com/wavesplatform/mining/microblocks/MicroBlockMinerImpl.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ class MicroBlockMinerImpl(
3434
settings: MinerSettings,
3535
minerScheduler: SchedulerService,
3636
appenderScheduler: SchedulerService,
37-
transactionAdded: Observable[Unit],
38-
nextMicroBlockSize: Int => Int
37+
transactionAdded: Observable[Unit]
3938
) extends MicroBlockMiner
4039
with ScorexLogging {
4140

@@ -73,7 +72,7 @@ class MicroBlockMinerImpl(
7372
val mdConstraint = MultiDimensionalMiningConstraint(
7473
restTotalConstraint,
7574
OneDimensionalMiningConstraint(
76-
nextMicroBlockSize(settings.maxTransactionsInMicroBlock),
75+
settings.maxTransactionsInMicroBlock,
7776
TxEstimators.one,
7877
"MaxTxsInMicroBlock"
7978
)

node/src/main/scala/com/wavesplatform/settings/BlockchainSettings.scala

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ case class FunctionalitySettings(
7878
xtnBuybackRewardPeriod: Int = Int.MaxValue,
7979
lightNodeBlockFieldsAbsenceInterval: Int = 1000,
8080
blockRewardBoostPeriod: Int = 1000,
81-
paymentsCheckHeight: Int = 0
81+
paymentsCheckHeight: Int = 0,
82+
unitsRegistryAddress: Option[String] = None
8283
) {
8384
val allowLeasedBalanceTransferUntilHeight: Int = blockVersion3AfterHeight
8485
val allowTemporaryNegativeUntil: Long = lastTimeBasedForkParameter
@@ -92,6 +93,8 @@ case class FunctionalitySettings(
9293
daoAddress.traverse(Address.fromString(_)).leftMap(_ => "Incorrect dao-address")
9394
lazy val xtnBuybackAddressParsed: Either[String, Option[Address]] =
9495
xtnBuybackAddress.traverse(Address.fromString(_)).leftMap(_ => "Incorrect xtn-buyback-address")
96+
lazy val unitsRegistryAddressParsed: Either[String, Option[Address]] =
97+
unitsRegistryAddress.traverse(Address.fromString(_)).leftMap(_ => "Incorrect units-registry-address")
9598

9699
require(featureCheckBlocksPeriod > 0, "featureCheckBlocksPeriod must be greater than 0")
97100
require(
@@ -133,7 +136,8 @@ object FunctionalitySettings {
133136
xtnBuybackAddress = Some("3PFjHWuH6WXNJbwnfLHqNFBpwBS5dkYjTfv"),
134137
xtnBuybackRewardPeriod = 100000,
135138
blockRewardBoostPeriod = 300_000,
136-
paymentsCheckHeight = 4303300
139+
paymentsCheckHeight = 4303300,
140+
unitsRegistryAddress = Some("3P8LfPXcveST7WKkV3UACQNdr6J3shPYong")
137141
)
138142

139143
val TESTNET: FunctionalitySettings = apply(
@@ -149,7 +153,8 @@ object FunctionalitySettings {
149153
daoAddress = Some("3Myb6G8DkdBb8YcZzhrky65HrmiNuac3kvS"),
150154
xtnBuybackAddress = Some("3N13KQpdY3UU7JkWUBD9kN7t7xuUgeyYMTT"),
151155
xtnBuybackRewardPeriod = 2000,
152-
blockRewardBoostPeriod = 2_000
156+
blockRewardBoostPeriod = 2_000,
157+
unitsRegistryAddress = Some("3N9fwNGJcUcAbhh7YPr6mrpuGJD4tApZFsT")
153158
)
154159

155160
val STAGENET: FunctionalitySettings = apply(

node/src/main/scala/com/wavesplatform/state/Blockchain.scala

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ trait Blockchain {
6161

6262
def balanceAtHeight(address: Address, height: Int, assetId: Asset = Waves): Option[(Int, Long)]
6363

64-
/**
65-
* Retrieves Waves balance snapshot in the [from, to] range (inclusive)
66-
* @return Balance snapshots from most recent to oldest.
64+
/** Retrieves Waves balance snapshot in the [from, to] range (inclusive)
65+
* @return
66+
* Balance snapshots from most recent to oldest.
6767
*/
6868
def balanceSnapshots(address: Address, from: Int, to: Option[BlockId]): Seq[BalanceSnapshot]
6969

@@ -225,13 +225,17 @@ object Blockchain {
225225
blockchain.effectiveBalanceBanHeights(address).contains(height)
226226

227227
def supportsLightNodeBlockFields(height: Int = blockchain.height): Boolean =
228-
blockchain.featureActivationHeight(LightNode.id).exists(height >= _ + blockchain.settings.functionalitySettings.lightNodeBlockFieldsAbsenceInterval)
228+
blockchain
229+
.featureActivationHeight(LightNode.id)
230+
.exists(height >= _ + blockchain.settings.functionalitySettings.lightNodeBlockFieldsAbsenceInterval)
229231

230232
def blockRewardBoost(height: Int): Int =
231233
blockchain
232234
.featureActivationHeight(BlockchainFeatures.BoostBlockReward.id)
233235
.filter { boostHeight =>
234236
boostHeight <= height && height < boostHeight + blockchain.settings.functionalitySettings.blockRewardBoostPeriod
235-
}.fold(1)(_ => BlockRewardCalculator.RewardBoost)
237+
}
238+
.fold(1)(_ => BlockRewardCalculator.RewardBoost)
239+
236240
}
237241
}

node/src/main/scala/com/wavesplatform/utx/UtxPoolImpl.scala

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ case class UtxPoolImpl(
5959
private[this] val inUTXPoolOrdering = TransactionsOrdering.InUTXPool(utxSettings.fastLaneAddresses)
6060

6161
// State
62-
val priorityPool = new UtxPriorityPool(blockchain)
62+
val priorityPool = new UtxPriorityPool
6363
private[this] val transactions = new ConcurrentHashMap[ByteStr, Transaction]()
6464

6565
override def getPriorityPool: Option[UtxPriorityPool] = Some(priorityPool)
6666

6767
override def putIfNew(tx: Transaction, forceValidate: Boolean): TracedResult[ValidationError, Boolean] = {
68-
if (transactions.containsKey(tx.id()) || priorityPool.contains(tx.id())) TracedResult.wrapValue(false)
68+
if (transactions.containsKey(tx.id())) TracedResult.wrapValue(false)
6969
else putNewTx(tx, forceValidate)
7070
}
7171

@@ -171,10 +171,8 @@ case class UtxPoolImpl(
171171
removeIds(ids)
172172
}
173173

174-
def setPrioritySnapshots(discSnapshots: Seq[StateSnapshot]): Unit = {
175-
val txs = priorityPool.setPriorityDiffs(discSnapshots)
176-
txs.foreach(addTransaction(_, verify = false, canLock = false))
177-
}
174+
def setPrioritySnapshots(discSnapshots: Seq[StateSnapshot]): Unit =
175+
priorityPool.setPriorityDiffs(discSnapshots).foreach(addTransaction(_, verify = false))
178176

179177
def resetPriorityPool(): Unit =
180178
priorityPool.setPriorityDiffs(Seq.empty)
@@ -186,23 +184,19 @@ case class UtxPoolImpl(
186184
}
187185
}
188186

189-
private[this] def removeIds(removed: Set[ByteStr]): Unit = {
190-
val priorityRemoved = priorityPool.removeIds(removed)
191-
val factRemoved = priorityRemoved ++ removed.flatMap(id => removeFromOrdPool(id))
192-
factRemoved.foreach(TxStateActions.removeMined(_))
193-
}
187+
private[this] def removeIds(removed: Set[ByteStr]): Unit =
188+
removed.flatMap(id => removeFromOrdPool(id)).foreach(TxStateActions.removeMined(_))
194189

195190
private[utx] def addTransaction(
196191
tx: Transaction,
197192
verify: Boolean,
198-
forceValidate: Boolean = false,
199-
canLock: Boolean = true
193+
forceValidate: Boolean = false
200194
): TracedResult[ValidationError, Boolean] = {
201195
val diffEi = {
202196
def calculateSnapshot(): TracedResult[ValidationError, StateSnapshot] = {
203197
if (forceValidate)
204198
TransactionDiffer.forceValidate(blockchain.lastBlockTimestamp, time.correctedTime(), enableExecutionLog = true)(
205-
priorityPool.compositeBlockchain,
199+
blockchain,
206200
tx
207201
)
208202
else
@@ -213,13 +207,12 @@ case class UtxPoolImpl(
213207
verify,
214208
enableExecutionLog = true
215209
)(
216-
priorityPool.compositeBlockchain,
210+
blockchain,
217211
tx
218212
)
219213
}
220214

221-
if (canLock) priorityPool.optimisticRead(calculateSnapshot())(_.resultE.isLeft)
222-
else calculateSnapshot()
215+
calculateSnapshot()
223216
}
224217

225218
if (!verify || diffEi.resultE.isRight) {
@@ -235,13 +228,12 @@ case class UtxPoolImpl(
235228
}
236229

237230
override def all: Seq[Transaction] =
238-
(priorityPool.priorityTransactions ++ nonPriorityTransactions).distinct
231+
(priorityPool.priorityTransactionIds.flatMap(id => Option(transactions.get(id))) ++ nonPriorityTransactions).distinct
239232

240233
override def size: Int = transactions.size
241234

242235
override def transactionById(transactionId: ByteStr): Option[Transaction] =
243236
Option(transactions.get(transactionId))
244-
.orElse(priorityPool.transactionById(transactionId))
245237

246238
private def scriptedAddresses(tx: Transaction): Set[Address] = tx match {
247239
case t if inUTXPoolOrdering.isWhitelisted(t) => Set.empty
@@ -256,23 +248,21 @@ case class UtxPoolImpl(
256248
private[this] case class TxEntry(tx: Transaction, priority: Boolean)
257249

258250
private[this] def createTxEntrySeq(): Seq[TxEntry] =
259-
priorityPool.priorityTransactions.map(TxEntry(_, priority = true)) ++ nonPriorityTransactions.map(
260-
TxEntry(_, priority = false)
261-
)
251+
priorityPool.priorityTransactionIds.flatMap(id => Option(transactions.get(id)).map(TxEntry(_, priority = true))) ++
252+
nonPriorityTransactions.map(TxEntry(_, priority = false))
262253

263254
override def packUnconfirmed(
264255
initialConstraint: MultiDimensionalMiningConstraint,
265256
prevStateHash: Option[ByteStr],
266257
strategy: PackStrategy,
267258
cancelled: () => Boolean
268-
): (Option[Seq[Transaction]], MultiDimensionalMiningConstraint, Option[ByteStr]) = {
259+
): (Option[Seq[Transaction]], MultiDimensionalMiningConstraint, Option[ByteStr]) =
269260
pack(TransactionDiffer(blockchain.lastBlockTimestamp, time.correctedTime(), enableExecutionLog = true))(
270261
initialConstraint,
271262
strategy,
272263
prevStateHash,
273264
cancelled
274265
)
275-
}
276266

277267
def cleanUnconfirmed(): Unit = {
278268
log.trace(s"Starting UTX cleanup at height ${blockchain.height}")
@@ -286,7 +276,7 @@ case class UtxPoolImpl(
286276
} else {
287277
val differ = if (!isMiningEnabled && utxSettings.forceValidateInCleanup) {
288278
TransactionDiffer.forceValidate(blockchain.lastBlockTimestamp, time.correctedTime(), enableExecutionLog = true)(
289-
priorityPool.compositeBlockchain,
279+
blockchain,
290280
_
291281
)
292282
} else {
@@ -296,7 +286,7 @@ case class UtxPoolImpl(
296286
utxSettings.alwaysUnlimitedExecution,
297287
enableExecutionLog = true
298288
)(
299-
priorityPool.compositeBlockchain,
289+
blockchain,
300290
_
301291
)
302292
}
@@ -480,11 +470,10 @@ case class UtxPoolImpl(
480470

481471
log.trace(
482472
s"Validated ${packResult.validatedTransactions.size} transactions, " +
483-
s"of which ${packResult.transactions.fold(0)(_.size)} were packed, ${transactions.size() + priorityPool.priorityTransactions.size} transactions remaining"
473+
s"of which ${packResult.transactions.fold(0)(_.size)} were packed, ${transactions.size()} transactions remaining"
484474
)
485475

486476
if (packResult.removedTransactions.nonEmpty) log.trace(s"Removing invalid transactions: ${packResult.removedTransactions.mkString(", ")}")
487-
priorityPool.invalidateTxs(packResult.removedTransactions)
488477
(packResult.transactions.map(_.reverse), packResult.constraint, packResult.stateHash)
489478
}
490479

@@ -563,7 +552,7 @@ case class UtxPoolImpl(
563552

564553
private def cleanupLoop(): Unit = cleanupScheduler.execute { () =>
565554
while (scheduled.compareAndSet(true, false)) {
566-
if (!transactions.isEmpty || priorityPool.priorityTransactions.nonEmpty) {
555+
if (!transactions.isEmpty) {
567556
cleanUnconfirmed()
568557
}
569558
}

0 commit comments

Comments
 (0)