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

Refactor kairos-tx #81

Merged
merged 12 commits into from
Apr 29, 2024
Merged

Refactor kairos-tx #81

merged 12 commits into from
Apr 29, 2024

Conversation

koxu1996
Copy link
Contributor

@koxu1996 koxu1996 commented Apr 29, 2024

I extracted great improvements of kairos-tx done by @Avi-D-coder in Trie integration, to reduce clutter in his PR.

List of changes:

  • Now all structures - Deposit, Withdrawal, Transfer, SigningPayload - can be created with flexible constructor. Thus helpers.rs got removed.
  • Now DER encoding/decoding is part of SigningPayload.
  • Updated Nix e2e test to use 2 different account for deposit and withdrawal, also fixed nonces.
  • Added Rust e2e test for encoding payloads.

One additional change that I made myself is to allow cloning the base fields, so we can extract nonce/amount/public-key without taking ownership of full transaction - 9fc5a00.

@koxu1996 koxu1996 self-assigned this Apr 29, 2024
@koxu1996 koxu1996 marked this pull request as ready for review April 29, 2024 11:42
Copy link

File Coverage
All files 63%
kairos-server/src/routes/deposit.rs 86%
kairos-server/src/routes/transfer.rs 73%
kairos-server/src/routes/withdraw.rs 91%
kairos-test-utils/src/cctl/parsers.rs 66%
kairos-crypto/src/implementations/casper.rs 3%
kairos-server/tests/transactions.rs 83%
kairos-server/src/config.rs 0%
kairos-server/src/errors.rs 16%
kairos-server/src/utils.rs 22%
kairos-tx/src/asn.rs 65%
kairos-tx/src/error.rs 0%
kairos-test-utils/src/cctl.rs 87%
kairos-test-utils/src/kairos.rs 95%

Minimum allowed coverage is 60%

Generated by 🐒 cobertura-action against 9fc5a00

@koxu1996 koxu1996 added the demo Required for our first demo label Apr 29, 2024
Copy link
Contributor

@Rom3dius Rom3dius 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 to me. I'm sure I'm missing context here, but why the name "der_encode" and "der_decode"?

Also these github actions are out of control, take far to long to run.

@koxu1996
Copy link
Contributor Author

@Rom3dius Thanks! Let me provide you context 😉 Schema for Kairos transaction is defined as ASN.1:

TxSchema DEFINITIONS AUTOMATIC TAGS ::= BEGIN

  -- Basic types.
  PublicKey ::= OCTET STRING
  Amount ::= INTEGER (0..18446744073709551615)

  Transfer ::= SEQUENCE {
    recipient PublicKey,
    amount Amount,
    ...
  }

Notably it's fully abstract syntax - there is no definition how those should be converted from and to bytes. However, ASN.1 is closely associated with multiple sets of encoding rules: BER, DER, CER, and others. DER-encoding is the one we are using, as it is fully deterministic, so we can have the exact same bytes representation that is implementation agnostic.

Copy link
Contributor

@Avi-D-coder Avi-D-coder left a comment

Choose a reason for hiding this comment

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

Lgtm

@koxu1996 koxu1996 merged commit e9ced86 into main Apr 29, 2024
7 checks passed
@marijanp marijanp deleted the feature/kairos-tx-improvements branch April 29, 2024 13:54
@marijanp
Copy link
Contributor

You did not address the comments I left about some of the changed files in Avi's PR:

  • Removing the Nonce from deposits
  • An explanation for why the payloads and signatures the way they changed in the end-to-end test

@koxu1996
Copy link
Contributor Author

@marijanp I believe that simple change in Nix e2e tests was explained 3 days ago. You are usually not closing PR discussions that you started, so should I wait for you to click "resolve conversation"?

Your objectives about nonce in schema are not relevant here: this PR is basically refactoring API of schema, but not changing schema itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
demo Required for our first demo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants