utils: use a cleaner pattern to capture wally allocations.

We force use of tal_wally_start/tal_wally_end around every wally
allocation, and with "end" make the caller choose where to reparent
everything.

This is particularly powerful where we allocate a tx or a psbt: we
want that tx or psbt to be the parent of the other allocations, so
this way we can reparent the tx or psbt, then reparent everything
else onto it.

Implementing psbt_finalize (which uses a behavior flag antipattern)
was tricky, so I ended up splitting that into 'psbt_finalize' and
'psbt_final_tx', which I think also makes the callers clearer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2020-09-23 20:13:28 +09:30
committed by Christian Decker
parent 66ffd7a73f
commit d5cb0d85b5
15 changed files with 225 additions and 148 deletions

View File

@@ -84,8 +84,11 @@ void setup_tmpctx(void);
/* Free any children of tmpctx. */
void clean_tmpctx(void);
/* Steal any wally allocations onto this context. */
void tal_gather_wally(const tal_t *ctx);
/* Call this before any libwally function which allocates. */
void tal_wally_start(void);
/* Then call this to reparent everything onto this parent (which must
* have been tal_steal() if it was allocated by libwally here) */
void tal_wally_end(const tal_t *parent);
/* Define sha256_eq. */
STRUCTEQ_DEF(sha256, 0, u);