Skip to content

Commit

Permalink
Add EVM header to block (#1956)
Browse files Browse the repository at this point in the history
* Add HD Wallet Ethereum address support

* Add dummy FFI file

* Add EVM attribute

* Add EVM context

* Convert uint256 to array or reversed array

* Add EVM header to block

* Fix failing test

* Remove now invalid test types from valid data

* Use hex variable in argument to IsHex

Co-authored-by: Mihailo Milenkovic <mihailo.milenkovic84@gmail.com>

* Rename array

Co-authored-by: Mihailo Milenkovic <mihailo.milenkovic84@gmail.com>

* Fork and EVM enabled guard new miner code

* Add missing include

* Minor changes. Skip OP_16 in test.

* Make IsEVMEnabled standalone function

* Move function to cpp file

* Height check in IsEVMEnabled. Miner use IsEVMEnabled.

---------

Co-authored-by: Mihailo Milenkovic <mihailo.milenkovic84@gmail.com>
  • Loading branch information
Bushstar and Mixa84 authored May 3, 2023
1 parent a768a03 commit 3b93574
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/masternodes/mn_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4787,7 +4787,11 @@ bool IsTestNetwork() {
return Params().NetworkIDString() == CBaseChainParams::TESTNET || Params().NetworkIDString() == CBaseChainParams::DEVNET;
}

bool IsEVMEnabled(const CCustomCSView &view) {
bool IsEVMEnabled(const int height, const CCustomCSView &view) {
if (height < Params().GetConsensus().NextNetworkUpgradeHeight) {
return false;
}

const CDataStructureV0 enabledKey{AttributeTypes::Param, ParamIDs::Feature, DFIPKeys::EVMEnabled};
auto attributes = view.GetAttributes();
assert(attributes);
Expand Down
2 changes: 1 addition & 1 deletion src/masternodes/mn_checks.h
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ Res SwapToDFIorDUSD(CCustomCSView &mnview,
bool forceLoanSwap = false);
Res storeGovVars(const CGovernanceHeightMessage &obj, CCustomCSView &view);
bool IsTestNetwork();
bool IsEVMEnabled(const CCustomCSView &view);
bool IsEVMEnabled(const int height, const CCustomCSView &view);

inline bool OraclePriceFeed(CCustomCSView &view, const CTokenCurrencyPair &priceFeed) {
// Allow hard coded DUSD/USD
Expand Down
18 changes: 18 additions & 0 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,14 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
addPackageTxs<ancestor_score>(nPackagesSelected, nDescendantsUpdated, nHeight, mnview, evmContext);
}

// TODO Get failed TXs and try to restore to mempool
std::vector<uint8_t> evmHeader{};
if (IsEVMEnabled(nHeight, mnview)) {
std::array<uint8_t, 20> dummyAddress{};
const auto rustHeader = evm_finalize(evmContext, false, pos::GetNextWorkRequired(pindexPrev, pblock->nTime, consensus), dummyAddress);
evmHeader.resize(rustHeader.size());
std::copy(rustHeader.begin(), rustHeader.end(), evmHeader.begin());
}

// TXs for the creationTx field in new tokens created via token split
if (nHeight >= chainparams.GetConsensus().FortCanningCrunchHeight) {
Expand Down Expand Up @@ -318,6 +326,16 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
coinbaseTx.vout[0].nValue = CalculateCoinbaseReward(blockReward, consensus.dist.masternode);
}

if (IsEVMEnabled(nHeight, mnview) && !evmHeader.empty()) {
const auto headerIndex = coinbaseTx.vout.size();
coinbaseTx.vout.resize(headerIndex + 1);
coinbaseTx.vout[headerIndex].nValue = 0;

CScript script;
script << OP_RETURN << evmHeader;
coinbaseTx.vout[headerIndex].scriptPubKey = script;
}

LogPrint(BCLog::STAKING, "%s: post Eunos logic. Block reward %d Miner share %d foundation share %d\n",
__func__, blockReward, coinbaseTx.vout[0].nValue, foundationValue);
}
Expand Down

0 comments on commit 3b93574

Please sign in to comment.