Skip to content

Plan driven strategy#88

Draft
arminsabouri wants to merge 10 commits into
masterfrom
plan-driven
Draft

Plan driven strategy#88
arminsabouri wants to merge 10 commits into
masterfrom
plan-driven

Conversation

@arminsabouri

Copy link
Copy Markdown
Contributor

I'll get a more comprehensive description up. Drafting this for now. Some of these commits may get subdivided further into other Prs

   The existing MultipartyStrategy recomputed input selection and change
   decomposition inline on every enumeration call. There was no persistent
   record of which action sequences were still viable, so the wallet redid
   the same BNB and change math every wake cycle and had no way to rank
   competing paths against each other before committing to one.

   Introduce the core plan tree types:

   - StepAction: a single RegisterInput or RegisterOutput event
   - PlanNode: one tree node carrying an action and its continuations
   - PlanTree: the full tree with a depth counter that tracks how many
     actions have been committed so far

   generate_input_candidates produces up to k disjoint input sets by
   running BNB iteratively, excluding previously selected coins each round,
   and falling back to spend-all when BNB finds nothing.

   build_plan_tree assembles a PlanTree from pre-computed input sets:
   sorts inputs by denomination fit, builds a linear RegisterInput chain,
   prepends fixed payment outputs, then attaches the branching change
   decomposition produced by DenominationMenu (introduced in the parent
   commit).
  Adds commit() to advance the cursor to a chosen StepAction (pruning all
  siblings), next_actions() to enumerate live choices at the current depth,
  reachable_leaves() to collect all root-to-leaf action paths from the cursor,
  and committed_inputs() to compute outpoints present on every reachable path.
  Includes CommitError for invalid commit attempts and full test coverage.
Introduces PeerState to carry observed participant inputs and outputs from
the bulletin board. Adds score_leaves() to re-rank all reachable leaf paths
using CompositeScorer, and plan_from_path() to reconstruct a Plan from a
leaf action sequence plus peer state for scoring purposes.
Adds wallet_plan_tree and selected_plan_branch fields to WalletData.
Advances the tree cursor as outputs and inputs are registered during
session participation, and resets both fields when a session completes
so a fresh plan is built on the next wake.
Adds an optional pre_enumerate() method to Strategy, called once per
wake_up before action enumeration, for strategies to build or update
persistent state such as a plan tree. When a selected_plan_branch is
already set, wake_up skips scoring and takes the first non-Wait action
directly.
Rewrites enumerate_candidate_actions to use the wallet_plan_tree and
selected_plan_branch from WalletData instead of recomputing coin
selection inline. Idle step now registers only the branch's committed
inputs and proposes cospend using those UTXOs. Output contribution uses
change amounts derived from the selected branch when available, falling
back to the previous heuristic. Removes CostBracket and bracket().
Renames the strategy to PlanDrivenStrategy throughout.
Replaces MultipartyStrategy with PlanDrivenStrategy in the allowlist
and adds missing min_fallback_plans fields to the example config.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant