Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent setting EVM or TD Gov var below height #2440

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/masternodes/govvariables/attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1972,21 +1972,24 @@ Res ATTRIBUTES::Validate(const CCustomCSView &view) const {
break;

case AttributeTypes::Param:
if (attrV0->typeId == ParamIDs::Feature && attrV0->key == DFIPKeys::MintTokens) {
if (view.GetLastHeight() < Params().GetConsensus().GrandCentralEpilogueHeight) {
return Res::Err("Cannot be set before GrandCentralEpilogueHeight");
}
} else if (attrV0->typeId == ParamIDs::Feature || attrV0->typeId == ParamIDs::Foundation ||
attrV0->key == DFIPKeys::Members) {
if (attrV0->typeId == ParamIDs::Feature) {
if (view.GetLastHeight() < Params().GetConsensus().GrandCentralHeight) {
return Res::Err("Cannot be set before GrandCentralHeight");
}
} else if (attrV0->typeId == ParamIDs::Foundation || attrV0->key == DFIPKeys::Members) {
if (attrV0->key == DFIPKeys::MintTokens) {
if (view.GetLastHeight() < Params().GetConsensus().GrandCentralEpilogueHeight) {
return Res::Err("Cannot be set before GrandCentralEpilogueHeight");
}
} else if (attrV0->key == DFIPKeys::EVMEnabled || attrV0->key == DFIPKeys::TransferDomain) {
if (view.GetLastHeight() < Params().GetConsensus().NextNetworkUpgradeHeight) {
return Res::Err("Cannot be set before NextNetworkUpgradeHeight");
}
}
} else if (attrV0->typeId == ParamIDs::Foundation) {
if (view.GetLastHeight() < Params().GetConsensus().GrandCentralHeight) {
return Res::Err("Cannot be set before GrandCentralHeight");
}
} else if (attrV0->typeId == ParamIDs::DFIP2206F || attrV0->key == DFIPKeys::StartBlock ||
attrV0->typeId == ParamIDs::DFIP2206A) {
} else if (attrV0->typeId == ParamIDs::DFIP2206F || attrV0->typeId == ParamIDs::DFIP2206A) {
if (view.GetLastHeight() < Params().GetConsensus().FortCanningSpringHeight) {
return Res::Err("Cannot be set before FortCanningSpringHeight");
}
Expand Down
12 changes: 12 additions & 0 deletions test/functional/feature_evm.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,18 @@ def erc55_wallet_support(self):

def evm_gov_vars(self):
# Check setting vars before height
assert_raises_rpc_error(
-32600,
"Cannot be set before NextNetworkUpgradeHeight",
self.nodes[0].setgov,
{"ATTRIBUTES": {"v0/params/feature/evm": "true"}},
)
assert_raises_rpc_error(
-32600,
"Cannot be set before NextNetworkUpgradeHeight",
self.nodes[0].setgov,
{"ATTRIBUTES": {"v0/params/feature/transferdomain": "true"}},
)
assert_raises_rpc_error(
-32600,
"called before NextNetworkUpgrade height",
Expand Down
1 change: 1 addition & 0 deletions test/functional/feature_evm_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from test_framework.evm_key_pair import EvmKeyPair
from web3._utils.events import get_event_data


class EVMTestLogs(DefiTestFramework):
def set_test_params(self):
self.num_nodes = 1
Expand Down
1 change: 0 additions & 1 deletion test/functional/feature_evm_rollback.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ def test_rollback_transactions(self):
def run_test(self):
self.setup()


self.nodes[0].transferdomain(
[
{
Expand Down
3 changes: 2 additions & 1 deletion test/functional/feature_evm_transaction_replacement.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ def should_prioritize_transaction_with_the_higher_gas_price(self):
-32001,
"lower fee as existing mempool entry",
self.send_transaction,
gasPrices[0], count
gasPrices[0],
count,
)

self.nodes[0].generate(1)
Expand Down
11 changes: 7 additions & 4 deletions test/functional/feature_evm_transferdomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,10 +908,12 @@ def invalid_transfer_evm_dvm_after_evm_tx(self):
self.valid_transfer_dvm_evm()

balance = self.nodes[0].eth_getBalance(self.eth_address)
assert_equal(balance, "0x56bc75e2d63100000") # 100 DFI
erc55_address = self.nodes[0].getnewaddress('', 'erc55')
assert_equal(balance, "0x56bc75e2d63100000") # 100 DFI
erc55_address = self.nodes[0].getnewaddress("", "erc55")

tx1 = self.nodes[0].evmtx(self.eth_address, 0, 21, 21001, erc55_address, 50) # Spend half balance
tx1 = self.nodes[0].evmtx(
self.eth_address, 0, 21, 21001, erc55_address, 50
) # Spend half balance

# Transfer 100 DFI from EVM to DVM
tx2 = transfer_domain(
Expand Down Expand Up @@ -947,7 +949,8 @@ def run_test(self):

self.valid_transfer_to_evm_then_move_then_back_to_dvm()

self.invalid_transfer_evm_dvm_after_evm_tx() # TODO assert behaviour here. transferdomain shouldn't be kept in mempool since its nonce will never be valid
self.invalid_transfer_evm_dvm_after_evm_tx() # TODO assert behaviour here. transferdomain shouldn't be kept in mempool since its nonce will never be valid


if __name__ == "__main__":
EVMTest().main()
6 changes: 5 additions & 1 deletion test/functional/feature_evm_vmmap_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,11 @@ def vmmap_transfer_domain(self):
tx = self.nodes[0].transferdomain(
[
{
"src": {"address": self.ethAddress, "amount": "100@DFI", "domain": 3},
"src": {
"address": self.ethAddress,
"amount": "100@DFI",
"domain": 3,
},
"dst": {
"address": self.address,
"amount": "100@DFI",
Expand Down