Skip to content

Save remaining utxos in a file#7

Open
mtrycz wants to merge 3 commits into
gandrewstone:masterfrom
mtrycz:save-utxos
Open

Save remaining utxos in a file#7
mtrycz wants to merge 3 commits into
gandrewstone:masterfrom
mtrycz:save-utxos

Conversation

@mtrycz

@mtrycz mtrycz commented Nov 23, 2020

Copy link
Copy Markdown
Contributor

At the end of a successful run an attempt to save the remaining utxos is made in utxos.json file. This will not work if the run is interrupted.

The new utxos can be simply copy-pasted to the txunami.json configuration file.

A small off-by-one bug is corrected: if the number of utxos read was already equal to the desired number of utxos, the old code would still cycle once. WIth this fix the preparation phase can be skipped entirely if the number of utxos read is already sufficient.

Comment thread main.cpp

printf("done in %f4.2 sec\n", ((float)(end-start))/1000000000.0);
printf("create tx loop in %6.2f sec\n", ((float)(end-createTxLoopStart))/1000000000.0);
printf("Generate a block and push <Enter>... ");

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think we want to system() a script (configured in txunami.json) here. That script can just wait for an enter, or it can wait while polling for a block.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah a simple script like the one in point 7 by Mr Toomim would probably suffice.

I have encountered instances where only part of my fan-out transactions would confirm in the first block, even in two stage setups.

For now I'm just monitoring getmempoolinfo to know when to push Enter.

Comment thread main.cpp
CScript script = utxo.constraintScript;
entry.pushKV("scriptPubKey", HexStr(script.begin(), script.end()));
entry.pushKV("privKey", CBitcoinSecret(utxo.privKey).ToString());
results.push_back(entry);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

write the address as well (yeah I know that txunami doesn't need it)... but it could be useful for scripts that read this and do things like access the spends in an explorer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I thought about it because it would be useful, but it's not part of the UTXO object, so didn't bother.

I have now added the address.

@gandrewstone

Copy link
Copy Markdown
Owner

I have a thought about the approach -- if we wrote the newly created private keys (and addresses for convenience) to a file BEFORE executing the txunami loop, then a script could easily be written that accessed electrscash or some other service to find the UTXOs associated with these private keys, and produce this utxo.json file for input.

I'm often ctrl-c -ing txunami to stop it, and even if you don't do that, as you get into higher rates you'll find that it sometimes "detaches" from the nodes state -- some tx gets rejected due to mempool policy or a dropped packet and then all spends are rejected due to missing parents. All of these utxo would then be lost.

So this would allow us to recover all coins even in these 2 cases. What do you think?

@mtrycz

mtrycz commented Nov 24, 2020

Copy link
Copy Markdown
Contributor Author

Reagarding recovering utxos on a non successful run: it makes perfect sense, but there are lower hanging fruit before I'd think to tackle that.

Regarding this PR in general, unfortunately it's broken, don't merge it yet. I have realised that the last iteration is not saved/considered in the array I'm saving. So I end up with an array of txos of which some are spent (starting from the top) and some are unspent. The proportion is a lottery.

I haven't dug into the code in great detail, do you know how can one update the txos easily after the last iteration?

@mtrycz

mtrycz commented Nov 24, 2020

Copy link
Copy Markdown
Contributor Author

Regarding recovering utxos on a non successful run: oh, do you mean to simply store the privkeys and let an external service to recover the UTXOs from that. It's simply doable, yeah.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants