-
Notifications
You must be signed in to change notification settings - Fork 267
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
Refactor rlp #2175
base: master
Are you sure you want to change the base?
Refactor rlp #2175
Conversation
a5f6dc8
to
bd8d819
Compare
Kudos, SonarCloud Quality Gate passed! |
throw new RuntimeException("Unsupported type: Only accepting String, Integer and BigInteger for now"); | ||
} | ||
|
||
private static final int OFFSET_SHORT_ITEM = 0x80; |
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.
Just a NIT, I suggest you move these constants declaration to the beginning of the class.
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.
LGTM
pipeline:run |
@ilanolkies could you please rebase your PR? The pipeline fails and that could be due to a bit outdated version of master the pr is based on.. |
pipeline:run |
@ilanolkies, seems the pipeline fails with on the powpeg jar building phase:
it looks like the powpeg code should be refactored as well according to your changes |
pipeline:run |
Quality Gate passedThe SonarCloud Quality Gate passed, but some issues were introduced. 3 New issues |
pipeline:run |
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.
LGTM
Description
This pull request is a refactor and it adds minor bug fixing. It shouldn't change any existing functionality, modifying test cases was avoided.
Remove unused methods
Remove methods from RLP class that are not used like decode set or full traverse
Remove type detection
encode(Object input)
was removed in favor of methods likeencodeRskAddress
that express the type of the element to be encoded. The overhead of detecting the type of the element, produced for example by creatingValue
class, is unnecessary since the developer needs to understand the protocol to know what element is decoded.(See also https://github.com/rsksmart/rskj/security/code-scanning/2392 triggered in this PR)
Similarly,
decode2
is removed in favor ofdecodeList
. Note that the overhead produce for detecting if the element was a string or a list is visible calls like(RLPList) RLP.decode2(rlpEncoded).get(0);
, two lists are created for decoding a single list.The methods were moved to test utilities to prevent modifying the tests (
RLPTestUtil
)Replace for constants
Constants hardcoded in the code are replaced for the respective
static final
constant. Also, duplicated constants were removed.Remove
decodeInt
and fixbyteArrayToInt
The method
decodeInt
is bugged. Thedata
might not fit in theint
. The method is removed in favor ofByteUtil.byteArrayToInt
inFrameCoded
that is used in other places.The method
decodeInt
had the same bug, but is fixed by comparing toInteger.MAX_VALUE
with intermediateBigInteger
conversion. The conversion was already in the code so it doesn’t add significant overhead.Fix
toGas
andbyteArrayToLong
It follows from the considerations mentioned above.
byteArrayToLong
now favors only naturals big endian.toGas
will returnLong.MAX_VALUE
on overflowing values, being gas limit natural number.Motivation and Context
Researching on RLP now 👍
How Has This Been Tested?
Almost no new implementation was written, existent unit tests stand as source of trust. Test was added for fixed bug.
Types of changes
Checklist:
fed:refactor-rlp