Anoma.Node.Intents.Solver (Anoma v0.29.0)

I am a strawman intent solver for testing purposes.

Public API

I have the following public functionality:

Summary

Types

t()

I hold the state for the solver process.

Functions

Returns a specification to start this module under a supervisor.

I am the core function responsible for solving.

I am a function for getting unsolved intents from the solver.

Given a list of intents, I attempt to find a subset of them that can be composed and verified and return it as a set.

I am a start_link function of the Solver.

I provide the submit functionality for the solver.

I generate all possible subsets of a given list of elements as a stream.

I check if a list of intents is valid by composing them and verifying if they satisfy the Intent.valid? predicate.

Types

@type t() :: %Anoma.Node.Intents.Solver{
  node_id: String.t() | nil,
  unsolved: MapSet.t(Anoma.RM.Intent.t())
}

I hold the state for the solver process.

Fields

  • :unsolved - The set of unsolved intents.
              Default: MapSet.new()
  • :node_id - The ID of the Node to which the Solver is connected.

Functions

Link to this function

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

do_solve(state)

@spec do_solve(t()) :: t()

I am the core function responsible for solving.

I use the solve function to grab the first (maximal) composable subset of intents from those given in the state. Then filter out whichever ones are present in the result and return the remaining ones.

Given a proper intent structure, I also submit it to the mempool using an appropriate wrapper.

Link to this function

get_unsolved(node_id)

@spec get_unsolved(String.t()) :: [Anoma.RM.Intent.t()]

I am a function for getting unsolved intents from the solver.

I dump the state of the solver converting the set of the unsolved intents into a list.

Given a list of intents, I attempt to find a subset of them that can be composed and verified and return it as a set.

I assume that the composition of intents is associative and commutative.

Link to this function

start_link(args)

@spec start_link([{:node_id, String.t()}]) :: GenServer.on_start()

I am a start_link function of the Solver.

I expect a keylist containing a node ID as startup argument.

Link to this function

submit(tx, node_id)

@spec submit(Anoma.RM.Intent.t(), String.t()) :: :ok

I provide the submit functionality for the solver.

Given something solved, I submit it to the Mempool with the provided ID.

Pattern-Matching Variations

  • submit(%TransparentResource.Transaction{}, node_id) - I wrap a transaction in trivial
                                                        core and send it to the Mempool.
  • submit(any, node_id) - I do nothing
@spec subsets([Anoma.RM.Intent.t()]) :: Enumerable.t()

I generate all possible subsets of a given list of elements as a stream.

Link to this function

valid?(intents)

@spec valid?([Anoma.RM.Intent.t()]) :: true | {:error, any()}

I check if a list of intents is valid by composing them and verifying if they satisfy the Intent.valid? predicate.