Repository navigation
feat(abci): indicate lock-free calls via ctx - #5791
Conversation
Greptile SummaryThis PR replaces the former Confidence Score: 5/5Safe 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 mempool/app_mempool_test.go — the "ok-no-callback" sub-test case is missing
|
| 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
Comments Outside Diff (1)
-
mempool/app_mempool_test.go, line 99-102 (link)"ok-no-callback" doesn't actually test the nil-callback path
noCallbackdefaults tofalse, socallbackis non-nil for this case and the goroutine will invoke it, storing a result. Therequire.Eventually(t, ensureResult, …)assertion then passes trivially, meaning theif callback != nilguard inAppMempool.CheckTxis never exercised. AddingnoCallback: truewould make it test the right path, but that requires removing or skipping therequire.Eventuallyassertion 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.Eventuallywill always time out when no callback is provided, so it needs a correspondingif !tt.noCallbackguard 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
**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
**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
Context
To support
rpc.BroadcastTxSync()while leveraging Krakatoa on the EVM, we addedclient.CheckTxUnlocked().I feel that this API can be expressed in a concise and idiomatic way. This PR replaces checkTxUnlocked with ctx key:
PR checklist
CHANGELOG.mddocs/orspec/) and code comments