Skip to content

Implement a way to sync only needed winners#1028

Merged
UdjinM6 merged 3 commits intodashpay:v0.12.1.xfrom
UdjinM6:msgWinnerBlock
Sep 18, 2016
Merged

Implement a way to sync only needed winners#1028
UdjinM6 merged 3 commits intodashpay:v0.12.1.xfrom
UdjinM6:msgWinnerBlock

Conversation

@UdjinM6
Copy link
Copy Markdown

@UdjinM6 UdjinM6 commented Sep 16, 2016

The idea is to ask node we are trying to sync from only for future payment blocks and for blocks where payment info is missing/incomplete for us instead of asking for the whole set of winners every time we sync. This (hopefully) should significantly lower cpu/net load if node was offline for not too long. For nodes which were offline for a period of time comparable to nMinBlocksToStore (~1 week on mainnet) there should be (almost) no difference.

Copy link
Copy Markdown

@tgflynn tgflynn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really get the point of RequestLowDataPaymentBlocks. It doesn't look like it guarantees that all votes are counted so why only count some of them ?

Moreover I don't see why votes for past blocks are needed at all, since they can't influence any decisions the node will now make.

Comment thread src/masternode-payments.h Outdated
CMasternodePayee(CScript payee, uint256 hashIn) :
scriptPubKey(payee),
nVotes(1),
vecVoteHashes(hashIn)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong. I'm surprised it even compiles. I think you want the default constructor here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eeek... I have no idea how this slipped in, will fix

Comment thread src/masternode-payments.h

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
READWRITE(*(CScriptBase*)(&scriptPubKey));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you didn't change this but this looks weird. Why all the casting ? Shouldn't READWRITE(scriptPubKey) suffice ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/masternode-payments.h Outdated
public:
CMasternodePayee() :
scriptPubKey(),
nVotes(0),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think nVotes is needed now. I would remove it and just return vecVoteHashes.size().

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, looks like a good idea

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done :)

Comment thread src/masternode-payments.h
{
public:
private:
CScript scriptPubKey;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't vin (ie. COutPoint) be used here to insure uniqueness ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that would be better but we only have CScript payee in CMasternodePaymentWinner and switching from payee to vin would break backward compatibility. This is still quite unique though because this one corresponds to pubKeyCollateralAddress.

BOOST_FOREACH(CMasternodePayee& payee, it->second.vecPayees) {
if(payee.GetVoteCount() >= MNPAYMENTS_SIGNATURES_REQUIRED) {
fFound = true;
break;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the break here will make nTotalVotes innacurate

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, but it will not be used if fFound is true anyway

@UdjinM6
Copy link
Copy Markdown
Author

UdjinM6 commented Sep 18, 2016

The point of RequestLowDataPaymentBlocks is to find "payment blocks" which have not enough votes to identify the winner. The reason it uses avg rather than max for votes threshold (which is the same criteria as in IsEnoughData) is because it's quite common to miss few votes for some old blocks or due to some voting issues (some MNs do not find themselves in top10 i.e. do not cast a vote at all).

Votes for past blocks are needed because you need to construct history of payments in some way. I would agree however that having new UpdateLastPaid in place (i.e. scanning back blockchain) could probably also help to optimize logic for selecting which "payment blocks" to request but I would leave this out of the scope of this PR.

@tgflynn
Copy link
Copy Markdown

tgflynn commented Sep 18, 2016

utACK

@UdjinM6 UdjinM6 merged commit 1e2d61a into dashpay:v0.12.1.x Sep 18, 2016
UdjinM6 added a commit that referenced this pull request Sep 21, 2016
Followup for the recent winner_block PR (#1028) and name confusion discovered during code review.

"Mostly" because also:

- CMasternodeBlockPayees::GetPayee -> CMasternodeBlockPayees::GetBestPayee which describes what this function is actually doing a bit better imo;
- fixing constructor CMasternodePaymentVote empty constructor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants