Skip to content

Commit

Permalink
Merge branch 'master' into feature/add-cycle-filter-listgovproposals
Browse files Browse the repository at this point in the history
  • Loading branch information
Bushstar authored Jan 4, 2023
2 parents 5a28b5f + 4acdcb0 commit d728646
Show file tree
Hide file tree
Showing 15 changed files with 293 additions and 54 deletions.
1 change: 1 addition & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ void SetupServerArgs()
gArgs.AddArg("-regtest-minttoken-simulate-mainnet", "Simulate mainnet for minttokens on regtest - default behavior on regtest is to allow anyone to mint mintable tokens for ease of testing", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS);
gArgs.AddArg("-simulatemainnet", "Configure the regtest network to mainnet target timespan and spacing ", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS);
gArgs.AddArg("-dexstats", strprintf("Enable storing live dex data in DB (default: %u)", DEFAULT_DEXSTATS), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
gArgs.AddArg("-blocktimeordering", strprintf("Whether to order transactions by time, otherwise ordered by fee (default: %u)", DEFAULT_FEE_ORDERING), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#ifdef USE_UPNP
#if USE_UPNP
gArgs.AddArg("-upnp", "Use UPnP to map the listening port (default: 1 when listening and no -proxy)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
Expand Down
18 changes: 18 additions & 0 deletions src/masternodes/mn_rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,24 @@ UniValue setgov(const JSONRPCRequest& request) {
if (!res) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, res.msg);
}

if (name == "ATTRIBUTES") {
const auto attributes = std::dynamic_pointer_cast<ATTRIBUTES>(gv);
if (!attributes) {
throw JSONRPCError(RPC_INVALID_REQUEST, "Failed to convert Gov var to attributes");
}

LOCK(cs_main);
const auto attrMap = attributes->GetAttributesMap();
for (const auto& [key, value] : attrMap) {
if (const auto attrV0 = std::get_if<CDataStructureV0>(&key)) {
if (attrV0->type == AttributeTypes::Consortium && (attrV0->typeId == 0 || pcustomcsview->GetLoanTokenByID({attrV0->typeId}))) {
throw JSONRPCError(RPC_INVALID_REQUEST, "Cannot set consortium on DFI or loan tokens");
}
}
}
}

varStream << name << *gv;
}
}
Expand Down
181 changes: 150 additions & 31 deletions src/masternodes/rpc_proposals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,51 +520,154 @@ UniValue listgovproposalvotes(const JSONRPCRequest &request) {
RPCHelpMan{
"listgovproposalvotes",
"\nReturns information about proposal votes.\n",
{{"proposalId", RPCArg::Type::STR, RPCArg::Optional::NO, "The proposal id)"},
{
{"proposalId", RPCArg::Type::STR, RPCArg::Optional::NO, "The proposal id)"},
{"masternode", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "mine/all/id (default = mine)"},
{"cycle",
RPCArg::Type::NUM,
RPCArg::Optional::OMITTED,
"cycle: 0 (show current), cycle: N (show cycle N), cycle: -1 (show all) (default = 0)"}},
RPCArg::Type::NUM,
RPCArg::Optional::OMITTED,
"cycle: 0 (show current), cycle: N (show cycle N), cycle: -1 (show all) (default = 0)"},
{
"pagination",
RPCArg::Type::OBJ,
RPCArg::Optional::OMITTED,
"",
{
{"start",
RPCArg::Type::NUM,
RPCArg::Optional::OMITTED,
"Vote index to iterate from."
"Typically it's set to last ID from previous request."},
{"including_start",
RPCArg::Type::BOOL,
RPCArg::Optional::OMITTED,
"If true, then iterate including starting position. False by default"},
{"limit",
RPCArg::Type::NUM,
RPCArg::Optional::OMITTED,
"Maximum number of votes to return, 100 by default"},
},
}, },
RPCResult{"{id:{...},...} (array) Json object with proposal vote information\n"},
RPCExamples{HelpExampleCli("listgovproposalvotes", "txid") + HelpExampleRpc("listgovproposalvotes", "txid")},
}
.Check(request);

RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VSTR, UniValue::VNUM}, true);
if (request.params[0].isObject())
RPCTypeCheck(request.params, {UniValue::VOBJ}, true);
else
RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VSTR, UniValue::VNUM, UniValue::VOBJ}, true);

auto propId = ParseHashV(request.params[0].get_str(), "proposalId");
CCustomCSView view(*pcustomcsview);

uint256 mnId;
uint256 propId;
bool isMine = true;
if (request.params.size() > 1) {
auto str = request.params[1].get_str();
if (str == "all") {
isMine = false;
} else if (str != "mine") {
isMine = false;
mnId = ParseHashV(str, "masternode");
}
}
CCustomCSView view(*pcustomcsview);

uint8_t cycle{1};
int8_t inputCycle{0};
if (request.params.size() > 2) {
inputCycle = request.params[2].get_int();
}
if (inputCycle == 0) {
auto prop = view.GetProp(propId);
if (!prop) {
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Proposal <%s> does not exist", propId.GetHex()));

size_t limit = 100;
size_t start = 0;
bool including_start = true;

if (request.params[0].isObject()) {
auto optionsObj = request.params[0].get_obj();
propId = ParseHashV(optionsObj["proposalId"].get_str(), "proposalId");

if (!optionsObj["masternode"].isNull()) {
if (optionsObj["masternode"].get_str() == "all") {
isMine = false;
} else if (optionsObj["masternode"].get_str() != "mine") {
isMine = false;
mnId = ParseHashV(optionsObj["masternode"].get_str(), "masternode");
}
}

if (!optionsObj["cycle"].isNull()) {
inputCycle = optionsObj["cycle"].get_int();
if (inputCycle == 0) {
auto prop = view.GetProp(propId);
if (!prop) {
throw JSONRPCError(RPC_INVALID_PARAMETER,
strprintf("Proposal <%s> does not exist", propId.GetHex()));
}
cycle = prop->cycle;
} else if (inputCycle > 0) {
cycle = inputCycle;
} else if (inputCycle == -1) {
cycle = 1;
} else {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Incorrect cycle value");
}
}

if (!optionsObj["pagination"].isNull()) {
UniValue paginationObj = optionsObj["pagination"].get_obj();
if (!paginationObj["limit"].isNull()) {
limit = (size_t)paginationObj["limit"].get_int64();
}
if (!paginationObj["start"].isNull()) {
including_start = false;
start = (size_t)paginationObj["start"].get_int();
}
if (!paginationObj["including_start"].isNull()) {
including_start = paginationObj["including_start"].getBool();
}
if (!including_start) {
++start;
}
}
cycle = prop->cycle;
} else if (inputCycle > 0) {
cycle = inputCycle;
} else if (inputCycle == -1) {
cycle = 1;
} else {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Incorrect cycle value");
propId = ParseHashV(request.params[0].get_str(), "proposalId");

if (request.params.size() > 1) {
auto str = request.params[1].get_str();
if (str == "all") {
isMine = false;
} else if (str != "mine") {
isMine = false;
mnId = ParseHashV(str, "masternode");
}
}

if (request.params.size() > 2) {
inputCycle = request.params[2].get_int();

if (inputCycle == 0) {
auto prop = view.GetProp(propId);
if (!prop) {
throw JSONRPCError(RPC_INVALID_PARAMETER,
strprintf("Proposal <%s> does not exist", propId.GetHex()));
}
cycle = prop->cycle;
} else if (inputCycle > 0) {
cycle = inputCycle;
} else if (inputCycle == -1) {
cycle = 1;
} else {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Incorrect cycle value");
}
}

if (request.params.size() > 3) {
UniValue paginationObj = request.params[3].get_obj();
if (!paginationObj["limit"].isNull()) {
limit = (size_t)paginationObj["limit"].get_int64();
}
if (!paginationObj["start"].isNull()) {
including_start = false;
start = (size_t)paginationObj["start"].get_int();
}
if (!paginationObj["including_start"].isNull()) {
including_start = paginationObj["including_start"].getBool();
}
if (!including_start) {
++start;
}
}
if (limit == 0) {
limit = std::numeric_limits<decltype(limit)>::max();
}
}

UniValue ret(UniValue::VARR);
Expand All @@ -584,15 +687,31 @@ UniValue listgovproposalvotes(const JSONRPCRequest &request) {
if (!node) {
return true;
}

// skip entries until we reach start index
if (start != 0) {
--start;
return true;
}

auto ownerDest = node->ownerType == 1 ? CTxDestination(PKHash(node->ownerAuthAddress))
: CTxDestination(WitnessV0KeyHash(node->ownerAuthAddress));
if (::IsMineCached(*pwallet, GetScriptForDestination(ownerDest))) {
ret.push_back(proposalVoteToJSON(propId, propCycle, id, vote));
limit--;
}
} else if (mnId.IsNull() || mnId == id) {
// skip entries until we reach start index
if (start != 0) {
--start;
return true;
}

ret.push_back(proposalVoteToJSON(propId, propCycle, id, vote));
limit--;
}
return true;

return limit != 0;
},
CMnVotePerCycle{propId, cycle, mnId});

Expand Down
18 changes: 13 additions & 5 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,14 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
if (!blockTime) {
UpdateTime(pblock, consensus, pindexPrev); // update time before tx packaging
}
addPackageTxs(nPackagesSelected, nDescendantsUpdated, nHeight, mnview);

const auto timeOrdering = gArgs.GetBoolArg("-blocktimeordering", DEFAULT_FEE_ORDERING);
if (timeOrdering) {
addPackageTxs<entry_time>(nPackagesSelected, nDescendantsUpdated, nHeight, mnview);
} else {
addPackageTxs<ancestor_score>(nPackagesSelected, nDescendantsUpdated, nHeight, mnview);
}


// TXs for the creationTx field in new tokens created via token split
if (nHeight >= chainparams.GetConsensus().FortCanningCrunchHeight) {
Expand Down Expand Up @@ -483,6 +490,7 @@ void BlockAssembler::SortForBlock(const CTxMemPool::setEntries& package, std::ve
// Each time through the loop, we compare the best transaction in
// mapModifiedTxs with the next transaction in the mempool to decide what
// transaction package to work on next.
template<class T>
void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpdated, int nHeight, CCustomCSView &view)
{
// mapModifiedTx will store sorted packages after they are modified
Expand All @@ -495,7 +503,7 @@ void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpda
// and modifying them for their already included ancestors
UpdatePackagesForAdded(inBlock, mapModifiedTx);

CTxMemPool::indexed_transaction_set::index<ancestor_score>::type::iterator mi = mempool.mapTx.get<ancestor_score>().begin();
auto mi = mempool.mapTx.get<T>().begin();
CTxMemPool::txiter iter;

// Limit the number of attempts to add transactions to the block when it is
Expand All @@ -510,10 +518,10 @@ void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpda
// Copy of the view
CCoinsViewCache coinsView(&::ChainstateActive().CoinsTip());

while (mi != mempool.mapTx.get<ancestor_score>().end() || !mapModifiedTx.empty())
while (mi != mempool.mapTx.get<T>().end() || !mapModifiedTx.empty())
{
// First try to find a new transaction in mapTx to evaluate.
if (mi != mempool.mapTx.get<ancestor_score>().end() &&
if (mi != mempool.mapTx.get<T>().end() &&
SkipMapTxEntry(mempool.mapTx.project<0>(mi), mapModifiedTx, failedTx)) {
++mi;
continue;
Expand All @@ -524,7 +532,7 @@ void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpda
bool fUsingModified = false;

modtxscoreiter modit = mapModifiedTx.get<ancestor_score>().begin();
if (mi == mempool.mapTx.get<ancestor_score>().end()) {
if (mi == mempool.mapTx.get<T>().end()) {
// We're out of entries in mapTx; use the entry from mapModifiedTx
iter = modit->iter;
fUsingModified = true;
Expand Down
1 change: 1 addition & 0 deletions src/miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class BlockAssembler
/** Add transactions based on feerate including unconfirmed ancestors
* Increments nPackagesSelected / nDescendantsUpdated with corresponding
* statistics from the package selection (for logging statistics). */
template<class T>
void addPackageTxs(int &nPackagesSelected, int &nDescendantsUpdated, int nHeight, CCustomCSView &view) EXCLUSIVE_LOCKS_REQUIRED(mempool.cs);

// helper functions for addPackageTxs()
Expand Down
6 changes: 6 additions & 0 deletions src/policy/fees.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <streams.h>
#include <txmempool.h>
#include <util/system.h>
#include <validation.h>

static constexpr double INF_FEERATE = 1e99;

Expand Down Expand Up @@ -787,6 +788,11 @@ CFeeRate CBlockPolicyEstimator::estimateSmartFee(int confTarget, FeeCalculation
{
LOCK(m_cs_fee_estimator);

// If block ordering by time is enabled return 0 to let fallback or discard fee be used.
if (gArgs.GetBoolArg("-blocktimeordering", DEFAULT_FEE_ORDERING)) {
return 0;
}

if (feeCalc) {
feeCalc->desiredTarget = confTarget;
feeCalc->returnedTarget = confTarget;
Expand Down
2 changes: 2 additions & 0 deletions src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,8 @@ static UniValue estimatesmartfee(const JSONRPCRequest& request)
CFeeRate feeRate = ::feeEstimator.estimateSmartFee(conf_target, &feeCalc, conservative);
if (feeRate != CFeeRate(0)) {
result.pushKV("feerate", ValueFromAmount(feeRate.GetFeePerK()));
} else if (gArgs.GetBoolArg("-blocktimeordering", DEFAULT_FEE_ORDERING)) {
result.pushKV("feerate", ValueFromAmount(DEFAULT_TRANSACTION_MINFEE));
} else {
errors.push_back("Insufficient data or no feerate found");
result.pushKV("errors", errors);
Expand Down
4 changes: 2 additions & 2 deletions src/spv/bitcoin/BRChainParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ static const char *BRMainNetDNSSeeds[] = {
};

static const char *BRTestNetDNSSeeds[] = {
"testnet-seed.breadwallet.com.", "testnet-seed.bitcoin.petertodd.org.", "testnet-seed.bluematt.me.",
"testnet-seed.bitcoin.schildbach.de.", NULL
"testnet-seed.breadwallet.com.", "testnet-seed.bitcoin.jonasschnelli.ch.", "seed.testnet.bitcoin.sprovoost.nl.",
"testnet-seed.bluematt.me.", NULL
};

// blockchain checkpoints - these are also used as starting points for partial chain downloads, so they must be at
Expand Down
4 changes: 4 additions & 0 deletions src/spv/bitcoin/BRPeerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1757,6 +1757,10 @@ void BRPeerManagerConnect(BRPeerManager *manager)
}

while (array_count(manager->peers) > 0 && array_count(manager->connectedPeers) < manager->maxConnectCount) {
// Break out of loop to allow shutdown.
if (ShutdownRequested()) {
break;
}
size_t i = BRRand((uint32_t)array_count(manager->peers)); // index of random peer
BRPeerCallbackInfo *info;

Expand Down
2 changes: 2 additions & 0 deletions src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ static const bool DEFAULT_FEEFILTER = true;
static const bool DEFAULT_DEXSTATS = false;
/** Default for tracking amount negated by negative interest in attributes */
static const bool DEFAULT_NEGATIVE_INTEREST = false;
/** Default for using TX fee ordering in blocks */
static const bool DEFAULT_FEE_ORDERING = false;

/** Maximum number of headers to announce when relaying blocks with headers message.*/
static const unsigned int MAX_BLOCKS_TO_ANNOUNCE = 8;
Expand Down
Loading

0 comments on commit d728646

Please sign in to comment.