-
Notifications
You must be signed in to change notification settings - Fork 988
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
Cannot spend coinbase for N blocks #111
Cannot spend coinbase for N blocks #111
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First set of comments and minor remarks. Directionally it looks good.
chain/src/chain.rs
Outdated
self.store.get_block_header_by_output_commit(commit).map_err( | ||
&Error::StoreErr, | ||
) | ||
pub fn get_block_header_by_output_commit(&self, commit: &Commitment) -> Option<BlockHeader> { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
chain/src/pipe.rs
Outdated
// TODO check every input exists as a UTXO using the UTXO index | ||
|
||
// now check that any coinbase inputs have matured sufficiently | ||
if let Ok(output) = ctx.store.get_output_by_commit(&input.commitment()) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
chain/src/types.rs
Outdated
@@ -57,6 +57,8 @@ pub enum Error { | |||
InvalidBlockTime, | |||
/// Block height is invalid (not previous + 1) | |||
InvalidBlockHeight, | |||
/// coinbase can only be spent after it has matured (n blocks) | |||
ImmatureCoinbase, |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
grin/src/adapters.rs
Outdated
@@ -295,4 +296,12 @@ impl pool::BlockChain for PoolToChainAdapter { | |||
fn get_unspent(&self, output_ref: &Commitment) -> Option<Output> { | |||
self.chain.borrow().get_unspent(output_ref) | |||
} | |||
|
|||
fn get_block_header_by_output_commit(&self, commit: &Commitment) -> Option<BlockHeader> { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
core/src/types.rs
Outdated
#[derive(Debug)] | ||
pub enum CoreError { | ||
/// TODO - rename this | ||
GenericCoreError, |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
163138c
to
e706e74
Compare
/// TODO - wip, just getting imports working, remove this and use more specific errors | ||
GenericPoolError, | ||
/// TODO - is this the right level of abstraction for pool errors? | ||
OutputNotFound, |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
f8a7256
to
c9ed989
Compare
|
||
let out_set = self.outputs | ||
.iter() | ||
.filter(|out| !out.features.contains(COINBASE_OUTPUT)) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -429,12 +438,12 @@ impl Block { | |||
fn verify_coinbase(&self, secp: &Secp256k1) -> Result<(), secp::Error> { | |||
let cb_outs = self.outputs | |||
.iter() | |||
.filter(|out| out.features.intersects(COINBASE_OUTPUT)) | |||
.filter(|out| out.features.contains(COINBASE_OUTPUT)) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@ignopeverell thoughts/feedback on how this is progressing? Went into this thinking this would be a relatively minor change... definitely given me a good deep-dive into the existing txn and block processing code. |
…nbase output commitments
…e that has not yet matured (remember to use a new reward_key for every block) test coverage in place to verify this
c29682b
to
1456a17
Compare
So what's the status on this? Are we giving it a little time to see if a solution that's also applicable to time locks can be found? |
@ignopeverell I think this is good to go. As you mentioned in another thread we should be able to migrate this to a more generalized solution for time locks. But for coinbase specific locks I think this works pretty well. |
get_block_header_by_output_commit
andhead_header
inadd_to_memory_pool
COINBASE_MATURITY
const in consensus (currently10
for testing/dev)PoolError::ImmatureCoinbase
output
inParent::BlockTransaction
validate_block
process_block
with uniquereward_key
per block (not enforced but by convention for it to work correctly)TODO -
validate_block()
I think?add_to_memory_pool
to coverImmatureCoinbase
pathvalidate_block
to coverImmatureCoinbase
path1_000
to10
for testing (revisit later)