Skip to content

Commit 8cca4bb

Browse files
committed
[FAB-16315] Unrequired lock
Change-Id: Ifc885b6e702a4722a8f5296c97e1c1a44f98d8c5 Signed-off-by: Matthew B. White <[email protected]>
1 parent bd59b34 commit 8cca4bb

File tree

1 file changed

+2
-47
lines changed
  • fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/impl

1 file changed

+2
-47
lines changed

fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/impl/Handler.java

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ public class Handler {
6767

6868
private static Logger logger = Logger.getLogger(Handler.class.getName());
6969
private final Chaincode chaincode;
70-
private final Map<String, Boolean> isTransaction = new HashMap<>();
7170
private final Map<String, Channel<ChaincodeMessage>> responseChannel = new HashMap<>();
7271
private Channel<ChaincodeMessage> outboundChaincodeMessages = new Channel<>();
7372
private CCState state;
@@ -236,28 +235,6 @@ private synchronized void releaseResponseChannelForTx(String channelId, String t
236235
}
237236
}
238237

239-
/**
240-
* Marks a CHANNELID+UUID as either a transaction or a query
241-
*
242-
* @param uuid ID to be marked
243-
* @param isTransaction true for transaction, false for query
244-
* @return whether or not the UUID was successfully marked
245-
*/
246-
private synchronized boolean markIsTransaction(String channelId, String uuid, boolean isTransaction) {
247-
if (this.isTransaction == null) {
248-
return false;
249-
}
250-
251-
String key = getTxKey(channelId, uuid);
252-
this.isTransaction.put(key, isTransaction);
253-
return true;
254-
}
255-
256-
private synchronized void deleteIsTransaction(String channelId, String uuid) {
257-
String key = getTxKey(channelId, uuid);
258-
isTransaction.remove(key);
259-
}
260-
261238
/**
262239
* Handles requests to initialize chaincode
263240
*
@@ -270,9 +247,6 @@ private void handleInit(ChaincodeMessage message) {
270247
// Get the function and args from Payload
271248
final ChaincodeInput input = ChaincodeInput.parseFrom(message.getPayload());
272249

273-
// Mark as a transaction (allow put/del state)
274-
markIsTransaction(message.getChannelId(), message.getTxid(), true);
275-
276250
// Create the ChaincodeStub which the chaincode can use to
277251
// callback
278252
final ChaincodeStub stub = new ChaincodeStubImpl(message.getChannelId(), message.getTxid(), this, input.getArgsList(), message.getProposal());
@@ -294,9 +268,6 @@ private void handleInit(ChaincodeMessage message) {
294268
} catch (InvalidProtocolBufferException | RuntimeException e) {
295269
logger.severe(format("[%-8.8s] Init failed. Sending %s: %s", message.getTxid(), ERROR, e));
296270
queueOutboundChaincodeMessage(newErrorEventMessage(message.getChannelId(), message.getTxid(), e));
297-
} finally {
298-
// delete isTransaction entry
299-
deleteIsTransaction(message.getChannelId(), message.getTxid());
300271
}
301272
}).start();
302273
}
@@ -309,9 +280,6 @@ private void handleTransaction(ChaincodeMessage message) {
309280
// Get the function and args from Payload
310281
final ChaincodeInput input = ChaincodeInput.parseFrom(message.getPayload());
311282

312-
// Mark as a transaction (allow put/del state)
313-
markIsTransaction(message.getChannelId(), message.getTxid(), true);
314-
315283
// Create the ChaincodeStub which the chaincode can use to
316284
// callback
317285
final ChaincodeStub stub = new ChaincodeStubImpl(message.getChannelId(), message.getTxid(), this, input.getArgsList(), message.getProposal());
@@ -334,9 +302,6 @@ private void handleTransaction(ChaincodeMessage message) {
334302
} catch (InvalidProtocolBufferException | RuntimeException e) {
335303
logger.severe(format("[%-8.8s] Invoke failed. Sending %s: %s", message.getTxid(), ERROR, e));
336304
queueOutboundChaincodeMessage(newErrorEventMessage(message.getChannelId(), message.getTxid(), e));
337-
} finally {
338-
// delete isTransaction entry
339-
deleteIsTransaction(message.getChannelId(), message.getTxid());
340305
}
341306
}).start();
342307
}
@@ -363,28 +328,18 @@ Map<String, ByteString> getStateMetadata(String channelId, String txId, String c
363328
}
364329
}
365330

366-
private boolean isTransaction(String channelId, String uuid) {
367-
String key = getTxKey(channelId, uuid);
368-
return isTransaction.containsKey(key) && isTransaction.get(key);
369-
}
370-
371-
void putState(String channelId, String txId, String collection, String key, ByteString value) {
331+
void putState(String channelId, String txId, String collection, String key, ByteString value) {
372332
if (logger.isLoggable(Level.FINE)) {
373-
logger.fine(format("[%-8.8s] Inside putstate (\"%s\":\"%s\":\"%s\"), isTransaction = %s", txId, collection, key, value, isTransaction(channelId, txId)));
333+
logger.fine(format("[%-8.8s] Inside putstate (\"%s\":\"%s\":\"%s\")", txId, collection, key, value));
374334
}
375-
if (!isTransaction(channelId, txId)) throw new IllegalStateException("Cannot put state in query context");
376335
invokeChaincodeSupport(newPutStateEventMessage(channelId, txId, collection, key, value));
377336
}
378337

379338
void putStateMetadata(String channelId, String txId, String collection, String key, String metakey, ByteString value) {
380-
if (!isTransaction(channelId, txId)) {
381-
throw new IllegalStateException("Cannot put state metadata in query context");
382-
}
383339
invokeChaincodeSupport(newPutStateMatadateEventMessage(channelId, txId, collection, key, metakey, value));
384340
}
385341

386342
void deleteState(String channelId, String txId, String collection, String key) {
387-
if (!isTransaction(channelId, txId)) throw new RuntimeException("Cannot del state in query context");
388343
invokeChaincodeSupport(newDeleteStateEventMessage(channelId, txId, collection, key));
389344
}
390345

0 commit comments

Comments
 (0)