Skip to content

Commit a747da8

Browse files
authored
Merge pull request duality-solutions#358 from duality-solutions/v2.4.22-DHT-Stats
Updates to BDAP DHT for v2.4.22
2 parents df2331f + 5261f84 commit a747da8

32 files changed

+1380
-746
lines changed

.gitmodules

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
[submodule "src/libtorrent"]
66
path = src/libtorrent
77
url = https://github.com/duality-solutions/libbdaptorrent.git
8+
branch = incompatible

src/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ DYNAMIC_CORE_H = \
131131
dht/datarecord.h \
132132
dht/dataset.h \
133133
dht/ed25519.h \
134+
dht/limits.h \
134135
dht/mutable.h \
135136
dht/mutabledb.h \
136137
dht/session.h \
@@ -287,6 +288,7 @@ libdynamic_server_a_SOURCES = \
287288
dht/dataheader.cpp \
288289
dht/datarecord.cpp \
289290
dht/dataset.cpp \
291+
dht/limits.cpp \
290292
dht/mutable.cpp \
291293
dht/mutabledb.cpp \
292294
dht/rpcdht.cpp \

src/bdap/domainentrydb.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ bool GetDomainEntryPubKey(const std::vector<unsigned char>& vchPubKey, CDomainEn
4545
return !entry.IsNull();
4646
}
4747

48+
bool AccountPubKeyExists(const std::vector<unsigned char>& vchPubKey)
49+
{
50+
CDomainEntry entry;
51+
return GetDomainEntryPubKey(vchPubKey, entry);
52+
}
53+
4854
bool DomainEntryExists(const std::vector<unsigned char>& vchObjectPath)
4955
{
5056
if (!pDomainEntryDB)

src/bdap/domainentrydb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class CDomainEntryDB : public CDBWrapper {
4141

4242
bool GetDomainEntry(const std::vector<unsigned char>& vchObjectPath, CDomainEntry& entry);
4343
bool GetDomainEntryPubKey(const std::vector<unsigned char>& vchPubKey, CDomainEntry& entry);
44+
bool AccountPubKeyExists(const std::vector<unsigned char>& vchPubKey);
4445
bool DomainEntryExists(const std::vector<unsigned char>& vchObjectPath);
4546
bool DeleteDomainEntry(const CDomainEntry& entry);
4647
bool UndoAddDomainEntry(const CDomainEntry& entry);

src/bdap/fees.cpp

Lines changed: 93 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,96 +9,149 @@
99
#include "util.h" // for LogPrintf
1010

1111
#include <boost/date_time/posix_time/posix_time.hpp>
12+
#include <limits>
13+
#include <map>
1214

1315
// Default BDAP Monthly Fees
14-
std::map<int32_t, CAmount> mapDefaultMonthlyFees = {
15-
{BDAP_MONTHY_USER_FEE, 50 * BDAP_CREDIT},
16-
{BDAP_MONTHY_GROUP_FEE, 200 * BDAP_CREDIT},
17-
{BDAP_MONTHY_CERTIFICATE_FEE, 100 * BDAP_CREDIT},
18-
{BDAP_MONTHY_SIDECHAIN_FEE, 1000 * BDAP_CREDIT},
16+
std::map<int32_t, CFeeItem> mapDefaultMonthlyFees = {
17+
{BDAP_MONTHY_USER_FEE, CFeeItem(BDAP_MONTHY_USER_FEE, 50 * BDAP_CREDIT, 0, std::numeric_limits<unsigned int>::max())},
18+
{BDAP_MONTHY_GROUP_FEE, CFeeItem(BDAP_MONTHY_GROUP_FEE, 200 * BDAP_CREDIT, 0, std::numeric_limits<unsigned int>::max())},
19+
{BDAP_MONTHY_CERTIFICATE_FEE, CFeeItem(BDAP_MONTHY_CERTIFICATE_FEE, 100 * BDAP_CREDIT, 0, std::numeric_limits<unsigned int>::max())},
20+
{BDAP_MONTHY_SIDECHAIN_FEE, CFeeItem(BDAP_MONTHY_SIDECHAIN_FEE, 1000 * BDAP_CREDIT, 0, std::numeric_limits<unsigned int>::max())},
1921
};
2022

2123
// Default BDAP One Time Fees
22-
std::map<int32_t, CAmount> mapOneTimeFees = {
23-
{BDAP_ONE_TIME_REQUEST_LINK_FEE, 99 * BDAP_CREDIT},
24-
{BDAP_ONE_TIME_ACCEPT_LINK_FEE, 99 * BDAP_CREDIT},
25-
{BDAP_ONE_TIME_AUDIT_RECORD_FEE, 99 * BDAP_CREDIT},
24+
std::multimap<int32_t, CFeeItem> mapOneTimeFees = {
25+
{BDAP_ONE_TIME_REQUEST_LINK_FEE, CFeeItem(BDAP_ONE_TIME_REQUEST_LINK_FEE, 99 * BDAP_CREDIT, 0, std::numeric_limits<unsigned int>::max())},
26+
{BDAP_ONE_TIME_ACCEPT_LINK_FEE, CFeeItem(BDAP_ONE_TIME_ACCEPT_LINK_FEE, 99 * BDAP_CREDIT, 0, std::numeric_limits<unsigned int>::max())},
27+
{BDAP_ONE_TIME_AUDIT_RECORD_FEE, CFeeItem(BDAP_ONE_TIME_AUDIT_RECORD_FEE, 99 * BDAP_CREDIT, 0, std::numeric_limits<unsigned int>::max())},
2628
};
2729

2830
// Default BDAP Non-Refundable Security Deposit Fees
29-
std::map<int32_t, CAmount> mapNoRefundDeposits = {
30-
{BDAP_NON_REFUNDABLE_USER_DEPOSIT, 1000 * BDAP_CREDIT},
31-
{BDAP_NON_REFUNDABLE_GROUP_DEPOSIT, 10000 * BDAP_CREDIT},
32-
{BDAP_NON_REFUNDABLE_CERTIFICATE_DEPOSIT, 5000 * BDAP_CREDIT},
33-
{BDAP_NON_REFUNDABLE_SIDECHAIN_DEPOSIT, 25000 * BDAP_CREDIT},
31+
std::map<int32_t, CFeeItem> mapNoRefundDeposits = {
32+
{BDAP_NON_REFUNDABLE_USER_DEPOSIT, CFeeItem(BDAP_NON_REFUNDABLE_USER_DEPOSIT, 1000 * BDAP_CREDIT, 0, std::numeric_limits<unsigned int>::max())},
33+
{BDAP_NON_REFUNDABLE_GROUP_DEPOSIT, CFeeItem(BDAP_NON_REFUNDABLE_GROUP_DEPOSIT, 10000 * BDAP_CREDIT, 0, std::numeric_limits<unsigned int>::max())},
34+
{BDAP_NON_REFUNDABLE_CERTIFICATE_DEPOSIT, CFeeItem(BDAP_NON_REFUNDABLE_CERTIFICATE_DEPOSIT, 5000 * BDAP_CREDIT, 0, std::numeric_limits<unsigned int>::max())},
35+
{BDAP_NON_REFUNDABLE_SIDECHAIN_DEPOSIT, CFeeItem(BDAP_NON_REFUNDABLE_SIDECHAIN_DEPOSIT, 25000 * BDAP_CREDIT, 0, std::numeric_limits<unsigned int>::max())},
3436
};
3537

3638
bool GetBDAPFees(const opcodetype& opCodeAction, const opcodetype& opCodeObject, const BDAP::ObjectType objType, const uint16_t nMonths, CAmount& monthlyFee, CAmount& oneTimeFee, CAmount& depositFee)
3739
{
3840
std::string strObjectType = BDAP::GetObjectTypeString((unsigned int)objType);
3941
LogPrint("bdap", "%s -- strObjectType = %s, OpAction %d, OpObject %d\n", __func__, strObjectType, opCodeAction, opCodeObject);
4042
if (opCodeAction == OP_BDAP_NEW && opCodeObject == OP_BDAP_ACCOUNT_ENTRY && objType == BDAP::ObjectType::BDAP_USER) {
41-
// new BDAP user account
43+
// Fees for a new BDAP user account
4244
oneTimeFee = 0;
43-
monthlyFee = mapDefaultMonthlyFees[BDAP_MONTHY_USER_FEE] * nMonths;
44-
depositFee = mapNoRefundDeposits[BDAP_NON_REFUNDABLE_USER_DEPOSIT];
45+
CFeeItem feeMonthly;
46+
std::multimap<int32_t, CFeeItem>::iterator iMonthly = mapDefaultMonthlyFees.find(BDAP_MONTHY_USER_FEE);
47+
if (iMonthly != mapDefaultMonthlyFees.end()) {
48+
feeMonthly = iMonthly->second;
49+
monthlyFee = (nMonths * feeMonthly.Fee);
50+
}
51+
CFeeItem feeDeposit;
52+
std::multimap<int32_t, CFeeItem>::iterator iDeposit = mapNoRefundDeposits.find(BDAP_NON_REFUNDABLE_USER_DEPOSIT);
53+
if (iDeposit != mapNoRefundDeposits.end()) {
54+
feeDeposit = iDeposit->second;
55+
depositFee = feeDeposit.Fee;
56+
}
4557

4658
} else if (opCodeAction == OP_BDAP_NEW && opCodeObject == OP_BDAP_ACCOUNT_ENTRY && objType == BDAP::ObjectType::BDAP_GROUP) {
47-
// new BDAP group account
59+
// Fees for a new BDAP group account
4860
oneTimeFee = 0;
49-
monthlyFee = mapDefaultMonthlyFees[BDAP_MONTHY_GROUP_FEE] * nMonths;
50-
depositFee = mapNoRefundDeposits[BDAP_NON_REFUNDABLE_GROUP_DEPOSIT];
61+
CFeeItem feeMonthly;
62+
std::multimap<int32_t, CFeeItem>::iterator iMonthly = mapDefaultMonthlyFees.find(BDAP_MONTHY_GROUP_FEE);
63+
if (iMonthly != mapDefaultMonthlyFees.end()) {
64+
feeMonthly = iMonthly->second;
65+
monthlyFee = (nMonths * feeMonthly.Fee);
66+
}
67+
CFeeItem feeDeposit;
68+
std::multimap<int32_t, CFeeItem>::iterator iDeposit = mapNoRefundDeposits.find(BDAP_NON_REFUNDABLE_GROUP_DEPOSIT);
69+
if (iDeposit != mapNoRefundDeposits.end()) {
70+
feeDeposit = iDeposit->second;
71+
depositFee = feeDeposit.Fee;
72+
}
5173

5274
} else if (opCodeAction == OP_BDAP_NEW && opCodeObject == OP_BDAP_CERTIFICATE && objType == BDAP::ObjectType::BDAP_CERTIFICATE) {
53-
// new BDAP certificate
75+
// Fees for a new BDAP certificate
5476
oneTimeFee = 0;
55-
monthlyFee = mapDefaultMonthlyFees[BDAP_MONTHY_CERTIFICATE_FEE] * nMonths;
56-
depositFee = mapNoRefundDeposits[BDAP_NON_REFUNDABLE_CERTIFICATE_DEPOSIT];
77+
CFeeItem feeMonthly;
78+
std::multimap<int32_t, CFeeItem>::iterator iMonthly = mapDefaultMonthlyFees.find(BDAP_MONTHY_CERTIFICATE_FEE);
79+
if (iMonthly != mapDefaultMonthlyFees.end()) {
80+
feeMonthly = iMonthly->second;
81+
monthlyFee = (nMonths * feeMonthly.Fee);
82+
}
83+
CFeeItem feeDeposit;
84+
std::multimap<int32_t, CFeeItem>::iterator iDeposit = mapNoRefundDeposits.find(BDAP_NON_REFUNDABLE_CERTIFICATE_DEPOSIT);
85+
if (iDeposit != mapNoRefundDeposits.end()) {
86+
feeDeposit = iDeposit->second;
87+
depositFee = feeDeposit.Fee;
88+
}
5789

5890
} else if (opCodeAction == OP_BDAP_NEW && opCodeObject == OP_BDAP_SIDECHAIN && objType == BDAP::ObjectType::BDAP_SIDECHAIN) {
59-
// new BDAP sidechain entry
91+
// Fees for a new BDAP sidechain entry
6092
oneTimeFee = 0;
61-
monthlyFee = mapDefaultMonthlyFees[BDAP_MONTHY_SIDECHAIN_FEE] * nMonths;
62-
depositFee = mapNoRefundDeposits[BDAP_NON_REFUNDABLE_SIDECHAIN_DEPOSIT];
93+
CFeeItem feeMonthly;
94+
std::multimap<int32_t, CFeeItem>::iterator iMonthly = mapDefaultMonthlyFees.find(BDAP_MONTHY_SIDECHAIN_FEE);
95+
if (iMonthly != mapDefaultMonthlyFees.end()) {
96+
feeMonthly = iMonthly->second;
97+
monthlyFee = (nMonths * feeMonthly.Fee);
98+
}
99+
CFeeItem feeDeposit;
100+
std::multimap<int32_t, CFeeItem>::iterator iDeposit = mapNoRefundDeposits.find(BDAP_NON_REFUNDABLE_SIDECHAIN_DEPOSIT);
101+
if (iDeposit != mapNoRefundDeposits.end()) {
102+
feeDeposit = iDeposit->second;
103+
depositFee = feeDeposit.Fee;
104+
}
63105

64106
} else if (opCodeAction == OP_BDAP_NEW && opCodeObject == OP_BDAP_LINK_REQUEST && objType == BDAP::ObjectType::BDAP_LINK_REQUEST) {
65-
// new BDAP link request
66-
oneTimeFee = mapOneTimeFees[BDAP_ONE_TIME_REQUEST_LINK_FEE];
107+
// Fees for a new BDAP link request
108+
CFeeItem feeOneTime;
109+
std::multimap<int32_t, CFeeItem>::iterator iOneTime = mapOneTimeFees.find(BDAP_ONE_TIME_REQUEST_LINK_FEE);
110+
if (iOneTime != mapOneTimeFees.end()) {
111+
feeOneTime = iOneTime->second;
112+
oneTimeFee = feeOneTime.Fee;
113+
}
67114
monthlyFee = 0;
68115
depositFee = BDAP_CREDIT;
69116

70117
} else if (opCodeAction == OP_BDAP_NEW && opCodeObject == OP_BDAP_LINK_ACCEPT && objType == BDAP::ObjectType::BDAP_LINK_ACCEPT) {
71-
// new BDAP link accept
72-
oneTimeFee = mapOneTimeFees[BDAP_ONE_TIME_ACCEPT_LINK_FEE];
118+
// Fees for a new BDAP link accept
119+
CFeeItem feeOneTime;
120+
std::multimap<int32_t, CFeeItem>::iterator iOneTime = mapOneTimeFees.find(BDAP_ONE_TIME_ACCEPT_LINK_FEE);
121+
if (iOneTime != mapOneTimeFees.end()) {
122+
feeOneTime = iOneTime->second;
123+
oneTimeFee = feeOneTime.Fee;
124+
}
73125
monthlyFee = 0;
74126
depositFee = BDAP_CREDIT;
75127

76128
} else if (opCodeAction == OP_BDAP_NEW && opCodeObject == OP_BDAP_AUDIT && objType == BDAP::ObjectType::BDAP_AUDIT) {
77-
// new BDAP audit record
78-
oneTimeFee = mapOneTimeFees[BDAP_ONE_TIME_AUDIT_RECORD_FEE];
129+
// Fees for a new BDAP audit record
130+
CFeeItem feeOneTime;
131+
std::multimap<int32_t, CFeeItem>::iterator iOneTime = mapOneTimeFees.find(BDAP_ONE_TIME_AUDIT_RECORD_FEE);
132+
if (iOneTime != mapOneTimeFees.end()) {
133+
feeOneTime = iOneTime->second;
134+
oneTimeFee = feeOneTime.Fee;
135+
}
79136
monthlyFee = 0;
80137
depositFee = BDAP_CREDIT;
81138

82139
} else if (opCodeAction == OP_BDAP_MODIFY && opCodeObject == OP_BDAP_ACCOUNT_ENTRY && objType == BDAP::ObjectType::BDAP_USER) {
83-
// update BDAP user account entry
140+
// Fees for an update BDAP user account entry
84141
oneTimeFee = 0;
85142
monthlyFee = 0;
86143
depositFee = BDAP_CREDIT;
87144

88145
} else if (opCodeAction == OP_BDAP_MODIFY && opCodeObject == OP_BDAP_ACCOUNT_ENTRY && objType == BDAP::ObjectType::BDAP_GROUP) {
89-
// update BDAP group account entry
146+
// Fees for an update BDAP group account entry
90147
oneTimeFee = 0;
91148
monthlyFee = 0;
92149
depositFee = BDAP_CREDIT;
93-
} else if (objType == BDAP::ObjectType::BDAP_DEFAULT_TYPE) {
94-
// ********** TODO (BDAP): Remove this
95-
oneTimeFee = 0;
150+
} else {
151+
oneTimeFee = BDAP_CREDIT;
96152
monthlyFee = 0;
97153
depositFee = BDAP_CREDIT;
98-
}
99-
else {
100154
LogPrintf("%s -- BDAP operation code pair (%d and %d) for %s not found or unsupported.\n", __func__, opCodeAction, opCodeObject, strObjectType);
101-
return false;
102155
}
103156

104157
return true;

src/bdap/fees.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ static const int32_t BDAP_NON_REFUNDABLE_GROUP_DEPOSIT = 7002;
3636
static const int32_t BDAP_NON_REFUNDABLE_CERTIFICATE_DEPOSIT = 7003;
3737
static const int32_t BDAP_NON_REFUNDABLE_SIDECHAIN_DEPOSIT = 7004;
3838

39+
class CFeeItem {
40+
public:
41+
static const int CURRENT_VERSION=1;
42+
int nVersion;
43+
int32_t nType;
44+
CAmount Fee;
45+
unsigned int nStartHeight;
46+
unsigned int nEndHeight;
47+
CFeeItem() : nVersion(CURRENT_VERSION), nType(0), Fee(0), nStartHeight(0), nEndHeight(0) {}
48+
CFeeItem(const int32_t& type, const CAmount& fee, const unsigned int& start, const unsigned int& end) : nVersion(CURRENT_VERSION), nType(type), Fee(fee), nStartHeight(start), nEndHeight(end) {}
49+
};
50+
3951
bool GetBDAPFees(const opcodetype& opCodeAction, const opcodetype& opCodeObject, const BDAP::ObjectType objType, const uint16_t nMonths, CAmount& monthlyFee, CAmount& oneTimeFee, CAmount& depositFee);
4052
int64_t AddMonthsToCurrentEpoch(const short nMonths);
4153
int64_t AddMonthsToBlockTime(const uint32_t& nBlockTime, const short nMonths);

0 commit comments

Comments
 (0)