Skip to content

feat: add global default hooks to MultiHookRouter#28

Open
JhiNResH wants to merge 2 commits intoerc-8183:mainfrom
JhiNResH:feat/global-hook-defaults
Open

feat: add global default hooks to MultiHookRouter#28
JhiNResH wants to merge 2 commits intoerc-8183:mainfrom
JhiNResH:feat/global-hook-defaults

Conversation

@JhiNResH
Copy link
Copy Markdown

@JhiNResH JhiNResH commented Apr 15, 2026

Summary

Builds on #21 — adds global default hooks that run for all jobs without per-job configuration.

Use case

When all jobs share the same hook pipeline (e.g. trust gate → trust update → attestation), the operator sets global hooks once at deploy time. New jobs automatically inherit them — zero per-job config, zero extra gas per job creation.

// Set once by owner
router.addGlobalHook(address(trustGate));
router.addGlobalHook(address(trustUpdate));
router.addGlobalHook(address(attestation));

// Every new job gets all three — no configureHooks() needed

Changes

File What
MultiHookRouter.sol +108 lines: _globalHooks storage, addGlobalHook/removeGlobalHook/reorderGlobalHooks, _resolveHooks fallback, resolveHooks view
test/MultiHookRouter.t.sol 13 tests: admin CRUD, resolution fallback, per-job override, max cap, no-op

Design decisions

  • Ordered array (not priority-sorted) — matches feat: add MultiHookRouter for composable per-job hooks #21's per-job hook style
  • MAX_GLOBAL_HOOKS = 10 — same gas safety cap as per-job
  • Per-job always wins_resolveHooks returns per-job if length > 0, else global
  • No mixing — a job runs either its per-job hooks or all global hooks, never both (keeps gas predictable)

Test plan

  • forge test --match-contract MultiHookRouterGlobalTest — 13/13 pass
  • Review: global hook admin (add/remove/reorder/max cap)
  • Review: resolution logic (per-job override, global fallback, empty no-op)

ariessa and others added 2 commits March 28, 2026 01:35
Jobs without per-job hooks now fall back to owner-configured global
defaults — useful when all jobs share the same pipeline (e.g. trust
gate → trust update → attestation) without per-job setup or extra gas.

Adds: addGlobalHook, removeGlobalHook, reorderGlobalHooks, resolveHooks
view, and 13 tests covering admin, resolution fallback, and per-job
override.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ariessa
Copy link
Copy Markdown
Contributor

ariessa commented Apr 17, 2026

Hi @JhiNResH,

I looked at your PR and saw that it is using MultiHookRouter V1 from PR #21. I've since updated PR #21 with MultiHookRouter V2, which addresses some scalability limitations in V1.

In MultiHookRouter V1, every hook receives the same optParams bytes, so hooks that need their own parameters must share a combined encoding where each reads specific byte offsets. This works fine for 1-2 hooks, but adding a third means every existing hook needs to know the new field layout. The coordination cost grows with each hook added.

MultiHookRouter V2 dispatches a separate optParams slice to each hook, so they don't need to know about each other's data format. Each cross-contract call carries its own isolated payload. It also lets you register hooks per selector instead of a single list for all functions, so hooks only run where they're actually needed.

Feel free to pull the latest changes, open a new PR with your improvements, and keep it small so it's easier to review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants