Commit ee2637c
authored
Replace mutex with sync.Map for ABI caching (#218)
### TL;DR
Replace mutex-protected map with sync.Map for ABI caching to improve concurrency.
### What changed?
- Replaced the manual mutex-protected map implementation with Go's built-in `sync.Map` for ABI caching
- Modified `GetABIForContractWithCache` to use `sync.Map` methods (`Load`, `Store`) instead of manual locking
- Removed mutex parameters from function signatures in `DecodeLogs` and `DecodeTransactions`
- Simplified the concurrent processing of logs and transactions by eliminating explicit mutex handling
### How to test?
1. Run concurrent processing of logs and transactions to verify that ABI caching works correctly
2. Verify that decoded logs and transactions contain the expected data
3. Check for any race conditions or deadlocks that might have been introduced
### 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.
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit
- **Refactor**
- Improved concurrency handling for ABI caching, resulting in more reliable and efficient processing of logs and transactions.
- Simplified internal logic for decoding logs and transactions, reducing potential synchronization issues.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->3 files changed
+27
-32
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
51 | 41 | | |
52 | 42 | | |
53 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
54 | 51 | | |
55 | 52 | | |
56 | 53 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
| 90 | + | |
91 | 91 | | |
92 | | - | |
| 92 | + | |
93 | 93 | | |
94 | | - | |
| 94 | + | |
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
112 | 111 | | |
113 | 112 | | |
114 | | - | |
| 113 | + | |
115 | 114 | | |
116 | 115 | | |
117 | 116 | | |
118 | 117 | | |
119 | | - | |
120 | | - | |
| 118 | + | |
| 119 | + | |
121 | 120 | | |
122 | 121 | | |
123 | 122 | | |
124 | 123 | | |
| 124 | + | |
125 | 125 | | |
126 | | - | |
127 | 126 | | |
128 | 127 | | |
129 | | - | |
| 128 | + | |
130 | 129 | | |
131 | | - | |
| 130 | + | |
132 | 131 | | |
133 | 132 | | |
134 | 133 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
114 | | - | |
| 113 | + | |
| 114 | + | |
115 | 115 | | |
116 | | - | |
| 116 | + | |
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
142 | | - | |
143 | 142 | | |
144 | 143 | | |
145 | | - | |
| 144 | + | |
146 | 145 | | |
147 | | - | |
| 146 | + | |
148 | 147 | | |
149 | | - | |
| 148 | + | |
150 | 149 | | |
151 | 150 | | |
152 | 151 | | |
| |||
0 commit comments