Skip to content

Commit

Permalink
Merge pull request #563 from pocketnetteam/consensus/bip100
Browse files Browse the repository at this point in the history
consensus: realize BIP 100
  • Loading branch information
andyoknen authored Mar 10, 2023
2 parents f385d2a + 3221928 commit 06c92c6
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 47 deletions.
40 changes: 2 additions & 38 deletions doc/bips.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,3 @@
BIPs that are implemented by Pocketcoin Core (up-to-date up to **v0.17.0**):
BIPs that are implemented by Pocketcoin Core:

* [`BIP 9`](https://github.com/pocketcoin/bips/blob/master/bip-0009.mediawiki): The changes allowing multiple soft-forks to be deployed in parallel have been implemented since **v0.12.1** ([PR #7575](https://github.com/pocketcoin/pocketcoin/pull/7575))
* [`BIP 11`](https://github.com/pocketcoin/bips/blob/master/bip-0011.mediawiki): Multisig outputs are standard since **v0.6.0** ([PR #669](https://github.com/pocketcoin/pocketcoin/pull/669)).
* [`BIP 13`](https://github.com/pocketcoin/bips/blob/master/bip-0013.mediawiki): The address format for P2SH addresses has been implemented since **v0.6.0** ([PR #669](https://github.com/pocketcoin/pocketcoin/pull/669)).
* [`BIP 14`](https://github.com/pocketcoin/bips/blob/master/bip-0014.mediawiki): The subversion string is being used as User Agent since **v0.6.0** ([PR #669](https://github.com/pocketcoin/pocketcoin/pull/669)).
* [`BIP 16`](https://github.com/pocketcoin/bips/blob/master/bip-0016.mediawiki): The pay-to-script-hash evaluation rules have been implemented since **v0.6.0**, and took effect on *April 1st 2012* ([PR #748](https://github.com/pocketcoin/pocketcoin/pull/748)).
* [`BIP 21`](https://github.com/pocketcoin/bips/blob/master/bip-0021.mediawiki): The URI format for Pocketcoin payments has been implemented since **v0.6.0** ([PR #176](https://github.com/pocketcoin/pocketcoin/pull/176)).
* [`BIP 22`](https://github.com/pocketcoin/bips/blob/master/bip-0022.mediawiki): The 'getblocktemplate' (GBT) RPC protocol for mining has been implemented since **v0.7.0** ([PR #936](https://github.com/pocketcoin/pocketcoin/pull/936)).
* [`BIP 23`](https://github.com/pocketcoin/bips/blob/master/bip-0023.mediawiki): Some extensions to GBT have been implemented since **v0.10.0rc1**, including longpolling and block proposals ([PR #1816](https://github.com/pocketcoin/pocketcoin/pull/1816)).
* [`BIP 30`](https://github.com/pocketcoin/bips/blob/master/bip-0030.mediawiki): The evaluation rules to forbid creating new transactions with the same txid as previous not-fully-spent transactions were implemented since **v0.6.0**, and the rule took effect on *March 15th 2012* ([PR #915](https://github.com/pocketcoin/pocketcoin/pull/915)).
* [`BIP 31`](https://github.com/pocketcoin/bips/blob/master/bip-0031.mediawiki): The 'pong' protocol message (and the protocol version bump to 60001) has been implemented since **v0.6.1** ([PR #1081](https://github.com/pocketcoin/pocketcoin/pull/1081)).
* [`BIP 32`](https://github.com/pocketcoin/bips/blob/master/bip-0032.mediawiki): Hierarchical Deterministic Wallets has been implemented since **v0.13.0** ([PR #8035](https://github.com/pocketcoin/pocketcoin/pull/8035)).
* [`BIP 34`](https://github.com/pocketcoin/bips/blob/master/bip-0034.mediawiki): The rule that requires blocks to contain their height (number) in the coinbase input, and the introduction of version 2 blocks has been implemented since **v0.7.0**. The rule took effect for version 2 blocks as of *block 224413* (March 5th 2013), and version 1 blocks are no longer allowed since *block 227931* (March 25th 2013) ([PR #1526](https://github.com/pocketcoin/pocketcoin/pull/1526)).
* [`BIP 35`](https://github.com/pocketcoin/bips/blob/master/bip-0035.mediawiki): The 'mempool' protocol message (and the protocol version bump to 60002) has been implemented since **v0.7.0** ([PR #1641](https://github.com/pocketcoin/pocketcoin/pull/1641)).
* [`BIP 37`](https://github.com/pocketcoin/bips/blob/master/bip-0037.mediawiki): The bloom filtering for transaction relaying, partial Merkle trees for blocks, and the protocol version bump to 70001 (enabling low-bandwidth SPV clients) has been implemented since **v0.8.0** ([PR #1795](https://github.com/pocketcoin/pocketcoin/pull/1795)).
* [`BIP 42`](https://github.com/pocketcoin/bips/blob/master/bip-0042.mediawiki): The bug that would have caused the subsidy schedule to resume after block 13440000 was fixed in **v0.9.2** ([PR #3842](https://github.com/pocketcoin/pocketcoin/pull/3842)).
* [`BIP 61`](https://github.com/pocketcoin/bips/blob/master/bip-0061.mediawiki): The 'reject' protocol message (and the protocol version bump to 70002) was added in **v0.9.0** ([PR #3185](https://github.com/pocketcoin/pocketcoin/pull/3185)). Starting *v0.17.0*, whether to send reject messages can be configured with the `-enablebip61` option.
* [`BIP 65`](https://github.com/pocketcoin/bips/blob/master/bip-0065.mediawiki): The CHECKLOCKTIMEVERIFY softfork was merged in **v0.12.0** ([PR #6351](https://github.com/pocketcoin/pocketcoin/pull/6351)), and backported to **v0.11.2** and **v0.10.4**. Mempool-only CLTV was added in [PR #6124](https://github.com/pocketcoin/pocketcoin/pull/6124).
* [`BIP 66`](https://github.com/pocketcoin/bips/blob/master/bip-0066.mediawiki): The strict DER rules and associated version 3 blocks have been implemented since **v0.10.0** ([PR #5713](https://github.com/pocketcoin/pocketcoin/pull/5713)).
* [`BIP 68`](https://github.com/pocketcoin/bips/blob/master/bip-0068.mediawiki): Sequence locks have been implemented as of **v0.12.1** ([PR #7184](https://github.com/pocketcoin/pocketcoin/pull/7184)), and have been activated since *block 419328*.
* [`BIP 70`](https://github.com/pocketcoin/bips/blob/master/bip-0070.mediawiki) [`71`](https://github.com/pocketcoin/bips/blob/master/bip-0071.mediawiki) [`72`](https://github.com/pocketcoin/bips/blob/master/bip-0072.mediawiki): Payment Protocol support has been available in Pocketcoin Core GUI since **v0.9.0** ([PR #5216](https://github.com/pocketcoin/pocketcoin/pull/5216)).
* [`BIP 90`](https://github.com/pocketcoin/bips/blob/master/bip-0090.mediawiki): Trigger mechanism for activation of BIPs 34, 65, and 66 has been simplified to block height checks since **v0.14.0** ([PR #8391](https://github.com/pocketcoin/pocketcoin/pull/8391)).
* [`BIP 111`](https://github.com/pocketcoin/bips/blob/master/bip-0111.mediawiki): `NODE_BLOOM` service bit added, and enforced for all peer versions as of **v0.13.0** ([PR #6579](https://github.com/pocketcoin/pocketcoin/pull/6579) and [PR #6641](https://github.com/pocketcoin/pocketcoin/pull/6641)).
* [`BIP 112`](https://github.com/pocketcoin/bips/blob/master/bip-0112.mediawiki): The CHECKSEQUENCEVERIFY opcode has been implemented since **v0.12.1** ([PR #7524](https://github.com/pocketcoin/pocketcoin/pull/7524)) and has been activated since *block 419328*.
* [`BIP 113`](https://github.com/pocketcoin/bips/blob/master/bip-0113.mediawiki): Median time past lock-time calculations have been implemented since **v0.12.1** ([PR #6566](https://github.com/pocketcoin/pocketcoin/pull/6566)) and have been activated since *block 419328*.
* [`BIP 125`](https://github.com/pocketcoin/bips/blob/master/bip-0125.mediawiki): Opt-in full replace-by-fee signaling honoured in mempool and mining as of **v0.12.0** ([PR 6871](https://github.com/pocketcoin/pocketcoin/pull/6871)).
* [`BIP 130`](https://github.com/pocketcoin/bips/blob/master/bip-0130.mediawiki): direct headers announcement is negotiated with peer versions `>=70012` as of **v0.12.0** ([PR 6494](https://github.com/pocketcoin/pocketcoin/pull/6494)).
* [`BIP 133`](https://github.com/pocketcoin/bips/blob/master/bip-0133.mediawiki): feefilter messages are respected and sent for peer versions `>=70013` as of **v0.13.0** ([PR 7542](https://github.com/pocketcoin/pocketcoin/pull/7542)).
* [`BIP 141`](https://github.com/pocketcoin/bips/blob/master/bip-0141.mediawiki): Segregated Witness (Consensus Layer) as of **v0.13.0** ([PR 8149](https://github.com/pocketcoin/pocketcoin/pull/8149)), and defined for mainnet as of **v0.13.1** ([PR 8937](https://github.com/pocketcoin/pocketcoin/pull/8937)).
* [`BIP 143`](https://github.com/pocketcoin/bips/blob/master/bip-0143.mediawiki): Transaction Signature Verification for Version 0 Witness Program as of **v0.13.0** ([PR 8149](https://github.com/pocketcoin/pocketcoin/pull/8149)) and defined for mainnet as of **v0.13.1** ([PR 8937](https://github.com/pocketcoin/pocketcoin/pull/8937)).
* [`BIP 144`](https://github.com/pocketcoin/bips/blob/master/bip-0144.mediawiki): Segregated Witness as of **0.13.0** ([PR 8149](https://github.com/pocketcoin/pocketcoin/pull/8149)).
* [`BIP 145`](https://github.com/pocketcoin/bips/blob/master/bip-0145.mediawiki): getblocktemplate updates for Segregated Witness as of **v0.13.0** ([PR 8149](https://github.com/pocketcoin/pocketcoin/pull/8149)).
* [`BIP 147`](https://github.com/pocketcoin/bips/blob/master/bip-0147.mediawiki): NULLDUMMY softfork as of **v0.13.1** ([PR 8636](https://github.com/pocketcoin/pocketcoin/pull/8636) and [PR 8937](https://github.com/pocketcoin/pocketcoin/pull/8937)).
* [`BIP 152`](https://github.com/pocketcoin/bips/blob/master/bip-0152.mediawiki): Compact block transfer and related optimizations are used as of **v0.13.0** ([PR 8068](https://github.com/pocketcoin/pocketcoin/pull/8068)).
* [`BIP 159`](https://github.com/pocketcoin/bips/blob/master/bip-0159.mediawiki): NODE_NETWORK_LIMITED service bit [signaling only] is supported as of **v0.16.0** ([PR 11740](https://github.com/pocketcoin/pocketcoin/pull/11740)).
* [`BIP 173`](https://github.com/pocketcoin/bips/blob/master/bip-0173.mediawiki): Bech32 addresses for native Segregated Witness outputs are supported as of **v0.16.0** ([PR 11167](https://github.com/pocketcoin/pocketcoin/pull/11167)).
* [`BIP 174`](https://github.com/pocketcoin/bips/blob/master/bip-0174.mediawiki): RPCs to operate on Partially Signed Pocketcoin Transactions (PSBT) are present as of **v0.17.0** ([PR 13557](https://github.com/pocketcoin/pocketcoin/pull/13557)).
* [`BIP 176`](https://github.com/pocketcoin/bips/blob/master/bip-0176.mediawiki): Bits Denomination [QT only] is supported as of **v0.16.0** ([PR 12035](https://github.com/pocketcoin/pocketcoin/pull/12035)).
* [`BIP 100`](): Changes in the policy of emission payments. ([PR #563](https://github.com/pocketnetteam/pocketnet.core/wiki/BIP-100:-Changes-in-emission-payments))
54 changes: 54 additions & 0 deletions src/pocketdb/consensus/Lottery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,60 @@ namespace PocketConsensus
return 0;
}

// ----------------------------------------
// Lottery checkpoint at 2162400 block
// Disable lottery payments for likes to comments.
// Also disable referral program
CAmount LotteryConsensus_bip_100::RatingReward(CAmount nCredit, opcodetype code)
{
if (code == OP_WINNER_POST) return nCredit * 0.025;
return 0;
}

LotteryWinners& LotteryConsensus_bip_100::Winners(const CBlock& block, CDataStream& hashProofOfStakeSource)
{
auto reputationConsensus = PocketConsensus::ReputationConsensusFactoryInst.Instance(Height);

map<string, int> postCandidates;

for (const auto& tx : block.vtx)
{
// Get destination address and score value
// In lottery allowed only likes to posts and comments
// Also in lottery allowed only positive scores
auto[parseScoreOk, scoreTxData] = TransactionHelper::ParseScore(tx);
if (!parseScoreOk)
continue;

// BIP100: Only scores to content allowed
if (scoreTxData->ScoreType == ACTION_SCORE_COMMENT)
continue;
if (scoreTxData->ScoreType == ACTION_SCORE_CONTENT
&& scoreTxData->ScoreValue != 4 && scoreTxData->ScoreValue != 5)
continue;

auto scoreData = PocketDb::ConsensusRepoInst.GetScoreData(tx->GetHash().GetHex());
if (!scoreData)
{
LogPrintf("%s: Failed get score data for tx: %s\n", __func__, tx->GetHash().GetHex());
continue;
}

if (!reputationConsensus->AllowModifyReputation(
scoreData,
true
))
continue;

postCandidates[scoreData->ContentAddressHash] += (scoreData->ScoreValue - 3);
}

// Sort founded users
SortWinners(postCandidates, hashProofOfStakeSource, _winners.PostWinners);

return _winners;
}

// ----------------------------------------
// Lottery checkpoint at _ block
void LotteryConsensus_checkpoint_::ExtendReferrer(const ScoreDataDtoRef& scoreData, map<string, string>& refs)
Expand Down
27 changes: 19 additions & 8 deletions src/pocketdb/consensus/Lottery.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,21 @@ namespace PocketConsensus
};

// ---------------------------------------
// Lottery checkpoint at _ block
class LotteryConsensus_checkpoint_ : public LotteryConsensus_checkpoint_1180000
class LotteryConsensus_bip_100 : public LotteryConsensus_checkpoint_1180000
{
protected:
int64_t MaxWinnersCount() override { return 5; };
public:
explicit LotteryConsensus_bip_100(int height) : LotteryConsensus_checkpoint_1180000(height) {}
CAmount RatingReward(CAmount nCredit, opcodetype code) override;
LotteryWinners& Winners(const CBlock& block, CDataStream& hashProofOfStakeSource) override;
};

// ---------------------------------------
class LotteryConsensus_checkpoint_ : public LotteryConsensus_bip_100
{
public:
explicit LotteryConsensus_checkpoint_(int height) : LotteryConsensus_checkpoint_1180000(height) {}
explicit LotteryConsensus_checkpoint_(int height) : LotteryConsensus_bip_100(height) {}
protected:
void ExtendReferrer(const ScoreDataDtoRef& scoreData, map<string, string>& refs) override;
void ExtendReferrers() override;
Expand All @@ -103,11 +113,12 @@ namespace PocketConsensus
{
private:
const vector<ConsensusCheckpoint < LotteryConsensus>> m_rules = {
{0, -1, -1, [](int height) { return make_shared<LotteryConsensus>(height); }},
{514185, -1, -1, [](int height) { return make_shared<LotteryConsensus_checkpoint_514185>(height); }},
{1035000, -1, -1, [](int height) { return make_shared<LotteryConsensus_checkpoint_1035000>(height); }},
{1124000, -1, -1, [](int height) { return make_shared<LotteryConsensus_checkpoint_1124000>(height); }},
{1180000, 0, 0, [](int height) { return make_shared<LotteryConsensus_checkpoint_1180000>(height); }},
{0, -1, -1, [](int height) { return make_shared<LotteryConsensus>(height); }},
{514185, -1, -1, [](int height) { return make_shared<LotteryConsensus_checkpoint_514185>(height); }},
{1035000, -1, -1, [](int height) { return make_shared<LotteryConsensus_checkpoint_1035000>(height); }},
{1124000, -1, -1, [](int height) { return make_shared<LotteryConsensus_checkpoint_1124000>(height); }},
{1180000, 0, -1, [](int height) { return make_shared<LotteryConsensus_checkpoint_1180000>(height); }},
{2162400, 1650652, 0, [](int height) { return make_shared<LotteryConsensus_bip_100>(height); }},
};
public:
shared_ptr<LotteryConsensus> Instance(int height)
Expand Down
5 changes: 4 additions & 1 deletion src/pos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,11 @@ bool GenerateOuts(CAmount nCredit,
return true;

CAmount ratingReward = lotteryInst->RatingReward(nCredit, type);
totalAmount += ratingReward;
if (ratingReward <= 0)
return true;

totalAmount += ratingReward;

int current = 0;
const int rewardsCount = (int)winners.size();
CAmount rewardsPool = ratingReward;
Expand Down
Loading

0 comments on commit 06c92c6

Please sign in to comment.