diff --git a/src/main/scala/units/ConsensusClient.scala b/src/main/scala/units/ConsensusClient.scala index cfc56148..f93e3931 100644 --- a/src/main/scala/units/ConsensusClient.scala +++ b/src/main/scala/units/ConsensusClient.scala @@ -102,7 +102,7 @@ class ConsensusClientDependencies(context: ExtensionContext) extends AutoCloseab val config: ClientConfig = context.settings.config.as[ClientConfig]("waves.l2") - private val payloadObserverScheduler = Schedulers.singleThread("block-observer-l2", reporter = { e => log.warn("Error in BlockObserver", e) }) + private val payloadObserverScheduler = Schedulers.singleThread("payload-observer-l2", reporter = { e => log.warn("Error in PayloadObserver", e) }) val globalScheduler: Scheduler = monix.execution.Scheduler.global val eluScheduler: SchedulerService = Scheduler.singleThread("el-updater", reporter = { e => log.warn("Exception in ELUpdater", e) }) diff --git a/src/main/scala/units/ELUpdater.scala b/src/main/scala/units/ELUpdater.scala index 5faf5f47..1b08afd2 100644 --- a/src/main/scala/units/ELUpdater.scala +++ b/src/main/scala/units/ELUpdater.scala @@ -62,7 +62,7 @@ class ELUpdater( def executionPayloadReceived(epi: ExecutionPayloadInfo): Unit = scheduler.execute { () => val payload = epi.payload - logger.debug(s"New block ${payload.hash}->${payload.parentHash} (timestamp=${payload.timestamp}, height=${payload.height}) appeared") + logger.debug(s"New payload for block ${payload.hash}->${payload.parentHash} (timestamp=${payload.timestamp}, height=${payload.height}) appeared") val now = time.correctedTime() / 1000 if (payload.timestamp - now <= MaxTimeDrift) { @@ -90,19 +90,19 @@ class ELUpdater( case Some(rInfo) if rInfo.missedBlock.hash == payload.hash => chainContractClient.getChainInfo(rInfo.chainId) match { case Some(chainInfo) if chainInfo.isMain => - validateAndApplyMissedBlock(epi, w, rInfo.missedBlock, rInfo.missedBlockParentPayload, chainInfo) + validateAndApplyMissed(epi, w, rInfo.missedBlock, rInfo.missedBlockParentPayload, chainInfo) case Some(_) => logger.debug(s"Chain ${rInfo.chainId} is not main anymore, ignoring ${payload.hash}") case _ => logger.error(s"Failed to get chain ${rInfo.chainId} info, ignoring ${payload.hash}") } - case _ => logger.debug(s"Expecting ${w.returnToMainChainInfo.fold("no block")(_.toString)}, ignoring unexpected ${payload.hash}") + case _ => logger.debug(s"Expecting ${w.returnToMainChainInfo.fold("no block payload")(_.toString)}, ignoring unexpected ${payload.hash}") } case other => logger.debug(s"$other: ignoring ${payload.hash}") } } else { - logger.debug(s"Block ${payload.hash} is from future: timestamp=${payload.timestamp}, now=$now, Δ${payload.timestamp - now}s") + logger.debug(s"Payload for block ${payload.hash} is from future: timestamp=${payload.timestamp}, now=$now, Δ${payload.timestamp - now}s") } } @@ -453,7 +453,7 @@ class ELUpdater( lastElWithdrawalIndex = None ) val options = chainContractClient.getOptions - followChainAndRequestNextBlock( + followChainAndRequestNextBlockPayload( newEpochInfo, mainChainInfo, lastPayload, @@ -468,8 +468,8 @@ class ELUpdater( _ => () ) case Right(None) => - logger.trace(s"Finalized block ${finalizedBlock.hash} payload is not in EC, requesting block from peers") - setState("15", WaitingForSyncHead(finalizedBlock, requestAndProcessPayload(finalizedBlock.hash))) + logger.trace(s"Finalized block ${finalizedBlock.hash} payload is not in EC, requesting from peers") + setState("15", WaitingForSyncHead(finalizedBlock, requestAndProcessBlockPayload(finalizedBlock.hash))) } } } @@ -509,12 +509,12 @@ class ELUpdater( } } - private def requestBlocksAndStartMining(prevState: Working[FollowingChain]): Unit = { + private def requestPayloadsAndStartMining(prevState: Working[FollowingChain]): Unit = { def check(missedBlock: ContractBlock): Unit = { state match { case w @ Working(epochInfo, lastPayload, finalizedBlock, mainChainInfo, _, fc: FollowingChain, _, returnToMainChainInfo) if fc.nextExpectedBlock.map(_.hash).contains(missedBlock.hash) && canSupportAnotherAltChain(fc.nodeChainInfo) => - logger.debug(s"Block ${missedBlock.hash} wasn't received for $WaitRequestedBlockTimeout, need to switch to alternative chain") + logger.debug(s"Block ${missedBlock.hash} payload wasn't received for $WaitRequestedPayloadTimeout, need to switch to alternative chain") (for { lastValidBlock <- getAltChainReferenceBlock(fc.nodeChainInfo, missedBlock) updatedState <- rollbackTo(w, lastValidBlock, finalizedBlock) @@ -556,8 +556,8 @@ class ELUpdater( case w: Working[ChainStatus] => w.chainStatus match { case FollowingChain(_, Some(nextExpectedBlock)) => - logger.debug(s"Waiting for block $nextExpectedBlock from peers") - scheduler.scheduleOnce(WaitRequestedBlockTimeout) { + logger.debug(s"Waiting for block $nextExpectedBlock payload from peers") + scheduler.scheduleOnce(WaitRequestedPayloadTimeout) { if (blockchain.height == prevState.epochInfo.number) { check(missedBlock) } @@ -574,7 +574,7 @@ class ELUpdater( prevState.chainStatus.nextExpectedBlock match { case Some(missedBlock) => - scheduler.scheduleOnce(WaitRequestedBlockTimeout) { + scheduler.scheduleOnce(WaitRequestedPayloadTimeout) { if (blockchain.height == prevState.epochInfo.number) { check(missedBlock) } @@ -600,7 +600,7 @@ class ELUpdater( finalizedBlock, options ).foreach { newState => - requestBlocksAndStartMining(newState) + requestPayloadsAndStartMining(newState) } } @@ -703,14 +703,14 @@ class ELUpdater( } } validateAppliedBlocks() - requestMainChainBlock() + requestMainChainBlockPayload() case Right(None) => - logger.trace(s"Finalized block ${finalizedBlock.hash} payload is not in EC, requesting block from peers") - setState("19", WaitingForSyncHead(finalizedBlock, requestAndProcessPayload(finalizedBlock.hash))) + logger.trace(s"Finalized block ${finalizedBlock.hash} payload is not in EC, requesting from peers") + setState("19", WaitingForSyncHead(finalizedBlock, requestAndProcessBlockPayload(finalizedBlock.hash))) } } - private def followChainAndRequestNextBlock( + private def followChainAndRequestNextBlockPayload( epochInfo: EpochInfo, nodeChainInfo: ChainInfo, lastPayload: ExecutionPayload, @@ -731,29 +731,29 @@ class ELUpdater( returnToMainChainInfo ) setState("3", newState) - maybeRequestNextBlock(newState, finalizedBlock) + maybeRequestNextBlockPayload(newState, finalizedBlock) } - private def requestPayload(contractBlock: ContractBlock): PayloadRequestResult = { + private def requestBlockPayload(contractBlock: ContractBlock): PayloadRequestResult = { logger.debug(s"Requesting payload for block ${contractBlock.hash}") engineApiClient.getBlockByHash(contractBlock.hash) match { case Right(Some(payload)) => PayloadRequestResult.Exists(payload) case Right(None) => - requestAndProcessPayload(contractBlock.hash) + requestAndProcessBlockPayload(contractBlock.hash) PayloadRequestResult.Requested(contractBlock) case Left(err) => logger.warn(s"Failed to get block ${contractBlock.hash} payload by hash: ${err.message}") - requestAndProcessPayload(contractBlock.hash) + requestAndProcessBlockPayload(contractBlock.hash) PayloadRequestResult.Requested(contractBlock) } } - private def requestMainChainBlock(): Unit = { + private def requestMainChainBlockPayload(): Unit = { state match { case w: Working[ChainStatus] => w.returnToMainChainInfo.foreach { returnToMainChainInfo => if (w.mainChainInfo.id == returnToMainChainInfo.chainId) { - requestPayload(returnToMainChainInfo.missedBlock) match { + requestBlockPayload(returnToMainChainInfo.missedBlock) match { case PayloadRequestResult.Exists(payload) => logger.debug(s"Block ${returnToMainChainInfo.missedBlock.hash} payload exists at execution chain, trying to validate") validateAppliedBlock(returnToMainChainInfo.missedBlock, payload, w) match { @@ -776,7 +776,7 @@ class ELUpdater( } } - private def requestAndProcessPayload(hash: BlockHash): CancelableFuture[ExecutionPayloadInfo] = { + private def requestAndProcessBlockPayload(hash: BlockHash): CancelableFuture[ExecutionPayloadInfo] = { payloadObserver .loadPayload(hash) .andThen { @@ -828,7 +828,7 @@ class ELUpdater( returnToMainChainInfo.filter(rInfo => rInfo.chainId != prevChainId && mainChainInfo.id == rInfo.chainId) ) setState("16", newState) - maybeRequestNextBlock(newState, finalizedContractBlock) + maybeRequestNextBlockPayload(newState, finalizedContractBlock) } def rollbackAndFollowChain( @@ -903,7 +903,7 @@ class ELUpdater( lastValidatedBlock = target, lastElWithdrawalIndex = None ) - followChainAndRequestNextBlock( + followChainAndRequestNextBlockPayload( newEpochInfo, mainChainInfo, lastPayload, @@ -994,16 +994,16 @@ class ELUpdater( .toRight(ClientError(s"Can't find a last block $referenceBlockHash of epoch #${lastEpoch.prevEpoch} on contract")) } yield referenceBlock } else { - val blockId = nodeChainInfo.firstBlock.parentHash + val blockHash = nodeChainInfo.firstBlock.parentHash chainContractClient - .getBlock(blockId) + .getBlock(blockHash) .toRight( - ClientError(s"Parent block $blockId for first block ${nodeChainInfo.firstBlock.hash} of chain ${nodeChainInfo.id} not found at contract") + ClientError(s"Parent block $blockHash for first block ${nodeChainInfo.firstBlock.hash} of chain ${nodeChainInfo.id} not found at contract") ) } } - private def validateAndApplyMissedBlock( + private def validateAndApplyMissed( epi: ExecutionPayloadInfo, prevState: Working[ChainStatus], contractBlock: ContractBlock, @@ -1065,7 +1065,7 @@ class ELUpdater( err => logger.error(s"Can't confirm block ${payload.hash} of chain ${nodeChainInfo.id}: ${err.message}"), _ => { logger.info(s"Successfully confirmed block ${payload.hash} of chain ${nodeChainInfo.id}") - followChainAndRequestNextBlock( + followChainAndRequestNextBlockPayload( prevState.epochInfo, nodeChainInfo, payload, @@ -1103,15 +1103,15 @@ class ELUpdater( } @tailrec - private def maybeRequestNextBlock(prevState: Working[FollowingChain], finalizedBlock: ContractBlock): Working[FollowingChain] = { + private def maybeRequestNextBlockPayload(prevState: Working[FollowingChain], finalizedBlock: ContractBlock): Working[FollowingChain] = { if (prevState.lastPayload.height < prevState.chainStatus.nodeChainInfo.lastBlock.height) { - logger.debug(s"EC chain is not synced, trying to find next block to request") + logger.debug(s"EC chain is not synced, trying to find next block to request payload") findBlockChild(prevState.lastPayload.hash, prevState.chainStatus.nodeChainInfo.lastBlock.hash) match { case Left(error) => logger.error(s"Could not find child of ${prevState.lastPayload.hash} on contract: $error") prevState case Right(contractBlock) => - requestPayload(contractBlock) match { + requestBlockPayload(contractBlock) match { case PayloadRequestResult.Exists(payload) => logger.debug(s"Block ${contractBlock.hash} payload exists at EC chain, trying to confirm") confirmBlock(payload, finalizedBlock) match { @@ -1121,7 +1121,7 @@ class ELUpdater( chainStatus = FollowingChain(prevState.chainStatus.nodeChainInfo, None) ) setState("7", newState) - maybeRequestNextBlock(newState, finalizedBlock) + maybeRequestNextBlockPayload(newState, finalizedBlock) case Left(err) => logger.error(s"Failed to confirm next block ${payload.hash}: ${err.message}") prevState @@ -1133,19 +1133,22 @@ class ELUpdater( } } } else { - logger.trace(s"EC chain ${prevState.chainStatus.nodeChainInfo.id} is synced, no need to request blocks") + logger.trace(s"EC chain ${prevState.chainStatus.nodeChainInfo.id} is synced, no need to request block payloads") prevState } } - private def mkRollbackBlock(rollbackTargetBlockId: BlockHash): JobResult[RollbackBlock] = for { - targetBlockDataOpt <- chainContractClient.getBlock(rollbackTargetBlockId) match { - case None => engineApiClient.getBlockByHash(rollbackTargetBlockId) + private def mkRollbackBlock(rollbackTargetBlockHash: BlockHash): JobResult[RollbackBlock] = for { + targetBlockDataOpt <- chainContractClient.getBlock(rollbackTargetBlockHash) match { + case None => engineApiClient.getBlockByHash(rollbackTargetBlockHash) case x => Right(x) } - targetBlockData <- Either.fromOption(targetBlockDataOpt, ClientError(s"Can't find block $rollbackTargetBlockId neither on a contract, nor in EC")) + targetBlockData <- Either.fromOption( + targetBlockDataOpt, + ClientError(s"Can't find block $rollbackTargetBlockHash neither on a contract, nor in EC") + ) parentPayloadOpt <- engineApiClient.getBlockByHash(targetBlockData.parentHash) - parentPayload <- Either.fromOption(parentPayloadOpt, ClientError(s"Can't find block $rollbackTargetBlockId parent payload in execution client")) + parentPayload <- Either.fromOption(parentPayloadOpt, ClientError(s"Can't find block $rollbackTargetBlockHash parent payload in execution client")) rollbackBlockOpt <- engineApiClient.applyNewPayload(EmptyPayload.mkExecutionPayloadJson(parentPayload)) rollbackBlock <- Either.fromOption(rollbackBlockOpt, ClientError("Rollback block hash is not defined as latest valid hash")) } yield RollbackBlock(rollbackBlock, parentPayload) @@ -1186,7 +1189,7 @@ class ELUpdater( } } yield rootHash - private def skipFinalizedBlocksValidation(curState: Working[ChainStatus]) = { + private def skipFinalizedBlocksValidation(curState: Working[ChainStatus]): Working[ChainStatus] = { if (curState.finalizedBlock.height > curState.fullValidationStatus.lastValidatedBlock.height) { val newState = curState.copy(fullValidationStatus = FullValidationStatus(curState.finalizedBlock, None)) setState("4", newState) @@ -1497,7 +1500,7 @@ object ELUpdater { val WaitForReferenceConfirmInterval: FiniteDuration = 500.millis val ClChangedProcessingDelay: FiniteDuration = 50.millis val MiningRetryInterval: FiniteDuration = 5.seconds - val WaitRequestedBlockTimeout: FiniteDuration = 2.seconds + val WaitRequestedPayloadTimeout: FiniteDuration = 2.seconds case class EpochInfo(number: Int, miner: Address, rewardAddress: EthAddress, hitSource: ByteStr, prevEpochLastBlockHash: Option[BlockHash]) @@ -1551,8 +1554,8 @@ object ELUpdater { case class ChainSwitchInfo(prevChainId: Long, referenceBlock: ContractBlock) - /** We haven't received a EC-block {@link missedBlock} of a previous epoch when started a mining on a new epoch. We can return to the main chain, if - * get a missed EC-block. + /** We haven't received block payload of a previous epoch when started a mining on a new epoch. We can return to the main chain, if get a missed + * block payload. */ case class ReturnToMainChainInfo(missedBlock: ContractBlock, missedBlockParentPayload: ExecutionPayload, chainId: Long) diff --git a/src/main/scala/units/network/HistoryReplier.scala b/src/main/scala/units/network/HistoryReplier.scala index 2a2c3814..b7083d46 100644 --- a/src/main/scala/units/network/HistoryReplier.scala +++ b/src/main/scala/units/network/HistoryReplier.scala @@ -31,9 +31,9 @@ class HistoryReplier(engineApiClient: EngineApiClient)(implicit sc: Scheduler) e ctx, loadPayload(hash) .map { - case Right(block) => - RawBytes(PayloadSpec.messageCode, PayloadSpec.serializeData(block)) - case Left(err) => throw new NoSuchElementException(s"Error loading block $hash: $err") + case Right(payloadMsg) => + RawBytes(PayloadSpec.messageCode, PayloadSpec.serializeData(payloadMsg)) + case Left(err) => throw new NoSuchElementException(s"Error loading block $hash payload: $err") } ) case _ => super.channelRead(ctx, msg) diff --git a/src/main/scala/units/network/PayloadMessage.scala b/src/main/scala/units/network/PayloadMessage.scala index 41366f33..59705e69 100644 --- a/src/main/scala/units/network/PayloadMessage.scala +++ b/src/main/scala/units/network/PayloadMessage.scala @@ -78,9 +78,9 @@ object PayloadMessage { .leftMap(err => s"Error creating payload message: $err") def apply(payloadBytes: Array[Byte], signature: Option[ByteStr]): Either[String, PayloadMessage] = for { - payload <- Try(Json.parse(payloadBytes).as[JsObject]).toEither.leftMap(err => s"Payload bytes are not a valid JSON object: ${err.getMessage}") - block <- apply(payload, signature) - } yield block + payload <- Try(Json.parse(payloadBytes).as[JsObject]).toEither.leftMap(err => s"Payload bytes are not a valid JSON object: ${err.getMessage}") + payloadMsg <- apply(payload, signature) + } yield payloadMsg def signed(payloadJson: JsObject, signer: PrivateKey): Either[String, PayloadMessage] = { val signature = crypto.sign(signer, Json.toBytes(payloadJson)) @@ -99,5 +99,5 @@ object PayloadMessage { } private def validateSignatureLength(signature: Option[ByteStr]): Either[String, Unit] = - Either.cond(signature.forall(_.size == SignatureLength), (), "Invalid block signature size") + Either.cond(signature.forall(_.size == SignatureLength), (), "Invalid payload signature size") } diff --git a/src/main/scala/units/util/HexBytesConverter.scala b/src/main/scala/units/util/HexBytesConverter.scala index d939087d..ae7721a0 100644 --- a/src/main/scala/units/util/HexBytesConverter.scala +++ b/src/main/scala/units/util/HexBytesConverter.scala @@ -1,7 +1,6 @@ package units.util import com.wavesplatform.common.state.ByteStr -import units.BlockHash import org.web3j.abi.datatypes.generated.Uint256 import org.web3j.utils.Numeric @@ -9,9 +8,6 @@ import java.math.BigInteger object HexBytesConverter { - def toByteStr(hash: BlockHash): ByteStr = - ByteStr(toBytes(hash)) - def toInt(intHex: String): Int = Numeric.toBigInt(intHex).intValueExact() diff --git a/src/test/scala/units/BlockFullValidationTestSuite.scala b/src/test/scala/units/BlockFullValidationTestSuite.scala index d222aa12..65ab7b19 100644 --- a/src/test/scala/units/BlockFullValidationTestSuite.scala +++ b/src/test/scala/units/BlockFullValidationTestSuite.scala @@ -27,11 +27,11 @@ class BlockFullValidationTestSuite extends BaseIntegrationTestSuite { val payload = d.createPayloadBuilder("0", reliable).buildAndSetLogs(blockLogs) d.advanceConsensusLayerChanged() - step(s"Receive network block ${payload.hash} with payload from a peer") + step(s"Receive block ${payload.hash} payload from a peer") d.receivePayload(payload, reliable.account) d.triggerScheduledTasks() - step(s"Append a CL micro block with payload ${payload.hash} confirmation") + step(s"Append a CL micro block with block ${payload.hash} confirmation") d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(reliable.account, payload)) d.advanceConsensusLayerChanged() @@ -55,11 +55,11 @@ class BlockFullValidationTestSuite extends BaseIntegrationTestSuite { val payload = d.createPayloadBuilder("0", reliable).buildAndSetLogs(blockLogs) d.advanceConsensusLayerChanged() - step(s"Receive network block ${payload.hash} with payload from a peer") + step(s"Receive block ${payload.hash} payload from a peer") d.receivePayload(payload, reliable.account) d.triggerScheduledTasks() - step(s"Append a CL micro block with payload ${payload.hash} confirmation") + step(s"Append a CL micro block with block ${payload.hash} confirmation") d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(reliable.account, payload, e2CTransfersRootHashHex)) d.advanceConsensusLayerChanged() @@ -98,11 +98,11 @@ class BlockFullValidationTestSuite extends BaseIntegrationTestSuite { val payload2 = badBlockPayloadPostProcessing(d.createPayloadBuilder("0-0", malfunction, payload1).rewardPrevMiner().buildAndSetLogs(blockLogs)) - step(s"Append a CL micro block with payload2 ${payload2.hash} confirmation") + step(s"Append a CL micro block with block2 ${payload2.hash} confirmation") d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(malfunction.account, payload2, e2CTransfersRootHashHex)) d.advanceConsensusLayerChanged() - step(s"Receive network block ${payload2.hash} with payload2 from a peer") + step(s"Receive block2 ${payload2.hash} payload2 from a peer") d.receivePayload(payload2, malfunction.account) d.triggerScheduledTasks() @@ -118,7 +118,7 @@ class BlockFullValidationTestSuite extends BaseIntegrationTestSuite { "Events from an unexpected EL bridge address" in { val fakeBridgeAddress = EthAddress.unsafeFrom("0x53481054Ad294207F6ed4B6C2E6EaE34E1Bb8704") - val block2Logs = transferEvents.map(x => getLogsResponseEntry(x).copy(address = fakeBridgeAddress)) + val block2Logs = transferEvents.map(x => getLogsResponseEntry(x).copy(address = fakeBridgeAddress)) e2CTest( blockLogs = block2Logs, e2CTransfersRootHashHex = e2CTransfersRootHashHex diff --git a/src/test/scala/units/BlockIssuesForgingTestSuite.scala b/src/test/scala/units/BlockIssuesForgingTestSuite.scala index e5e824a3..81b9a0c3 100644 --- a/src/test/scala/units/BlockIssuesForgingTestSuite.scala +++ b/src/test/scala/units/BlockIssuesForgingTestSuite.scala @@ -4,7 +4,7 @@ import com.wavesplatform.db.WithState.AddrWithBalance import com.wavesplatform.transaction.TxHelpers import com.wavesplatform.wallet.Wallet import units.ELUpdater.State.ChainStatus.{FollowingChain, Mining, WaitForNewChain} -import units.ELUpdater.WaitRequestedBlockTimeout +import units.ELUpdater.WaitRequestedPayloadTimeout import units.client.contract.HasConsensusLayerDappTxHelpers.defaultFees import units.client.engine.model.ExecutionPayload @@ -52,13 +52,13 @@ class BlockIssuesForgingTestSuite extends BaseIntegrationTestSuite { f(d, payload2, block2Epoch) } - "EC-block comes within timeout - then we continue forging" in test { (d, payload2, block2Epoch) => - d.advanceElu(WaitRequestedBlockTimeout - 1.millis) + "Block payload comes within timeout - then we continue forging" in test { (d, payload2, block2Epoch) => + d.advanceElu(WaitRequestedPayloadTimeout - 1.millis) d.waitForCS[FollowingChain](s"Still waiting payload2 ${payload2.hash}") { s => s.nextExpectedBlock.map(_.hash).value shouldBe payload2.hash } - step(s"Receive network block ${payload2.hash} with payload2") + step(s"Receive block2 ${payload2.hash} payload2") d.receivePayload(payload2, otherMiner1.account, block2Epoch) d.triggerScheduledTasks() @@ -69,13 +69,13 @@ class BlockIssuesForgingTestSuite extends BaseIntegrationTestSuite { } } - "Network block with payload doesn't come - then we start an alternative chain" in test { (d, _, _) => + "Block payload doesn't come - then we start an alternative chain" in test { (d, _, _) => d.waitForCS[WaitForNewChain](s"Switched to alternative chain") { _ => } } } "We're on the alternative chain and" - { - "Network block with payload comes within timeout - then we continue forging" in withExtensionDomain() { d => + "Block payload comes within timeout - then we continue forging" in withExtensionDomain() { d => step(s"Start a new epoch of otherMiner1 ${otherMiner1.address} with payload1") d.advanceNewBlocks(otherMiner1.address) val payload1 = d.createPayloadBuilder("0", otherMiner1).buildAndSetLogs() @@ -135,7 +135,7 @@ class BlockIssuesForgingTestSuite extends BaseIntegrationTestSuite { step(s"Start a new epoch of thisMiner ${thisMiner.address}") d.advanceNewBlocks(thisMiner.address) d.advanceConsensusLayerChanged() - d.advanceElu(WaitRequestedBlockTimeout - 1.millis) + d.advanceElu(WaitRequestedPayloadTimeout - 1.millis) d.waitForCS[FollowingChain](s"Waiting payload3 ${payload3.hash}") { s => s.nodeChainInfo.isMain shouldBe false @@ -143,7 +143,7 @@ class BlockIssuesForgingTestSuite extends BaseIntegrationTestSuite { s.nextExpectedBlock.map(_.hash).value shouldBe payload3.hash } - step(s"Receive network block ${payload3.hash} with payload3") + step(s"Receive block3 ${payload3.hash} payload3") d.receivePayload(payload3, thisMiner.account, block3Epoch) d.ecClients.willForge(d.createPayloadBuilder("0-1-1-1", thisMiner, payload3).rewardPrevMiner(2).build()) @@ -152,73 +152,72 @@ class BlockIssuesForgingTestSuite extends BaseIntegrationTestSuite { } } - "We mined before the alternative chain before and network block with payload doesn't come - then we still wait for it" in withExtensionDomain() { - d => - step(s"Start a new epoch of otherMiner1 ${otherMiner1.address} with payload1") - d.advanceNewBlocks(otherMiner1.address) - val payload1 = d.createPayloadBuilder("0", otherMiner1).buildAndSetLogs() - d.ecClients.addKnown(payload1) - d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(otherMiner1.account, payload1)) + "We mined before the alternative chain before and block payload doesn't come - then we still wait for it" in withExtensionDomain() { d => + step(s"Start a new epoch of otherMiner1 ${otherMiner1.address} with payload1") + d.advanceNewBlocks(otherMiner1.address) + val payload1 = d.createPayloadBuilder("0", otherMiner1).buildAndSetLogs() + d.ecClients.addKnown(payload1) + d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(otherMiner1.account, payload1)) - d.waitForCS[FollowingChain]() { s => - s.nodeChainInfo.isMain shouldBe true - s.nodeChainInfo.lastBlock.hash shouldBe payload1.hash - } + d.waitForCS[FollowingChain]() { s => + s.nodeChainInfo.isMain shouldBe true + s.nodeChainInfo.lastBlock.hash shouldBe payload1.hash + } - step(s"Start a new epoch of otherMiner1 ${otherMiner1.address} with badPayload2") - d.advanceNewBlocks(otherMiner1.address) - val badPayload2 = d.createPayloadBuilder("0-0", otherMiner1, payload1).rewardPrevMiner().buildAndSetLogs() - d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(otherMiner1.account, badPayload2)) + step(s"Start a new epoch of otherMiner1 ${otherMiner1.address} with badPayload2") + d.advanceNewBlocks(otherMiner1.address) + val badPayload2 = d.createPayloadBuilder("0-0", otherMiner1, payload1).rewardPrevMiner().buildAndSetLogs() + d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(otherMiner1.account, badPayload2)) - d.waitForCS[FollowingChain]() { s => - s.nodeChainInfo.isMain shouldBe true - s.nodeChainInfo.lastBlock.hash shouldBe badPayload2.hash - } + d.waitForCS[FollowingChain]() { s => + s.nodeChainInfo.isMain shouldBe true + s.nodeChainInfo.lastBlock.hash shouldBe badPayload2.hash + } - step(s"Start a new epoch of thisMiner ${thisMiner.address} with alternative chain payload2") - d.advanceNewBlocks(thisMiner.address) - val payload2 = d.createPayloadBuilder("0-1", thisMiner, payload1).rewardPrevMiner().buildAndSetLogs() - d.ecClients.willForge(payload2) - d.ecClients.willForge(d.createPayloadBuilder("0-1-i", thisMiner, payload2).buildAndSetLogs()) + step(s"Start a new epoch of thisMiner ${thisMiner.address} with alternative chain payload2") + d.advanceNewBlocks(thisMiner.address) + val payload2 = d.createPayloadBuilder("0-1", thisMiner, payload1).rewardPrevMiner().buildAndSetLogs() + d.ecClients.willForge(payload2) + d.ecClients.willForge(d.createPayloadBuilder("0-1-i", thisMiner, payload2).buildAndSetLogs()) - d.waitForCS[Mining]() { s => - val ci = s.nodeChainInfo.left.value - ci.referenceBlock.hash shouldBe payload1.hash - } + d.waitForCS[Mining]() { s => + val ci = s.nodeChainInfo.left.value + ci.referenceBlock.hash shouldBe payload1.hash + } - d.advanceMining() - d.forgeFromUtxPool() + d.advanceMining() + d.forgeFromUtxPool() - d.waitForCS[Mining]() { s => - val ci = s.nodeChainInfo.value - ci.lastBlock.hash shouldBe payload2.hash - } + d.waitForCS[Mining]() { s => + val ci = s.nodeChainInfo.value + ci.lastBlock.hash shouldBe payload2.hash + } - step(s"Continue an alternative chain by otherMiner2 ${otherMiner2.address} with badPayload3") - d.advanceNewBlocks(otherMiner2.address) - val badPayload3 = d.createPayloadBuilder("0-1-1", otherMiner2, payload2).rewardMiner(otherMiner2.elRewardAddress, 1).buildAndSetLogs() - d.appendMicroBlockAndVerify(d.chainContract.extendAltChain(otherMiner2.account, badPayload3, chainId = 1)) + step(s"Continue an alternative chain by otherMiner2 ${otherMiner2.address} with badPayload3") + d.advanceNewBlocks(otherMiner2.address) + val badPayload3 = d.createPayloadBuilder("0-1-1", otherMiner2, payload2).rewardMiner(otherMiner2.elRewardAddress, 1).buildAndSetLogs() + d.appendMicroBlockAndVerify(d.chainContract.extendAltChain(otherMiner2.account, badPayload3, chainId = 1)) - d.waitForCS[FollowingChain]() { s => - s.nodeChainInfo.isMain shouldBe false - s.nodeChainInfo.lastBlock.hash shouldBe badPayload3.hash - s.nextExpectedBlock.map(_.hash).value shouldBe badPayload3.hash - } + d.waitForCS[FollowingChain]() { s => + s.nodeChainInfo.isMain shouldBe false + s.nodeChainInfo.lastBlock.hash shouldBe badPayload3.hash + s.nextExpectedBlock.map(_.hash).value shouldBe badPayload3.hash + } - step(s"Continue an alternative chain by thisMiner ${thisMiner.address}") - d.advanceNewBlocks(thisMiner.address) + step(s"Continue an alternative chain by thisMiner ${thisMiner.address}") + d.advanceNewBlocks(thisMiner.address) - d.advanceWaitRequestedBlock() - d.advanceWaitRequestedBlock() + d.advanceWaitRequestedBlockPayload() + d.advanceWaitRequestedBlockPayload() - d.waitForCS[FollowingChain](s"Still wait for badPayload3 ${badPayload3.hash}") { s => - s.nodeChainInfo.isMain shouldBe false - s.nodeChainInfo.lastBlock.hash shouldBe badPayload3.hash - s.nextExpectedBlock.map(_.hash).value shouldBe badPayload3.hash - } + d.waitForCS[FollowingChain](s"Still wait for badPayload3 ${badPayload3.hash}") { s => + s.nodeChainInfo.isMain shouldBe false + s.nodeChainInfo.lastBlock.hash shouldBe badPayload3.hash + s.nextExpectedBlock.map(_.hash).value shouldBe badPayload3.hash + } } - "We haven't mined the alternative chain before and network block with payload doesn't come - then we wait for a new alternative chain" in + "We haven't mined the alternative chain before and block payload doesn't come - then we wait for a new alternative chain" in withExtensionDomain() { d => step(s"Start a new epoch of otherMiner1 ${otherMiner1.address} with payload1") d.advanceNewBlocks(otherMiner1.address) diff --git a/src/test/scala/units/E2CTransfersTestSuite.scala b/src/test/scala/units/E2CTransfersTestSuite.scala index 5093da6b..612acfcc 100644 --- a/src/test/scala/units/E2CTransfersTestSuite.scala +++ b/src/test/scala/units/E2CTransfersTestSuite.scala @@ -21,7 +21,7 @@ class E2CTransfersTestSuite extends BaseIntegrationTestSuite { private val transferReceiver = TxHelpers.secondSigner private val transfer = Bridge.ElSentNativeEvent(transferReceiver.toAddress, 1) private val transferEvent = getLogsResponseEntry(transfer) - private val blockLogs = List(transferEvent) + private val blockLogs = List(transferEvent) private val e2CTransfersRootHashHex = HexBytesConverter.toHex(Bridge.mkTransfersHash(blockLogs).explicitGet()) private val transferProofs = Bridge.mkTransferProofs(List(transfer), 0).reverse // Contract requires from bottom to top @@ -63,7 +63,7 @@ class E2CTransfersTestSuite extends BaseIntegrationTestSuite { tryWithdraw() should produce("not found for the contract address") - step("Append a CL micro block with payload confirmation") + step("Append a CL micro block with block confirmation") d.ecClients.addKnown(payload) d.appendMicroBlockAndVerify(d.chainContract.extendMainChain(reliable.account, payload, e2CTransfersRootHashHex)) d.advanceConsensusLayerChanged() diff --git a/src/test/scala/units/ExtensionDomain.scala b/src/test/scala/units/ExtensionDomain.scala index 72e60491..10959c0a 100644 --- a/src/test/scala/units/ExtensionDomain.scala +++ b/src/test/scala/units/ExtensionDomain.scala @@ -134,7 +134,7 @@ class ExtensionDomain( triggers = triggers.appended(consensusClient) val defaultMaxTimeout: FiniteDuration = - List(WaitForReferenceConfirmInterval, ClChangedProcessingDelay, MiningRetryInterval, WaitRequestedBlockTimeout).max + 1.millis + List(WaitForReferenceConfirmInterval, ClChangedProcessingDelay, MiningRetryInterval, WaitRequestedPayloadTimeout).max + 1.millis val defaultInterval: FiniteDuration = ClChangedProcessingDelay def waitForWorking( @@ -292,8 +292,8 @@ class ExtensionDomain( // See ELUpdater.consensusLayerChanged def advanceConsensusLayerChanged(): Unit = advanceElu(ELUpdater.ClChangedProcessingDelay, "advanceConsensusLayerChanged") - // See ELUpdater.requestBlocksAndStartMining - def advanceWaitRequestedBlock(): Unit = advanceElu(ELUpdater.WaitRequestedBlockTimeout, "advanceWaitRequestedBlock") + // See ELUpdater.requestPayloadsAndStartMining + def advanceWaitRequestedBlockPayload(): Unit = advanceElu(ELUpdater.WaitRequestedPayloadTimeout, "advanceWaitRequestedBlockPayload") def advanceMiningRetry(): Unit = advanceElu(ELUpdater.MiningRetryInterval, "advanceMiningRetry") diff --git a/src/test/scala/units/network/TestPayloadObserver.scala b/src/test/scala/units/network/TestPayloadObserver.scala index e8033cec..d9fc1186 100644 --- a/src/test/scala/units/network/TestPayloadObserver.scala +++ b/src/test/scala/units/network/TestPayloadObserver.scala @@ -18,7 +18,7 @@ class TestPayloadObserver(messages: Observable[PayloadMessage], allChannels: Def new ConcurrentHashMap[BlockHash, PayloadMessage]() override def loadPayload(req: BlockHash): CancelableFuture[ExecutionPayloadInfo] = { - log.debug(s"loadBlock($req)") + log.debug(s"loadPayload($req)") CancelableFuture.never }