Relax timing requirements for expiring deferred transactions (adds new expired status type to transaction receipts)
This issue replaces #2063.
After talking with Dan about the problem described in #2063, we will be going forward with a different solution to the problem. The attack vector described in that issue is repeated below:
If deferred transactions (whether delayed input transactions or generated transactions) expire, they must all be processed in clear_expired_transactions() at the end of the block (or at least prior to the start of the next block) in order to delete them from the generated_transaction_multi_index and return the allocated RAM back to the payer.
The problem arises from the fact that users can target a particular time slot in which this processing must happen by setting the appropriate expiration time. If their deferred transaction is processed prior to the expiration, then it will be destroyed prior to getting to clear_expired_transactions(). But block producers make no guarantees of processing deferred transactions at any particular time or at all prior to execution. If an attacker creates lots of deferred transactions with an expiration that is a very short time away, there is a good possibility that a large subset of them are not able to be processed by the expiration time. This subset would then have to be processed prior to the next block in our current design, which could overload a producer to the point of causing them to miss the time slot to produce their block. The attacker has the flexibility to target their efforts with this attack to a particular block producer.
Instead of requiring explicit "reaping" of expired deferred transactions, we want this to be done automatically by block producers. But to avoid the attack vector described above, we cannot demand as part of consensus that destroying an expired deferred transaction (and returning the RAM usage to the payer) be done by a particular time (or at all).
The solution is to add an expired status for transaction receipts which can be added into the block summary by a producer if the deferred transaction has in fact expired. Processing such an expired transaction receipt causes the generated_transaction_object to be removed and the RAM usage to be returned to the payer.
Block producers are expected (but not required by consensus) to add expired transaction receipts for all expired deferred transactions as soon as is reasonable. This is a subjective policy: block producers are technically free to implement their own policy for their generated block (subject to pressures put on them by their voters of course). All 21 block producers could just not bother to appropriately add expired transaction receipts for some expired deferred transactions (thus locking up some of the RAM of the payers of those deferred transactions), but that is functionally no different than block producers colluding to censor particular reap actions in the previous solution described in #2063.
Other things to note:
canceldelaywould be invalid if the delayed transaction it refers to has expired regardless of whether theexpiredtransaction receipt for it has been processed yet or not.- Contract code calling
cancel_deferredon a generated transaction that has already expired has no side effect (it is not an error, it just does nothing just like it would do nothing right now if a generated transaction from thesenderwith the specifiedsender_iddidn't exist).
That has been implemented in slim, but it needs testing.
Hi I've pushed a pull request https://github.com/EOSIO/eos/pull/3027 to fix the expired scheduled txn handing. Please would you review my code?
Closed by PR #3027