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

store incoming transactions in a database #1828

Merged
merged 6 commits into from
Mar 5, 2024
Merged

Conversation

zkokelj
Copy link
Contributor

@zkokelj zkokelj commented Mar 4, 2024

Why this change is needed

For debugging purposes we would like to store unencrypted transactions in the gateway to be able to reproduce some errors if they occur.

What changes were made as part of this PR

Additional database table, storing transactions

PR checks pre-merging

Please indicate below by ticking the checkbox that you have read and performed the required
PR checks

  • PR checks reviewed and performed

https://github.com/ten-protocol/ten-test/actions/runs/8143119529

@zkokelj zkokelj marked this pull request as ready for review March 5, 2024 10:25
Copy link
Collaborator

@BedrockSquirrel BedrockSquirrel left a comment

Choose a reason for hiding this comment

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

LGTM

id INT AUTO_INCREMENT PRIMARY KEY,
user_id varbinary(20),
tx TEXT,
tx_time DATETIME DEFAULT CURRENT_TIMESTAMP
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wonder if it be possible to store the tx hash as well or is that going to be too expensive to figure out on the fly? Just thinking about being able to do lookups if investigating an issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added tx_hash

Copy link
Collaborator

@BedrockSquirrel BedrockSquirrel left a comment

Choose a reason for hiding this comment

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

Couple minor tweaks/things I wanted to check.

w.Logger().Error(fmt.Errorf("error decoding string (%s), %w", hexUserID[2:], err).Error())
return nil, errors.New("error decoding userID. It should be in hex format")
}
err = w.storage.StoreTransaction(request.Params[0].(string), userIDBytes)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we 100% certain that the first param exists, can be cast to a string and will have "0x" as the first two characters so you can strip them off?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Things are checked in a function that calls that function, but added additional check there to avoid an edge case that might happen.

// Calculate tx hash
rawTxBytes, err := hex.DecodeString(rawTx[2:])
if err != nil {
panic(err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We shouldn't panic here imo, just log the error and store it without the tx hash. (Same on the sqlite impl)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, good catch!

Copy link
Collaborator

@BedrockSquirrel BedrockSquirrel left a comment

Choose a reason for hiding this comment

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

lgtm

@zkokelj zkokelj merged commit 6083d1e into main Mar 5, 2024
2 checks passed
@zkokelj zkokelj deleted the ziga/save_txs_to_gateway_db branch March 5, 2024 16:48
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.

2 participants