Skip to content

Commit

Permalink
Savepoint
Browse files Browse the repository at this point in the history
  • Loading branch information
InversionSpaces committed Jul 5, 2023
1 parent ed14fb7 commit 3625e87
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ trait After {
case (e, a, _) if e == a => Chain.empty
case (e, a, l) if l.contains(e) =>
// Pingback in case no relays involved
Chain.fromOption(a.headOption.map(_.peerId))
Chain.fromOption(
a.headOption
.filterNot(e.headOption.contains)
.map(_.peerId)
)
case (e, a, _) =>
// We wasn't at e, so need to get through the last peer in case it matches with the relay
Topology.findRelayPathEnforcement(a, e) ++ Chain.fromOption(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package aqua.model.transform.topology.strategy

import aqua.model.transform.topology.Topology
import aqua.model.{OnModel, ParGroupModel, SeqGroupModel, ValueModel}
import aqua.model.{OnModel, ParGroupModel, SeqGroupModel, ValueModel, XorModel}

import cats.Eval
import cats.data.Chain
import cats.syntax.functor.*
import cats.instances.lazyList.*
import cats.syntax.option.*

// Parent == Xor
object XorBranch extends Before with After {
Expand All @@ -13,24 +16,26 @@ object XorBranch extends Before with After {
override def beforeOn(current: Topology): Eval[List[OnModel]] =
current.prevSibling.map(_.endsOn) getOrElse super.beforeOn(current)

private def closestParExit(current: Topology): Option[Topology] =
private def closestParExitChild(current: Topology): Option[Topology] =
current.parents
.map(t => t -> t.parent.map(_.cursor.op))
.takeWhile {
case (t, Some(_: ParGroupModel)) => true
case (t, Some(_: SeqGroupModel)) => t.nextSibling.isEmpty
.fproduct(_.parent.map(_.cursor.op))
.dropWhile {
case (t, Some(_: SeqGroupModel)) =>
t.nextSibling.isEmpty
case (_, Some(XorModel)) =>
true
case _ => false
}
.map(_._1)
.map(t => t -> t.cursor.op)
.collectFirst { case (t, _: ParGroupModel) =>
// println(Console.GREEN + s"collect ${t}" + Console.RESET)
t
}
.headOption
.collect { case (t, Some(_: ParGroupModel)) => t }

private def closestParExit(current: Topology): Option[Topology] =
closestParExitChild(current).flatMap(_.parent)

override def forceExit(current: Topology): Eval[Boolean] =
closestParExit(current)
.fold(Eval.later(current.cursor.moveUp.exists(_.hasExecLater)))(_.forceExit)
closestParExitChild(current).fold(
Eval.later(current.cursor.moveUp.exists(_.hasExecLater))
)(_.forceExit)

override def afterOn(current: Topology): Eval[List[OnModel]] =
current.forceExit.flatMap {
Expand All @@ -41,5 +46,8 @@ object XorBranch extends Before with After {

// Parent of this branch's parent xor – fixes the case when this xor is in par
override def pathAfter(current: Topology): Eval[Chain[ValueModel]] =
closestParExit(current).fold(super.pathAfter(current))(_ => pathAfterAndPingNext(current))
closestParExit(current).fold(super.pathAfter(current))(_ =>
println(s"here ${current.cursor.op}")
super.pathAfterAndPingNext(current)
)
}

0 comments on commit 3625e87

Please sign in to comment.