Skip to content

Commit

Permalink
Merge branch '0.21' into feature/events
Browse files Browse the repository at this point in the history
  • Loading branch information
lostystyg committed Jul 1, 2022
2 parents 16a3455 + c0f6636 commit ef32565
Show file tree
Hide file tree
Showing 24 changed files with 366 additions and 79 deletions.
18 changes: 18 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
template: |
## What’s Changed
$CHANGES
**Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...v$RESOLVED_VERSION
## SHA256 checksums
```
```
## Attention!
We distribute our software only through https://github.com/pocketnetteam
Any other resources offering to download executables, "installers" or source code are not related to the Pocketnet Team community
## Help
https://github.com/pocketnetteam/pocketnet.core/issues
11 changes: 2 additions & 9 deletions .github/workflows/makecheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: make check

on:
workflow_dispatch:
pull_request:
branches: [ $default-branch, "0.20", "0.21" ]
push:
tags: v*.*.*

jobs:
build:
Expand Down Expand Up @@ -35,10 +35,3 @@ jobs:
run: |
cd src/bench
./bench_pocketcoin
cd ../..
- name: make deploy
run: make deploy
- uses: actions/upload-artifact@v2
with:
name: package
path: pocketnet*.deb
22 changes: 22 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Release Draft

on:
push:
tags: v*.*.*

permissions:
contents: read

jobs:

CreateReleaseDraft:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@v5
with:
prerelease: true

env:
GITHUB_TOKEN: ${{ secrets.release_token }}
4 changes: 2 additions & 2 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ class CMainParams : public CChainParams
consensus.nHeight_version_1_0_0 = 108300;

// The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x0000000000000000000000000000000000000000000000341f03e8566c0f82ca"); // 1592575
consensus.nMinimumChainWork = uint256S("0x00000000000000000000000000000000000000000000003e0ce94c0f07fc1cea"); // 1761588

// By default assume that the signatures in ancestors of this block are valid.
consensus.defaultAssumeValid = uint256S("0x945933ac93cbd50f5e9978e895cf8cfdbf4c242ecb6c81a13ef6d8baa8067139"); // 1592575
consensus.defaultAssumeValid = uint256S("0x7d49542fc498f0bfcb5201df6e244377d3e8d9f1bb7c0646ec8f7d9a2c4705e0"); // 1761588

