-
Notifications
You must be signed in to change notification settings - Fork 992
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
Ensure new coins can't be spent for X blocks #27
Comments
First part of this implemented in 38d5d67, by explicitly flagging coinbase outputs. |
Question about this - Would signing the |
A miner can't mess with these bits without invalidating the coinbase sums of outputs and kernels: https://github.com/ignopeverell/grin/blob/master/core/src/core/block.rs#L418 If you want to convince yourself of it, adding a unit test would be great :-) |
I see some discussion around a possibly related idea in #25? Feels like these two requirements "prevent spending of coinbase for n blocks" and "time locked transactions" may be examples of a more generalized solution somehow - like tracking a "minimum block height before spendable" on outputs of a transaction. Maybe every transaction has this (and normally this is the current block height)? |
Ah got it - on the block containing the coinbase itself we check that the coinbase output (presumably a single output normally?) and the coinbase transaction kernels are all consistent. I think my question was poorly written - I'm thinking more in terms of what happens when that coinbase output becomes an input into a subsequent transaction, say in the next block vs. 1001 blocks later. (And yes a unit test here is something I'd definitely like to put together to convince myself of some of this...) |
No, you have to track the features on the output the input is referencing. If the output is a coinbase, then you check the block distance. |
Throwaway spike/experiment PR up here - antiochp#1 This is more playing around to get a better feel for the various data structures in grin than a real attempt at solving this issue but I would appreciate any feedback you have? |
This looks like it's going the right way. As your comment indicates, it needs to be merged with get_unspent somehow as the current brute-force lookup block by block and output by output definitely won't perform very well. We may need to tweak the storage structure a little to have that information readily available. Also, not sure if you haven't come around it yet, but similar validation will need to be done on block outputs. |
In terms of the storage structure - are we opposed to swapping out the |
I was thinking about database storage structure. Loading all blocks backward from storage is still going to be a lot more expensive than an in-memory iteration. Maybe commitment to block header hash entries in rocksdb? |
Realizing how steep the learning curve is here... Planning to take some time to read up on the Exposed through something roughly like -
I assume we will eventually need to handle a re-org (rewound?) but will worry about that later. |
Correct on everything. |
PR up for adding (and using) |
Reworked the previous spike based on better understanding - ignopeverell/grin#111 I think this covers this rule when adding new transactions via Also need to make sure we have decent test coverage around this. |
@ignopeverell The block reward is currently hard-coded to This has surfaced in a couple of places while adding test coverage for #111 -
Edit:
I sort of see why this makes sense for an individual transaction. But if the inputs and outputs of a block can be treated as a single transaction for validation purposes - does this restriction also apply? And if we can apply cut-through across multiple blocks - does it also apply here? Is the answer here to simply never reuse a private key - and to enforce this somehow? |
Yes, we really want to enforce each commitment to be unique. Otherwise this can create a few headaches, like the ones you mention. And we generally don't want people to reuse keys for even more reasons than in Bitcoin. |
So in the tests do we just want to use a unique |
Also looking through the code - I see |
Yes, just assume it's in there for now. It will actually be enforced by what I'm working on right now: the UTXO sum tree. |
This should be resolved by #111 |
We need to prevent miners from being able to spend their reward for enough blocks so that they can't benefit from forking the chain. A sensible default may be 1000 blocks, which would be 10 times Bitcoin's (given that our block time is 1/10th).
The text was updated successfully, but these errors were encountered: