-
Notifications
You must be signed in to change notification settings - Fork 19
Replace mutex with sync.Map for ABI caching #218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThread-safe caching for contract ABIs was refactored across the codebase by replacing manual map and mutex usage with Go's Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant DecodeFunc
participant ABI_Cache(sync.Map)
participant ABI_Loader
Caller->>DecodeFunc: Start decoding (log/transaction)
DecodeFunc->>ABI_Cache: Load ABI for contract
alt ABI found in cache
ABI_Cache-->>DecodeFunc: Return cached ABI
else ABI not found
DecodeFunc->>ABI_Loader: Fetch ABI from source
alt Fetch success
ABI_Loader-->>DecodeFunc: Return ABI
DecodeFunc->>ABI_Cache: Store ABI in cache
else Fetch error
ABI_Loader-->>DecodeFunc: Return nil
DecodeFunc->>ABI_Cache: Store nil in cache
end
end
DecodeFunc-->>Caller: Return decoded result
Possibly related PRs
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
🧰 Additional context used🧬 Code Graph Analysis (1)internal/common/log.go (1)
🔇 Additional comments (6)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
c864a90
to
666bea0
Compare
666bea0
to
5196a3f
Compare
TL;DR
Replace mutex-protected map with sync.Map for ABI caching to improve concurrency.
What changed?
sync.Map
for ABI cachingGetABIForContractWithCache
to usesync.Map
methods (Load
,Store
) instead of manual lockingDecodeLogs
andDecodeTransactions
How to test?
Why make this change?
The previous implementation used a manual mutex to protect a map during concurrent access, which can lead to contention and reduced performance.
sync.Map
is specifically designed for concurrent use cases where items are frequently read but infrequently updated, which matches the ABI caching pattern. This change improves code safety and performance by using a more appropriate concurrency primitive.Summary by CodeRabbit