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

feat(sequencer-util): get json from transaction base64 #1694

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

joroshiba
Copy link
Member

@joroshiba joroshiba commented Oct 18, 2024

Summary

Add a utility to the sequencer-transaction-utils to parse a transaction protobuf data from the base64 of the transaction.

Background

The mempool and rpc endpoints for sequencer give base64 bytes, and there is no clean way to interpret the transaciton information from this. This provides a utility which can be useful for testing to do this.

@github-actions github-actions bot added the sequencer pertaining to the astria-sequencer crate label Oct 18, 2024
github-merge-queue bot pushed a commit that referenced this pull request Oct 23, 2024
## Summary

> [!NOTE]  
> Most of the code is copied from Sam
(#1695) and Jordan's
(#1694) PRs.

Add two new subcommands `sign` and `submit` to the `sequencer`
subcommand.

### `sign`
1. Reads a pbjson formatted
`astria.protocol.transaction.v1.TransactionBody` from a file or `STDIN`
(`file` is a positional argument; `STDIN` is read when providing `-` as
the trailing argument).
2. Signs it with a given private key (`--private-key`).
3. Writes the pbjson formatted
`astria.protocol.transaction.v1.Transaction` to `--output`/`-o`, if
provided, or `STDOUT`.

### `submit`
1. 1. Reads a pbjson formatted
`astria.protocol.transaction.v1.Transaction` from a file or `STDIN`
(`file` is a positional argument; `STDIN` is read when providing `-` as
the trailing argument).
2. Submits it to a sequencer's CometBFT url (`--sequencer-url`)

## Background

We want to be able to test the submitting txs signed via FROST threshold
signing (see #1654) but do not
have a CLI command to submit already signed transactions. The `submit`
command resolves this.

To test the `submit` command it is desirable to have a corresponding
`sign` command which creates a signed `Transaction` from a single
private key.

## Changes
- List changes which were made.

## Testing
1. Run a local sequencer network using `astria-cli-go`
```
just run dev purge all
just run dev init
just run dev run --network local
```
2. Sign a `TransactionBody`:
```
cargo run -p astria-cli -- sequencer sign --private-key 2bd806c97f0e00af1a1fc3328fa763a9269723c8db8fac4f93af71db186d6e90 - <<EOF
{
  "params": {
    "nonce": 0,
    "chainId": "sequencer-test-chain-0"
  },
  "actions": [
    {
      "ibcRelayerChange": {
        "removal": {
          "bech32m": "astria13r24h8mj42sdfqflqyg2fycqf9mdqqzmm2xllj"
        }
      }
    }
  ]
}
EOF
```
3. Submit the signed `Transaction`
```
cargo run -p astria-cli -- sequencer submit --sequencer-url http://127.0.0.1:26657 - <<EOF
{
  "signature": "+hb4bd8kEM8/AQ3wJ2znXcF3Ds1iLZu6OieNOnxY7n1SZsiDr5NQP3lMK4s5134O629XjXhae/FsL+qtbXnBDw==",
  "publicKey": "1b9KP8znF7A4i8wnSevBSK2ZabI/Re4bYF/Vh3hXasQ=",
  "body": {
    "typeUrl": "/astria.protocol.transaction.v1.TransactionBody",
    "value": "ChgSFnNlcXVlbmNlci10ZXN0LWNoYWluLTASNKIDMRIvEi1hc3RyaWExM3IyNGg4bWo0MnNkZnFmbHF5ZzJmeWNxZjltZHFxem1tMnhsbGo="
  }
}
EOF 
```

> [!NOTE]  
> You can also do this is in a single command using `xargs -0`

```
cargo run -p astria-cli -- sequencer sign --private-key 2bd806c97f0e00af1a1fc3328fa763a9269723c8db8fac4f93af71db186d6e90 - <<EOF
{
  "params": {
    "nonce": 3,
    "chainId": "sequencer-test-chain-0"
  },
  "actions": [
    {
      "ibcRelayerChange": {
        "removal": {
          "bech32m": "astria13r24h8mj42sdfqflqyg2fycqf9mdqqzmm2xllj"
        }
      }
    }
  ]
}
EOF | xargs -0 cargo run -p astria-cli -- sequencer submit  --sequencer-url http://127.0.0.1:26657
```

## Metrics
- List out metrics added by PR, delete section if none. 

## Breaking Changelist
- Bulleted list of breaking changes, any notes on migration. Delete
section if none.

## Related Issues
Link any issues that are related, prefer full github links.

closes <!-- list any issues closed here -->

---------

Co-authored-by: Sam Bukowski <[email protected]>
Co-authored-by: Richard Janis Goldschmidt <[email protected]>
Co-authored-by: Fraser Hutchison <[email protected]>
Co-authored-by: Jordan Oroshiba <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sequencer pertaining to the astria-sequencer crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant