Skip to content

Commit

Permalink
consensus: Remove redundant contextual consensus rules
Browse files Browse the repository at this point in the history
By the time we reach any of these rules, we have already rejected
transactions without fOverwintered set, so we can assume that it is set.

We replace the vague "overwinter is active" message with a more specific
"overwintered flag must be set" from one of the removed rules.
  • Loading branch information
nuttycom authored and str4d committed Aug 22, 2020
1 parent 56de0a0 commit 4089e76
Showing 1 changed file with 7 additions and 23 deletions.
30 changes: 7 additions & 23 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,8 +813,8 @@ bool ContextualCheckTransaction(
if (!tx.fOverwintered) {
return state.DoS(
dosLevelConstricting,
error("ContextualCheckTransaction: overwinter is active"),
REJECT_INVALID, "tx-overwinter-active");
error("ContextualCheckTransaction: fOverwintered flag must be set when Overwinter is active"),
REJECT_INVALID, "tx-overwintered-flag-not-set");
}

// Check that all transactions are unexpired
Expand All @@ -830,23 +830,15 @@ bool ContextualCheckTransaction(
// Rules that became inactive after Sapling activation.
if (!saplingActive) {
// Reject transactions with invalid version
if (tx.fOverwintered && tx.nVersion > OVERWINTER_MAX_TX_VERSION ) {
if (tx.nVersion > OVERWINTER_MAX_TX_VERSION ) {
return state.DoS(
dosLevelPotentiallyRelaxing,
error("CheckTransaction(): overwinter version too high"),
REJECT_INVALID, "bad-tx-overwinter-version-too-high");
}

// Reject transactions with valid version but missing overwinter flag
if (tx.nVersion >= OVERWINTER_MIN_TX_VERSION && !tx.fOverwintered) {
return state.DoS(
dosLevelConstricting,
error("ContextualCheckTransaction(): overwinter flag must be set"),
REJECT_INVALID, "tx-overwinter-flag-not-set");
}

// Reject transactions with non-Overwinter version group ID
if (tx.fOverwintered && tx.nVersionGroupId != OVERWINTER_VERSION_GROUP_ID) {
if (tx.nVersionGroupId != OVERWINTER_VERSION_GROUP_ID) {
return state.DoS(
dosLevelPotentiallyRelaxing,
error("CheckTransaction(): invalid Overwinter tx version"),
Expand All @@ -857,32 +849,24 @@ bool ContextualCheckTransaction(

// Rules that apply to Sapling and later:
if (saplingActive) {
// Reject transactions with valid version but missing overwintered flag
if (tx.nVersion >= SAPLING_MIN_TX_VERSION && !tx.fOverwintered) {
return state.DoS(
dosLevelConstricting,
error("ContextualCheckTransaction(): overwintered flag must be set"),
REJECT_INVALID, "tx-overwintered-flag-not-set");
}

// Reject transactions with non-Sapling version group ID
if (tx.fOverwintered && tx.nVersionGroupId != SAPLING_VERSION_GROUP_ID) {
if (tx.nVersionGroupId != SAPLING_VERSION_GROUP_ID) {
return state.DoS(
dosLevelPotentiallyRelaxing,
error("CheckTransaction(): invalid Sapling tx version"),
REJECT_INVALID, "bad-sapling-tx-version-group-id");
}

// Reject transactions with invalid version
if (tx.fOverwintered && tx.nVersion < SAPLING_MIN_TX_VERSION ) {
if (tx.nVersion < SAPLING_MIN_TX_VERSION) {
return state.DoS(
dosLevelConstricting,
error("CheckTransaction(): Sapling version too low"),
REJECT_INVALID, "bad-tx-sapling-version-too-low");
}

// Reject transactions with invalid version
if (tx.fOverwintered && tx.nVersion > SAPLING_MAX_TX_VERSION ) {
if (tx.nVersion > SAPLING_MAX_TX_VERSION) {
return state.DoS(
dosLevelPotentiallyRelaxing,
error("CheckTransaction(): Sapling version too high"),
Expand Down

0 comments on commit 4089e76

Please sign in to comment.