Skip to content

feat(abci): indicate lock-free calls via ctx - #5791

Merged
swift1337 merged 1 commit into
mainfrom
feat/check-tx-ctx-main
Apr 17, 2026
Merged

swift1337 merged 1 commit into
mainfrom
feat/check-tx-ctx-main

Conversation

@swift1337

Copy link
Copy Markdown
Member

Context

To support rpc.BroadcastTxSync() while leveraging Krakatoa on the EVM, we added client.CheckTxUnlocked().

I feel that this API can be expressed in a concise and idiomatic way. This PR replaces checkTxUnlocked with ctx key:

ctx = client.LockFreeContext(ctx)
app.CheckTx(ctx, req)

PR checklist

  • Tests written/updated
  • Changelog entry added in CHANGELOG.md
  • Updated relevant documentation (docs/ or spec/) and code comments

@swift1337 swift1337 self-assigned this Apr 17, 2026
@swift1337
swift1337 marked this pull request as ready for review April 17, 2026 16:20
@swift1337
swift1337 requested a review from a team as a code owner April 17, 2026 16:20
@greptile-apps

greptile-apps Bot commented Apr 17, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR replaces the former CheckTxUnlocked API with a context-key approach (client.LockFreeContext / client.IsLockFreeContext) so localClient.CheckTx can skip its mutex when the caller explicitly opts in. The implementation is clean and idiomatic; the only finding is a minor test correctness issue in the "ok-no-callback" sub-case.

Confidence Score: 5/5

Safe to merge — the lock-free context key pattern is correct and no production logic is broken.

All findings are P2 (test naming / coverage gap). The production path in localClient.CheckTx correctly guards with IsLockFreeContext, the unexported key type prevents accidental collisions, and the context is properly propagated through appConnMempool.

mempool/app_mempool_test.go — the "ok-no-callback" sub-test case is missing noCallback: true.

Important Files Changed

Filename Overview
abci/client/client.go Adds lockFreeCallCtxKey, LockFreeContext, and IsLockFreeContext — clean idiomatic context-key pattern with unexported key type and exported helpers.
abci/client/local_client.go CheckTx now skips the mutex when IsLockFreeContext(ctx) is true; all other methods are unchanged and still acquire the lock unconditionally.
mempool/app_mempool.go Replaces the implicit lock-free convention with explicit client.LockFreeContext(m.ctx) before calling app.CheckTx in the async goroutine.
mempool/app_mempool_test.go Test for "ok-no-callback" is missing noCallback: true, so the nil-callback code path is never actually exercised — it runs as a redundant "ok" variant.
mempool/app_reactor_test.go Integration test for AppReactor gossip; no changes to test structure, only adds mock setup for the client.
proxy/app_conn.go Passthrough layer for AppConnMempool; forwards context as-is so the lock-free key propagates correctly to localClient.
proxy/mocks/app_conn_mempool.go Auto-generated mock updated to include InsertTx and ReapTxs methods added to the AppConnMempool interface.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant AppMempool
    participant appConnMempool
    participant localClient
    participant Application

    Caller->>AppMempool: CheckTx(tx, callback, _)
    AppMempool->>AppMempool: guardTx(tx)
    AppMempool->>AppMempool: ctx = LockFreeContext(m.ctx)
    AppMempool->>AppMempool: go func()
    AppMempool-->>Caller: nil (async)

    Note over AppMempool: goroutine
    AppMempool->>appConnMempool: CheckTx(lockFreeCtx, req)
    appConnMempool->>localClient: CheckTx(lockFreeCtx, req)
    localClient->>localClient: IsLockFreeContext(ctx) == true → skip mtx.Lock()
    localClient->>Application: CheckTx(lockFreeCtx, req)
    Application-->>localClient: ResponseCheckTx
    localClient-->>appConnMempool: ResponseCheckTx
    appConnMempool-->>AppMempool: ResponseCheckTx
    AppMempool->>AppMempool: callback(res) if callback != nil
