Skip to content

Commit

Permalink
Pass miner address to EVM side (#1957)
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

* Pass block miner to EVM side

* 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

* Check EVM enabled

* Minor changes. Skip OP_16 in test.

* Make IsEVMEnabled standalone function

* Move function to cpp file

* Height check in IsEVMEnabled. Miner use IsEVMEnabled.

* Use IsEVMEnabled when adding miner address

---------

Co-authored-by: Mihailo Milenkovic <mihailo.milenkovic84@gmail.com>
  • Loading branch information
Bushstar and Mixa84 authored May 3, 2023
1 parent 3b93574 commit a574f65
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2828,6 +2828,48 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
}
mnview.SetLastHeight(pindex->nHeight);

if (IsEVMEnabled(pindex->nHeight, mnview)) {
CKeyID minter;
assert(block.ExtractMinterKey(minter));
std::array<uint8_t, 20> minerAddress{};

if (!fMockNetwork) {
const auto id = mnview.GetMasternodeIdByOperator(minter);
assert(id);
const auto node = mnview.GetMasternode(*id);
assert(node);

auto height = node->creationHeight;
auto mnID = *id;
if (!node->collateralTx.IsNull()) {
const auto idHeight = mnview.GetNewCollateral(node->collateralTx);
assert(idHeight);
height = idHeight->blockHeight - GetMnResignDelay(std::numeric_limits<int>::max());
mnID = node->collateralTx;
}

const auto blockindex = ::ChainActive()[height];
assert(blockindex);


CTransactionRef tx;
uint256 hash_block;
assert(GetTransaction(mnID, tx, Params().GetConsensus(), hash_block, blockindex));
assert(tx->vout.size() >= 2);

CTxDestination dest;
assert(ExtractDestination(tx->vout[1].scriptPubKey, dest));
assert(dest.index() == PKHashType || dest.index() == WitV0KeyHashType);

const auto keyID = dest.index() == PKHashType ? CKeyID(std::get<PKHash>(dest)) : CKeyID(std::get<WitnessV0KeyHash>(dest));
std::copy(keyID.begin(), keyID.end(), minerAddress.begin());
} else {
std::copy(minter.begin(), minter.end(), minerAddress.begin());
}

evm_finalize(evmContext, true, block.nBits, minerAddress);
}

auto &checkpoints = chainparams.Checkpoints().mapCheckpoints;
auto it = checkpoints.lower_bound(pindex->nHeight);
if (it != checkpoints.begin()) {
Expand Down

0 comments on commit a574f65

Please sign in to comment.