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

Issue #1032 Use null safe method for bytes to hex string conversion #1069

Merged
merged 4 commits into from
May 16, 2018

Conversation

kishansagathiya
Copy link
Contributor

This is does not include all such cases
Fix for #1032

@zilm13 Since I would be using the same approach throughout all such cases, i just wanted to get this validated if this approach looks good to you.

@kishansagathiya
Copy link
Contributor Author

@zilm13 If you are ok with static imports, I will use the same thing throughout all files wherever I make changes

@coveralls
Copy link

coveralls commented May 9, 2018

Coverage Status

Coverage decreased (-0.2%) to 55.861% when pulling a5f4e74 on kishansagathiya:issue_1032 into cac6ade on ethereum:develop.

@kishansagathiya kishansagathiya changed the title [WIP] Issue #1032 Use null safe method for bytes to hex string conversion Issue #1032 Use null safe method for bytes to hex string conversion May 9, 2018
@kishansagathiya
Copy link
Contributor Author

To avoid making this a huge PR, I have added changes only to the implementation and once this is merged I will make another for test, Is that cool?

Also, I have made changes only at those place where we are printing or logging some message ( i.e, logs, some println, exception or error messages etc ). Have avoided changing toString() functions. I can do that with subsequent PRs with making sure that my new change don't avoid throwing an error that should been thrown otherwise.

@zilm13
Copy link
Collaborator

zilm13 commented May 9, 2018

@kishansagathiya

Have avoided changing toString() functions

We need to change them too. It's object logging that fails in case of one field is null.

You'd better move file by file, so I could check that it's done for this file but as you already did it for many files, just add it to toString methods too and I will check everything together. From first view you did it ok, but it needs more attention with branch checkout before merge, so it's better to finish it for toString methods too or any other methods that are called from logging.

@kishansagathiya kishansagathiya changed the title Issue #1032 Use null safe method for bytes to hex string conversion [WIP]Issue #1032 Use null safe method for bytes to hex string conversion May 11, 2018
@kishansagathiya kishansagathiya changed the title [WIP]Issue #1032 Use null safe method for bytes to hex string conversion Issue #1032 Use null safe method for bytes to hex string conversion May 11, 2018
@kishansagathiya
Copy link
Contributor Author

kishansagathiya commented May 11, 2018

@zilm13 ready for review. I hope none of the toString() methods are being used for anything except logging, otherwise this might break things.

Copy link
Collaborator

@zilm13 zilm13 left a comment

Choose a reason for hiding this comment

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

Looks good, but few changes required according to comments.

And it would be good!

@@ -45,6 +44,7 @@
import static org.ethereum.util.ByteUtil.toHexString;
import static org.ethereum.vm.VMUtils.saveProgramTraceFile;
import static org.ethereum.vm.VMUtils.zipAndEncode;
import static org.ethereum.util.ByteUtil.toHexString;
Copy link
Collaborator

Choose a reason for hiding this comment

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

duplicate import

@@ -40,6 +40,7 @@
import java.util.concurrent.locks.ReentrantReadWriteLock;

import static java.lang.System.arraycopy;
import static org.ethereum.util.ByteUtil.toHexString;
Copy link
Collaborator

Choose a reason for hiding this comment

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

unused org.spongycastle.util.encoders.Hex import above

@@ -25,6 +25,8 @@
import java.util.ArrayList;
import java.util.List;

import static org.ethereum.util.ByteUtil.toHexString;
Copy link
Collaborator

Choose a reason for hiding this comment

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

unused org.spongycastle.util.encoders.Hex import above

@@ -25,6 +25,8 @@

import java.math.BigInteger;

import static org.ethereum.util.ByteUtil.toHexString;
Copy link
Collaborator

Choose a reason for hiding this comment

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

unused org.spongycastle.util.encoders.Hex import above

@@ -25,6 +25,8 @@

import java.math.BigInteger;

import static org.ethereum.util.ByteUtil.toHexString;
Copy link
Collaborator

Choose a reason for hiding this comment

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

unused org.spongycastle.util.encoders.Hex import above

@@ -101,7 +97,7 @@ public String toString() {
long currTime = System.currentTimeMillis() / 1000;

String out = String.format("[PongMessage] \n token: %s \n expires in %d seconds \n %s\n",
Hex.toHexString(token), (expires - currTime), super.toString());
ByteUtil.toHexString(token), (expires - currTime), super.toString());
Copy link
Collaborator

Choose a reason for hiding this comment

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

correct spacing, please

Hex.toHexString(lastHash.getData()),
Hex.toHexString(coinbase.getLast20Bytes()),
ByteUtil.toHexString(callValue.getNoLeadZeroesData()),
data == null ? "" : ByteUtil.toHexString(data),
Copy link
Collaborator

Choose a reason for hiding this comment

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

As you've changed it to null-safe, condition checking is no more required

This commit replaces use of
`org.spongycastle.util.encoders.Hex.toHexString()` (Not null safe) with
`org.ethereum.util.ByteUtil.toHexString()` (null safe) while logging
and in all toString() methods.

This covers only logging in the implementation(`/src/main`) and doesn't
cover any logging in tests(`/src/tests`)

Issue ethereum#1032
`hint` and `contract` are only being used in logs. Changing the
toHexString function for them should not break anything.

Issue ethereum#1032
Removed unused imports and other changes as asked for

Issue ethereum#1032
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is weird. The comment is not changed at all, but GitHub is showing it to be changed.

@@ -225,7 +225,7 @@ public void onPendingTransactionUpdate(TransactionReceipt txReceipt, PendingTran
}

public void requestFreeEther(byte[] addressBytes) {
String address = "0x" + Hex.toHexString(addressBytes);
String address = "0x" + toHexString(addressBytes);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

address is used only for logging, so no harm changing it here.

import static org.apache.commons.lang3.ArrayUtils.isEmpty;
import static org.apache.commons.lang3.ArrayUtils.nullToEmpty;
import static org.ethereum.util.ByteUtil.toHexString;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because duplicate imports

@@ -1255,7 +1255,7 @@ else if (oldValue != null && newValue.isZero()) {
program.setHReturn(hReturn);

if (logger.isInfoEnabled())
hint = "data: " + Hex.toHexString(hReturn)
hint = "data: " + toHexString(hReturn)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

hint is used only in logs

@@ -1401,7 +1401,7 @@ private void dumpLine(OpCode op, long gasBefore, long gasCost, long memWords, Pr
}

int level = program.getCallDeep();
String contract = Hex.toHexString(program.getOwnerAddress().getLast20Bytes());
String contract = toHexString(program.getOwnerAddress().getLast20Bytes());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

contract is used only in logs

@zilm13 zilm13 merged commit e6a5dd6 into ethereum:develop May 16, 2018
@zilm13
Copy link
Collaborator

zilm13 commented May 16, 2018

Thank you!

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.

3 participants