Skip to content

Commit

Permalink
Added attrs index fixes, change default, add v27
Browse files Browse the repository at this point in the history
  • Loading branch information
prasannavl committed May 24, 2022
1 parent 0c5329b commit ea0ecae
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/masternodes/govvariables/attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ Res ATTRIBUTES::Import(const UniValue & val) {
// Keys to exclude when using the legacy filter mode, to keep things the
// same as pre 2.7.x versions, to reduce noise. Eventually, the APIs that
// cause too much noise can be deprecated and this code removed.
std::set<uint32_t> legacyTokenKeysBlacklist = {
std::set<uint32_t> attrsVersion27TokenHiddenSet = {
TokenKeys::LoanCollateralEnabled,
TokenKeys::LoanCollateralFactor,
TokenKeys::LoanMintingEnabled,
Expand All @@ -644,12 +644,12 @@ UniValue ATTRIBUTES::ExportFiltered(GovVarsFilter filter, const std::string &pre
if (!attrV0) {
continue;
}
if (filter == GovVarsFilter::LiveAttributes &&
if (filter == GovVarsFilter::Version2Dot7 &&
attrV0->type != AttributeTypes::Live) {
continue;
} else if (filter == GovVarsFilter::Legacy) {
} else if (filter == GovVarsFilter::) {
if (attrV0->type == AttributeTypes::Token &&
legacyTokenKeysBlacklist.find(attrV0->key) != legacyTokenKeysBlacklist.end())
attrsVersion27TokenHiddenSet.find(attrV0->key) != attrsVersion27TokenHiddenSet.end())
continue;
}
try {
Expand Down
2 changes: 1 addition & 1 deletion src/masternodes/govvariables/attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ using CAttributeType = boost::variant<CDataStructureV0, CDataStructureV1>;
using CAttributeValue = boost::variant<bool, CAmount, CBalances, CTokenPayback, CTokenCurrencyPair, OracleSplits, DescendantValue, AscendantValue>;

enum GovVarsFilter {
Legacy,
All,
NoAttributes,
AttributesOnly,
PrefixedAttributes,
LiveAttributes,
Version2Dot7,
};

class ATTRIBUTES : public GovVariable, public AutoRegistrator<GovVariable, ATTRIBUTES>
Expand Down
12 changes: 8 additions & 4 deletions src/masternodes/mn_rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ UniValue listgovs(const JSONRPCRequest& request) {
"\nReturns information about all governance variables including pending changes\n",
{
{"prefix", RPCArg::Type::STR, RPCArg::Optional::OMITTED,
"One of all, gov, live. Defaults to the legacy view. Any other string is treated as\n"
"One of all, gov, attrs, live. Defaults to the all view. Any other string is treated as\n"
"a prefix of attributes to filter with. `v0/` is assumed if not explicitly provided."},
},
RPCResult{
Expand All @@ -712,7 +712,7 @@ UniValue listgovs(const JSONRPCRequest& request) {
},
}.Check(request);

GovVarsFilter mode{GovVarsFilter::Legacy};
GovVarsFilter mode{GovVarsFilter::All};
std::string prefix;
if (request.params.size() > 0) {
prefix = request.params[0].getValStr();
Expand All @@ -724,12 +724,16 @@ UniValue listgovs(const JSONRPCRequest& request) {
mode = GovVarsFilter::NoAttributes;
} else if (prefix == "attrs") {
mode = GovVarsFilter::AttributesOnly;

} else if (prefix == "v/2.7") {
// Undocumented. Make be removed or deprecated without notice.
// Only here for unforeseen compatibility concern downstream
// for transitions.
mode = GovVarsFilter::Version2Dot7;
} else if (prefix == "live") {
mode = GovVarsFilter::LiveAttributes;
} else {
mode = GovVarsFilter::PrefixedAttributes;
const std::regex versionRegex("v[0-9].*");
const std::regex versionRegex("^v[0-9].*");
if (!std::regex_match(prefix.begin(), prefix.end(), versionRegex)) {
prefix = "v0/" + prefix;
}
Expand Down
8 changes: 4 additions & 4 deletions test/functional/feature_token_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def check_token_split(self, token_id, token_symbol, token_suffix, multiplier, mi
assert_equal(result['destructionHeight'], self.nodes[0].getblockcount())

# Check old token in Gov vars
result = self.nodes[0].listgovs("all")[8][0]['ATTRIBUTES']
result = self.nodes[0].listgovs("attrs")[0][0]['ATTRIBUTES']
assert(f'v0/token/{token_id}/fixed_interval_price_id' not in result)
if collateral:
assert(f'v0/token/{token_id}/loan_collateral_enabled' not in result)
Expand Down Expand Up @@ -316,7 +316,7 @@ def check_pool_split(self, pool_id, pool_symbol, token_id, token_symbol, token_s
assert_equal(result['rewardLoanPct'], Decimal('0.00000000'))

# Validate old Gov vars removed
result = self.nodes[0].listgovs("all")[8][0]['ATTRIBUTES']
result = self.nodes[0].listgovs("attrs")[0][0]['ATTRIBUTES']
assert(f'v0/poolpairs/{pool_id}/token_a_fee_pct' not in result)
assert(f'v0/poolpairs/{pool_id}/token_b_fee_pct' not in result)
assert(f'v0/token/{token_id}/dex_in_fee_pct' not in result)
Expand Down Expand Up @@ -617,7 +617,7 @@ def check_govvar_deletion(self):
self.nodes[0].generate(1)

# Check splits
result = self.nodes[0].listgovs("all")[8][0]['ATTRIBUTES']
result = self.nodes[0].listgovs("attrs")[0][0]['ATTRIBUTES']
assert_equal(result[f'v0/oracles/splits/{split_height}'], f'{self.idTSLA}/2,')
assert_equal(result[f'v0/oracles/splits/500000'], f'{self.idTSLA}/2,')
assert_equal(result[f'v0/oracles/splits/1000000'], f'{self.idTSLA}/2,{self.idNVDA}/2,')
Expand All @@ -626,7 +626,7 @@ def check_govvar_deletion(self):
self.nodes[0].generate(1)

# Check TSLA entries removed
result = self.nodes[0].listgovs("all")[8][0]['ATTRIBUTES']
result = self.nodes[0].listgovs("attrs")[0][0]['ATTRIBUTES']
assert(f'v0/oracles/splits/{split_height}' not in result)
assert(f'v0/oracles/splits/500000' not in result)
assert_equal(result[f'v0/oracles/splits/1000000'], f'{self.idNVDA}/2,')
Expand Down

0 comments on commit ea0ecae

Please sign in to comment.