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

Ensures the tx controller + state-manager orders transactions as received #7484

Merged
merged 4 commits into from
Nov 27, 2019

Conversation

danjm
Copy link
Contributor

@danjm danjm commented Nov 21, 2019

These changes are needed to ensure consistency of transaction order. This was an issue for batch transactions and the same change is included in #7473 It was also needed to get my local e2e tests passing.

The strategy here is to ensure that the tx-state-manager orders transactions by id, and to ensure that ids are applied in the order they are received by the transaction controller (and not after an indeterminate async operation).

Although this commit is currently also part of #7473 and #7368, I believe it should be made directly to develop and then those can be rebased accordingly.

@metamaskbot
Copy link
Collaborator

Builds ready [36ade8b]

@@ -193,12 +193,12 @@ class TransactionController extends EventEmitter {
}
txUtils.validateTxParams(normalizedTxParams)
// construct txMeta
Copy link
Member

Choose a reason for hiding this comment

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

Nit: maybe a comment here would be useful, to explain that this step must happen synchronously, before anything else, because it assigns the tx id? It's really not obvious what's going on here at first glance.

This is a follow up from this discussion: #7473 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@metamaskbot
Copy link
Collaborator

Builds ready [47bd579]

Gudahtt
Gudahtt previously approved these changes Nov 26, 2019
Copy link
Member

@Gudahtt Gudahtt 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 think adding transactions according to id order is harmless. I know of no cases where it would be harmful at least.

@frankiebee
Copy link
Contributor

does this mean the history is reversed in the ui?


newTxIndex === -1
? transactions.push(txMeta)
: transactions.splice(newTxIndex, 0, txMeta)
Copy link
Contributor

Choose a reason for hiding this comment

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

if this is a new tx why the splice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this inserts the transaction in the list according to its id, before the first transaction with a greater id

@@ -167,7 +167,12 @@ class TransactionStateManager extends EventEmitter {
transactions.splice(index, 1)
}
}
transactions.push(txMeta)
const newTxIndex = transactions
.findIndex((currentTxMeta) => currentTxMeta.id > txMeta.id)
Copy link
Contributor

Choose a reason for hiding this comment

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

ids should be random?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh really?

Copy link
Contributor

Choose a reason for hiding this comment

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

so im not sure this works

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we could use timestamp instead

Copy link
Contributor

Choose a reason for hiding this comment

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

timestamp could work

Copy link
Contributor

@frankiebee frankiebee left a comment

Choose a reason for hiding this comment

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

id's are random so this will be replacing other txmeta's

frankiebee
frankiebee previously approved these changes Nov 26, 2019
Copy link
Contributor

@frankiebee frankiebee left a comment

Choose a reason for hiding this comment

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

Great thank you!

Copy link
Contributor

@frankiebee frankiebee left a comment

Choose a reason for hiding this comment

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

🤙 great thanks!

@metamaskbot
Copy link
Collaborator

Builds ready [81f0afe]

@danjm danjm merged commit 724bd42 into develop Nov 27, 2019
Gudahtt pushed a commit that referenced this pull request Dec 5, 2019
…ived (#7484)

* Ensures the tx controller + tx-state-manager orders transactions in the order they are received

* Handle transaction ordering in cases where tx ids are off by more than 1 in tx-state-manager

* Add comment to addUnapprovedTransaction explaining calling _determineTransactionCategory after generateTxMeta

* Sort txes by timestamp of creation instead of id
@whymarrh whymarrh deleted the tx-state-order-guarantee branch January 15, 2020 17:00
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.

None yet

4 participants