File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
framework/src/main/java/org/tron/core/services/jsonrpc Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -117,6 +117,11 @@ public enum RequestSource {
117117 .maximumSize (300_000L ) // 300s * tps(1000) * 1 log/tx ≈ 300_000
118118 .expireAfterWrite (EXPIRE_SECONDS , TimeUnit .SECONDS )
119119 .recordStats ().build (); //LRU cache
120+ private static final Cache <String , String > blockHashCache =
121+ CacheBuilder .newBuilder ()
122+ .maximumSize (60_000L ) // 300s * 200 block/s when syncing
123+ .expireAfterWrite (EXPIRE_SECONDS , TimeUnit .SECONDS )
124+ .recordStats ().build (); //LRU cache
120125 /**
121126 * for log filter in Full Json-RPC
122127 */
@@ -194,7 +199,16 @@ public static void handleBLockFilter(BlockFilterCapsule blockFilterCapsule) {
194199 it .remove ();
195200 continue ;
196201 }
197- entry .getValue ().getResult ().add (ByteArray .toJsonHex (blockFilterCapsule .getBlockHash ()));
202+ String blockHash = ByteArray .toJsonHex (blockFilterCapsule .getBlockHash ());
203+ String finalBlockHash = blockHash ;
204+ try {
205+ // compare with hashcode() first, then with equals(). If not exist, put it.
206+ blockHash = blockHashCache .get (blockHash , () -> finalBlockHash );
207+ } catch (ExecutionException e ) {
208+ logger .error ("Getting/loading blockHash from cache fails" , e );// never happen
209+ continue ;
210+ }
211+ entry .getValue ().getResult ().add (blockHash );
198212 }
199213 }
200214
You can’t perform that action at this time.
0 commit comments