Skip to content

Commit

Permalink
Merge branch 'master' into niven/fix-mempool-view
Browse files Browse the repository at this point in the history
  • Loading branch information
prasannavl authored Oct 20, 2023
2 parents 6a22f18 + cb99ffd commit d9ca8dd
Show file tree
Hide file tree
Showing 11 changed files with 422 additions and 14 deletions.
12 changes: 6 additions & 6 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,11 @@ class CTestNetParams : public CChainParams {
consensus.DF15FortCanningRoadHeight = 893700;
consensus.DF16FortCanningCrunchHeight = 1011600;
consensus.DF17FortCanningSpringHeight = 1086000;
consensus.DF18FortCanningGreatWorldHeight = 1200000;
consensus.DF19FortCanningEpilogueHeight = 1200010;
consensus.DF20GrandCentralHeight = 1200020;
consensus.DF21GrandCentralEpilogueHeight = 1200030;
consensus.DF22MetachainHeight = 1200040;
consensus.DF18FortCanningGreatWorldHeight = 1150000;
consensus.DF19FortCanningEpilogueHeight = 1150010;
consensus.DF20GrandCentralHeight = 1150020;
consensus.DF21GrandCentralEpilogueHeight = 1150030;
consensus.DF22MetachainHeight = 1150040;

consensus.pos.diffLimit = uint256S("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
// consensus.pos.nTargetTimespan = 14 * 24 * 60 * 60; // two weeks
Expand Down Expand Up @@ -569,6 +569,7 @@ class CTestNetParams : public CChainParams {
vSeeds.clear();
// nodes with support for servicebits filtering should be at the top
vSeeds.emplace_back("testnet-seed.defichain.io");
vSeeds.emplace_back("35.195.186.78");

vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_test, pnSeed6_test + ARRAYLEN(pnSeed6_test));

Expand Down Expand Up @@ -784,7 +785,6 @@ class CChangiParams : public CChainParams {
vSeeds.clear();
// nodes with support for servicebits filtering should be at the top
vSeeds.emplace_back("35.187.53.161");
vSeeds.emplace_back("34.89.47.54");
vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_changi, pnSeed6_changi + ARRAYLEN(pnSeed6_changi));

fDefaultConsistencyChecks = false;
Expand Down
8 changes: 8 additions & 0 deletions src/dfi/govvariables/attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1955,6 +1955,9 @@ Res ATTRIBUTES::Validate(const CCustomCSView &view) const {
break;

case AttributeTypes::Consortium:
if (view.GetLastHeight() >= Params().GetConsensus().DF22MetachainHeight && !IsRegtestNetwork()) {
return Res::Err("Cannot be set after MetachainHeight");
}
switch (attrV0->key) {
case ConsortiumKeys::MemberValues: {
if (view.GetLastHeight() < Params().GetConsensus().DF20GrandCentralHeight) {
Expand Down Expand Up @@ -2072,6 +2075,11 @@ Res ATTRIBUTES::Validate(const CCustomCSView &view) const {
if (view.GetLastHeight() < Params().GetConsensus().DF22MetachainHeight) {
return Res::Err("Cannot be set before MetachainHeight");
}
} else if (attrV0->key == DFIPKeys::ConsortiumEnabled) {
if (view.GetLastHeight() >= Params().GetConsensus().DF22MetachainHeight &&
!IsRegtestNetwork()) {
return Res::Err("Cannot be set after MetachainHeight");
}
}
} else if (attrV0->typeId == ParamIDs::Foundation) {
if (view.GetLastHeight() < Params().GetConsensus().DF20GrandCentralHeight) {
Expand Down
1 change: 1 addition & 0 deletions src/dfi/res.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define DEFI_DFI_RES_H

#include <tinyformat.h>
#include <cstdint>
#include <functional>
#include <optional>
#include <string>
Expand Down
4 changes: 4 additions & 0 deletions src/policy/fees.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <policy/fees.h>

#include <clientversion.h>
#include <consensus/tx_check.h>
#include <primitives/transaction.h>
#include <streams.h>
#include <txmempool.h>
Expand Down Expand Up @@ -516,6 +517,9 @@ CBlockPolicyEstimator::~CBlockPolicyEstimator()
void CBlockPolicyEstimator::processTransaction(const CTxMemPoolEntry& entry, bool validFeeEstimate)
{
LOCK(m_cs_fee_estimator);
if (IsEVMTx(entry.GetTx())) {
return;
}
unsigned int txHeight = entry.GetHeight();
uint256 hash = entry.GetTx().GetHash();
if (mapMemPoolTxs.count(hash)) {
Expand Down
6 changes: 5 additions & 1 deletion src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,11 @@ static UniValue estimatesmartfee(const JSONRPCRequest& request)
FeeCalculation feeCalc;
CFeeRate feeRate = ::feeEstimator.estimateSmartFee(conf_target, &feeCalc, conservative);
if (feeRate != CFeeRate(0)) {
result.pushKV("feerate", ValueFromAmount(feeRate.GetFeePerK()));
auto amount = feeRate.GetFeePerK();
if (amount < DEFAULT_TRANSACTION_MINFEE) {
amount = DEFAULT_TRANSACTION_MINFEE;
}
result.pushKV("feerate", ValueFromAmount(amount));
} else if (txOrdering == MIXED_ORDERING || txOrdering == ENTRYTIME_ORDERING) {
result.pushKV("feerate", ValueFromAmount(DEFAULT_TRANSACTION_MINFEE));
} else {
Expand Down
1 change: 1 addition & 0 deletions src/support/lockedpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <support/lockedpool.h>
#include <support/cleanse.h>
#include <stdexcept>

#if defined(HAVE_CONFIG_H)
#include <config/defi-config.h>
Expand Down
1 change: 1 addition & 0 deletions src/util/bip32.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define DEFI_UTIL_BIP32_H

#include <attributes.h>
#include <cstdint>
#include <string>
#include <vector>

Expand Down
18 changes: 11 additions & 7 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,8 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
auto txMessage = customTypeToMessage(txType);
res = CustomMetadataParse(height, consensus, metadata, txMessage);
if (!res) {
return state.Invalid(ValidationInvalidReason::TX_NOT_STANDARD, error("Failed to parse EVM tx metadata"), REJECT_INVALID, "failed-to-parse-evm-tx-metadata");
LogPrint(BCLog::MEMPOOL, "Failed to parse EVM tx metadata\n");
return state.Invalid(ValidationInvalidReason::TX_NOT_STANDARD, false, REJECT_INVALID, "failed-to-parse-evm-tx-metadata");
}

std::string rawEVMTx;
Expand All @@ -942,7 +943,8 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
CrossBoundaryResult result;
auto txResult = evm_try_get_tx_miner_info_from_raw_tx(result, rawEVMTx);
if (!result.ok) {
return state.Invalid(ValidationInvalidReason::TX_NOT_STANDARD, error("evm tx failed to get sender info %s", result.reason.c_str()), REJECT_INVALID, "evm-sender-info");
LogPrint(BCLog::MEMPOOL, "EVM tx failed to get sender info %s\n", result.reason.c_str());
return state.Invalid(ValidationInvalidReason::TX_NOT_STANDARD, false, REJECT_INVALID, "evm-sender-info");
}

EvmAddressWithNonce evmAddrAndNonce{txResult.nonce, txResult.address.c_str()};
Expand All @@ -957,23 +959,25 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
auto senderLimitFlag{false};
if (!pool.checkAddressNonceAndFee(entry, entryTipFee, txResultSender, senderLimitFlag)) {
if (senderLimitFlag) {
return state.Invalid(ValidationInvalidReason::TX_MEMPOOL_POLICY, error("Too many replace-by-fee evm tx from the same sender in mempool. Limit %d.", MEMPOOL_MAX_ETH_RBF), REJECT_INVALID, "too-many-evm-rbf-txs-by-sender");
LogPrint(BCLog::MEMPOOL, "Too many replace-by-fee EVM tx from the same sender in mempool. Limit %d.\n", MEMPOOL_MAX_ETH_RBF);
return state.Invalid(ValidationInvalidReason::TX_MEMPOOL_POLICY, false, REJECT_INVALID, "too-many-evm-rbf-txs-by-sender");
} else {
return state.Invalid(ValidationInvalidReason::TX_MEMPOOL_POLICY, error("Rejected due to same or lower fee as existing mempool entry"), REJECT_INVALID, "evm-low-fee");
LogPrint(BCLog::MEMPOOL, "EVM tx rejected due to same or lower fee as existing mempool entry\n");
return state.Invalid(ValidationInvalidReason::TX_MEMPOOL_POLICY, false, REJECT_INVALID, "evm-low-fee");
}
}

const auto sender = pool.evmTxsBySender.find(txResultSender);
if (sender != pool.evmTxsBySender.end() && sender->second.size() >= MEMPOOL_MAX_ETH_TXS) {
return state.Invalid(ValidationInvalidReason::TX_MEMPOOL_POLICY, error("Too many evm tx from the same sender in mempool. Limit %d.", MEMPOOL_MAX_ETH_TXS), REJECT_INVALID, "too-many-evm-txs-by-sender");
LogPrint(BCLog::MEMPOOL, "Too many EVM tx from the same sender in mempool. Limit %d.\n", MEMPOOL_MAX_ETH_TXS);
return state.Invalid(ValidationInvalidReason::TX_MEMPOOL_POLICY, false, REJECT_INVALID, "too-many-evm-txs-by-sender");
} else {
ethSender = txResultSender;
}


evm_try_dispatch_pending_transactions_event(result, rawEVMTx);
if (!result.ok) {
LogPrint(BCLog::MEMPOOL, "evm tx failed to generate events %s\n", result.reason.c_str());
LogPrint(BCLog::MEMPOOL, "EVM tx failed to generate events %s\n", result.reason.c_str());
}
}

Expand Down
24 changes: 24 additions & 0 deletions test/functional/contracts/Withdraw.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;

contract Withdraw {

address public owner;

constructor () payable {
owner = msg.sender;
}

function withdraw() public {
// get the amount of DFI stored in this contract
uint amount = address(this).balance;

// send all DFI to owner
(bool success, ) = owner.call{value: amount}("");
require(success, "Failed to send DFI");
}

receive() external payable {}

}
Loading

0 comments on commit d9ca8dd

Please sign in to comment.