Skip to content

Commit 8267bae

Browse files
committed
more fixes
1 parent 352b287 commit 8267bae

File tree

7 files changed

+69
-50
lines changed

7 files changed

+69
-50
lines changed

node-it/src/test/scala/com/wavesplatform/it/api/AsyncHttpApi.scala

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import com.wavesplatform.api.http.{ConnectReq, DebugMessage, RollbackParams, `X-
99
import com.wavesplatform.common.state.ByteStr
1010
import com.wavesplatform.common.utils.EitherExt2.*
1111
import com.wavesplatform.common.utils.{Base58, Base64}
12-
import com.wavesplatform.features.api.{ActivationStatus, activationStatusFormat}
12+
import com.wavesplatform.features.api.{ActivationStatus, FinalityStatus, activationStatusFormat}
1313
import com.wavesplatform.it.Node
1414
import com.wavesplatform.it.sync.invokeExpressionFee
1515
import com.wavesplatform.it.util.*
@@ -28,18 +28,7 @@ import com.wavesplatform.transaction.lease.{LeaseCancelTransaction, LeaseTransac
2828
import com.wavesplatform.transaction.smart.{InvokeExpressionTransaction, InvokeScriptTransaction, SetScriptTransaction}
2929
import com.wavesplatform.transaction.transfer.*
3030
import com.wavesplatform.transaction.transfer.MassTransferTransaction.{ParsedTransfer, Transfer}
31-
import com.wavesplatform.transaction.{
32-
Asset,
33-
DataTransaction,
34-
Proofs,
35-
TransactionValidationOps,
36-
TxDecimals,
37-
TxExchangeAmount,
38-
TxExchangePrice,
39-
TxNonNegativeAmount,
40-
TxPositiveAmount,
41-
TxVersion
42-
}
31+
import com.wavesplatform.transaction.{Asset, DataTransaction, Proofs, TransactionValidationOps, TxDecimals, TxExchangeAmount, TxExchangePrice, TxNonNegativeAmount, TxPositiveAmount, TxVersion}
4332
import monix.execution.atomic.AtomicInt
4433
import org.asynchttpclient.*
4534
import org.asynchttpclient.Dsl.{delete as _delete, get as _get, post as _post, put as _put}
@@ -225,6 +214,8 @@ object AsyncHttpApi extends Assertions {
225214
def finalizedHeight: Future[Height] = get("/blocks/height/finalized").as[JsValue].map(v => (v \ "height").as[Height])
226215

227216
def finalizedHeightAt(at: Height): Future[Height] = get(s"/blocks/finalized/at/$at").as[JsValue].map(v => (v \ "height").as[Height])
217+
218+
def finalityStatus: Future[FinalityStatus] = get("/blockchain/finality").as[FinalityStatus]
228219

229220
def blockAt(height: Height, amountsAsStrings: Boolean = false): Future[Block] =
230221
get(s"/blocks/at/$height", amountsAsStrings).as[Block](amountsAsStrings)

node-it/src/test/scala/com/wavesplatform/it/api/SyncHttpApi.scala

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import com.wavesplatform.api.http.requests.IssueRequest
66
import com.wavesplatform.api.http.{ApiError, DebugMessage}
77
import com.wavesplatform.common.state.ByteStr
88
import com.wavesplatform.common.utils.EitherExt2.*
9-
import com.wavesplatform.features.BlockchainFeatures
10-
import com.wavesplatform.features.api.{ActivationStatus, FeatureActivationStatus}
9+
import com.wavesplatform.features.api.{ActivationStatus, FeatureActivationStatus, FinalityStatus}
1110
import com.wavesplatform.it.Node
1211
import com.wavesplatform.it.sync.*
1312
import com.wavesplatform.lang.script.v1.ExprScript
@@ -604,11 +603,7 @@ object SyncHttpApi extends Assertions with matchers.should.Matchers {
604603
def waitForHeight(expectedHeight: Height, requestAwaitTime: FiniteDuration = RequestAwaitTime): Height =
605604
sync(async(n).waitForHeight(expectedHeight), requestAwaitTime)
606605

607-
def currentGenerationPeriod: Option[GenerationPeriod] = for {
608-
activationStatus <- sync(async(n).activationStatus).features.find(_.id == BlockchainFeatures.DeterministicFinality.id)
609-
activation <- activationStatus.activationHeight
610-
r <- GenerationPeriod.from(sync(async(n).height), activation, n.settings)
611-
} yield r
606+
def currentGenerationPeriod: Option[GenerationPeriod] = sync(async(n).finalityStatus).currentGenerationPeriod
612607

613608
def waitForGenerationPeriod(p: GenerationPeriod, requestAwaitTime: FiniteDuration = 3.minutes): Height =
614609
waitForHeight(p.start, requestAwaitTime)
@@ -635,6 +630,8 @@ object SyncHttpApi extends Assertions with matchers.should.Matchers {
635630

636631
def finalizedHeightAt(at: Height): Height = sync(async(n).finalizedHeightAt(at))
637632

633+
def finalityStatus: FinalityStatus = sync(async(n).finalityStatus)
634+
638635
def blockAt(height: Height, amountsAsStrings: Boolean = false): Block = sync(async(n).blockAt(height, amountsAsStrings))
639636

640637
def blockSeq(fromHeight: Height, toHeight: Height, amountsAsStrings: Boolean = false): Seq[Block] =

node-it/src/test/scala/com/wavesplatform/it/sync/activation/VRFProtobufActivationSuite.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import scala.concurrent.duration.*
2020

2121
class VRFProtobufActivationSuite extends BaseTransactionSuite {
2222
val activationHeight = Height(10)
23-
val updateInterval = 3
23+
val updateInterval = 10
2424
import NodeConfigs.*
2525
override protected def nodeConfigs: Seq[Config] = Seq(
2626
BiggestMiner
@@ -40,13 +40,13 @@ class VRFProtobufActivationSuite extends BaseTransactionSuite {
4040
val (defaultName, defaultDescription) = ("asset", "description")
4141
assetId =
4242
sender.broadcastIssue(senderAcc, defaultName, defaultDescription, someAssetAmount, 8, reissuable = true, script = None, waitForTx = true).id
43-
sender.waitForHeight(Height(7), 3.minutes)
43+
sender.waitForHeight(Height(6), 3.minutes)
4444
otherAssetId =
4545
sender.broadcastIssue(senderAcc, defaultName, defaultDescription, someAssetAmount, 8, reissuable = true, script = None, waitForTx = true).id
4646
}
4747

4848
test("miner generates block v4 before activation") {
49-
val height = sender.height
49+
val height = sender.height
5050
val blockBeforeActivationHeight = sender.blockAt(height)
5151
val blockHeaderBeforeActivationHeight = sender.blockHeaderAt(height)
5252
blockBeforeActivationHeight.version.get shouldBe Block.RewardBlockVersion
@@ -109,7 +109,7 @@ class VRFProtobufActivationSuite extends BaseTransactionSuite {
109109
}
110110

111111
test("miner generates block v5 after activation") {
112-
val height = sender.height
112+
val height = sender.height
113113
val blockAtActivationHeight = sender.blockAt(height)
114114
val blockHeaderAtActivationHeight = sender.blockHeaderAt(height)
115115
blockAtActivationHeight.version.get shouldBe Block.ProtoBlockVersion
@@ -128,6 +128,7 @@ class VRFProtobufActivationSuite extends BaseTransactionSuite {
128128
}
129129

130130
test("able to broadcast UpdateAssetInfoTransaction if interval's reached before activation") {
131+
sender.waitForHeight(Height(sender.waitForTransaction(assetId).height + updateInterval))
131132
sender.updateAssetInfo(senderAcc, assetId, "updatedName", "updatedDescription", minFee, waitForTx = true)
132133
}
133134

node-it/src/test/scala/com/wavesplatform/it/sync/finalization/OneNodeFinalizationTestSuite.scala

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ import scala.concurrent.duration.DurationInt
1616
class OneNodeFinalizationTestSuite extends BaseFreeSpec, OptionValues, ScorexLogging {
1717
import com.wavesplatform.it.NodeConfigs.*
1818
override val nodeConfigs: Seq[Config] = Seq(
19-
BiggestMiner.quorum(0).preactivatedFeatures((BlockchainFeatures.DeterministicFinality.id, Height(0)))
19+
BiggestMiner.quorum(0).preactivatedFeatures(
20+
(BlockchainFeatures.FairPoS.id, Height(0)),
21+
(BlockchainFeatures.DeterministicFinality.id, Height(0)),
22+
)
2023
)
2124

2225
private def node = dockerNodes().last
@@ -54,8 +57,7 @@ class OneNodeFinalizationTestSuite extends BaseFreeSpec, OptionValues, ScorexLog
5457
}
5558

5659
step("Finalized height checks")
57-
val deadline = 2.minutes.fromNow
58-
var finalizedHeight1 = node.finalizedHeight
60+
val finalizedHeight1 = node.finalizedHeight
5961
val waitingFinalizedHeight = finalizedHeight1 + 2
6062

6163
withClue("Finalized height is unknown: ") {
@@ -70,28 +72,19 @@ class OneNodeFinalizationTestSuite extends BaseFreeSpec, OptionValues, ScorexLog
7072
}
7173
}
7274

73-
var done = false
74-
while (!done && deadline.hasTimeLeft()) {
75-
val currHeight = node.height
76-
if (currHeight > waitingFinalizedHeight + 2)
77-
fail(
78-
s"Finalization height doesn't rise: height=$currHeight, waiting for finalized height=$waitingFinalizedHeight, last finalized height=$finalizedHeight1"
79-
)
80-
81-
// We need at least one transaction, otherwise there won't be a microblock, thus no voting, no finalization
82-
node.transfer(miner1Acc, miner3Addr, 1.waves, waitForTx = true)
83-
84-
val updatedFinalizedHeight = node.finalizedHeight
85-
if (updatedFinalizedHeight < finalizedHeight1)
86-
fail(s"Finalized height $updatedFinalizedHeight became lower than the previous $finalizedHeight1")
87-
else if (updatedFinalizedHeight != finalizedHeight1)
88-
log.debug(s"New finalized height: $finalizedHeight1 -> $updatedFinalizedHeight")
89-
90-
finalizedHeight1 = updatedFinalizedHeight
91-
done = finalizedHeight1 >= waitingFinalizedHeight
92-
}
75+
// We need at least one transaction, otherwise there won't be a microblock, thus no voting, no finalization
76+
// Finalization happened in a microblock
77+
node.waitForHeight(Height(node.waitForTransaction(node.transfer(miner1Acc, miner3Addr, 1.waves, waitForTx = true).id).height + 1))
78+
val fs = node.finalityStatus
79+
if (fs.height > waitingFinalizedHeight + 2)
80+
fail(
81+
s"Finalization height doesn't rise: height=${fs.height}, waiting for finalized height=$waitingFinalizedHeight, last finalized height=$finalizedHeight1"
82+
)
9383

94-
node.waitForHeight(node.height + 1) // Finalization happened in a microblock
84+
if (fs.finalizedHeight < finalizedHeight1)
85+
fail(s"Finalized height ${fs.finalizedHeight} became lower than the previous $finalizedHeight1")
86+
else if (fs.finalizedHeight != finalizedHeight1)
87+
log.debug(s"New finalized height: $finalizedHeight1 -> ${fs.finalizedHeight}")
9588

9689
step("Survives restart")
9790
isolated {
@@ -106,7 +99,7 @@ class OneNodeFinalizationTestSuite extends BaseFreeSpec, OptionValues, ScorexLog
10699
node.finalizedHeightAt(finalizedBlock1.height) should be <= finalizedBlock1.height
107100

108101
step("Finalization voting in a block header")
109-
val votingBlockHeader = node.blockHeaderAt(finalizedHeight1 + 1)
102+
val votingBlockHeader = node.blockHeaderAt(finalizedBlock1.height + 1)
110103
val finalizationVoting = votingBlockHeader.finalizationVoting.value
111104

112105
val generators: Seq[(data: GeneratorsResponse.Entry, index: Int)] = node.generators(votingBlockHeader.height).zipWithIndex

node-it/src/test/scala/com/wavesplatform/it/sync/smartcontract/RideV4ActivationSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class RideV4ActivationSuite extends BaseTransactionSuite with CancelAfterFailure
2323
import NodeConfigs.*
2424
import RideV4ActivationSuite.*
2525
override protected def nodeConfigs: Seq[Config] = Seq(
26-
BiggestMiner.quorum(0).preactivatedFeatures((BlockchainFeatures.BlockV5.id, activationHeight - 1))
26+
Miners(7).quorum(0).preactivatedFeatures((BlockchainFeatures.BlockV5.id, activationHeight - 1))
2727
)
2828

2929
private def smartAccV4 = firstKeyPair

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.wavesplatform.api.http
22

33
import com.wavesplatform.api.common.CommonGeneratorsApi.GeneratorEntry
44
import com.wavesplatform.api.common.{CommonBlocksApi, CommonGeneratorsApi}
5+
import com.wavesplatform.features.BlockchainFeatures
56
import com.wavesplatform.state.{Blockchain, GenerationPeriod, Height}
67
import org.apache.pekko.http.scaladsl.server.Route
78
import play.api.libs.json.*
@@ -21,6 +22,7 @@ case class FinalityApiRoute(blockchain: Blockchain, blocksApi: CommonBlocksApi,
2122
Json.obj(
2223
"height" -> currentHeight,
2324
"finalizedHeight" -> blocksApi.currentFinalizedHeight,
25+
"activationHeight" -> blockchain.featureActivationHeight(BlockchainFeatures.DeterministicFinality),
2426
"currentGenerationPeriod" -> currentPeriod,
2527
"currentGenerators" -> generatorsApi.generators(currentHeight),
2628
"nextGenerationPeriod" -> currentPeriod.map(_.next),
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.wavesplatform.features.api
2+
3+
import com.wavesplatform.state.{GenerationPeriod, Height}
4+
import play.api.libs.json.*
5+
import play.api.libs.functional.syntax._
6+
7+
case class FinalityStatus(
8+
height: Height,
9+
finalizedHeight: Height,
10+
currentGenerationPeriod: Option[GenerationPeriod],
11+
nextGenerationPeriod: Option[GenerationPeriod]
12+
)
13+
14+
object FinalityStatus {
15+
private def generationPeriodReads(activationHeight: Height): Reads[GenerationPeriod] =
16+
(
17+
(__ \ "start").read[Height] and (__ \ "end").read[Height]
18+
)((start, end) => GenerationPeriod(activationHeight, start, end - start))
19+
20+
given Reads[FinalityStatus] =
21+
(
22+
(__ \ "height").read[Height] and
23+
(__ \ "finalizedHeight").read[Height] and
24+
(__ \ "activationHeight").read[Height] and
25+
(__ \ "currentGenerationPeriod").readNullable[JsObject] and
26+
(__ \ "nextGenerationPeriod").readNullable[JsObject]
27+
)((h, fh, ah, cgp, ngp) =>
28+
FinalityStatus(
29+
h,
30+
fh,
31+
cgp.map(_.as[GenerationPeriod](using generationPeriodReads(ah))),
32+
ngp.map(_.as[GenerationPeriod](using generationPeriodReads(ah)))
33+
)
34+
)
35+
}

0 commit comments

Comments
 (0)