Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

PH integrity validation improvements + gateway fix #3726

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

noescape00
Copy link
Contributor

@noescape00 noescape00 commented Jun 14, 2019

Dont merge before the release

see #3720

zeptin
zeptin previously requested changes Jun 14, 2019
Copy link
Contributor

@zeptin zeptin left a comment

Choose a reason for hiding this comment

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

Blocking until release

// In case we are in PoW era there might be no coinstake tx.
// We have no way of telling if the block was supposed to be PoW or PoS so attacker
// can trick us into thinking that all of them are PoW so no PH is required.
if (header == null || !header.Coinstake.IsCoinStake)
Copy link
Contributor

Choose a reason for hiding this comment

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

I actually don't understand why the need to fail in case we are bellow the checkpoint.
If this is a regular header this rule does not need to do anything just return.

The purpose of this rule is only to ensure the PH coinstake and bloc coinstake are equal, the other checks don't belong to this rule (and some may even be duplicates)

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if we should remove this rule when the node is setup as gateway

Copy link
Contributor

Choose a reason for hiding this comment

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

It will be actually more complicated to do that.

@dangershony
Copy link
Contributor

This PR is totally bloated for no reason, injecting the connection for the settings is really not needed.
Also there is no need to check gateway just do nothing if its a regular header.

@noescape00
Copy link
Contributor Author

Agreed with @dangershony .
Removed bloating.

dangershony
dangershony previously approved these changes Jul 1, 2019
Copy link
Contributor

@dangershony dangershony left a comment

Choose a reason for hiding this comment

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

Looks good.
I suggest testing on one gateway before pushing to master (as a precaution)

@zeptin zeptin dismissed their stale review October 2, 2019 20:15

I think that after the conflicts are resolved this can be re-looked at for merging

namespace Stratis.Bitcoin.Features.Consensus.Rules.CommonRules
{
/// <summary>Checks that coinstake tx from the proven header is the 2nd transaction in a block and that the block has at least 2 transactions.</summary>
public class PosTransactionsOrderRule : IntegrityValidationConsensusRule
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the right name?
Looks like the main check of this Rule is that the coinstake on the block and on the proven header match.
There re is no regard to the order of transactions

/// <exception cref="ConsensusErrors.InvalidTxCount">Thrown in case block has less than 2 transaction.</exception>
/// <exception cref="ConsensusErrors.PHCoinstakeMissmatch">Thrown in case coinstake transaction from the proven header missmatches 2nd block transaction.</exception>
/// <exception cref="ConsensusErrors.ProofOfWorkTooHigh">Thrown in case block is a PoW block but created after the last pow height.</exception>
public override void Run(RuleContext context)
Copy link
Collaborator

Choose a reason for hiding this comment

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

@noescape00 I would split this rule into three separately rules. The logic looks good but it might be better to have the logic split then we can name each rule properly according to its purpose.

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe there already is a rue to check for ProofOfWorkTooHigh

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants