Merge pull request #2442 from UdjinM6/spectx

Various fixes for special txes
This commit is contained in:
Alexander Block 2018-11-15 05:18:44 +01:00 committed by GitHub
commit f4ec3db067
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 56 additions and 39 deletions

View File

@ -655,7 +655,7 @@ class DIP3Test(BitcoinTestFramework):
address = node.getnewaddress()
key = node.getnewaddress()
blsKey = node.bls('generate')
assert_raises_jsonrpc(None, "bad-tx-type", node.protx, 'register_fund', address, '127.0.0.1:10000', key, blsKey['public'], key, 0, address)
assert_raises_jsonrpc(None, "bad-tx-type-dip3", node.protx, 'register_fund', address, '127.0.0.1:10000', key, blsKey['public'], key, 0, address)
def test_success_create_protx(self, node):
address = node.getnewaddress()

View File

@ -12,7 +12,9 @@
bool CheckCbTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CValidationState& state)
{
AssertLockHeld(cs_main);
if (tx.nType != TRANSACTION_COINBASE) {
return state.DoS(100, false, REJECT_INVALID, "bad-cbtx-type");
}
if (!tx.IsCoinBase()) {
return state.DoS(100, false, REJECT_INVALID, "bad-cbtx-invalid");
@ -20,7 +22,7 @@ bool CheckCbTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CValidatio
CCbTx cbTx;
if (!GetTxPayload(tx, cbTx)) {
return state.DoS(100, false, REJECT_INVALID, "bad-tx-payload");
return state.DoS(100, false, REJECT_INVALID, "bad-cbtx-payload");
}
if (cbTx.nVersion > CCbTx::CURRENT_VERSION) {
@ -37,15 +39,13 @@ bool CheckCbTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CValidatio
// This can only be done after the block has been fully processed, as otherwise we won't have the finished MN list
bool CheckCbTxMerkleRootMNList(const CBlock& block, const CBlockIndex* pindex, CValidationState& state)
{
AssertLockHeld(cs_main);
if (block.vtx[0]->nType != TRANSACTION_COINBASE) {
return true;
}
CCbTx cbTx;
if (!GetTxPayload(*block.vtx[0], cbTx)) {
return state.DoS(100, false, REJECT_INVALID, "bad-tx-payload");
return state.DoS(100, false, REJECT_INVALID, "bad-cbtx-payload");
}
if (pindex) {
@ -63,7 +63,6 @@ bool CheckCbTxMerkleRootMNList(const CBlock& block, const CBlockIndex* pindex, C
bool CalcCbTxMerkleRootMNList(const CBlock& block, const CBlockIndex* pindexPrev, uint256& merkleRootRet, CValidationState& state)
{
AssertLockHeld(cs_main);
LOCK(deterministicMNManager->cs);
CDeterministicMNList tmpMNList;

View File

@ -676,7 +676,7 @@ int64_t CDeterministicMNManager::GetSpork15Value()
bool CDeterministicMNManager::IsProTxWithCollateral(const CTransactionRef& tx, uint32_t n)
{
if (tx->nVersion < 3 || tx->nType != TRANSACTION_PROVIDER_REGISTER) {
if (tx->nVersion != 3 || tx->nType != TRANSACTION_PROVIDER_REGISTER) {
return false;
}
CProRegTx proTx;

View File

@ -76,11 +76,13 @@ static bool CheckInputsHash(const CTransaction& tx, const ProTx& proTx, CValidat
bool CheckProRegTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CValidationState& state)
{
AssertLockHeld(cs_main);
if (tx.nType != TRANSACTION_PROVIDER_REGISTER) {
return state.DoS(100, false, REJECT_INVALID, "bad-protx-type");
}
CProRegTx ptx;
if (!GetTxPayload(tx, ptx)) {
return state.DoS(100, false, REJECT_INVALID, "bad-tx-payload");
return state.DoS(100, false, REJECT_INVALID, "bad-protx-payload");
}
if (ptx.nVersion > CProRegTx::CURRENT_VERSION) {
@ -203,11 +205,13 @@ bool CheckProRegTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CValid
bool CheckProUpServTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CValidationState& state)
{
AssertLockHeld(cs_main);
if (tx.nType != TRANSACTION_PROVIDER_UPDATE_SERVICE) {
return state.DoS(100, false, REJECT_INVALID, "bad-protx-type");
}
CProUpServTx ptx;
if (!GetTxPayload(tx, ptx)) {
return state.DoS(100, false, REJECT_INVALID, "bad-tx-payload");
return state.DoS(100, false, REJECT_INVALID, "bad-protx-payload");
}
if (ptx.nVersion > CProRegTx::CURRENT_VERSION) {
@ -255,11 +259,13 @@ bool CheckProUpServTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CVa
bool CheckProUpRegTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CValidationState& state)
{
AssertLockHeld(cs_main);
if (tx.nType != TRANSACTION_PROVIDER_UPDATE_REGISTRAR) {
return state.DoS(100, false, REJECT_INVALID, "bad-protx-type");
}
CProUpRegTx ptx;
if (!GetTxPayload(tx, ptx)) {
return state.DoS(100, false, REJECT_INVALID, "bad-tx-payload");
return state.DoS(100, false, REJECT_INVALID, "bad-protx-payload");
}
if (ptx.nVersion > CProRegTx::CURRENT_VERSION) {
@ -335,11 +341,13 @@ bool CheckProUpRegTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CVal
bool CheckProUpRevTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CValidationState& state)
{
AssertLockHeld(cs_main);
if (tx.nType != TRANSACTION_PROVIDER_UPDATE_REVOKE) {
return state.DoS(100, false, REJECT_INVALID, "bad-protx-type");
}
CProUpRevTx ptx;
if (!GetTxPayload(tx, ptx)) {
return state.DoS(100, false, REJECT_INVALID, "bad-tx-payload");
return state.DoS(100, false, REJECT_INVALID, "bad-protx-payload");
}
if (ptx.nVersion > CProRegTx::CURRENT_VERSION) {

View File

@ -16,9 +16,7 @@
bool CheckSpecialTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CValidationState& state)
{
AssertLockHeld(cs_main);
if (tx.nVersion < 3 || tx.nType == TRANSACTION_NORMAL)
if (tx.nVersion != 3 || tx.nType == TRANSACTION_NORMAL)
return true;
if (pindexPrev && VersionBitsState(pindexPrev, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0003, versionbitscache) != THRESHOLD_ACTIVE) {
@ -38,12 +36,12 @@ bool CheckSpecialTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CVali
return CheckCbTx(tx, pindexPrev, state);
}
return state.DoS(10, false, REJECT_INVALID, "bad-tx-type");
return state.DoS(10, false, REJECT_INVALID, "bad-tx-type-check");
}
bool ProcessSpecialTx(const CTransaction& tx, const CBlockIndex* pindex, CValidationState& state)
{
if (tx.nVersion < 3 || tx.nType == TRANSACTION_NORMAL) {
if (tx.nVersion != 3 || tx.nType == TRANSACTION_NORMAL) {
return true;
}
@ -57,12 +55,12 @@ bool ProcessSpecialTx(const CTransaction& tx, const CBlockIndex* pindex, CValida
return true; // nothing to do
}
return state.DoS(100, false, REJECT_INVALID, "bad-tx-type");
return state.DoS(100, false, REJECT_INVALID, "bad-tx-type-proc");
}
bool UndoSpecialTx(const CTransaction& tx, const CBlockIndex* pindex)
{
if (tx.nVersion < 3 || tx.nType == TRANSACTION_NORMAL) {
if (tx.nVersion != 3 || tx.nType == TRANSACTION_NORMAL) {
return true;
}

View File

@ -260,7 +260,7 @@ public:
s << vin;
s << vout;
s << nLockTime;
if (this->nVersion >= 3 && this->nType != TRANSACTION_NORMAL)
if (this->nVersion == 3 && this->nType != TRANSACTION_NORMAL)
s << vExtraPayload;
}
@ -339,7 +339,7 @@ struct CMutableTransaction
READWRITE(vin);
READWRITE(vout);
READWRITE(nLockTime);
if (this->nVersion >= 3 && this->nType != TRANSACTION_NORMAL) {
if (this->nVersion == 3 && this->nType != TRANSACTION_NORMAL) {
READWRITE(vExtraPayload);
}
}

View File

@ -1112,7 +1112,7 @@ public:
SerializeOutput(s, nOutput);
// Serialize nLockTime
::Serialize(s, txTo.nLockTime);
if (txTo.nVersion >= 3 && txTo.nType != TRANSACTION_NORMAL)
if (txTo.nVersion == 3 && txTo.nType != TRANSACTION_NORMAL)
::Serialize(s, txTo.vExtraPayload);
}
};

View File

@ -444,7 +444,8 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry,
if (tx.nType == TRANSACTION_PROVIDER_REGISTER) {
CProRegTx proTx;
if (!GetTxPayload(tx, proTx)) {
assert(false);
LogPrintf("%s: ERROR: Invalid transaction payload, tx: %s", __func__, tx.ToString());
return false;
}
mapProTxAddresses.emplace(proTx.addr, tx.GetHash());
mapProTxPubKeyIDs.emplace(proTx.keyIDOwner, tx.GetHash());
@ -455,13 +456,15 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry,
} else if (tx.nType == TRANSACTION_PROVIDER_UPDATE_SERVICE) {
CProUpServTx proTx;
if (!GetTxPayload(tx, proTx)) {
assert(false);
LogPrintf("%s: ERROR: Invalid transaction payload, tx: %s", __func__, tx.ToString());
return false;
}
mapProTxAddresses.emplace(proTx.addr, tx.GetHash());
} else if (tx.nType == TRANSACTION_PROVIDER_UPDATE_REGISTRAR) {
CProUpRegTx proTx;
if (!GetTxPayload(tx, proTx)) {
assert(false);
LogPrintf("%s: ERROR: Invalid transaction payload, tx: %s", __func__, tx.ToString());
return false;
}
mapProTxBlsPubKeyHashes.emplace(proTx.pubKeyOperator.GetHash(), tx.GetHash());
}
@ -825,7 +828,8 @@ void CTxMemPool::removeProTxConflicts(const CTransaction &tx)
if (tx.nType == TRANSACTION_PROVIDER_REGISTER) {
CProRegTx proTx;
if (!GetTxPayload(tx, proTx)) {
assert(false);
LogPrintf("%s: ERROR: Invalid transaction payload, tx: %s", __func__, tx.ToString());
return;
}
if (mapProTxAddresses.count(proTx.addr)) {
@ -842,7 +846,8 @@ void CTxMemPool::removeProTxConflicts(const CTransaction &tx)
} else if (tx.nType == TRANSACTION_PROVIDER_UPDATE_SERVICE) {
CProUpServTx proTx;
if (!GetTxPayload(tx, proTx)) {
assert(false);
LogPrintf("%s: ERROR: Invalid transaction payload, tx: %s", __func__, tx.ToString());
return;
}
if (mapProTxAddresses.count(proTx.addr)) {
@ -854,7 +859,8 @@ void CTxMemPool::removeProTxConflicts(const CTransaction &tx)
} else if (tx.nType == TRANSACTION_PROVIDER_UPDATE_REGISTRAR) {
CProUpRegTx proTx;
if (!GetTxPayload(tx, proTx)) {
assert(false);
LogPrintf("%s: ERROR: Invalid transaction payload, tx: %s", __func__, tx.ToString());
return;
}
removeProTxPubKeyConflicts(tx, proTx.pubKeyOperator);
@ -1142,8 +1148,10 @@ bool CTxMemPool::existsProviderTxConflict(const CTransaction &tx) const {
LOCK(cs);
if (tx.nType == TRANSACTION_PROVIDER_REGISTER) {
CProRegTx proTx;
if (!GetTxPayload(tx, proTx))
assert(false);
if (!GetTxPayload(tx, proTx)) {
LogPrintf("%s: ERROR: Invalid transaction payload, tx: %s", __func__, tx.ToString());
return true; // i.e. can't decode payload == conflict
}
if (mapProTxAddresses.count(proTx.addr) || mapProTxPubKeyIDs.count(proTx.keyIDOwner) || mapProTxBlsPubKeyHashes.count(proTx.pubKeyOperator.GetHash()))
return true;
if (!proTx.collateralOutpoint.hash.IsNull() && mapProTxCollaterals.count(proTx.collateralOutpoint))
@ -1151,14 +1159,18 @@ bool CTxMemPool::existsProviderTxConflict(const CTransaction &tx) const {
return false;
} else if (tx.nType == TRANSACTION_PROVIDER_UPDATE_SERVICE) {
CProUpServTx proTx;
if (!GetTxPayload(tx, proTx))
assert(false);
if (!GetTxPayload(tx, proTx)) {
LogPrintf("%s: ERROR: Invalid transaction payload, tx: %s", __func__, tx.ToString());
return true; // i.e. can't decode payload == conflict
}
auto it = mapProTxAddresses.find(proTx.addr);
return it != mapProTxAddresses.end() && it->second != proTx.proTxHash;
} else if (tx.nType == TRANSACTION_PROVIDER_UPDATE_REGISTRAR) {
CProUpRegTx proTx;
if (!GetTxPayload(tx, proTx))
assert(false);
if (!GetTxPayload(tx, proTx)) {
LogPrintf("%s: ERROR: Invalid transaction payload, tx: %s", __func__, tx.ToString());
return true; // i.e. can't decode payload == conflict
}
auto it = mapProTxBlsPubKeyHashes.find(proTx.pubKeyOperator.GetHash());
return it != mapProTxBlsPubKeyHashes.end() && it->second != proTx.proTxHash;
}

View File

@ -2975,7 +2975,7 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, bool ov
coinControl.Select(txin.prevout);
int nExtraPayloadSize = 0;
if (tx.nVersion >= 3 && tx.nType != TRANSACTION_NORMAL)
if (tx.nVersion == 3 && tx.nType != TRANSACTION_NORMAL)
nExtraPayloadSize = (int)tx.vExtraPayload.size();
CReserveKey reservekey(this);