-
Notifications
You must be signed in to change notification settings - Fork 415
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
allow breaking inside for_blocks closures using ControlFlow #925
base: master
Are you sure you want to change the base?
Conversation
Thanks for the contribution! |
ba04a6e
to
4775424
Compare
yes, exiting early means that after the right one if found no more block parsing and hashing has to be done. actually, i just found out that #913 changed this function to return the last matching transaction, whereas before it returned the first one. i think it is best to get the last one as according to bip 30 it is allowed to have duplicate txids, just not duplicate utxos, and i think that it is more likely that a transaction is found in more recent blocks, so reversing
the may be collisions in txids as long as no utxos from the utxo set would be overwritten by it.
i dont see a complexity increase in this code, and find this well worth the optimization |
4775424
to
f46cffc
Compare
reversing (btw that force push was just a rebase) |
Not sure - do you mean that two different transactions having the same txid? |
i meant that two transaction having the same txid is allowed in bitcoin, as stated in bip 30. if this would happen i believe it would be more likely because of a bug than a collision of sha 256 if a user requests a transaction by txid, which transaction should be returned? before #913 this was the first one, now every transaction it finds is assigned to a variable, overwriting a previous result, resulting in the last one being returned |
I think that #933 should resolve the ordering (returning the first matching tx), as well as not parsing the next blocks. |
i think as well (it reuses the old logic). actually, such a thing should probably be clarified in the electrum server protocol spec. that fixes one point of this pr (i actually found out about it later than making this). i would like to have the possible optimization i mentioned in the first message, to save bitcoin core from having to send all blocks after the tx has already been found, using this method of 'telling' |
f46cffc
to
dcae47f
Compare
dcae47f
to
cbb0ed1
Compare
bitcoind will keep sending blocks even if
ControlFlow::Break(_)
if returned, so they have to be received to not interfere with future calls. blocks technically do not have to be parsed then, which happens now at the sender side ofblocks_recv
, but this makes more sense to optimize that together with using bitcoin_slices (#913 moves parsing of the block to the receiver side).is it possible to send bitcoind some message to stop sending blocks? otherwise it would be possible to request a few at a time and stop when
ControlFlow::Break(_)
is returned to prevent having to receive (and bitcoind having to read from disk and send) many blocks.i also rewrote
lookup_transaction
to use this method of breaking, which will save at least parsing unneeded blocks later (#913). the only change to this function right now isfor_blocks
will keep the state with the ControlFlow enum instead oflookup_transaction
with Optioni also happened to need this when making a poc implementation for is_unused (#920)