-
Notifications
You must be signed in to change notification settings - Fork 370
Feature: Truncate transaction bytes before persisting them to the database #1635
Conversation
2bbdc51
to
712022c
Compare
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.
Overall it looks good, the regression tests failed however as a result of the expansion logic. I made it work locally with a quick patch so adding those few lines should finish it off.
byte[] txDataBytes = new byte[Transaction.SIZE]; | ||
int numOfBytesOfSigMsgFragToExpand = referenceSize - data.length; | ||
byte[] sigMsgFragPadding = new byte[numOfBytesOfSigMsgFragToExpand]; | ||
int sigMsgFragBytesToCopy = data.length - TransactionTruncator.NON_SIG_TX_PART_BYTES_LENGTH; |
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.
@luca-moser Tests fail due to this line right here. Now that you have the expandTransaction()
call taking in variable sizes of transaction you need to also have a conditional here that varies the size of the sigMsgFragBytesToCopy
. When gossiping you still need the Protocol.GOSSIP_REQUESTED_TX_HASH_BYTES_LENGTH
to be subtracted from the data.length
. When expanding for other parts of the code (i.e. Transaction.read()
) this current logic works.
I tested the following locally and it started gossiping and registering gossiped transactions properly:
if(referenceSize == Transaction.SIZE) {
sigMsgFragBytesToCopy = data.length - TransactionTruncator.NON_SIG_TX_PART_BYTES_LENGTH;
} else {
sigMsgFragBytesToCopy = data.length - Protocol.GOSSIP_REQUESTED_TX_HASH_BYTES_LENGTH - TransactionTruncator.NON_SIG_TX_PART_BYTES_LENGTH;
}
675b165
to
a42b180
Compare
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.
💯
…abase Merge pull request iotaledger#1635 from luca-moser/truncate-tx-db
Description
Lets the
Transaction
Persistable
truncate the transaction bytes up on saving it by removing zero bytes from the signature message fragment (from the right). Up on loading a transaction, the bytes are back expanded to their full capacity (1604 bytes). This reduces the stored size of a transaction up to 81% (given a complete empty signature message fragment).Fixes # (issue)
#1626
Type of change
How Has This Been Tested?
Moved the expand/truncate methods from the
Protocol
class to a new separate class calledTransactionTruncator
and writing relevant unit tests for it.Checklist: