From 2dd6b04d2e04ed1264f6b3200971e902d3fe55c3 Mon Sep 17 00:00:00 2001 From: Jordan Earls Date: Wed, 28 Jun 2017 18:41:34 -0400 Subject: [PATCH 1/2] Change block author to be 2nd vout/2nd tx for PoS This also uses safer code to ensure that P2SH addresses are not treated as a P2PKH address --- src/validation.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/validation.cpp b/src/validation.cpp index e63035437d88c..09a0eabcee93c 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2260,20 +2260,27 @@ dev::eth::EnvInfo ByteCodeExec::BuildEVMEnvironment(){ } env.setLastHashes(std::move(lh)); env.setGasLimit(blockGasLimit); - env.setAuthor(EthAddrFromScript(block.vtx.at(0)->vout.at(0).scriptPubKey)); + if(block.IsProofOfStake()){ + env.setAuthor(EthAddrFromScript(block.vtx[1]->vout[1].scriptPubKey)); + }else { + env.setAuthor(EthAddrFromScript(block.vtx[0]->vout[0].scriptPubKey)); + } return env; } -dev::Address ByteCodeExec::EthAddrFromScript(const CScript& scriptIn){ - CTxDestination resDest; - if(!ExtractDestination(scriptIn, resDest)){ - return dev::Address(); +dev::Address ByteCodeExec::EthAddrFromScript(const CScript& script){ + CTxDestination addressBit; + txnouttype txType=TX_NONSTANDARD; + if(ExtractDestination(script, addressBit, &txType)){ + if ((txType == TX_PUBKEY || txType == TX_PUBKEYHASH) && + addressBit.type() == typeid(CKeyID)){ + CKeyID addressKey(boost::get(addressBit)); + std::vector addr(addressKey.begin(), addressKey.end()); + return dev::Address(addr); + } } - CKeyID resPH(boost::get(resDest)); - - std::vector addr(resPH.begin(), resPH.end()); - - return dev::Address(addr); + //if not standard or not a pubkey or pubkeyhash output, then return 0 + return dev::Address(); } bool QtumTxConverter::extractionQtumTransactions(ExtractQtumTX& qtumtx){ From 63211ca820684d09269f9b3a0154313c8b23753c Mon Sep 17 00:00:00 2001 From: Jordan Earls Date: Fri, 8 Sep 2017 10:10:58 +0800 Subject: [PATCH 2/2] Use PoS key rather than reserve key script when populating block --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 8fcebdbaf7102..0c85845c697a3 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1130,7 +1130,7 @@ void ThreadStakeMiner(CWallet *pwallet) SetThreadPriority(THREAD_PRIORITY_ABOVE_NORMAL); // Create a block that's properly populated with transactions std::unique_ptr pblocktemplatefilled( - BlockAssembler(Params()).CreateNewBlock(reservekey.reserveScript, true, &nTotalFees, + BlockAssembler(Params()).CreateNewBlock(pblock->vtx[1]->vout[1].scriptPubKey, true, &nTotalFees, i, FutureDrift(GetAdjustedTime()) - STAKE_TIME_BUFFER)); if (!pblocktemplatefilled.get()) return;