/**
* The message start string is designed to be unlikely to occur in normal data.
Expand Down
6 changes: 6 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ void Shutdown(NodeContext& node)

StopTorControl();

if (notifyClientsThread)
notifyClientsThread->Stop();

// After everything has been shut down, but before things get flushed, stop the
// CScheduler/checkqueue, threadGroup and load block thread.
if (node.scheduler) node.scheduler->stop();
Expand Down Expand Up @@ -2114,6 +2117,9 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
return false;
}

if (!gArgs.GetBoolArg("-withoutweb", false) && gArgs.GetArg("-reindex", 0) == 0)
PocketServices::WebPostProcessorInst.Enqueue(ChainActive().Height());

fs::path est_path = GetDataDir() / FEE_ESTIMATES_FILENAME;
CAutoFile est_filein(fsbridge::fopen(est_path, "rb"), SER_DISK, CLIENT_VERSION);
// Allowed to fail as this file IS missing on first startup.
Expand Down
2 changes: 2 additions & 0 deletions src/pocketdb/SQLiteDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ namespace PocketDb

LogPrint(BCLog::MIGRATION, "Migration Sqlite database `%s` structure..\n---\n%s\n---\n", m_file_path, token);

LogPrint(BCLog::MIGRATION, "Migration Sqlite database `%s` structure..\n---\n%s\n---\n", m_file_path, token);

BeginTransaction();

if (sqlite3_exec(m_db, token.c_str(), nullptr, nullptr, &errMsg) != SQLITE_OK)
Expand Down
8 changes: 4 additions & 4 deletions src/pocketdb/consensus/Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,27 +412,27 @@ namespace PocketConsensus
} },

{ ConsensusLimit_full_post, {
{ NetworkMain, { {0, 30}, {1757000, 10} } },
{ NetworkMain, { {0, 30}, {1757000, 10}, {1791787, 30} } },
{ NetworkTest, { {0, 30} } }
} },
{ ConsensusLimit_full_video, {
{ NetworkMain, { {0, 30}, {1757000, 10} } },
{ NetworkMain, { {0, 30}, {1757000, 10}, {1791787, 30} } },
{ NetworkTest, { {0, 30} } }
} },
{ ConsensusLimit_full_article, {
{ NetworkMain, { {0, 3} } },
{ NetworkTest, { {0, 30} } }
} },
{ ConsensusLimit_full_score, {
{ NetworkMain, { {0, 90}, {175600, 200}, {1757000, 60} } },
{ NetworkMain, { {0, 90}, {175600, 200}, {1757000, 60}, {1791787, 100} } },
{ NetworkTest, { {0, 200} } }
} },
{ ConsensusLimit_full_complain, {
{ NetworkMain, { {0, 12} } },
{ NetworkTest, { {0, 12} } }
} },
{ ConsensusLimit_full_comment, {
{ NetworkMain, { {0, 300}, {1757000, 100} } },
{ NetworkMain, { {0, 300}, {1757000, 100}, {1791787, 200} } },
{ NetworkTest, { {0, 300} } }
} },
{ ConsensusLimit_full_comment_score, {
Expand Down
14 changes: 14 additions & 0 deletions src/pocketdb/consensus/Reputation.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,20 @@ namespace PocketConsensus
ratingValues[scoreData->LikerType(true)][scoreData->ContentAddressId] += 1;
}
}

virtual BadgeSharkConditions GetBadgeSharkConditions()
{
BadgeSharkConditions cond = {
Height,
GetConsensusLimit(threshold_shark_likers_all),
GetConsensusLimit(threshold_shark_likers_content),
GetConsensusLimit(threshold_shark_likers_comment),
GetConsensusLimit(threshold_shark_likers_comment_answer),
GetConsensusLimit(threshold_shark_reg_depth)
};

return cond;
}
};

// Consensus checkpoint at 151600 block
Expand Down
18 changes: 18 additions & 0 deletions src/pocketdb/migrations/web.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ namespace PocketDb
);
)sql");

_tables.emplace_back(R"sql(
create table if not exists Badges
(
AccountId int not null,
Badge int not null,
primary key (AccountId, Badge)
);
)sql");

// _tables.emplace_back(R"sql(
// create table if not exists Authors
// (
// AccountId int not null,
// SharkCommented int not null,
// primary key (AccountId)
// );
// )sql");

_indexes = R"sql(
create unique index if not exists Tags_Lang_Value on Tags (Lang, Value);
create index if not exists Tags_Lang_Id on Tags (Lang, Id);
Expand Down
10 changes: 10 additions & 0 deletions src/pocketdb/repositories/ConsensusRepository.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ namespace PocketDb
}
};

struct BadgeSharkConditions
{
int Height;
int64_t LikersAll;
int64_t LikersContent;
int64_t LikersComment;
int64_t LikersAnswer;
int64_t RegistrationDepth;
};

struct BadgeSet
{
bool Shark = false;
Expand Down
10 changes: 8 additions & 2 deletions src/pocketdb/repositories/web/NotifierRepository.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,10 @@ namespace PocketDb
UniValue result(UniValue::VOBJ);

string sql = R"sql(
select count(1)
select count(1) as cntTotal,
ifnull((case when post.Type = 200 then 1 else 0 end),0) as cntPost,
ifnull((case when post.Type = 201 then 1 else 0 end),0) as cntVideo,
ifnull((case when post.Type = 202 then 1 else 0 end),0) as cntArticle
from Transactions sub
join Transactions post
on post.String1 = sub.String2 and post.Type in (200, 201, 202, 203) and post.Last = 1
Expand All @@ -480,7 +483,10 @@ namespace PocketDb

if (sqlite3_step(*stmt) == SQLITE_ROW)
{
if (auto[ok, value] = TryGetColumnInt(*stmt, 0); ok) result.pushKV("count", value);
if (auto[ok, value] = TryGetColumnInt(*stmt, 0); ok) result.pushKV("cntTotal", value);
if (auto[ok, value] = TryGetColumnInt(*stmt, 1); ok) result.pushKV("cntPost", value);
if (auto[ok, value] = TryGetColumnInt(*stmt, 2); ok) result.pushKV("cntVideo", value);
if (auto[ok, value] = TryGetColumnInt(*stmt, 3); ok) result.pushKV("cntArticle", value);
}

FinalizeSqlStatement(*stmt);
Expand Down
86 changes: 86 additions & 0 deletions src/pocketdb/repositories/web/WebRepository.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,90 @@ namespace PocketDb
);
});
}

void WebRepository::CalculateSharkAccounts(BadgeSharkConditions& cond)
{
TryTransactionStep(__func__, [&]()
{
// Clear badges table before insert new values
auto stmtClear = SetupSqlStatement(R"sql(
delete from web.Badges
)sql");
TryStepStatement(stmtClear);

// Clear old Last record
auto stmtInsert = SetupSqlStatement(R"sql(
insert into web.Badges (AccountId, Badge)
select u.Id, 1
from Transactions u indexed by Transactions_Type_Last_Height_Id
where u.Type in (100)
and u.Last = 1
and u.Height is not null
and ifnull((select sum(r.Value) from Ratings r where r.Type in (111,112,113) and r.Last = 1 and r.Id = u.Id),0) >= ?
and ifnull((select r.Value from Ratings r where r.Type = 111 and r.Last = 1 and r.Id = u.Id),0) >= ?
and ifnull((select r.Value from Ratings r where r.Type = 112 and r.Last = 1 and r.Id = u.Id),0) >= ?
and ifnull((select r.Value from Ratings r where r.Type = 113 and r.Last = 1 and r.Id = u.Id),0) >= ?
and ? - (select min(reg1.Height) from Transactions reg1 indexed by Transactions_Id where reg1.Id = u.Id) > ?
)sql");
int i = 1;
TryBindStatementInt(stmtInsert, i++, cond.LikersAll);
TryBindStatementInt64(stmtInsert, i++, cond.LikersContent);
TryBindStatementInt64(stmtInsert, i++, cond.LikersComment);
TryBindStatementInt64(stmtInsert, i++, cond.LikersAnswer);
TryBindStatementInt64(stmtInsert, i++, cond.Height);
TryBindStatementInt64(stmtInsert, i++, cond.RegistrationDepth);
TryStepStatement(stmtInsert);
});
}

void WebRepository::CalculateValidAuthors(int blockHeight)
{
TryTransactionStep(__func__, [&]()
{
// Clear badges table before insert new values
auto stmtClear = SetupSqlStatement(R"sql(
delete from web.Authors
)sql");
TryStepStatement(stmtClear);

// Clear old Last record
auto stmtInsert = SetupSqlStatement(R"sql(
insert into web.Authors (AccountId, SharkCommented)
select
pu.Id
,count( distinct u.Id )
from Transactions p indexed by Transactions_Type_Last_String1_Height_Id
cross join Transactions c indexed by Transactions_Type_Last_String3_Height
on c.Type in (204, 205)
and c.Last = 1
and c.String3 = p.String2
and c.Height is not null
cross join Transactions u indexed by Transactions_Type_Last_String1_Height_Id
on u.Type in (100)
and u.Last = 1
and u.String1 = c.String1
and u.Height is not null
cross join web.Badges b on b.AccountId = u.Id and b.Badge = 1
cross join Transactions pu indexed by Transactions_Type_Last_String1_Height_Id
on pu.Type in (100)
and pu.Last = 1
and pu.String1 = p.String1
and pu.Height is not null
where p.Type in (200,201,202)
and p.Last = 1
and p.Height is not null
group by pu.Id
)sql");
TryStepStatement(stmtInsert);
});
}
}
6 changes: 6 additions & 0 deletions src/pocketdb/repositories/web/WebRepository.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "core_io.h"

#include "pocketdb/repositories/BaseRepository.h"
#include "pocketdb/repositories/ConsensusRepository.h"
#include "pocketdb/models/web/WebTag.h"
#include "pocketdb/models/web/WebContent.h"

Expand All @@ -34,6 +35,11 @@ namespace PocketDb

vector<WebContent> GetContent(const string& blockHash);
void UpsertContent(const vector<WebContent>& contentList);

void CalculateSharkAccounts(BadgeSharkConditions& cond);
void CalculateValidAuthors(int blockHeight);

// TODO (brangr): расчитать авторов согласно комментариев от акул на их посты
};

typedef shared_ptr<WebRepository> WebRepositoryRef;
Expand Down
Loading

0 comments on commit ef32565

Please sign in to comment.