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

implement instant return from sendTransaction #3142

Merged
merged 1 commit into from
May 10, 2019
Merged

Conversation

cellog
Copy link
Contributor

@cellog cellog commented May 10, 2019

Description

In preparation for upgrading to 0.0.25, it turned out that the default behavior of ethers contract transaction-based method calls does not return the hash until the first mined block. This is between 5-20 seconds on mainnet. Based on discussions with the maintainer of ethers, found in ethers-io/ethers.js#511, this PR implements a new Signer that wraps the built-in one, but extends the behavior of sendTransaction to return right away.

In testing, it solves the delay.

As version 5 of ethers is due out soon and includes a first-class citizen UncheckedJsonRpcSigner that does this same thing, this is a temporary fix.

Checklist:

  • 1 PR, 1 purpose: my Pull Request applies to a single purpose
    • This PR only contains configuration changes (package.json, etc.)
    • This PR only contains code changes (if configuration changes are required, do a separate PR first, then re-base)
  • My code follows the style guidelines of this project, including naming conventions
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • If my code adds or changes components, I have written corresponding stories with Storybook
  • I have performed a self-review of my own code
  • If my code involves visual changes, I am adding applicable screenshots to this thread

@cellog cellog requested review from julien51, akeem and cnasc May 10, 2019 19:26
@cellog cellog self-assigned this May 10, 2019
*
* See https://github.com/ethers-io/ethers.js/issues/511
*/
export default class FastJsonRpcSigner extends ethers.Signer {
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 file is tested by the existing tests. If it changed behavior at all, they would fail (and did for many attempts in testing until I got the thing right)

@@ -135,7 +137,9 @@ export default class UnlockService extends EventEmitter {
}

async getWritableContract(address, contract) {
const signer = this.provider.getSigner()
// TODO: replace this when v5 of ethers is out
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 is the first important change to see

@@ -105,7 +105,8 @@ export default class WalletService extends UnlockService {
transactionType,
'submitted'
)
return transaction.hash
Copy link
Contributor Author

Choose a reason for hiding this comment

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

and the other important change to see

@@ -79,6 +79,7 @@ describe('v0', () => {
// verify that the promise passed to _handleMethodCall actually resolves
// to the result the chain returns from a sendTransaction call to createLock
const result = await mock.mock.calls[0][0]
await result.wait()
Copy link
Contributor Author

@cellog cellog May 10, 2019

Choose a reason for hiding this comment

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

all the tests are adjusted for the double wait (would be unnecessary if we weren't testing implementation details, it might be good to remove this test of the mocking, perhaps for a follow-up PR)

Copy link
Contributor

@cnasc cnasc left a comment

Choose a reason for hiding this comment

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

LGTM! I feel like this could be a good basis for an hourlong session like our Solidity discussions, since so far you've been the only one to get elbow-deep in ethers

@cellog
Copy link
Contributor Author

cellog commented May 10, 2019

Great idea, I'll talk to Julien about this!

@cellog cellog merged commit 154cea0 into master May 10, 2019
@cellog cellog deleted the greg-3090-slow-ethers branch May 10, 2019 20:28
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.

2 participants