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

Add advanced setting to enable editing nonce on confirmation screens #7089

Merged
merged 51 commits into from
Sep 27, 2019
Merged

Add advanced setting to enable editing nonce on confirmation screens #7089

merged 51 commits into from
Sep 27, 2019

Conversation

rickycodes
Copy link
Contributor

@rickycodes rickycodes commented Aug 31, 2019

re: #6757

This gives us a new nonce toggle in settings:

image

Which enables adding one to the transaction:

image

@rickycodes rickycodes changed the title WIP: Add UseNonce toggle Add advanced setting to enable editing nonce on confirmation screens Sep 2, 2019
Copy link
Contributor Author

@rickycodes rickycodes left a comment

Choose a reason for hiding this comment

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

This is almost done, just a couple things need to be tied together

sendTransaction: txData => {
const _txData = customNonceValue ? {
...txData,
customNonceValue,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried doing: nonce: customNonceValue to see if i could get the nonce into the transaction that way, but it didn't appear to work as expected...

Copy link
Contributor

Choose a reason for hiding this comment

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

This is due to how the nonce is set when a transaction is approved. See line 379 of the transactions controller: https://github.com/MetaMask/metamask-extension/pull/7089/files/5e653e49f9376c12a33b77ce5813bb30468c2c33#diff-97c997fde8231c768b7f2393fd3012e1L379

It looks like you were on your way to updating that code based on your comment in that file

@@ -376,6 +376,7 @@ class TransactionController extends EventEmitter {
// add nonce to txParams
// if txMeta has lastGasPrice then it is a retry at same nonce with higher
// gas price transaction and their for the nonce should not be calculated
log.debug('customNonceValue', txMeta.customNonceValue)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd assume this property exists at this point, but I don't see this log anywhere? not sure what makes the most sense to debug this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Were you looking in the background console for the log? To see it you need to:

  • go to chrome://extensions/ or the Brave equivalent
  • turn "Developer Mode" on
  • under the MetaMask app you are building, inspect the "Background page"
  • click the "console" tab

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I got things sorta working... was able to kick off a transaction with a custom nonce of 4:

image

however it's just been pending this whole time... I'm not sure what the requirements of nonce are... trying strings like 'testing123' (as an example) just seems to break things (transaction doesn't go through and I get a bunch of errors).

Copy link
Contributor

Choose a reason for hiding this comment

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

In fact, I think what you have is working. That the tx is in pending the whole time is due to how transactions are handled by the ethereum blockchain. If the network only has record of nonces 1 and 2 for your account, and you custom edit a new transaction to nonce 5, that new one will remain pending until transactions with nonces 3 and 4 are successfully confirmed.

Read this for a helpful explanation: https://www.reddit.com/r/ethereum/comments/6ihw6p/can_someone_please_explain_nonce_to_me/dj6r1lk/

You are right, however, that a nonce cannot just be any arbitrary string. It must be a natural number >= 0. So we should prevent other values from being entered in this input field.

Copy link
Contributor

Choose a reason for hiding this comment

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

  • Ensure inputs can only be submitted if nonce is a whole number >= 0, or ensure those are the only input possible in the nonce field

@danjm
Copy link
Contributor

danjm commented Sep 5, 2019

We should move the toggle to the "Advanced" settings page.

  • move the toggle to the "Advanced" settings page.

@rickycodes
Copy link
Contributor Author

rickycodes commented Sep 6, 2019

I've moved the nonce toggle to the Advanced settings page, I've added some additional styles and things, but I am sure there is still more to do around where to reset the customNonceValue... I've got it resetting when you toggle and when the transaction goes through, but it might need to be sprinkled out a bit more?

@rickycodes
Copy link
Contributor Author

Oh also there might need to be more of a sanity check on customNonceValue when it's getting set, i don't know if parseInt would suffice in this case? 0 is valid, but 001 is invalid (if I understand things correctly)... maybe there's already a thing in the wild for validating nonce? anyway, i don't think setting the input to type=number really satisfies the requirements?

@fabtho
Copy link

fabtho commented Sep 11, 2019

Thanks for this! I'am looking forward to use it. I got a stuck tx since more then 4 days, metamask not showing speed up or cancel on this one. (Browser freeze, so tx somewhat lost)

@danjm danjm added this to the UI Sprint 20 [Sept 16] milestone Sep 16, 2019
@danjm danjm self-assigned this Sep 16, 2019
@danjm
Copy link
Contributor

danjm commented Sep 19, 2019

Updated demo: https://streamable.com/noij3

And screen shot:

Screenshot from 2019-09-19 09-49-30

@cjeria
Copy link
Contributor

cjeria commented Sep 19, 2019

The nonce input field is very wide. Probably could reduce the width by 1/2 it's current size. I noticed the placeholder text "automatically calculate", however, I'd suggest populating the custom nonce field with the nonce calculated by MM as opposed to an empty field w/placeholder.

image

I'd update the text in settings to something like this instead.
image

cc @danjm

@danjm
Copy link
Contributor

danjm commented Sep 21, 2019

@cjeria Made changes according to your suggestions:

Screenshot from 2019-09-21 13-53-51

Screenshot from 2019-09-21 13-50-59

app/_locales/en/messages.json Outdated Show resolved Hide resolved
ui/app/store/actions.js Outdated Show resolved Hide resolved
@cjeria
Copy link
Contributor

cjeria commented Sep 24, 2019

There's a lot of emphasis on the component "nonce field" in the title. Titles should help answer user questions like what the feature will enable them to do. In this case, the "nonce field" lets users "customize transaction nonces". More broadly this feature will let users "Edit transaction nonces on confirm screens".

Also, remove the period at the end of the title. WDYT?

// add nonce debugging information to txMeta
txMeta.nonceDetails = nonceLock.nonceDetails
txMeta.nonceDetails = customNonceValue
? { isCustomNonce: true }
Copy link
Contributor

Choose a reason for hiding this comment

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

add this value to nonce details

@@ -365,28 +365,36 @@ class TransactionController extends EventEmitter {
return
}
this.inProcessOfSigning.add(txId)
let nonceLock
let nonceLock = {}
Copy link
Contributor

Choose a reason for hiding this comment

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

revert this change

try {
// approve
this.txStateManager.setTxStatusApproved(txId)
// get next nonce
const txMeta = this.txStateManager.getTx(txId)
const fromAddress = txMeta.txParams.from
// wait for a nonce
nonceLock = await this.nonceTracker.getNonceLock(fromAddress)
const { customNonceValue = null } = txMeta
if (!customNonceValue) {
Copy link
Contributor

Choose a reason for hiding this comment

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

id like it if we still got are calculated nonce for debug purposes

app/scripts/controllers/transactions/index.js Show resolved Hide resolved
@frankiebee
Copy link
Contributor

frankiebee commented Sep 26, 2019

QUESTION: should we address the showing of a warning if the custom nonce is distance one or greater from our suggested nonce

feel free to ignore this question this is mainly a reminder that the question was brought up

this.setState({ submitWarning: '' })
}
updateCustomNonce(String(newCustomNonce))
getNextNonce()
Copy link
Member

Choose a reason for hiding this comment

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

If this results in the nextNonce changing to one that would invalidate the custom nonce, it won't result in a warning. I think this case could be caught by re-validating the custom nonce field in the lifecycle function when the nextNonce prop changes

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.

Thanks looks great

@danjm danjm merged commit 5f254f7 into MetaMask:develop Sep 27, 2019
Gudahtt added a commit to Gudahtt/metamask-extension that referenced this pull request Sep 27, 2019
* origin/develop: (56 commits)
  Add advanced setting to enable editing nonce on confirmation screens (MetaMask#7089)
  Add migration on 3box imports and remove feature flag (MetaMask#7209)
  ci - install deps - limit install scripts to whitelist (MetaMask#7208)
  Add a/b test for full screen transaction confirmations (MetaMask#7162)
  Update minimum Firefox verison to 56.0 (MetaMask#7213)
  mesh-testing - submit infura rpc requests to mesh-testing container (MetaMask#7031)
  obs-store/local-store should upgrade webextension error to real error (MetaMask#7207)
  sesify-viz - bump dep for visualization enhancement (MetaMask#7175)
  address book entries by chainId (MetaMask#7205)
  Optimize images only during production build (MetaMask#7194)
  Use common test build during CI (MetaMask#7196)
  Report missing `en` locale messages to Sentry (MetaMask#7197)
  Verify locales on CI (MetaMask#7199)
  updated ganache and addons-linter (MetaMask#7204)
  fixup! add user rejected errors
  add user rejected errors
  update json-rpc-engine
  use eth-json-rpc-errors
  Remove unused locale messages (MetaMask#7190)
  Remove unused components (MetaMask#7191)
  ...
@rickycodes rickycodes deleted the add-advanced-setting-to-enable-editing-nonce branch February 11, 2020 23:56
@tbenr
Copy link

tbenr commented Jun 17, 2020

@danjm this is not implemented for ERC20 "approve" transactions, am I right?

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.

7 participants