Test peer banning logic in both pre- and post-initial block download states
This commit is contained in:
parent
d2b5a2daeb
commit
6206d86237
|
@ -506,8 +506,11 @@ TEST(checktransaction_tests, bad_txns_invalid_joinsplit_signature) {
|
||||||
CTransaction tx(mtx);
|
CTransaction tx(mtx);
|
||||||
|
|
||||||
MockCValidationState state;
|
MockCValidationState state;
|
||||||
|
// during initial block download, DoS ban score should be zero, else 100
|
||||||
EXPECT_CALL(state, DoS(0, false, REJECT_INVALID, "bad-txns-invalid-joinsplit-signature", false)).Times(1);
|
EXPECT_CALL(state, DoS(0, false, REJECT_INVALID, "bad-txns-invalid-joinsplit-signature", false)).Times(1);
|
||||||
ContextualCheckTransaction(tx, state, 0, 100);
|
ContextualCheckTransaction(tx, state, 0, 100, []() { return true; });
|
||||||
|
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-invalid-joinsplit-signature", false)).Times(1);
|
||||||
|
ContextualCheckTransaction(tx, state, 0, 100, []() { return false; });
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(checktransaction_tests, non_canonical_ed25519_signature) {
|
TEST(checktransaction_tests, non_canonical_ed25519_signature) {
|
||||||
|
@ -539,8 +542,11 @@ TEST(checktransaction_tests, non_canonical_ed25519_signature) {
|
||||||
CTransaction tx(mtx);
|
CTransaction tx(mtx);
|
||||||
|
|
||||||
MockCValidationState state;
|
MockCValidationState state;
|
||||||
|
// during initial block download, DoS ban score should be zero, else 100
|
||||||
EXPECT_CALL(state, DoS(0, false, REJECT_INVALID, "bad-txns-invalid-joinsplit-signature", false)).Times(1);
|
EXPECT_CALL(state, DoS(0, false, REJECT_INVALID, "bad-txns-invalid-joinsplit-signature", false)).Times(1);
|
||||||
ContextualCheckTransaction(tx, state, 0, 100);
|
ContextualCheckTransaction(tx, state, 0, 100, []() { return true; });
|
||||||
|
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "bad-txns-invalid-joinsplit-signature", false)).Times(1);
|
||||||
|
ContextualCheckTransaction(tx, state, 0, 100, []() { return false; });
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(checktransaction_tests, OverwinterConstructors) {
|
TEST(checktransaction_tests, OverwinterConstructors) {
|
||||||
|
@ -829,8 +835,11 @@ TEST(checktransaction_tests, OverwinterNotActive) {
|
||||||
|
|
||||||
CTransaction tx(mtx);
|
CTransaction tx(mtx);
|
||||||
MockCValidationState state;
|
MockCValidationState state;
|
||||||
|
// during initial block download, DoS ban score should be zero, else 100
|
||||||
EXPECT_CALL(state, DoS(0, false, REJECT_INVALID, "tx-overwinter-not-active", false)).Times(1);
|
EXPECT_CALL(state, DoS(0, false, REJECT_INVALID, "tx-overwinter-not-active", false)).Times(1);
|
||||||
ContextualCheckTransaction(tx, state, 1, 100);
|
ContextualCheckTransaction(tx, state, 1, 100, []() { return true; });
|
||||||
|
EXPECT_CALL(state, DoS(100, false, REJECT_INVALID, "tx-overwinter-not-active", false)).Times(1);
|
||||||
|
ContextualCheckTransaction(tx, state, 1, 100, []() { return false; });
|
||||||
}
|
}
|
||||||
|
|
||||||
// This tests a transaction without the fOverwintered flag set, against the Overwinter consensus rule set.
|
// This tests a transaction without the fOverwintered flag set, against the Overwinter consensus rule set.
|
||||||
|
|
12
src/main.cpp
12
src/main.cpp
|
@ -877,8 +877,14 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& in
|
||||||
* 1. AcceptToMemoryPool calls CheckTransaction and this function.
|
* 1. AcceptToMemoryPool calls CheckTransaction and this function.
|
||||||
* 2. ProcessNewBlock calls AcceptBlock, which calls CheckBlock (which calls CheckTransaction)
|
* 2. ProcessNewBlock calls AcceptBlock, which calls CheckBlock (which calls CheckTransaction)
|
||||||
* and ContextualCheckBlock (which calls this function).
|
* and ContextualCheckBlock (which calls this function).
|
||||||
|
* 3. The isInitBlockDownload argument is only to assist with testing.
|
||||||
*/
|
*/
|
||||||
bool ContextualCheckTransaction(const CTransaction& tx, CValidationState &state, const int nHeight, const int dosLevel)
|
bool ContextualCheckTransaction(
|
||||||
|
const CTransaction& tx,
|
||||||
|
CValidationState &state,
|
||||||
|
const int nHeight,
|
||||||
|
const int dosLevel,
|
||||||
|
bool (*isInitBlockDownload)())
|
||||||
{
|
{
|
||||||
bool overwinterActive = NetworkUpgradeActive(nHeight, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER);
|
bool overwinterActive = NetworkUpgradeActive(nHeight, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER);
|
||||||
bool saplingActive = NetworkUpgradeActive(nHeight, Params().GetConsensus(), Consensus::UPGRADE_SAPLING);
|
bool saplingActive = NetworkUpgradeActive(nHeight, Params().GetConsensus(), Consensus::UPGRADE_SAPLING);
|
||||||
|
@ -886,7 +892,7 @@ bool ContextualCheckTransaction(const CTransaction& tx, CValidationState &state,
|
||||||
|
|
||||||
// If Sprout rules apply, reject transactions which are intended for Overwinter and beyond
|
// If Sprout rules apply, reject transactions which are intended for Overwinter and beyond
|
||||||
if (isSprout && tx.fOverwintered) {
|
if (isSprout && tx.fOverwintered) {
|
||||||
return state.DoS(IsInitialBlockDownload() ? 0 : dosLevel,
|
return state.DoS(isInitBlockDownload() ? 0 : dosLevel,
|
||||||
error("ContextualCheckTransaction(): overwinter is not active yet"),
|
error("ContextualCheckTransaction(): overwinter is not active yet"),
|
||||||
REJECT_INVALID, "tx-overwinter-not-active");
|
REJECT_INVALID, "tx-overwinter-not-active");
|
||||||
}
|
}
|
||||||
|
@ -987,7 +993,7 @@ bool ContextualCheckTransaction(const CTransaction& tx, CValidationState &state,
|
||||||
dataToBeSigned.begin(), 32,
|
dataToBeSigned.begin(), 32,
|
||||||
tx.joinSplitPubKey.begin()
|
tx.joinSplitPubKey.begin()
|
||||||
) != 0) {
|
) != 0) {
|
||||||
return state.DoS(IsInitialBlockDownload() ? 0 : 100,
|
return state.DoS(isInitBlockDownload() ? 0 : 100,
|
||||||
error("CheckTransaction(): invalid joinsplit signature"),
|
error("CheckTransaction(): invalid joinsplit signature"),
|
||||||
REJECT_INVALID, "bad-txns-invalid-joinsplit-signature");
|
REJECT_INVALID, "bad-txns-invalid-joinsplit-signature");
|
||||||
}
|
}
|
||||||
|
|
|
@ -343,7 +343,8 @@ bool ContextualCheckInputs(const CTransaction& tx, CValidationState &state, cons
|
||||||
std::vector<CScriptCheck> *pvChecks = NULL);
|
std::vector<CScriptCheck> *pvChecks = NULL);
|
||||||
|
|
||||||
/** Check a transaction contextually against a set of consensus rules */
|
/** Check a transaction contextually against a set of consensus rules */
|
||||||
bool ContextualCheckTransaction(const CTransaction& tx, CValidationState &state, int nHeight, int dosLevel);
|
bool ContextualCheckTransaction(const CTransaction& tx, CValidationState &state, int nHeight, int dosLevel,
|
||||||
|
bool (*isInitBlockDownload)() = IsInitialBlockDownload);
|
||||||
|
|
||||||
/** Apply the effects of this transaction on the UTXO set represented by view */
|
/** Apply the effects of this transaction on the UTXO set represented by view */
|
||||||
void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight);
|
void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight);
|
||||||
|
|
Loading…
Reference in New Issue