-
-
Notifications
You must be signed in to change notification settings - Fork 262
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
Conversation
* | ||
* See https://github.com/ethers-io/ethers.js/issues/511 | ||
*/ | ||
export default class FastJsonRpcSigner extends ethers.Signer { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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)
There was a problem hiding this 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
Great idea, I'll talk to Julien about this! |
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 ofsendTransaction
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: