-
Notifications
You must be signed in to change notification settings - Fork 266
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
Common format for transaction logging #423
Conversation
|
||
txsToRemove.add(tx); | ||
continue; | ||
} | ||
|
||
if (!expectedNonce.equals(txNonce)) { | ||
logger.warn("Invalid nonce, expected {}, found {}, tx {}", expectedNonce.toString(), txNonce.toString(), Hex.toHexString(tx.getHash())); | ||
logger.warn("Invalid nonce, expected {}, found {}, tx={}", expectedNonce, txNonce, hexHash); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we log the BigInteger
nonce, vs the Hex.toHexString(nonce)
before. we should make it consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
String hash = null == tx.getHash() ? "" : Hex.toHexString(tx.getHash()); | ||
logger.warn("Error when processing transaction: " + hash, e); | ||
String hash = null == tx.getHash() ? "" : Hex.toHexString(tx.getHash());; | ||
logger.warn(String.format("Error when processing tx=%s" + hash), e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's a bug here. you're concatenating instead of formatting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
} catch (Exception e) { | ||
// Txs that can't be selected by any reason should be removed from pending state | ||
String hash = null == tx.getHash() ? "" : Hex.toHexString(tx.getHash()); | ||
logger.warn("Error when processing transaction: " + hash, e); | ||
String hash = null == tx.getHash() ? "" : Hex.toHexString(tx.getHash());; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove extra semicolon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
panicProcessor.panic("invalidmingasprice", "Tx gas price is under the Min gas Price of the block"); | ||
String logMessage = String.format("Tx gas price is under the Min gas Price of the block tx=%s", Hex.toHexString(tx.getHash())); | ||
logger.warn(logMessage); | ||
panicProcessor.panic("invalidmingasprice", logMessage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This panic can be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll remove it in the other PR 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good
} catch (Exception e) { | ||
// Txs that can't be selected by any reason should be removed from pending state | ||
String hash = null == tx.getHash() ? "" : Hex.toHexString(tx.getHash()); | ||
logger.warn("Error when processing transaction: " + hash, e); | ||
logger.warn(String.format("Error when processing tx=%s", hash), e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to use String.format instead of {} in log message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because if we use {} we lose the ability to hold the stack trace of the exception. The method that allows a Throwable only allows sending a plain String
@@ -49,8 +50,9 @@ public boolean isValid(Block block) { | |||
if(CollectionUtils.isNotEmpty(block.getTransactionsList())) { | |||
for (Transaction tx : txs) { | |||
if (!(tx instanceof RemascTransaction) && tx.getGasPriceAsInteger().compareTo(blockMgp) < 0) { | |||
logger.warn("Tx gas price is under the Min gas Price of the block"); | |||
panicProcessor.panic("invalidmingasprice", "Tx gas price is under the Min gas Price of the block"); | |||
String logMessage = String.format("Tx gas price is under the Min gas Price of the block tx=%s", Hex.toHexString(tx.getHash())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment, why use String.format in one place, and log message with {} in other places?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here the idea was to avoid doing string formatting 2 times for warning and panic. Maybe in the other PR this panic disappears and makes less sense doing things like this.
} | ||
|
||
@Override | ||
public void setGasLimit(byte[] gasLimit) { | ||
throw new ImmutableTransactionException("trying to set gas limit"); | ||
throw new ImmutableTransactionException(String.format("trying to set gas limit tx=%s", Hex.toHexString(this.getHash()))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The String.format FORCES the execution and concatenation of the references expressions. Log message with {} only invokes .toString when the message level is on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I'm adding some info on the Exception, I was tryng to avoid simple concatenation
be4d638
to
02300c1
Compare
02300c1
to
a639f95
Compare
SonarQube analysis reported 27 issues Top 10 issues
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved
Transactions now use a basic format tx=transaction-hash