consensus: pass spent KIs to cuprated#605
Open
redsh4de wants to merge 1 commit into
Open
Conversation
c0c79de to
4b96430
Compare
4b96430 to
6251608
Compare
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What
Addresses the FIXME in
add_valid_block_to_main_chain.Why
Block verification in consensus walks every transaction's inputs to dedupe and check key images. After verification, cuprated walked them a second time to notify the txpool.
This makes it so that the KI vec is returned from consensus, eliminating the second walk.
Where
consensus, helper, cuprated
How
In
helper:tx_key_images()helper for extracting a transactions key imagesIn
consensus:TxsWithKisper block (transactions + validated key images).VerifiedBlock(wrapper for verified block info + the spent key images).verify_prepped_main_chain_blocktakes aPreparedBlockTxs::{Checked, Unchecked}enum so the caller can say whether key images still need checking:Unchecked(Vec<TransactionVerificationData>)- single-block path. Extracts KIs and checks.Checked(TxsWithKis)- batch-sync path.TxsWithKisis only produced bybatch_prepare_main_chain_blockswhere validation was already done, so we skip checking here and use the passed KIs as is.FullVerificationinto two methods, so the txpool path doesn't allocate a key-image Vec it would discard:verify(txpool): returns just the transactions.verify_with_kis(block, internal): returns transactions and key images.check_kis: used by the batch & txpool paths. Takes pre-computed key images.extract_and_check_kis: single-block path. Walks inputs once and builds both the KI dedup set and Vec in one pass.check_kis_unspent: shared chain-spent db query, skipped on a empty set.key_images_spent_checkedbool removed fromBatchPrepareCache. The existence ofTxsWithKismeans that the key images were checked, so this becomes redundant.check_kis_unique's oldwith_capacity(size_hint().1.unwrap_or(0) * 2)always resolved to zero for the batch caller, because whenflat_mapis used on a slice iter, the upper-bound size hint is alwaysNone. To avoid rehashing, we count the KIs once up front and pass capacity as a param.alt_block_to_verified_blockreplaces cuprated'salt_block_to_verified_block_information. Computestotal_feesandspent_key_imagesin one pass, then constructs aVerifiedBlock.In
cuprated:add_valid_block_to_main_chainsplits the newVerifiedBlockinto block information and key images, used like before.alt_block_to_verified_blockin consensus; the local helper is removed.