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

Confirmations #105

Merged
merged 18 commits into from
Jan 8, 2020
Merged

Confirmations #105

merged 18 commits into from
Jan 8, 2020

Conversation

nlordell
Copy link
Contributor

@nlordell nlordell commented Jan 6, 2020

This PR unifies the confirmation API between all transaction (deployment and method calls) and eliminates the send_and_confirm method as now confirmation parameters are part of the transaction builder.

Note that this also addresses some issues with confirmation. A new case was created to upstream some of these issues to web3 crate here: #104. Details of the issues with the current confirmation implementation are in the aforementioned issue.

This closes #95

Test Plan

New unit tests for the confirmation implementation and add waiting for confirmation with Ganache example. (Note that Rinkeby example currently waits for confirmation already).

@nlordell nlordell requested review from fleupold and bh2smith January 6, 2020 14:11
Copy link
Contributor

@fleupold fleupold left a comment

Choose a reason for hiding this comment

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

Wow, very strong PR. Lot of stuff happening. I looked through the state machine logic and am really glad you added unit tests. This will be a huge semantic improvement to the library.

/// specified will use a period of 7 seconds.
pub fn poll_interval(mut self, value: Duration) -> DeployBuilder<T, D> {
self.poll_interval = Some(value);
self.tx = self.tx.nonce(value);
Copy link
Contributor

Choose a reason for hiding this comment

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

All these copy pasta errors that are being fixed here 🙈

Copy link
Contributor Author

@nlordell nlordell Jan 8, 2020

Choose a reason for hiding this comment

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

This was addressed in #108, it’s just the github GUI showing it.


/// Represents the result of a sent transaction that can either be a transaction
/// hash, in the case the transaction was not confirmed, or a full transaction
/// receipt is the `TransactionBuilder` was configured to wait for confirmation
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: if

Pending,
/// Wait for confirmation with the specified `ConfirmParams`. A confirmed
/// transaction is always mined. There is a chance, however, that the block
/// in which the transaction was mined becomes an ommer block. Confirming
Copy link
Contributor

Choose a reason for hiding this comment

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

uncle block? Unless you feel strongly about trading general comprehension for gender neutrality.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Isn’t the official term “ommer block”? It was originally chosen for gender neutrality reasons, but I think it is pretty widely understood now.

Copy link
Contributor

Choose a reason for hiding this comment

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

I have never heard the term ommer block before.

#[cfg(test)]
pub const DEFAULT_POLL_INTERVAL: Duration = Duration::from_secs(0);

/// The default poll interval to use for confirming transactions.
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy Pasta, is this number of blocks or seconds? From reading below I found its blocks. Maybe rename to DEFAULT_TIMEOUT_IN_BLOCK? A block timeout could be interpreted as the time it takes to get a new block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a copy pasta, should already be fixed in confirmation future PR

/// the node (for example when using Infura over HTTP(S)).
pub poll_interval: Duration,
/// The maximum number of blocks to wait for a transaction to get confirmed.
pub block_timeout: usize,
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense for this to be an option? Given that the tx will be in the mem pool you might not want to stop waiting for it (I realize you could use a very high value here).

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 can do that, it’s not too hard.

fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
let unpinned = self.get_mut();
loop {
unpinned.state = match &mut unpinned.state {
Copy link
Contributor

Choose a reason for hiding this comment

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

nice state machine. Is this a common pattern in rust? I was wondering if it made sense for the SendFuture (as the flow is only linear) but here it makes a lot of sense with all the jumps.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a common pattern for futures and is how the generated async code by the compiler looks like in theory.

if block_num == *target_block_num {
ConfirmState::Checking(future::try_join(
MaybeReady::ready(Ok(block_num)),
unpinned
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 where you were wondering if you can reuse the old tx hash once it's mined or if you have to always refetch it?

}

#[test]
fn confirmations_with_reorg_tx_receipt() {
Copy link
Contributor

Choose a reason for hiding this comment

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

@nlordell nlordell changed the title [WIP] Confirmations Confirmations Jan 8, 2020
@nlordell nlordell merged commit 2a47f7f into master Jan 8, 2020
@nlordell nlordell deleted the confirmations branch January 8, 2020 19:50
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.

Unify "confirmations" behavior for contract.deploy and tx.send
2 participants