Skip to content

Commit

Permalink
feat(log): disable log for getMerkleTreeKey
Browse files Browse the repository at this point in the history
  • Loading branch information
halibobo1205 committed Jul 16, 2024
1 parent 5f113c4 commit 0be66bb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,10 @@ public static boolean isOpenZen() {
}

private static void log(int c, byte[] ... params) {
GlobalContext.getHeader().ifPresent(header -> logger.info("{}:{}:{}", header, c,
Stream.of(params).map(ByteArray::toHexString).collect(Collectors.joining(","))));
if (GlobalContext.isLog()) {
GlobalContext.getHeader().ifPresent(header -> logger.info("{}:{}:{}", header, c,
Stream.of(params).map(ByteArray::toHexString).collect(Collectors.joining(","))));
}
}

private static byte[] l2B(long value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.tron.common.context.GlobalContext;
import org.tron.core.capsule.IncrementalMerkleTreeCapsule;
import org.tron.core.capsule.PedersenHashCapsule;
import org.tron.core.exception.ZksnarkException;
Expand Down Expand Up @@ -62,14 +63,18 @@ public void resetCurrentMerkleTree() {

public void saveCurrentMerkleTreeAsBestMerkleTree(long blockNum) throws ZksnarkException {
IncrementalMerkleTreeContainer treeContainer = getCurrentMerkle();
setBestMerkle(blockNum, treeContainer);
putMerkleTreeIntoStore(treeContainer.getMerkleTreeKey(), treeContainer.getTreeCapsule());
byte[] key = setBestMerkle(blockNum, treeContainer);
putMerkleTreeIntoStore(key, treeContainer.getTreeCapsule());
}

public void setBestMerkle(long blockNum, IncrementalMerkleTreeContainer treeContainer)
public byte[] setBestMerkle(long blockNum, IncrementalMerkleTreeContainer treeContainer)
throws ZksnarkException {
incrementalMerkleTreeStore.put(lastTreeKey, treeContainer.getTreeCapsule());
merkleTreeIndexStore.put(blockNum, treeContainer.getMerkleTreeKey());
GlobalContext.disableLog();
byte[] key = treeContainer.getMerkleTreeKey();
GlobalContext.enableLog();
merkleTreeIndexStore.put(blockNum, key);
return key;
}

public boolean merkleRootExist(byte[] rt) {
Expand Down
14 changes: 14 additions & 0 deletions common/src/main/java/org/tron/common/context/GlobalContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ public class GlobalContext {

private static final ThreadLocal<Long> HEADER = new ThreadLocal<>();

private static final ThreadLocal<Boolean> LOG = ThreadLocal.withInitial(() -> true);

private GlobalContext() {
}

Expand All @@ -20,4 +22,16 @@ public static void setHeader(long header) {
public static void removeHeader() {
HEADER.remove();
}

public static boolean isLog() {
return LOG.get();
}

public static void enableLog() {
LOG.set(true);
}

public static void disableLog() {
LOG.set(false);
}
}

0 comments on commit 0be66bb

Please sign in to comment.