Loading

Comments Outside Diff (1)

  1. mempool/app_mempool_test.go, line 99-102 (link)

    P2 "ok-no-callback" doesn't actually test the nil-callback path

    noCallback defaults to false, so callback is non-nil for this case and the goroutine will invoke it, storing a result. The require.Eventually(t, ensureResult, …) assertion then passes trivially, meaning the if callback != nil guard in AppMempool.CheckTx is never exercised. Adding noCallback: true would make it test the right path, but that requires removing or skipping the require.Eventually assertion for that sub-case (otherwise the test would time out waiting for a result that's never stored).

    The assertion block should also guard against the no-callback case — require.Eventually will always time out when no callback is provided, so it needs a corresponding if !tt.noCallback guard around that assertion.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: mempool/app_mempool_test.go
    Line: 99-102
    
    Comment:
    **"ok-no-callback" doesn't actually test the nil-callback path**
    
    `noCallback` defaults to `false`, so `callback` is non-nil for this case and the goroutine will invoke it, storing a result. The `require.Eventually(t, ensureResult, …)` assertion then passes trivially, meaning the `if callback != nil` guard in `AppMempool.CheckTx` is never exercised. Adding `noCallback: true` would make it test the right path, but that requires removing or skipping the `require.Eventually` assertion for that sub-case (otherwise the test would time out waiting for a result that's never stored).
    
    The assertion block should also guard against the no-callback case — `require.Eventually` will always time out when no callback is provided, so it needs a corresponding `if !tt.noCallback` guard around that assertion.
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: mempool/app_mempool_test.go
Line: 99-102

Comment:
**"ok-no-callback" doesn't actually test the nil-callback path**

`noCallback` defaults to `false`, so `callback` is non-nil for this case and the goroutine will invoke it, storing a result. The `require.Eventually(t, ensureResult, …)` assertion then passes trivially, meaning the `if callback != nil` guard in `AppMempool.CheckTx` is never exercised. Adding `noCallback: true` would make it test the right path, but that requires removing or skipping the `require.Eventually` assertion for that sub-case (otherwise the test would time out waiting for a result that's never stored).

The assertion block should also guard against the no-callback case — `require.Eventually` will always time out when no callback is provided, so it needs a corresponding `if !tt.noCallback` guard around that assertion.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "simplify CheckTx w/o lock" | Re-trigger Greptile

@swift1337
swift1337 enabled auto-merge April 17, 2026 16:27
@swift1337
swift1337 added this pull request to the merge queue Apr 17, 2026
Merged via the queue into main with commit 9fcf861 Apr 17, 2026
35 checks passed
@swift1337
swift1337 deleted the feat/check-tx-ctx-main branch April 17, 2026 16:39
mattac21 pushed a commit that referenced this pull request May 4, 2026
**Context**

To support `rpc.BroadcastTxSync()` while leveraging Krakatoa on the EVM,
we added `client.CheckTxUnlocked()`.

I feel that this API can be expressed in a concise and idiomatic way.
This PR replaces checkTxUnlocked with ctx key:

```go
ctx = client.LockFreeContext(ctx)
app.CheckTx(ctx, req)
```
---

#### PR checklist

- [x] Tests written/updated
- [ ] Changelog entry added in `CHANGELOG.md`
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments
kevindharmawan pushed a commit to SeeMoReLab/cometbft that referenced this pull request Jul 30, 2026
**Context**

To support `rpc.BroadcastTxSync()` while leveraging Krakatoa on the EVM,
we added `client.CheckTxUnlocked()`.

I feel that this API can be expressed in a concise and idiomatic way.
This PR replaces checkTxUnlocked with ctx key:

```go
ctx = client.LockFreeContext(ctx)
app.CheckTx(ctx, req)
```
---

#### PR checklist

- [x] Tests written/updated
- [ ] Changelog entry added in `CHANGELOG.md`
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments
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.

2 participants