Skip to content

Commit

Permalink
"WE-8917-fix-error-execution"
Browse files Browse the repository at this point in the history
  • Loading branch information
egnatovskiy committed Jul 11, 2024
1 parent b625394 commit 37dbc1a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,12 @@ object ApiError extends IntEnum[ApiError] {
override val message: String = s"Contract transaction too big, actual size $wrongSize bytes, expected size $rightSize bytes"
}

case class ContractExecutionNotFound(txId: ByteStr) extends ApiError {
case class ContractExecutionNotFound(txId: ByteStr, ignoreSuccessful: Boolean) extends ApiError {
override val value: Int = 605
override val code: StatusCode = StatusCodes.NotFound
override val message: String = s"Contract execution result is not found for transaction with txId = '$txId'"
override val message: String =
s"Contract execution result is not found for transaction with txId = '$txId'. ${if (ignoreSuccessful) "Transaction with Success status are ignored"
else ""}"
}

case class ParticipantNotRegistered(unregisteredAddress: Address) extends ApiError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class ContractsApiService(
def executionStatuses(transactionId: ByteStr): Either[ApiError, Seq[ContractExecutionMessage]] = {
messagesCache.get(transactionId) match {
case Some(messages) => Right(messages.toSeq.sortBy(_.timestamp))
case None => Left(ContractExecutionNotFound(transactionId))
case None => Left(ContractExecutionNotFound(transactionId, messagesCache.settings.ignoreSuccessful))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import java.util.concurrent.TimeUnit
* Cache for [[ContractExecutionMessage]]
*/
class ContractExecutionMessagesCache(
settings: ContractExecutionMessagesCacheSettings,
val settings: ContractExecutionMessagesCacheSettings,
dockerMiningEnabled: Boolean,
activePeerConnections: ActivePeerConnections,
utx: UtxPool,
Expand All @@ -43,6 +43,7 @@ class ContractExecutionMessagesCache(

def put(txId: ByteStr, message: ContractExecutionMessage): Unit = {
saveToCache(txId, message)
log.debug(s"Status execution TX from contract: ${message.status}, Setting ignoreSuccessful: ${settings.ignoreSuccessful}")
if (message.status != ContractExecutionStatus.Success || !settings.ignoreSuccessful)
activePeerConnections.broadcast(NetworkContractExecutionMessage(message))
}
Expand Down Expand Up @@ -107,6 +108,7 @@ class ContractExecutionMessagesCache(
messages.foreach {
case (_, networkMessage @ NetworkContractExecutionMessage(message)) =>
saveToCache(message.txId, message)
log.debug(s"Status execution TX from contract: ${message.status}, Setting ignoreSuccessful: ${settings.ignoreSuccessful}")
if (message.status != ContractExecutionStatus.Success || !settings.ignoreSuccessful)
activePeerConnections.writeMsg(networkMessage, channelMatcher)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ class ContractsApiRouteSpec extends RouteSpec("/contracts")
Get(routePath(s"/status/$notFoundTxId")) ~> route ~> check {
status shouldBe StatusCodes.NotFound
val response = responseAs[JsObject]
(response \ "message").as[String] shouldBe s"Contract execution result is not found for transaction with txId = '$notFoundTxId'"
(response \ "message").as[String] shouldBe s"Contract execution result is not found for transaction with txId = '$notFoundTxId'. "
}
}

Expand Down

0 comments on commit 37dbc1a

Please sign in to comment.