Skip to content
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

Merged
merged 2 commits into from
Feb 2, 2018
Merged

Conversation

lsebrie
Copy link
Contributor

@lsebrie lsebrie commented Jan 17, 2018

Transactions now use a basic format tx=transaction-hash


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);
Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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());;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove extra semicolon

Copy link
Contributor Author

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);
Copy link
Collaborator

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

Copy link
Contributor Author

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 😅

Copy link
Collaborator

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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()));
Copy link
Contributor

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?

Copy link
Contributor Author

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())));
Copy link
Contributor

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.

Copy link
Contributor Author

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

@lsebrie lsebrie force-pushed the tx_logging_format branch 2 times, most recently from be4d638 to 02300c1 Compare January 22, 2018 15:41
@aeidelman aeidelman added this to the Bamboo v0.4.1 milestone Jan 22, 2018
ajlopezrsk
ajlopezrsk previously approved these changes Feb 1, 2018
@rskops
Copy link
Collaborator

rskops commented Feb 2, 2018

SonarQube analysis reported 27 issues

  • MAJOR 17 major
  • MINOR 4 minor
  • INFO 6 info

Top 10 issues

  1. MAJOR MinerUtils.java#L71: Define and throw a dedicated exception instead of using a generic one. rule
  2. MAJOR MinerUtils.java#L109: Define and throw a dedicated exception instead of using a generic one. rule
  3. MAJOR MinerUtils.java#L120: Define and throw a dedicated exception instead of using a generic one. rule
  4. MAJOR MinerUtils.java#L196: Method co.rsk.mine.MinerUtils.filterTransactions(List, List, Map, Repository, BigInteger) does not presize the allocation of a collection rule
  5. MAJOR TxsMinGasPriceRule.java#L39: Remove this unused "panicProcessor" private field. rule
  6. MAJOR HandshakeHandler.java#L101: Method org.ethereum.net.rlpx.HandshakeHandler.decode(ChannelHandlerContext, ByteBuf, List) passes a concatenated string to SLF4J's format string rule
  7. MAJOR HandshakeHandler.java#L142: The Cyclomatic Complexity of this method "decodeHandshake" is 15 which is greater than 10 authorized. rule
  8. MAJOR HandshakeHandler.java#L142: Define and throw a dedicated exception instead of using a generic one. rule
  9. MAJOR HandshakeHandler.java#L160: Either log or rethrow this exception. rule
  10. MAJOR HandshakeHandler.java#L180: Method org.ethereum.net.rlpx.HandshakeHandler.decodeHandshake(ChannelHandlerContext, ByteBuf) passes a concatenated string to SLF4J's format string rule

Copy link
Collaborator

@aeidelman aeidelman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

@aeidelman aeidelman merged commit 1ee92ae into master Feb 2, 2018
@aeidelman aeidelman deleted the tx_logging_format branch February 2, 2018 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants