Skip to content

Commit

Permalink
Merge branch 'master' into beta-10
Browse files Browse the repository at this point in the history
  • Loading branch information
shohamc1 authored Aug 22, 2023
2 parents 19df372 + 9859e68 commit 0c92a26
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 45 deletions.
2 changes: 1 addition & 1 deletion lib/ain-contracts/dfi_intrinsics/DFIIntrinsics.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: GPL-3.0
// SPDX-License-Identifier: MIT

pragma solidity >=0.8.2 <0.9.0;

Expand Down
2 changes: 1 addition & 1 deletion lib/ain-contracts/dst20/ERC20.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

// SPDX-License-Identifier: MIT
// File: @openzeppelin/[email protected]/utils/Context.sol


Expand Down
3 changes: 2 additions & 1 deletion lib/ain-contracts/system_reserved/SystemReservedContract.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

contract SystemReservedContract {
Expand Down
68 changes: 33 additions & 35 deletions src/masternodes/rpc_evm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ UniValue vmmap(const JSONRPCRequest &request) {
RPCArg::Optional::NO,
"Map types: \n\
0 - Auto \n\
1 - Block Number: DFI -> EVM (Unsupported yet) \n\
2 - Block Number: EVM -> DFI (Unsupported yet) \n\
1 - Block Number: DFI -> EVM \n\
2 - Block Number: EVM -> DFI \n\
3 - Block Hash: DFI -> EVM \n\
4 - Block Hash: EVM -> DFI \n\
5 - Tx Hash: DFI -> EVM \n\
Expand Down Expand Up @@ -234,44 +234,42 @@ UniValue vmmap(const JSONRPCRequest &request) {

return VMDomainRPCMapType::Unknown;
};
/*

auto crossBoundaryOkOrThrow = [&throwInvalidParam](CrossBoundaryResult &result) {
if (!result.ok) {
throwInvalidParam(result.reason.c_str());
}
};

auto tryResolveBlockNumberType =
[&throwUnsupportedAuto, &crossBoundaryOkOrThrow](const std::string input) {
[&throwUnsupportedAuto](const std::string input) {
uint64_t height;
if (!ParseUInt64(input, &height)) {
return VMDomainRPCMapType::Unknown;
}
CrossBoundaryResult result;
auto evmBlockCount = evm_try_get_block_count(result);
crossBoundaryOkOrThrow(result);

// evm block count always less than dvm block count
if (height > evmBlockCount) {
CrossBoundaryResult evmResult;
evm_try_get_block_hash_by_number(evmResult, height);
if (evmResult.ok) {
return VMDomainRPCMapType::BlockNumberEVMToDVM;
}

CBlockIndex* dvmBlock = ::ChainActive()[height];
if (dvmBlock != nullptr) {
return VMDomainRPCMapType::BlockNumberDVMToEVM;
} else {
// auto evmFirstBlock = evm_try_get_first_block(result);
// crossBoundaryOkOrThrow(result);
// if (height >= evmFirstBlock && height <= evmBlockCount) {
// return VMDomainRPCMapType::BlockNumberEVMToDVM;
// }
throwUnsupportedAuto();
return VMDomainRPCMapType::Unknown;
}

throwUnsupportedAuto();
return VMDomainRPCMapType::Unknown;
};
*/

auto type = static_cast<VMDomainRPCMapType>(typeInt);
ResVal res = ResVal<std::string>(std::string{}, Res::Ok());

auto handleAutoInfer = [&]() -> std::tuple<VMDomainRPCMapType, bool> {
// auto mapType = tryResolveBlockNumberType(input);
// if (mapType != VMDomainRPCMapType::Unknown)
// return {mapType, false};
auto mapType = tryResolveBlockNumberType(input);
if (mapType != VMDomainRPCMapType::Unknown)
return {mapType, false};

auto inLength = input.length();
if (inLength == 64 || inLength == 66) {
Expand All @@ -296,7 +294,7 @@ UniValue vmmap(const JSONRPCRequest &request) {
return ret;
}
};
/*

auto finalizeBlockNumberResult = [&](uint64_t &number, const VMDomainRPCMapType type, const uint64_t input) {
UniValue ret(UniValue::VOBJ);
ret.pushKV("input", input);
Expand All @@ -307,6 +305,7 @@ UniValue vmmap(const JSONRPCRequest &request) {

auto handleMapBlockNumberEVMToDVMRequest = [&throwInvalidParam,
&finalizeBlockNumberResult,
&ensureEVMHashStripped,
&crossBoundaryOkOrThrow](const std::string &input) -> UniValue {
uint64_t height;
bool success = ParseUInt64(input, &height);
Expand All @@ -315,13 +314,13 @@ UniValue vmmap(const JSONRPCRequest &request) {
}
CrossBoundaryResult result;
auto evmHash = evm_try_get_block_hash_by_number(result, height);
auto evmBlockHash = std::string(evmHash.data(), evmHash.length());
auto evmBlockHash = ensureEVMHashStripped(std::string(evmHash.data(), evmHash.length()));
crossBoundaryOkOrThrow(result);
ResVal<uint256> dvm_block = pcustomcsview->GetVMDomainBlockEdge(VMDomainEdge::EVMToDVM, evmBlockHash);
if (!dvm_block) {
throwInvalidParam(dvm_block.msg);
auto dvmBlockHash = pcustomcsview->GetVMDomainBlockEdge(VMDomainEdge::EVMToDVM, evmBlockHash);
if (!dvmBlockHash.val.has_value()) {
throwInvalidParam(dvmBlockHash.msg);
}
CBlockIndex *pindex = LookupBlockIndex(*dvm_block.val);
CBlockIndex *pindex = LookupBlockIndex(uint256S(*dvmBlockHash.val));
uint64_t blockNumber = pindex->GetBlockHeader().deprecatedHeight;
return finalizeBlockNumberResult(blockNumber, VMDomainRPCMapType::BlockNumberEVMToDVM, height);
};
Expand All @@ -346,7 +345,7 @@ UniValue vmmap(const JSONRPCRequest &request) {
crossBoundaryOkOrThrow(result);
return finalizeBlockNumberResult(blockNumber, VMDomainRPCMapType::BlockNumberDVMToEVM, height);
};
*/

LOCK(cs_main);

if (type == VMDomainRPCMapType::Auto) {
Expand Down Expand Up @@ -374,13 +373,12 @@ UniValue vmmap(const JSONRPCRequest &request) {
res = pcustomcsview->GetVMDomainBlockEdge(VMDomainEdge::EVMToDVM, input);
break;
}
// TODO(canonbrother): disable for release, more investigation needed
// case VMDomainRPCMapType::BlockNumberDVMToEVM: {
// return handleMapBlockNumberDVMToEVMRequest(input);
// }
// case VMDomainRPCMapType::BlockNumberEVMToDVM: {
// return handleMapBlockNumberEVMToDVMRequest(input);
// }
case VMDomainRPCMapType::BlockNumberDVMToEVM: {
return handleMapBlockNumberDVMToEVMRequest(input);
}
case VMDomainRPCMapType::BlockNumberEVMToDVM: {
return handleMapBlockNumberEVMToDVMRequest(input);
}
default: {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Unknown map type");
}
Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_dst20.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from test_framework.test_framework import DefiTestFramework
from test_framework.util import assert_equal, assert_raises_rpc_error


class DST20(DefiTestFramework):
def set_test_params(self):
self.num_nodes = 1
Expand Down Expand Up @@ -808,7 +809,6 @@ def run_test(self):
).read()
)["object"]


# Generate chain
self.node.generate(150)
self.nodes[0].utxostoaccount({self.address: "1000@DFI"})
Expand Down
12 changes: 6 additions & 6 deletions test/functional/feature_evm_vmmap_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,10 @@ def vmmap_valid_block_number_should_succeed(self):
assert_equal(res["type"], "BlockNumberDVMToEVM")
assert_equal(res["output"], item[1])

# res = self.nodes[0].vmmap(str(item[1]), VMMapType.Auto)
# assert_equal(res['input'], item[1])
# assert_equal(res['type'], 'BlockNumberEVMToDVM')
# assert_equal(res['output'], item[0])
res = self.nodes[0].vmmap(str(item[1]), VMMapType.Auto)
assert_equal(res["input"], item[1])
assert_equal(res["type"], "BlockNumberEVMToDVM")
assert_equal(res["output"], item[0])

def vmmap_invalid_block_number_should_fail(self):
assert_invalid = lambda *args: assert_raises_rpc_error(
Expand Down Expand Up @@ -368,8 +368,8 @@ def run_test(self):
self.vmmap_valid_tx_should_succeed()
self.vmmap_valid_block_should_succeed()
self.vmmap_invalid_should_fail()
# self.vmmap_valid_block_number_should_succeed()
# self.vmmap_invalid_block_number_should_fail()
self.vmmap_valid_block_number_should_succeed()
self.vmmap_invalid_block_number_should_fail()
self.vmmap_rollback_should_succeed()
self.vmmap_auto_invalid_input_should_fail()
# logvmmap tests
Expand Down

0 comments on commit 0c92a26

Please sign in to comment.