Skip to content

Add chainId to every transaction - #349

Merged
andrepimenta merged 7 commits into
developfrom
improvement/transactions-chainId
Mar 10, 2021
Merged

andrepimenta merged 7 commits into
developfrom
improvement/transactions-chainId

Conversation

@andrepimenta

@andrepimenta andrepimenta commented Feb 15, 2021 •

Copy link
Copy Markdown
Member
  • Add chainId to every transaction while maintaining compatibility with networkID
  • Optimize adding multiple tokens at the same time (for improving transaction history view performance on the app)

@andrepimenta
andrepimenta requested a review from a team as a code owner February 15, 2021 16:18

@Gudahtt Gudahtt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure what to think of this "backwards compatibility" strategy 🤔 I think it will ensure things are no worse than they are today, but it'll still result in some interactions with the wrong transaction (e.g. if you have two networks with the same network ID but different chain IDs).

What's worse, this flaw will apply not just to old transactions, but to new ones as well.

I can approve this anyway (after tests have been added to pass the coverage requirements on CI), since it's less broken than before. But this remains somewhat broken. Maybe this could be improved in the future by removing the "networkID" property for new transactions, and only considering that for older transactions.

@@ -255,14 +256,15 @@ export class TransactionController extends BaseController<TransactionConfig, Tra
* @param currentNetworkID - string representing the current network id

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: The additional parameter should be documented here:

Suggested change
* @param currentNetworkID - string representing the current network id
* @param currentNetworkID - string representing the current network id
* @param currentChainId - The current chain ID

@andrepimenta andrepimenta Feb 19, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not sure what to think of this "backwards compatibility" strategy 🤔 I think it will ensure things are no worse than they are today, but it'll still result in some interactions with the wrong transaction (e.g. if you have two networks with the same network ID but different chain IDs).

What's worse, this flaw will apply not just to old transactions, but to new ones as well.

I can approve this anyway (after tests have been added to pass the coverage requirements on CI), since it's less broken than before. But this remains somewhat broken. Maybe this could be improved in the future by removing the "networkID" property for new transactions, and only considering that for older transactions.

@Gudahtt I am 100% with you on all your comments. The end goal is to remove networkID completely. We are doing this incrementally because we still use it in some parts of the app so I thought it would be safer to keep it but always prefer chainId over it.

I have changed some part of the code to be sure that chainId is always preferred, we only fallback to networkID in case chainId is not there. For all new transactions, chainId will always be added, so at least we know that for new transactions, networkID will not be used.

We had a change some time ago where we basically did
const currentNetworkID = network.state.provider.chainId;
which could cause problems like you mentioned: could result in the wrong set of transactions being returned whenever the chainId was different from the networkId.
I now differentiate them:

const currentChainId= network.state.provider.chainId;
const currentNetworkID= network.state.network;

In this way, chainId and networkID at least can now have different values resolving that problem for now, but yes the objective is still to remove networkID completely in the near future.

Let me know what are your thoughts on this and if it's ok to merge!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That sounds good to me! Better to make these changes incrementally if possible

Comment thread src/transaction/TransactionController.ts Outdated

@Gudahtt Gudahtt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM! I can re-review after the conflict is resolved.

# Conflicts:
#	src/transaction/TransactionController.ts

@estebanmino estebanmino left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚀

@andrepimenta
andrepimenta merged commit f11c097 into develop Mar 10, 2021
@andrepimenta
andrepimenta deleted the improvement/transactions-chainId branch March 10, 2021 14:32
Mrtenz pushed a commit that referenced this pull request Oct 16, 2025
This is the release candidate for version 12.2.1.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Bumps version to 12.2.1 and updates CHANGELOG entries and comparison
links for the release.
> 
> - **Release 12.2.1**:
>   - Bump `package.json` version to `12.2.1`.
>   - Update `CHANGELOG.md`:
>     - Add `## [12.2.1]` section.
> - Update reference links: `[Unreleased]` compares from
`v12.2.1...HEAD`; add `[12.2.1]` compare link.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
1e8174fec420a2338f0f39494746d9424e89cd10. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: Jiexi Luan <jiexiluan@gmail.com>
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.

3 participants