Skip to content

Commit

Permalink
Sync with master
Browse files Browse the repository at this point in the history
  • Loading branch information
prasannavl committed May 31, 2022
2 parents 21a9cd3 + a2cf10b commit a58c785
Show file tree
Hide file tree
Showing 29 changed files with 182 additions and 105 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/dev-builds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ on:
- e/*
- v*
- "[0-9]+.[0-9]+.x"

env:
MAKE_CONF_ARGS: --disable-bench

jobs:

linux:
Expand All @@ -43,7 +47,7 @@ jobs:
with:
name: defichain-${{ env.BUILD_VERSION }}-x86_64-pc-linux-gnu
path: ./build/defichain-${{ env.BUILD_VERSION }}-x86_64-pc-linux-gnu.tar.gz

# Linux build additionally pushes the docker images to docker hub on successful build
- name: Tag dockerhub build
if: ${{ github.repository == 'DeFiCh/ain' }}
Expand Down
2 changes: 1 addition & 1 deletion contrib/dockerfiles/x86_64-apple-darwin18.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ COPY . .
RUN ./autogen.sh

# XREF: #make-configure
RUN ./configure --prefix=`pwd`/depends/${TARGET}
RUN ./configure --prefix=`pwd`/depends/${TARGET} ${MAKE_CONF_ARGS}

ARG BUILD_VERSION=

Expand Down
2 changes: 1 addition & 1 deletion contrib/dockerfiles/x86_64-pc-linux-gnu.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ COPY . .
RUN ./autogen.sh

# XREF: #make-configure
RUN ./configure CC=clang-11 CXX=clang++-11 --prefix=`pwd`/depends/${TARGET}
RUN ./configure CC=clang-11 CXX=clang++-11 --prefix=`pwd`/depends/${TARGET} ${MAKE_CONF_ARGS}

ARG BUILD_VERSION=

Expand Down
2 changes: 1 addition & 1 deletion contrib/dockerfiles/x86_64-w64-mingw32.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ COPY . .
RUN ./autogen.sh

# XREF: #make-configure
RUN CONFIG_SITE=`pwd`/depends/x86_64-w64-mingw32/share/config.site ./configure --prefix=/
RUN CONFIG_SITE=`pwd`/depends/x86_64-w64-mingw32/share/config.site ./configure --prefix=/ ${MAKE_CONF_ARGS}

ARG BUILD_VERSION=

Expand Down
10 changes: 8 additions & 2 deletions make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ setup_vars() {
default_compiler_flags="CC=clang-11 CXX=clang++-11"
fi

MAKE_JOBS=${MAKE_JOBS:-$(nproc)}
if [[ "${OSTYPE}" == "darwin"* ]]; then
default_jobs=$(sysctl -n hw.logicalcpu)
else
default_jobs=$(nproc)
fi

MAKE_JOBS=${MAKE_JOBS:-"${default_jobs}"}
MAKE_COMPILER=${MAKE_COMPILER:-"${default_compiler_flags}"}
MAKE_CONF_ARGS="${MAKE_COMPILER} ${MAKE_CONF_ARGS:-}"
MAKE_ARGS=${MAKE_ARGS:-}
Expand Down Expand Up @@ -289,7 +295,7 @@ docker_release_git() {
}

docker_build_deploy_git() {
git_version
git_version
docker_build "$@"
docker_deploy "$@"
}
Expand Down
2 changes: 2 additions & 0 deletions src/bench/bench_defi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <memory>

/*
static const int64_t DEFAULT_BENCH_EVALUATIONS = 5;
static const char* DEFAULT_BENCH_FILTER = ".*";
static const char* DEFAULT_BENCH_SCALING = "1.0";
Expand All @@ -30,6 +31,7 @@ static void SetupBenchArgs()
gArgs.AddArg("-plot-width=<x>", strprintf("Plot width in pixel (default: %u)", DEFAULT_PLOT_WIDTH), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
gArgs.AddArg("-plot-height=<x>", strprintf("Plot height in pixel (default: %u)", DEFAULT_PLOT_HEIGHT), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
}
*/

int main(int argc, char** argv)
{
Expand Down
4 changes: 4 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,3 +1060,7 @@ void SelectParams(const std::string& network)
SelectBaseParams(network);
globalChainParams = CreateChainParams(network);
}

void ClearCheckpoints(CChainParams &params) {
params.checkpointData = {};
}
2 changes: 2 additions & 0 deletions src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ class CChainParams
std::vector<MasternodeKeys> vMasternodes;
std::vector<CTransactionRef> CreateGenesisMasternodes();
std::set<CKeyID> genesisTeam;

friend void ClearCheckpoints(CChainParams &params);
};

const auto SMART_CONTRACT_DFIP_2201 = "DFIP2201";
Expand Down
2 changes: 1 addition & 1 deletion src/flushablestorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ class CStorageView {
// second type of 'ReadBy' (may be 'GetBy'?)
template<typename By, typename ResultType, typename KeyType>
boost::optional<ResultType> ReadBy(KeyType const & id) const {
ResultType result;
ResultType result{};
if (ReadBy<By>(id, result))
return {result};
return {};
Expand Down
50 changes: 47 additions & 3 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ void SetupServerArgs()
gArgs.AddArg("-server", "Accept command line and JSON-RPC commands", ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
gArgs.AddArg("-rpcallowcors=<host>", "Allow CORS requests from the given host origin. Include scheme and port (eg: -rpcallowcors=http://127.0.0.1:5000)", ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
gArgs.AddArg("-rpcstats", strprintf("Log RPC stats. (default: %u)", DEFAULT_RPC_STATS), ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
gArgs.AddArg("-consolidaterewards=<token-or-pool-symbol>", "Consolidate rewards on startup. Accepted multiple times for each token symbol", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);

#if HAVE_DECL_DAEMON
gArgs.AddArg("-daemon", "Run in the background as a daemon and accept commands", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
Expand Down Expand Up @@ -1085,8 +1086,14 @@ bool AppInitParameterInteraction()
mempool.setSanityCheck(1.0 / ratio);
}
fCheckBlockIndex = gArgs.GetBoolArg("-checkblockindex", chainparams.DefaultConsistencyChecks());
if (gArgs.GetBoolArg("-checkpoints", DEFAULT_CHECKPOINTS_ENABLED))
LogPrintf("Warning: -checkpoints does nothing, it will be removed in next release.\n");
if (!gArgs.GetBoolArg("-checkpoints", DEFAULT_CHECKPOINTS_ENABLED)) {
LogPrintf("conf: checkpoints disabled.\n");
// Safe to const_cast, as we know it's always allocated, and is always in the global var
// and it is not used anywhere yet.
ClearCheckpoints(const_cast<CChainParams&>(chainparams));
} else {
LogPrintf("conf: checkpoints enabled.\n");
}

hashAssumeValid = uint256S(gArgs.GetArg("-assumevalid", chainparams.GetConsensus().defaultAssumeValid.GetHex()));
if (!hashAssumeValid.IsNull())
Expand Down Expand Up @@ -1360,7 +1367,7 @@ bool AppInitMain(InitInterfaces& interfaces)
// Warn about relative -datadir path.
if (gArgs.IsArgSet("-datadir") && !fs::path(gArgs.GetArg("-datadir", "")).is_absolute()) {
LogPrintf("Warning: relative datadir option '%s' specified, which will be interpreted relative to the " /* Continued */
"current working directory '%s'. This is fragile, because if defi is started in the future "
"current working directory '%s'. This is fragile, because if defid is started in the future "
"from a different location, it will be unable to locate the current data files. There could "
"also be data loss if defi is started while in a temporary directory.\n",
gArgs.GetArg("-datadir", ""), fs::current_path().string());
Expand Down Expand Up @@ -1859,6 +1866,43 @@ bool AppInitMain(InitInterfaces& interfaces)
nLocalServices = ServiceFlags(nLocalServices | NODE_WITNESS);
}

if (gArgs.IsArgSet("-consolidaterewards")) {
const std::vector<std::string> tokenSymbolArgs = gArgs.GetArgs("-consolidaterewards");
auto fullRewardConsolidation = false;
for (const auto& tokenSymbolInput : tokenSymbolArgs) {
auto tokenSymbol = trim_ws(tokenSymbolInput);
if (tokenSymbol.empty()) {
fullRewardConsolidation = true;
continue;
}
LogPrintf("Consolidate rewards for token: %s\n", tokenSymbol);
auto token = pcustomcsview->GetToken(tokenSymbol);
if (!token) {
InitError(strprintf("Invalid token \"%s\" for reward consolidation.\n", tokenSymbol));
return false;
}

std::vector<std::pair<CScript, CAmount>> balancesToMigrate;
pcustomcsview->ForEachBalance([&, tokenId = token->first](CScript const& owner, CTokenAmount balance) {
if (tokenId.v == balance.nTokenId.v && balance.nValue > 0) {
balancesToMigrate.emplace_back(owner, balance.nValue);
}
return true;
});
}
if (fullRewardConsolidation) {
LogPrintf("Consolidate rewards for all addresses..\n");
std::vector<std::pair<CScript, CAmount>> balancesToMigrate;
pcustomcsview->ForEachBalance([&](CScript const& owner, CTokenAmount balance) {
if (balance.nValue > 0) {
balancesToMigrate.emplace_back(owner, balance.nValue);
}
return true;
});
ConsolidateRewards(*pcustomcsview, ::ChainActive().Height(), balancesToMigrate, true);
}
}

// ********************************************************* Step 11: import blocks

if (!CheckDiskSpace(GetDataDir())) {
Expand Down
2 changes: 1 addition & 1 deletion src/masternodes/anchors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ bool ContextualValidateAnchor(const CAnchorData &anchor, CBlockIndex& anchorBloc
}

// Recreate deeper anchor depth
if (anchorCreationHeight >= Params().GetConsensus().FortCanningHeight) {
if (anchorCreationHeight >= static_cast<uint64_t>(Params().GetConsensus().FortCanningHeight)) {
timeDepth += Params().GetConsensus().mn.anchoringAdditionalTimeDepth;
while (anchorHeight > 0 && ::ChainActive()[anchorHeight]->nTime + timeDepth > anchorCreationBlock->nTime) {
--anchorHeight;
Expand Down
6 changes: 3 additions & 3 deletions src/masternodes/loan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ void CLoanView::EraseDelayedDestroyScheme(const std::string& loanSchemeID)

boost::optional<CInterestRateV2> CLoanView::GetInterestRate(const CVaultId& vaultId, DCT_ID id, uint32_t height)
{
if (height >= Params().GetConsensus().FortCanningHillHeight)
if (height >= static_cast<uint32_t>(Params().GetConsensus().FortCanningHillHeight))
return ReadBy<LoanInterestV2ByVault, CInterestRateV2>(std::make_pair(vaultId, id));

if (auto rate = ReadBy<LoanInterestByVault, CInterestRate>(std::make_pair(vaultId, id)))
Expand Down Expand Up @@ -251,7 +251,7 @@ CAmount InterestPerBlock(const CInterestRateV2& rate, uint32_t height)

void CLoanView::WriteInterestRate(const std::pair<CVaultId, DCT_ID>& pair, const CInterestRateV2& rate, uint32_t height)
{
if (height >= Params().GetConsensus().FortCanningHillHeight)
if (height >= static_cast<uint32_t>(Params().GetConsensus().FortCanningHillHeight))
WriteBy<LoanInterestV2ByVault>(pair, rate);
else
WriteBy<LoanInterestByVault>(pair, ConvertInterestRateToV1(rate));
Expand Down Expand Up @@ -376,7 +376,7 @@ void DeleteInterest(CLoanView& view, const CVaultId& vaultId)

Res CLoanView::DeleteInterest(const CVaultId& vaultId, uint32_t height)
{
if (height >= Params().GetConsensus().FortCanningHillHeight)
if (height >= static_cast<uint32_t>(Params().GetConsensus().FortCanningHillHeight))
::DeleteInterest<LoanInterestV2ByVault>(*this, vaultId);
else
::DeleteInterest<LoanInterestByVault>(*this, vaultId);
Expand Down
4 changes: 2 additions & 2 deletions src/masternodes/masternodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ std::vector<int64_t> CMasternodesView::GetSubNodesBlockTime(const CKeyID & minte
for (uint8_t i{0}; i < SUBNODE_COUNT; ++i) {
ForEachSubNode([&](const SubNodeBlockTimeKey &key, int64_t blockTime)
{
if (height >= Params().GetConsensus().FortCanningHeight) {
if (height >= static_cast<uint32_t>(Params().GetConsensus().FortCanningHeight)) {
if (key.masternodeID == nodeId && key.subnode == i) {
times[i] = blockTime;
}
Expand Down Expand Up @@ -522,7 +522,7 @@ uint16_t CMasternodesView::GetTimelock(const uint256& nodeId, const CMasternode&
auto lastHeight = height - 1;

// Cannot expire below block count required to calculate average time
if (lastHeight < Params().GetConsensus().mn.newResignDelay) {
if (lastHeight < static_cast<uint64_t>(Params().GetConsensus().mn.newResignDelay)) {
return *timelock;
}

Expand Down
12 changes: 6 additions & 6 deletions src/masternodes/mn_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor
updatedToken.creationTx = token.creationTx;
updatedToken.destructionTx = token.destructionTx;
updatedToken.destructionHeight = token.destructionHeight;
if (height >= consensus.FortCanningHeight) {
if (height >= static_cast<uint32_t>(consensus.FortCanningHeight)) {
updatedToken.symbol = trim_ws(updatedToken.symbol).substr(0, CToken::MAX_TOKEN_SYMBOL_LENGTH);
}

Expand Down Expand Up @@ -1158,7 +1158,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor
return Res::Err("token %s does not exist!", poolPair.idTokenB.ToString());
}

const auto symbolLength = height >= consensus.FortCanningHeight ? CToken::MAX_TOKEN_POOLPAIR_LENGTH : CToken::MAX_TOKEN_SYMBOL_LENGTH;
const auto symbolLength = height >= static_cast<uint32_t>(consensus.FortCanningHeight) ? CToken::MAX_TOKEN_POOLPAIR_LENGTH : CToken::MAX_TOKEN_SYMBOL_LENGTH;
if (pairSymbol.empty()) {
pairSymbol = trim_ws(tokenA->symbol + "-" + tokenB->symbol).substr(0, symbolLength);
} else {
Expand Down Expand Up @@ -3886,7 +3886,7 @@ Res ApplyCustomTx(CCustomCSView& mnview, const CCoinsViewCache& coins, const CTr
return res;
}
std::vector<unsigned char> metadata;
const auto metadataValidation = height >= consensus.FortCanningHeight;
const auto metadataValidation = height >= static_cast<uint32_t>(consensus.FortCanningHeight);

auto txType = GuessCustomTxType(tx, metadata, metadataValidation);
if (txType == CustomTxType::None) {
Expand Down Expand Up @@ -3928,7 +3928,7 @@ Res ApplyCustomTx(CCustomCSView& mnview, const CCoinsViewCache& coins, const CTr
}
res.code |= CustomTxErrCodes::Fatal;
}
if (height >= consensus.DakotaHeight) {
if (height >= static_cast<uint32_t>(consensus.DakotaHeight)) {
res.code |= CustomTxErrCodes::Fatal;
}
return res;
Expand Down Expand Up @@ -4216,7 +4216,7 @@ Res CPoolSwap::ExecuteSwap(CCustomCSView& view, std::vector<DCT_ID> poolIDs, boo
Res poolResult = Res::Ok();

// No composite swap allowed before Fort Canning
if (height < Params().GetConsensus().FortCanningHeight && !poolIDs.empty()) {
if (height < static_cast<uint32_t>(Params().GetConsensus().FortCanningHeight) && !poolIDs.empty()) {
poolIDs.clear();
}

Expand Down Expand Up @@ -4354,7 +4354,7 @@ Res CPoolSwap::ExecuteSwap(CCustomCSView& view, std::vector<DCT_ID> poolIDs, boo
}

// Reject if price paid post-swap above max price provided
if (height >= Params().GetConsensus().FortCanningHeight && obj.maxPrice != POOLPRICE_MAX) {
if (height >= static_cast<uint32_t>(Params().GetConsensus().FortCanningHeight) && obj.maxPrice != POOLPRICE_MAX) {
if (swapAmountResult.nValue != 0) {
const auto userMaxPrice = arith_uint256(obj.maxPrice.integer) * COIN + obj.maxPrice.fraction;
if (arith_uint256(obj.amountFrom) * COIN / swapAmountResult.nValue > userMaxPrice) {
Expand Down
2 changes: 1 addition & 1 deletion src/masternodes/poolpairs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ void CPoolPairView::CalculatePoolRewards(DCT_ID const & poolId, std::function<CA
auto nextCustomRewards = begin;
auto itCustomRewards = LowerBound<ByCustomReward>(poolKey);

PoolSwapValue poolSwap;
PoolSwapValue poolSwap{};
auto nextPoolSwap = UINT_MAX;
auto poolSwapHeight = UINT_MAX;
auto itPoolSwap = LowerBound<ByPoolSwap>(poolKey);
Expand Down
13 changes: 8 additions & 5 deletions src/masternodes/rpc_accounts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,8 @@ UniValue gettokenbalances(const JSONRPCRequest& request) {
return true;
});
auto it = totalBalances.balances.lower_bound(start);
for (int i = 0; it != totalBalances.balances.end() && i < limit; it++, i++) {
CTokenAmount bal = CTokenAmount{(*it).first, (*it).second};
for (size_t i = 0; it != totalBalances.balances.end() && i < limit; it++, i++) {
auto bal = CTokenAmount{(*it).first, (*it).second};
std::string tokenIdStr = bal.nTokenId.ToString();
if (symbol_lookup) {
auto token = mnview.GetToken(bal.nTokenId);
Expand Down Expand Up @@ -1191,10 +1191,13 @@ UniValue listaccounthistory(const JSONRPCRequest& request) {
count = limit;
searchInWallet(pwallet, account, filter,
[&](CBlockIndex const * index, CWalletTx const * pwtx) {
return txs.count(pwtx->GetHash()) || startBlock > index->nHeight || index->nHeight > maxBlockHeight;
uint32_t height = index->nHeight;
return txs.count(pwtx->GetHash()) || startBlock > height || height > maxBlockHeight;
},
[&](COutputEntry const & entry, CBlockIndex const * index, CWalletTx const * pwtx) {
if (txn != std::numeric_limits<uint32_t>::max() && index->nHeight == maxBlockHeight && pwtx->nIndex > txn ) {
uint32_t height = index->nHeight;
uint32_t nIndex = pwtx->nIndex;
if (txn != std::numeric_limits<uint32_t>::max() && height == maxBlockHeight && nIndex > txn ) {
return true;
}
auto& array = ret.emplace(index->nHeight, UniValue::VARR).first->second;
Expand Down Expand Up @@ -1563,7 +1566,7 @@ UniValue accounthistorycount(const JSONRPCRequest& request) {
if (shouldSearchInWallet) {
searchInWallet(pwallet, owner, filter,
[&](CBlockIndex const * index, CWalletTx const * pwtx) {
return txs.count(pwtx->GetHash()) || index->nHeight > currentHeight;
return txs.count(pwtx->GetHash()) || static_cast<uint32_t>(index->nHeight) > currentHeight;
},
[&count](COutputEntry const &, CBlockIndex const *, CWalletTx const *) {
++count;
Expand Down
2 changes: 1 addition & 1 deletion src/masternodes/rpc_icxorderbook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ UniValue icxOrderToJSON(CICXOrderImplemetation const& order, uint8_t const statu
orderObj.pushKV("closeHeight", static_cast<int>(order.closeHeight));
if (!order.closeTx.IsNull()) orderObj.pushKV("closeTx", order.closeTx.GetHex());
}
else if (order.creationHeight + order.expiry <= pcustomcsview->GetLastHeight())
else if (order.creationHeight + order.expiry <= static_cast<uint32_t>(pcustomcsview->GetLastHeight()))
{
orderObj.pushKV("expired", true);
}
Expand Down
3 changes: 1 addition & 2 deletions src/masternodes/rpc_loan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,7 @@ UniValue getinterest(const JSONRPCRequest& request) {
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Token %s does not exist!", tokenStr));

UniValue ret(UniValue::VARR);
uint32_t height = ::ChainActive().Height() + 1;
const auto height = ::ChainActive().Height() + 1;

std::map<DCT_ID, std::pair<base_uint<128>, base_uint<128>> > interest;

Expand Down Expand Up @@ -1453,7 +1453,6 @@ UniValue getinterest(const JSONRPCRequest& request) {
for (auto it=interest.begin(); it != interest.end(); ++it)
{
auto tokenId = it->first;
auto interestRate = it->second;
auto totalInterest = it->second.first;
auto interestPerBlock = it->second.second;

Expand Down
2 changes: 1 addition & 1 deletion src/masternodes/rpc_masternodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ UniValue getmasternodeblocks(const JSONRPCRequest& request) {
depth = std::min(depth, currentHeight);
auto startBlock = currentHeight - depth;

auto masternodeBlocks = [&](const uint256& masternodeID, uint32_t blockHeight) {
auto masternodeBlocks = [&](const uint256& masternodeID, int blockHeight) {
if (masternodeID != mn_id) {
return false;
}
Expand Down
Loading

0 comments on commit a58c785

Please sign in to comment.