diff --git a/src/assetdb.cpp b/src/assetdb.cpp index 4350c8e..ba6dcb5 100755 --- a/src/assetdb.cpp +++ b/src/assetdb.cpp @@ -23,7 +23,7 @@ CAssetData::CAssetData(const CAsset& _asset, const CTransactionRef& assetTx, con asset = _asset; nTime = _nTime; txhash = assetTx->GetHash(); - const CTxOut& txout = assetTx->vout[nOut]; + CTxOutAsset txout = assetTx->vpout[nOut]; issuingAddress = txout.scriptPubKey; if(txout.nValue) issuedAmount = txout.nValue; diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 6610d5c..fa8705c 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -247,8 +247,8 @@ class CTestNetParams : public CChainParams { consensus.BIP34Hash = uint256S("0x0000000023b3a96d3484e5abb3755c413e7d41500f8e2a5c3f0dd01299cd8ef8"); consensus.BIP65Height = 581885; // 00000000007f6655f22f98e72ed80d8b06dc761d5da09df0fa1dc4be4f861eb6 consensus.BIP66Height = 330776; // 000000002104c8c45e99a8853285a3b592602a3ccde2b832481da85e9e4ba182 - consensus.CSVHeight = 4000; // 00000000025e930139bac5c6c31a403776da130831ab85be56578f3fa75369bb - consensus.SegwitHeight = 4000; // 00000000002b980fcd729daaa248fd9316a5200e9b367f4ff2c42453e84201ca + consensus.CSVHeight = 1; // 00000000025e930139bac5c6c31a403776da130831ab85be56578f3fa75369bb + consensus.SegwitHeight = 1; // 00000000002b980fcd729daaa248fd9316a5200e9b367f4ff2c42453e84201ca consensus.MinBIP9WarningHeight = 836640; // segwit activation height + miner confirmation window consensus.powLimit = uint256S("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); consensus.nPowTargetTimespan = 60; // two weeks diff --git a/src/consensus/validation.h b/src/consensus/validation.h index d409b43..9aa8f0f 100644 --- a/src/consensus/validation.h +++ b/src/consensus/validation.h @@ -168,10 +168,8 @@ inline int GetWitnessCommitmentIndex(const CBlock& block) { int commitpos = NO_WITNESS_COMMITMENT; if (!block.vtx.empty()) { - - for(unsigned int i = 0; i < (block.vtx[0]->nVersion >= TX_ELE_VERSION ? block.vtx[0]->vpout.size() : block.vtx[0]->vout.size()) ; i++){ - const CTxOutAsset& vout = (block.vtx[0]->nVersion >= TX_ELE_VERSION ? block.vtx[0]->vpout[i] : block.vtx[0]->vout[i]); - + for(size_t o = 0; o < (block.vtx[0]->nVersion >= TX_ELE_VERSION ? block.vtx[0]->vpout.size() : block.vtx[0]->vout.size()) ; o++){ + const CTxOutAsset& vout = (block.vtx[0]->nVersion >= TX_ELE_VERSION ? block.vtx[0]->vpout[o] : block.vtx[0]->vout[o]); if (vout.scriptPubKey.size() >= MINIMUM_WITNESS_COMMITMENT && vout.scriptPubKey[0] == OP_RETURN && vout.scriptPubKey[1] == 0x24 && @@ -179,7 +177,7 @@ inline int GetWitnessCommitmentIndex(const CBlock& block) vout.scriptPubKey[3] == 0x21 && vout.scriptPubKey[4] == 0xa9 && vout.scriptPubKey[5] == 0xed) { - commitpos = i; + commitpos = o; } } } diff --git a/src/core_write.cpp b/src/core_write.cpp index 6ffb9a2..aa63572 100644 --- a/src/core_write.cpp +++ b/src/core_write.cpp @@ -294,12 +294,11 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, entry.pushKV("data", vdata); UniValue vout(UniValue::VARR); - for(unsigned int k = 0; k < (tx.nVersion >= TX_ELE_VERSION ? tx.vpout.size() : tx.vout.size()) ; k++){ - CTxOutAsset txout = (tx.nVersion >= TX_ELE_VERSION ? tx.vpout[k] : tx.vout[k]); + for(unsigned int k = 0; k < tx.vout.size(); k++){ + CTxOut txout = tx.vout[k]; UniValue out(UniValue::VOBJ); out.pushKV("value", ValueFromAmount(txout.nValue)); - out.pushKV("asset", txout.nAsset.getName()); out.pushKV("n", (int64_t)k); UniValue o(UniValue::VOBJ); @@ -309,6 +308,24 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, } entry.pushKV("vout", vout); + if(tx.nVersion >= TX_ELE_VERSION ){ + UniValue vpout(UniValue::VARR); + for(unsigned int k = 0; k < tx.vpout.size(); k++){ + CTxOutAsset txout = tx.vpout[k]; + + UniValue out(UniValue::VOBJ); + out.pushKV("value", ValueFromAmount(txout.nValue)); + out.pushKV("asset", txout.nAsset.getName()); + out.pushKV("n", (int64_t)k); + + UniValue o(UniValue::VOBJ); + ScriptPubKeyToUniv(txout.scriptPubKey, o, true); + out.pushKV("scriptPubKey", o); + vout.push_back(out); + } + entry.pushKV("vpout", vout); + } + if (!tx.extraPayload.empty()) { entry.pushKV("extraPayloadSize", (int)tx.extraPayload.size()); entry.pushKV("extraPayload", HexStr(tx.extraPayload)); diff --git a/src/miner.cpp b/src/miner.cpp index f3a5ccc..5699638 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -157,13 +157,13 @@ std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& sc // Create coinbase transaction. CMutableTransaction coinbaseTx; - if(nHeight >= 4000) + if(nHeight >= 1) coinbaseTx.nVersion = TX_ELE_VERSION; coinbaseTx.vin.resize(1); coinbaseTx.vin[0].prevout.SetNull(); coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0; - if(nHeight <= 4000){ + if(Params().NetworkIDString() == CBaseChainParams::TESTNET && nHeight < 1){ coinbaseTx.vout.resize(1); coinbaseTx.vout[0].scriptPubKey = scriptPubKeyIn; coinbaseTx.vout[0].nValue = nFees + GetBlockSubsidy(nHeight, chainparams.GetConsensus()); @@ -194,7 +194,7 @@ std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& sc } int64_t nTime2 = GetTimeMicros(); - LogPrint(BCLog::BENCH, "CreateNewBlock() packages: %.2fms (%d packages, %d updated descendants), validity: %.2fms (total %.2fms)\n", 0.001 * (nTime1 - nTimeStart), nPackagesSelected, nDescendantsUpdated, 0.001 * (nTime2 - nTime1), 0.001 * (nTime2 - nTimeStart)); + LogPrint(BCLog::BENCH, "CreateNewBlock() packages: %.2fms (%d packages, %d updated descendants), validity: %.2fms (total %.2fms)\n %s \n", 0.001 * (nTime1 - nTimeStart), nPackagesSelected, nDescendantsUpdated, 0.001 * (nTime2 - nTime1), 0.001 * (nTime2 - nTimeStart), pblock->ToString()); return std::move(pblocktemplate); } diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index bc40ba5..081a170 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -345,23 +345,6 @@ inline void UnserializeTransaction(TxType& tx, Stream& s) { else s >> tx.vout; } - - if ((flags & 1) && fAllowWitness) { - /* The witness flag is present, and we support witnesses. */ - flags ^= 1; - for (size_t i = 0; i < tx.vin.size(); i++) { - s >> tx.vin[i].scriptWitness.stack; - } - if (!tx.HasWitness()) { - /* It's illegal to encode witnesses when all witness stacks are empty. */ - throw std::ios_base::failure("Superfluous witness record"); - } - } - if (flags) { - /* Unknown flag in the serialization */ - throw std::ios_base::failure("Unknown transaction optional data"); - } - s >> tx.nLockTime; if (tx.nVersion >= TX_ELE_VERSION) { size_t nOutputs = ReadCompactSize(s); tx.vdata.reserve(nOutputs); @@ -381,7 +364,25 @@ inline void UnserializeTransaction(TxType& tx, Stream& s) { tx.vdata[k]->nVersion = bv; s >> *tx.vdata[k]; } - } else if (tx.nVersion >= 3 && tx.nType != TRANSACTION_NORMAL) { + } + + if ((flags & 1) && fAllowWitness) { + /* The witness flag is present, and we support witnesses. */ + flags ^= 1; + for (size_t i = 0; i < tx.vin.size(); i++) { + s >> tx.vin[i].scriptWitness.stack; + } + if (!tx.HasWitness()) { + /* It's illegal to encode witnesses when all witness stacks are empty. */ + throw std::ios_base::failure("Superfluous witness record"); + } + } + if (flags) { + /* Unknown flag in the serialization */ + throw std::ios_base::failure("Unknown transaction optional data"); + } + s >> tx.nLockTime; + if (tx.nVersion == 3 && tx.nType != TRANSACTION_NORMAL) { s >> tx.extraPayload; } } @@ -408,26 +409,25 @@ inline void SerializeTransaction(const TxType& tx, Stream& s) { s << flags; } s << tx.vin; - if (tx.nVersion >= TX_ELE_VERSION) s << tx.vpout; else s << tx.vout; - if (flags & 1) { - for (size_t i = 0; i < tx.vin.size(); i++) { - s << tx.vin[i].scriptWitness.stack; - } - } - s << tx.nLockTime; - if (tx.nVersion >= TX_ELE_VERSION) { WriteCompactSize(s, tx.vdata.size()); for (size_t k = 0; k < tx.vdata.size(); ++k) { s << tx.vdata[k]->nVersion; s << *tx.vdata[k]; } - } else if (tx.nVersion >= 3 && tx.nType != TRANSACTION_NORMAL) { + } + if (flags & 1) { + for (size_t i = 0; i < tx.vin.size(); i++) { + s << tx.vin[i].scriptWitness.stack; + } + } + s << tx.nLockTime; + if (tx.nVersion == 3 && tx.nType != TRANSACTION_NORMAL) { s << tx.extraPayload; } } diff --git a/src/validation.cpp b/src/validation.cpp index 19817fd..e018620 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1346,7 +1346,7 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) } int halvings = nHeight / Params().GetConsensus().nSubsidyHalvingInterval; - if (Params().NetworkIDString() == CBaseChainParams::TESTNET && nHeight < 4000) + if (Params().NetworkIDString() == CBaseChainParams::TESTNET && nHeight < 1000) nSubsidy = 100 * COIN; // Subsidy is cut in half every 2,100,000 blocks which will occur approximately every 4 years. @@ -1360,7 +1360,7 @@ CAmount GetBlockValue(int nHeight, const CAmount &nFees) int64_t budgetValue = nSubsidy * 0.25; if (Params().NetworkIDString() == CBaseChainParams::TESTNET) { - if (nHeight >= 4000) + if (nHeight >= 1000) nSubsidy -= budgetValue; } else { if (nHeight > 1265000) @@ -4055,21 +4055,17 @@ std::vector GenerateCoinbaseCommitment(CBlock& block, const CBloc { std::vector commitment; int commitpos = GetWitnessCommitmentIndex(block); + LogPrintf("COMMIT POSE %d\n", commitpos); + std::vector ret(32, 0x00); if (consensusParams.SegwitHeight != std::numeric_limits::max()) { if (commitpos == NO_WITNESS_COMMITMENT) { - CMutableTransaction tx0(*block.vtx[0]); - if(block.vtx[0]->nVersion == TX_ELE_VERSION) - tx0.vpout.push_back(CTxOutAsset()); - else - tx0.vout.push_back(CTxOut()); - block.vtx[0] = MakeTransactionRef(std::move(tx0)); uint256 witnessroot = BlockWitnessMerkleRoot(block, nullptr); CHash256().Write(witnessroot).Write(ret).Finalize(witnessroot); CTxOutAsset out; out.nValue = 0; if(block.vtx[0]->nVersion == TX_ELE_VERSION) - out.nAsset = block.vtx[0]->vpout[0].nAsset; + out.nAsset = consensusParams.subsidy_asset; out.scriptPubKey.resize(MINIMUM_WITNESS_COMMITMENT); out.scriptPubKey[0] = OP_RETURN; out.scriptPubKey[1] = 0x24; @@ -4081,9 +4077,9 @@ std::vector GenerateCoinbaseCommitment(CBlock& block, const CBloc commitment = std::vector(out.scriptPubKey.begin(), out.scriptPubKey.end()); CMutableTransaction tx(*block.vtx[0]); if(block.vtx[0]->nVersion == TX_ELE_VERSION) - tx.vpout.back() = out; + tx.vpout.push_back(out); else - tx.vout.back() = out; + tx.vout.push_back(out); block.vtx[0] = MakeTransactionRef(std::move(tx)); } } @@ -4176,7 +4172,6 @@ static bool ContextualCheckBlock(const CBlock& block, BlockValidationState& stat return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-txns-nonfinal", "non-final transaction"); } } - // Enforce rule that the coinbase starts with serialized block height if (nHeight >= consensusParams.BIP34Height) { @@ -4186,7 +4181,6 @@ static bool ContextualCheckBlock(const CBlock& block, BlockValidationState& stat return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cb-height", "block height mismatch in coinbase"); } } - // Validation for witness commitments. // * We compute the witness hash (which is the hash including witnesses) of all the block's transactions, except the // coinbase (where 0x0000....0000 is used instead). @@ -4199,21 +4193,26 @@ static bool ContextualCheckBlock(const CBlock& block, BlockValidationState& stat if (nHeight >= consensusParams.SegwitHeight) { int commitpos = GetWitnessCommitmentIndex(block); + LogPrintf("COMMIT POSE2 %d\n", commitpos); + if (commitpos != NO_WITNESS_COMMITMENT) { bool malleated = false; uint256 hashWitness = BlockWitnessMerkleRoot(block, &malleated); + LogPrintf("TESTING 0 \n %s \n", block.ToString()); // The malleation check is ignored; as the transaction tree itself // already does not permit it, it is impossible to trigger in the // witness tree. + LogPrintf("TESTING 1 %d \n", block.vtx[0]->vin[0].scriptWitness.stack[0].size()); if (block.vtx[0]->vin[0].scriptWitness.stack.size() != 1 || block.vtx[0]->vin[0].scriptWitness.stack[0].size() != 32) { - return state.Invalid(BlockValidationResult::BLOCK_MUTATED, "bad-witness-nonce-size", strprintf("%s : invalid witness reserved value size", __func__)); + return state.Invalid(BlockValidationResult::BLOCK_MUTATED, "bad-witness-nonce-size", + strprintf("%s : %d %d invalid witness reserved value size", __func__, block.vtx[0]->vin[0].scriptWitness.stack.size(), block.vtx[0]->vin[0].scriptWitness.stack[0].size())); } + LogPrintf("TESTING 2 %d \n", block.vtx[0]->vin[0].scriptWitness.stack.size()); CHash256().Write(hashWitness).Write(block.vtx[0]->vin[0].scriptWitness.stack[0]).Finalize(hashWitness); if (memcmp(hashWitness.begin(),(block.vtx[0]->nVersion == TX_ELE_VERSION ? &block.vtx[0]->vpout[commitpos].scriptPubKey[6] : &block.vtx[0]->vout[commitpos].scriptPubKey[6]), 32)) { return state.Invalid(BlockValidationResult::BLOCK_MUTATED, "bad-witness-merkle-match", strprintf("%s : witness merkle commitment mismatch", __func__)); } - fHaveWitness = true; } } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index afaeeb8..cd105a5 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -497,7 +497,7 @@ static RPCHelpMan sendtoaddress() } if (asset.IsNull()) { - throw JSONRPCError(RPC_WALLET_ERROR, strprintf("Unknown label and invalid asset hex: %s", asset.GetHex())); + throw JSONRPCError(RPC_WALLET_ERROR, strprintf("Unknown label and invalid asset hex: %s %s", asset.GetHex(), asset.getName())); } // Wallet comments