-
Notifications
You must be signed in to change notification settings - Fork 98
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
A technique to access cc transactions in the connecting block #405
Comments
Could you give specific examples of validation code that will use this? Please go into detail as to why |
An example is any myGetTransaction call which refers to a previous transaction in the same block (that is, when added to mempool this tx was spending another tx sitting in mempool. Spending in mempool is enabled by default by myGetTransaction). |
Below is a SWOT at what I see as the problem and a possible solution. I appreciate comments and corrections. This will be helpful in clarifying my understanding of the problem and "missing pieces" in my knowledge of the existing process. Adjusting the mempool during transaction validationSituationThe code validating transactions entering the mempool is very similar to validating transactions that are received in a block. A major difference is what the mempool contains when those processes complete. WeaponsThe existing code works and must keep working. This provides existing processes that provide a baseline (templates to work with). ObjectivesThe existing code is overly complicated which makes adding features difficult and error-prone. New code that is performant, uncomplicated, and centralized (easy to adjust) should replace the existing sections of code. TacticsThe mempool is not important to block addition until the end, but is important to adding transactions to the mempool. Therefore, transaction validation should be passed an object that is similar (has the same interface) to a mempool. I will call this a A
Such a strategy allows the validation code to receive minimal changes and work regardless of the context of why the validation code was called. Methods such as In the case of processing a block, "removing" a transaction from the pool because it was successfully validated has implications to the real mempool. Such transactions should be marked so that further transaction validation code sees the transaction as "available" or "spent" and successful block validation sees the transaction as needing to be removed from the true mempool if it exists. |
Status: I have been working on some unit tests in the Reference: how SmartUSD did it: https://github.com/pbcllc/sfusd-core/blob/b4ccf54db8e6a1dfa87f1756d273c1bb0cca463d/src/validation.cpp#L2249 |
Seems TransactionPool is interesting idea (I suppose you mean it is an instance of CTxMempool). So we switch pools from the global to the TransactionPool when a block is connected. This would allow to use some services of the CtxMempool like check if an output is spent in the pool, maybe search functions. |
Think of CTxMempool as a child class of the TransactionPool class.
Agreed
I will research the implications. Thanks again for your input. |
In cc modules a tx could spend another tx while it is staying in mempool, so when those two txns are added to the chain they are put in the same block.
So in the cc validation code we should provide that functions like myGetTransaction or CCgetspenttxid could access txns in the connecting block (when the cc validation code is run).
Currently this task is done as follows:
before a block is connected all mempool txns are removed and stored in a temp object, then mempool is filled with the block's transactions, the original mempool state is restored, the block is validated.
There are several issues with this approach:
There is another experimental implementation of this feature, in an additional repository (we worked out it with decker).
This implementation does not change the mempool state at all but instead has a special version of myGetTransaction (eval->GetTxUnconfirmed) for use inside validation which accesses block txns directly (instead of mempool) when the block is connected.
This solution does not change the mempool state so no performance issues and no need to cleanup. Also there is no side effects if the validation code checks if a tx is spent in mempool (as the mempool state might be different on different nodes).
What we need to do for this case is make special functions for use inside the validation code that will look into connecting block transactions instead of mempool.
(would like to get opinions, @ca333, @Alrighttt, @jl777, @DeckerSU)
The text was updated successfully, but these errors were encountered: