Skip to content
This repository has been archived by the owner on Aug 23, 2020. It is now read-only.

Feature: Truncate transaction bytes before persisting them to the database #1635

Merged
merged 4 commits into from
Nov 5, 2019

Conversation

luca-moser
Copy link
Member

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

  • Enhancement (a non-breaking change which adds functionality)

How Has This Been Tested?

Moved the expand/truncate methods from the Protocol class to a new separate class called TransactionTruncator and writing relevant unit tests for it.

Checklist:

  • My code follows the style guidelines for this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@iotaledger iotaledger deleted a comment Oct 3, 2019
@iotaledger iotaledger deleted a comment Oct 3, 2019
@iotaledger iotaledger deleted a comment Oct 3, 2019
@luca-moser luca-moser requested a review from kwek20 October 3, 2019 09:02
Copy link
Contributor

@DyrellC DyrellC left a 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;
Copy link
Contributor

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;
}

@iotaledger iotaledger deleted a comment Oct 8, 2019
Copy link
Contributor

@GalRogozinski GalRogozinski left a comment

Choose a reason for hiding this comment

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

💯

@GalRogozinski GalRogozinski merged commit 381cd74 into iotaledger:dev Nov 5, 2019
GalRogozinski pushed a commit to GalRogozinski/iri that referenced this pull request Apr 15, 2020
…abase

Merge pull request iotaledger#1635 from luca-moser/truncate-tx-db
@GalRogozinski GalRogozinski mentioned this pull request May 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants