Skip to content

Conversation

@jonasschnelli
Copy link
Contributor

@jonasschnelli jonasschnelli commented May 17, 2018

This adds a new wallet RPC call listsincetx that allows to list follow-up transactions (in order / wtxOrdered) from a specified transaction.

If the latest transaction was used as base-point for finding follow-up transactions and the long-polling timeout if set greater then zero, it will wait until new transactions has been found or the timeout has been expired (http push channel). Used together with a https proxy, one can build a very robust wallet transaction push channel (that can bypass NATs, proxys, etc.)

This does allow to build a wallet-notify push channel without keeping client-states on the server side.
It does also allow clients to effectively sync the transaction list.

A client can simply loop over listsincetx(<newest_known_txid>, 30/*timeout*/) and will immediately get new txns once they arrive.

Mitigates #13237
Related #7949

This (or a similar) approach was once discussed during an IRC meeting (can't find it anymore in the logs).

  • Needs release notes
  • Needs wallet notify example python script

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

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

Concept ACK.

I'm not aware of the wtxOrdered details, but is the key always increasing? Also, it's a multimap so the same key can have multiple transactions, isn't that a problem?

Some comments though.

Copy link
Contributor

Choose a reason for hiding this comment

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

nit, space after if.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be nullptr? Could assert(pwtx) instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

Could keep wtxOrdered back iterator instead:

TxItems::const_iterator m_latest_wtx = wtxOrdered.rbegin();

Then above could be:

if (m_latest_wtxid != wtxOrdered.rbegin()) {
    ...
}

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 prefer to keep a non references object in this case.

Copy link
Contributor

Choose a reason for hiding this comment

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

... = wtxOrdered.rbegin()->second.first;

Copy link
Contributor

Choose a reason for hiding this comment

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

Missing notify on m_cond_txadd?

Copy link
Contributor

Choose a reason for hiding this comment

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

txid is required, should be out of ( ).

Copy link
Contributor

Choose a reason for hiding this comment

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

Should be

throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id");

which is the error used in other calls.

Copy link
Contributor

Choose a reason for hiding this comment

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

nit move up

Copy link
Contributor

Choose a reason for hiding this comment

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

clang-format would fix a few other minor things as well

Copy link
Contributor

Choose a reason for hiding this comment

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

arg name should be poll?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed the above; polltime is correct

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this invalid usage?

@jonasschnelli jonasschnelli changed the title Wallet/RPC: Add listsincetx with a stateless (server-side) long polling option Wallet/RPC: Add listsincetx method with a stateless (server-side) long polling option May 17, 2018
@jonasschnelli jonasschnelli force-pushed the 2018/05/listsincetx branch from ecb2e20 to d68f662 Compare May 17, 2018 16:30
@jonasschnelli jonasschnelli force-pushed the 2018/05/listsincetx branch from d68f662 to 139ade1 Compare May 17, 2018 16:36
@jonasschnelli
Copy link
Contributor Author

  • Fixed points found by @promag, ran clang-format
  • Added an example python script that shows the push channel capabilities

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

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

Will play around, just some nits that could be fixed meanwhile.

Copy link
Contributor

Choose a reason for hiding this comment

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

polltime.

Copy link
Contributor

Choose a reason for hiding this comment

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

polltime.

Copy link
Contributor

Choose a reason for hiding this comment

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

nit, add newline.

@jonasschnelli jonasschnelli force-pushed the 2018/05/listsincetx branch 2 times, most recently from 51ea1fd to 2f505ac Compare May 17, 2018 16:52
@promag
Copy link
Contributor

promag commented May 17, 2018

You could note that this is not the same as -walletnotify because that also notifies when a wallet transaction state changes between mempool <-> block.

@jonasschnelli
Copy link
Contributor Author

You could note that this is not the same as -walletnotify because that also notifies when a wallet transaction state changes between mempool <-> block.

Good point.
Conceptually, I think that confirmation change should be detected with another push function (non wallet general "tip has changes" like function).

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

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

Another round.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nit, space example code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fix usage.

Copy link
Contributor

Choose a reason for hiding this comment

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

nit, sort these.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

greater than zero

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 don't understand that comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

s/then/than: If greater than zero, wait with ...

Copy link
Contributor

Choose a reason for hiding this comment

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

Why lock cs_main?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO cs_main should always be locked before cs_wallet, especially with the usage of ListTransactions() and its subclass.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could have a limit argument? Otherwise it would dump the whole wallet?

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 thought of it,... but would like to keep it simple for a first implementation (limit could follow next)

Copy link
Contributor

@promag promag May 17, 2018

Choose a reason for hiding this comment

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

Should not use request.params[1].isNum() otherwise the caller can pass a string (for example) and it won't raise an error. I suggest to change to:

if (transactions.empty() && !request.params[1].isNull() && request.params[1].get_int() > 0)

@jonasschnelli jonasschnelli force-pushed the 2018/05/listsincetx branch from 2f505ac to 3f1b0a1 Compare May 17, 2018 18:40
@DrahtBot
Copy link
Contributor

Needs rebase

@DrahtBot
Copy link
Contributor

There hasn't been much activity lately and the patch still needs rebase, so I am closing this for now. Please let me know when you want to continue working on this, so the pull request can be re-opened.

@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants