Skip to content

Commit

Permalink
Merge pull request #375 from lostystyg/0.21
Browse files Browse the repository at this point in the history
0.21 Actualization
  • Loading branch information
lostystyg authored Aug 24, 2022
2 parents 6e53078 + 29abe39 commit b7b4991
Show file tree
Hide file tree
Showing 16 changed files with 274 additions and 237 deletions.
39 changes: 39 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## Standards checklist:

<!---
Pull request must have next naming format:
- For fixes use "fix:" prefix, e.g. "fix: video transcoding"
- For consensus use "consensus:" prefix, e.g. "consensus: increasing Scores limits"
- For patches use "patch:" prefix, e.g. "patch: docker image change"
- For features use "feature:" prefix, e.g. "feat: voice messages"
- For refactoring use "refactor:" prefix, e.g. "refactor: workflow actions"
- For documentation use "docs:" prefix, e.g. "docs: readme.md header logo"
- For workflow process use "workflow:" prefix, e.g. "workflow: added PR template"
Use this prefixes for PR branches also, eg:
workflow/pr-template
-->

<!-- Fill with an x the ones that apply. Example: [x] -->

- [ ] The PR title is descriptive.
- [ ] The PR doesn't replicate another PR which is already open.
- [ ] The PR has self-explained commits history.
<!--
- [ ] I have read the contribution guide and followed all the instructions.
- [ ] The code follows the code style guide detailed in the wiki.
-->
- [ ] The code is mine or it's from somewhere with an Apache-2.0 compatible license.
- [ ] The code is efficient, to the best of my ability, and does not waste computer resources.
- [ ] The code is stable and I have tested it myself, to the best of my abilities.
- [ ] If the code introduces new classes, methods, I provide a valid use case for all of them.

## Changes:

- [...]

## Other comments:

...
6 changes: 3 additions & 3 deletions src/pocketdb/consensus/Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ namespace PocketConsensus
{ NetworkTest, { {0, 0} } }
} },
{ threshold_shark_likers_comment, {
{ NetworkMain, { {0, 15} } },
{ NetworkMain, { {0, 15}, {1862000, 25} } },
{ NetworkTest, { {0, 1} } }
} },
{ threshold_shark_likers_comment_answer, {
Expand Down Expand Up @@ -426,7 +426,7 @@ namespace PocketConsensus
{ NetworkTest, { {0, 30} } }
} },
{ ConsensusLimit_full_score, {
{ NetworkMain, { {0, 90}, {175600, 200}, {1757000, 60}, {1791787, 100} } },
{ NetworkMain, { {0, 90}, {175600, 200}, {1757000, 60}, {1791787, 100}, {1862000, 200} } },
{ NetworkTest, { {0, 200} } }
} },
{ ConsensusLimit_full_complain, {
Expand All @@ -438,7 +438,7 @@ namespace PocketConsensus
{ NetworkTest, { {0, 300} } }
} },
{ ConsensusLimit_full_comment_score, {
{ NetworkMain, { {0, 600}, {1757000, 200} } },
{ NetworkMain, { {0, 600}, {1757000, 200}, {1862000, 300} } },
{ NetworkTest, { {0, 600} } }
} },

Expand Down
4 changes: 2 additions & 2 deletions src/pocketdb/consensus/social/Blocking.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ namespace PocketConsensus
{
protected:
const vector<ConsensusCheckpoint<BlockingConsensus>> m_rules = {
{ 0, 0, [](int height) { return make_shared<BlockingConsensus>(height); }},
{ 5555555,1114500, [](int height) { return make_shared<BlockingConsensus_checkpoint_multiple_blocking>(height); }}, // TODO (o1q): set checkpoint height for multiple locks
{ 0, 0, [](int height) { return make_shared<BlockingConsensus>(height); }},
{ 1862000, 1114500, [](int height) { return make_shared<BlockingConsensus_checkpoint_multiple_blocking>(height); }}, // TODO (o1q): set checkpoint height for multiple locks
};
public:
shared_ptr<BlockingConsensus> Instance(int height)
Expand Down
37 changes: 34 additions & 3 deletions src/pocketdb/consensus/social/CommentDelete.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ namespace PocketConsensus
if (!actuallTxOk || !originalTxOk)
return {false, SocialConsensusResult_NotFound};

auto originalPtx = static_pointer_cast<CommentDelete>(originalTx);

auto originalPtx = static_pointer_cast<Comment>(originalTx);
// Parent comment
{
auto currParentTxHash = IsEmpty(ptx->GetParentTxHash()) ? "" : *ptx->GetParentTxHash();
Expand Down Expand Up @@ -69,6 +69,17 @@ namespace PocketConsensus
return {false, SocialConsensusResult_InvalidAnswerComment};
}

// Check exists content transaction
auto[contentOk, contentTx] = PocketDb::ConsensusRepoInst.GetLastContent(
*ptx->GetPostTxHash(), { CONTENT_POST, CONTENT_VIDEO, CONTENT_ARTICLE, CONTENT_DELETE });

if (!contentOk)
return {false, SocialConsensusResult_NotFound};

// Check author of comment
if (auto[ok, result] = CheckAuthor(ptx, originalPtx, contentTx); !ok)
return {false, result};

return Success;
}
ConsensusValidateResult Check(const CTransactionRef& tx, const CommentDeleteRef& ptx) override
Expand Down Expand Up @@ -113,6 +124,25 @@ namespace PocketConsensus
{
return {*ptx->GetString1()};
}
virtual ConsensusValidateResult CheckAuthor(const CommentDeleteRef& ptx, const CommentRef& originalPtx, const PTransactionRef& contentTx)
{
return Success;
}
};

// Protect deleting comment only for authors and authors of content
class CommentDeleteConsensus_checkpoint_check_author : public CommentDeleteConsensus
{
public:
CommentDeleteConsensus_checkpoint_check_author(int height) : CommentDeleteConsensus(height) {}
protected:
ConsensusValidateResult CheckAuthor(const CommentDeleteRef& ptx, const CommentRef& originalPtx, const PTransactionRef& contentTx) override
{
if (*ptx->GetAddress() != *originalPtx->GetAddress() && *ptx->GetAddress() != *contentTx->GetString1())
return {false, SocialConsensusResult_ContentEditUnauthorized};

return Success;
}
};

/*******************************************************************************************************************
Expand All @@ -122,7 +152,8 @@ namespace PocketConsensus
{
private:
const vector<ConsensusCheckpoint < CommentDeleteConsensus>> m_rules = {
{ 0, 0, [](int height) { return make_shared<CommentDeleteConsensus>(height); }},
{ 0, 0, [](int height) { return make_shared<CommentDeleteConsensus>(height); }},
{ 1862000, 1155000, [](int height) { return make_shared<CommentDeleteConsensus_checkpoint_check_author>(height); }},
};
public:
shared_ptr<CommentDeleteConsensus> Instance(int height)
Expand Down
38 changes: 30 additions & 8 deletions src/pocketdb/consensus/social/CommentEdit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ namespace PocketConsensus
if (!actuallTxOk || !originalTxOk)
return {false, SocialConsensusResult_NotFound};

auto originalPtx = static_pointer_cast<CommentEdit>(originalTx);
auto originalPtx = static_pointer_cast<Comment>(originalTx);

// Check author of comment
if (auto[ok, result] = CheckAuthor(ptx, originalPtx); !ok)
return {false, result};

// Parent comment
{
Expand Down Expand Up @@ -157,7 +161,7 @@ namespace PocketConsensus
return {*ptx->GetAddress()};
}

virtual bool AllowEditWindow(const CommentEditRef& ptx, const CommentEditRef& blockPtx)
virtual bool AllowEditWindow(const CommentEditRef& ptx, const CommentRef& blockPtx)
{
return (*ptx->GetTime() - *blockPtx->GetTime()) <= GetConsensusLimit(ConsensusLimit_edit_comment_depth);
}
Expand All @@ -178,33 +182,51 @@ namespace PocketConsensus

return Success;
}
virtual ConsensusValidateResult CheckAuthor(const CommentEditRef& ptx, const CommentRef& originalPtx)
{
return Success;
}
};

/*******************************************************************************************************************
* Start checkpoint at 1180000 block
*******************************************************************************************************************/

class CommentEditConsensus_checkpoint_1180000 : public CommentEditConsensus
{
public:
CommentEditConsensus_checkpoint_1180000(int height) : CommentEditConsensus(height) {}
protected:
bool AllowEditWindow(const CommentEditRef& ptx, const CommentEditRef& originalTx) override
bool AllowEditWindow(const CommentEditRef& ptx, const CommentRef& originalTx) override
{
auto[ok, originalTxHeight] = ConsensusRepoInst.GetTransactionHeight(*originalTx->GetHash());
if (!ok) return false;
return (Height - originalTxHeight) <= GetConsensusLimit(ConsensusLimit_edit_comment_depth);
}
};


class CommentEditConsensus_checkpoint_check_author : public CommentEditConsensus_checkpoint_1180000
{
public:
CommentEditConsensus_checkpoint_check_author(int height) : CommentEditConsensus_checkpoint_1180000(height) {}
protected:
ConsensusValidateResult CheckAuthor(const CommentEditRef& ptx, const CommentRef& originalPtx) override
{
if (*ptx->GetAddress() != *originalPtx->GetAddress())
return {false, SocialConsensusResult_ContentEditUnauthorized};

return Success;
}
};

/*******************************************************************************************************************
* Factory for select actual rules version
*******************************************************************************************************************/
class CommentEditConsensusFactory
{
private:
const vector<ConsensusCheckpoint < CommentEditConsensus>> m_rules = {
{ 0, -1, [](int height) { return make_shared<CommentEditConsensus>(height); }},
{ 1180000, 0, [](int height) { return make_shared<CommentEditConsensus_checkpoint_1180000>(height); }},
{ 0, -1, [](int height) { return make_shared<CommentEditConsensus>(height); }},
{ 1180000, 0, [](int height) { return make_shared<CommentEditConsensus_checkpoint_1180000>(height); }},
{ 1862000, 1155000, [](int height) { return make_shared<CommentEditConsensus_checkpoint_check_author>(height); }},
};
public:
shared_ptr<CommentEditConsensus> Instance(int height)
Expand Down
23 changes: 12 additions & 11 deletions src/pocketdb/helpers/PocketnetHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@ namespace PocketHelpers
return find(PocketnetDevelopers[net].begin(), PocketnetDevelopers[net].end(), address) != PocketnetDevelopers[net].end();
}

static inline std::vector<std::string> GetPocketnetteamAddresses()
{
switch (Params().NetworkID()) {
case NetworkMain:
return {"PEj7QNjKdDPqE9kMDRboKoCtp8V6vZeZPd"};
case NetworkTest:
return {"TAqR1ncH95eq9XKSDRR18DtpXqktxh74UU"};
default:
return {};
}
}
// TODO: Notification from POCKETNET_TEAM
// static inline std::vector<std::string> GetPocketnetteamAddresses()
// {
// switch (Params().NetworkID()) {
// case NetworkMain:
// return {"PEj7QNjKdDPqE9kMDRboKoCtp8V6vZeZPd"};
// case NetworkTest:
// return {"TAqR1ncH95eq9XKSDRR18DtpXqktxh74UU"};
// default:
// return {};
// }
// }
}

#endif // POCKETHELPERS_POCKETNET_HELPER_H
2 changes: 0 additions & 2 deletions src/pocketdb/helpers/ShortFormHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

static const std::map<PocketDb::ShortTxType, std::string>& GetTypesMap() {
static const std::map<PocketDb::ShortTxType, std::string> typesMap = {
{ PocketDb::ShortTxType::PocketnetTeam, "pocketnetteam" },
{ PocketDb::ShortTxType::Money, "money" },
{ PocketDb::ShortTxType::Referal, "referal" },
{ PocketDb::ShortTxType::Answer, "answer" },
Expand Down Expand Up @@ -39,7 +38,6 @@ std::string PocketHelpers::ShortTxTypeConvertor::toString(PocketDb::ShortTxType
bool PocketHelpers::ShortTxFilterValidator::Notifications::IsFilterAllowed(PocketDb::ShortTxType type)
{
static const std::set<PocketDb::ShortTxType> allowed = {
PocketDb::ShortTxType::PocketnetTeam,
PocketDb::ShortTxType::Money,
PocketDb::ShortTxType::Answer,
PocketDb::ShortTxType::PrivateContent,
Expand Down
1 change: 0 additions & 1 deletion src/pocketdb/models/shortform/ShortTxType.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace PocketDb
enum class ShortTxType
{
NotSet,
PocketnetTeam,
Money,
Referal,
Answer,
Expand Down
Loading

0 comments on commit b7b4991

Please sign in to comment.