enforce coinbase maturity rule, skip shielded-only rule instead
This commit is contained in:
parent
7db0de5e0c
commit
6574a561b5
|
@ -310,7 +310,7 @@ impl Transaction {
|
|||
// because of other consensus rules
|
||||
OnlyShieldedOutputs { spend_height }
|
||||
} else {
|
||||
SomeTransparentOutputs
|
||||
SomeTransparentOutputs { spend_height }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -126,7 +126,10 @@ impl OrderedUtxo {
|
|||
)]
|
||||
pub enum CoinbaseSpendRestriction {
|
||||
/// The UTXO is spent in a transaction with one or more transparent outputs
|
||||
SomeTransparentOutputs,
|
||||
SomeTransparentOutputs {
|
||||
/// The height at which the UTXO is spent
|
||||
spend_height: block::Height,
|
||||
},
|
||||
|
||||
/// The UTXO is spent in a transaction which only has shielded outputs
|
||||
OnlyShieldedOutputs {
|
||||
|
|
|
@ -83,7 +83,10 @@ fn reject_unshielded_coinbase_utxo_spend() {
|
|||
};
|
||||
let ordered_utxo = transparent::OrderedUtxo::new(output, created_height, 0);
|
||||
|
||||
let spend_restriction = transparent::CoinbaseSpendRestriction::SomeTransparentOutputs;
|
||||
let spend_restriction = transparent::CoinbaseSpendRestriction::SomeTransparentOutputs {
|
||||
// Use some fake height, this is only used on Regtest
|
||||
spend_height: Height::MIN,
|
||||
};
|
||||
|
||||
let result = check::utxo::transparent_coinbase_spend(
|
||||
outpoint,
|
||||
|
|
|
@ -204,23 +204,26 @@ pub fn transparent_coinbase_spend(
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
match spend_restriction {
|
||||
OnlyShieldedOutputs { spend_height } => {
|
||||
let min_spend_height = utxo.height + MIN_TRANSPARENT_COINBASE_MATURITY.into();
|
||||
let min_spend_height =
|
||||
min_spend_height.expect("valid UTXOs have coinbase heights far below Height::MAX");
|
||||
if spend_height >= min_spend_height || network.is_regtest() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(ImmatureTransparentCoinbaseSpend {
|
||||
outpoint,
|
||||
spend_height,
|
||||
min_spend_height,
|
||||
created_height: utxo.height,
|
||||
})
|
||||
}
|
||||
let spend_height = match spend_restriction {
|
||||
OnlyShieldedOutputs { spend_height } => spend_height,
|
||||
SomeTransparentOutputs { spend_height } if network.is_regtest() => spend_height,
|
||||
SomeTransparentOutputs { .. } => {
|
||||
return Err(UnshieldedTransparentCoinbaseSpend { outpoint })
|
||||
}
|
||||
SomeTransparentOutputs => Err(UnshieldedTransparentCoinbaseSpend { outpoint }),
|
||||
};
|
||||
|
||||
let min_spend_height = utxo.height + MIN_TRANSPARENT_COINBASE_MATURITY.into();
|
||||
let min_spend_height =
|
||||
min_spend_height.expect("valid UTXOs have coinbase heights far below Height::MAX");
|
||||
if spend_height >= min_spend_height {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(ImmatureTransparentCoinbaseSpend {
|
||||
outpoint,
|
||||
spend_height,
|
||||
min_spend_height,
|
||||
created_height: utxo.height,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue