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!: require chain id in transactions #973

Merged
merged 15 commits into from
Apr 20, 2024
Merged

Conversation

joroshiba
Copy link
Member

Summary

Adds the concept of TransactionParams to UnsignedTransaction as a body that can grow to include many different parameters which much pass for a transaction to be valid, and uses this structure to add a chain_id to ensure that transactions from one Astria network cannot be replayed on another.

Background

There are likely to be additional parameters we can add onto transactions (such a expiration or things relating to auction bids), and we needed to add the chain id parameter.

Changes

  • Modify Transaction format
  • Add chain id param and checks.

Testing

CI/CD

@github-actions github-actions bot added proto pertaining to the Astria Protobuf spec sequencer pertaining to the astria-sequencer crate composer pertaining to composer cd labels Apr 18, 2024
@joroshiba joroshiba marked this pull request as ready for review April 18, 2024 02:33
@joroshiba joroshiba requested review from a team, SuperFluffy and noot as code owners April 18, 2024 02:33
@bharath-123
Copy link
Contributor

LGTM from composer

Copy link
Member

@SuperFluffy SuperFluffy left a comment

Choose a reason for hiding this comment

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

The chain ID is already available when connecting to sequencer by querying it's ABCI /genesis endpoint, which is what conductor is doing.

I would like our services to be consistent in how they query the chain ID and use a single source of truth (the mentioned endpoint).

However, if you prefer to explicitly use a configuration parameter for this (for example to guard against accidentally connecting to the wrong sequencer network), then please still query /genesis and check that configured_chain_id == remote_chain_id to have composer before it receives or polls any transactions.

@@ -27,6 +27,9 @@ ASTRIA_COMPOSER_API_LISTEN_ADDR="0.0.0.0:0"
# Address of the RPC server for the sequencer chain
ASTRIA_COMPOSER_SEQUENCER_URL="http://127.0.0.1:26657"

# Chain ID of the sequencer chain which transactions are submitted to.
ASTRIA_COMPOSER_SEQUENCER_CHAIN_ID="astria-dev-1"
Copy link
Member

Choose a reason for hiding this comment

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

IMO remove in favor of querying sequencer's /genesis endpoint to extract the cometbft chain ID from there. This is how conductor is doing it and I would like this to be consistent between services.

@@ -157,6 +173,21 @@ pub(crate) async fn execute<S: StateWriteExt>(
.await
}

#[derive(Debug)]
pub(crate) struct InvalidChainId(pub(crate) String);
Copy link
Member

Choose a reason for hiding this comment

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

why pub(crate)?

Copy link
Member Author

@joroshiba joroshiba Apr 19, 2024

Choose a reason for hiding this comment

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

Admittedly I just matched the InvalidNonce error publicity since these should be consumed similarly, it is referenced in a test I added in app.rs to ensure it fails correctly.

Copy link
Member

@SuperFluffy SuperFluffy left a comment

Choose a reason for hiding this comment

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

Approving after syncing offline. We decided to a) require Sequencer chain IDs be set in config, and b) the configured Sequencer chain IDs be checked against the /genesis endpoint. However, this will and can be done in follow PRs (for both composer and conductor).

I am approving this PR. Before merge, please address my comments re the ABCI error codes:

  1. add entries to the Display and From impls
  2. add matching protobuf ABCI error codes (note: apparently these have been removed feat(sequencer): check for sufficient balance in check_tx #869 for some reason)

Base automatically changed from joroshiba/proto-reform to main April 19, 2024 19:44
@joroshiba joroshiba requested a review from a team as a code owner April 19, 2024 19:44
@github-actions github-actions bot added ci issues that are related to ci and github workflows conductor pertaining to the astria-conductor crate sequencer-relayer pertaining to the astria-sequencer-relayer crate labels Apr 19, 2024
@joroshiba
Copy link
Member Author

Follow up issue: #986

@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 19, 2024
Comment on lines +275 to +281
// Transactions must match the chain id of the node.
let chain_id = state.get_chain_id().await?;
ensure!(
self.params.chain_id == chain_id.as_str(),
InvalidChainId(self.params.chain_id.clone())
);

Copy link
Collaborator

Choose a reason for hiding this comment

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

you can remove this - the mempool check is sufficient, no txs with invalid chain ids will make it here. the nonce check below is needed for strict equality before execution

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we need to protect against a validator running their node with a no op mempool. IE someone can modify code for their validator grab alternate transactions and propose?

@@ -2111,6 +2182,52 @@ mod test {
);
}

#[tokio::test]
async fn app_deliver_tx_invalid_chain_id() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

move/change this test to test the mempool check (after you delete the check_stateful check this test will fail)

@joroshiba joroshiba added this pull request to the merge queue Apr 20, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 20, 2024
@joroshiba joroshiba added this pull request to the merge queue Apr 20, 2024
Merged via the queue into main with commit 6f13e7f Apr 20, 2024
36 checks passed
@joroshiba joroshiba deleted the joroshiba/transaction-format branch April 20, 2024 01:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cd ci issues that are related to ci and github workflows composer pertaining to composer conductor pertaining to the astria-conductor crate proto pertaining to the Astria Protobuf spec sequencer pertaining to the astria-sequencer crate sequencer-relayer pertaining to the astria-sequencer-relayer crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants