Skip to content

refactor(protocol): extract shared MastForestScript type - #3516

Merged
bobbinth merged 2 commits into
nextfrom
zeapoz/refactor-note-transaction-script
Aug 7, 2026
Merged

refactor(protocol): extract shared MastForestScript type#3516
bobbinth merged 2 commits into
nextfrom
zeapoz/refactor-note-transaction-script

Conversation

@zeapoz

@zeapoz zeapoz commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Closes #3189

Extracts the MastForestScript type and MastForestScriptError that back both NoteScript and TransactionScript, moving TransactionScript into its own transaction::script module. The wrappers now delegate to the shared type instead of duplicating the logic, and resolution errors are unified under MastForestScriptError.

@zeapoz
zeapoz force-pushed the zeapoz/refactor-note-transaction-script branch 2 times, most recently from d998e12 to ef51882 Compare August 6, 2026 14:45
@zeapoz
zeapoz force-pushed the zeapoz/refactor-note-transaction-script branch 2 times, most recently from 90c8b8a to 7ccbbcf Compare August 7, 2026 08:52
@zeapoz
zeapoz marked this pull request as ready for review August 7, 2026 08:59

@PhilippGackstatter PhilippGackstatter left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, great observation!

Left comments for potential follow-ups.

Comment on lines +70 to +74
Self {
mast,
entrypoint,
package_debug_info: None,
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might not be from this PR, and does not need to be addressed here, but can we refactor this so we have a single place where the type is instantiated (Self { ... })?

I think not following this rule is the number 1 cause of all bugs we've encountered so far. We've had countless instances where some constructor did and some other did not enforce a check. Having a single place for instantiating a struct makes it way easier to reason about. (Recent examples: #3411, #3494). This type is a good example of being hard to reason about, as we have four places where the struct is instantiated, so understanding what the type really enforces is hard.

We have also mostly moved away from panicking constructors, and I would suggest removing it. That would be especially good because we use it in deserialization code, and we should definitely not panic there.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fully agree here! It should be relatively easy to refactor such that from_parts is the canonical instantatior returning a Result<Self, MastForestScriptError>. All other methods could just wrap it with their own invariant checks.

In any case, I think these are better left for a follow-up PR.

Comment on lines +79 to +83
pub(crate) fn from_parts_with_package_debug_info(
package: &Package,
mast: Arc<MastForest>,
entrypoint: MastNodeId,
) -> Self {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like an internal helper and it reads a bit awkward, since the MastForest being passed is the one from Package, so it feels redundant. Consider removing it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. It's only used in TransactionScript::from_package currently, so I think it'd be good to tackle this in tandem with #3516 (comment).

@bobbinth bobbinth left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you!

@bobbinth
bobbinth added this pull request to the merge queue Aug 7, 2026
Merged via the queue into next with commit 75c4aaf Aug 7, 2026
19 checks passed
@bobbinth
bobbinth deleted the zeapoz/refactor-note-transaction-script branch August 7, 2026 20:41
@Sertug17

Sertug17 commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Agree completely this is exactly the pattern I flagged in #3494 for BlockSignatures::read_from. Happy to open a PR for that fix as well once #3494 gets a green light.

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.

Refactor code out of NoteScript and TransactionScript

4 participants