Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
destream-blockchain
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DeStream-public
destream-blockchain
Commits
775402e3
Commit
775402e3
authored
6 years ago
by
Sergei Zubov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge block fee rule
parent
fbf32102
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
13 deletions
+25
-13
DeStreamFullNodeBuilderConsensusExtension.cs
...es.Consensus/DeStreamFullNodeBuilderConsensusExtension.cs
+4
-2
DeStreamBlockFeeRule.cs
...tures.Consensus/Rules/CommonRules/DeStreamBlockFeeRule.cs
+21
-11
No files found.
Sources/Stratis.Bitcoin.Features.Consensus/DeStreamFullNodeBuilderConsensusExtension.cs
View file @
775402e3
...
@@ -118,7 +118,8 @@ namespace Stratis.Bitcoin.Features.Consensus
...
@@ -118,7 +118,8 @@ namespace Stratis.Bitcoin.Features.Consensus
new
LoadCoinviewRule
(),
new
LoadCoinviewRule
(),
new
TransactionDuplicationActivationRule
(),
// implements BIP30
new
TransactionDuplicationActivationRule
(),
// implements BIP30
new
DeStreamPowCoinviewRule
(),
// implements BIP68, MaxSigOps and BlockReward calculation
new
DeStreamPowCoinviewRule
(),
// implements BIP68, MaxSigOps and BlockReward calculation
new
SaveCoinviewRule
()
new
SaveCoinviewRule
(),
new
DeStreamBlockFeeRule
()
};
};
}
}
}
}
...
@@ -178,7 +179,8 @@ namespace Stratis.Bitcoin.Features.Consensus
...
@@ -178,7 +179,8 @@ namespace Stratis.Bitcoin.Features.Consensus
// Place the PosColdStakingRule after the PosCoinviewRule to ensure that all input scripts have been evaluated
// Place the PosColdStakingRule after the PosCoinviewRule to ensure that all input scripts have been evaluated
// and that the "IsColdCoinStake" flag would have been set by the OP_CHECKCOLDSTAKEVERIFY opcode if applicable.
// and that the "IsColdCoinStake" flag would have been set by the OP_CHECKCOLDSTAKEVERIFY opcode if applicable.
new
PosColdStakingRule
(),
new
PosColdStakingRule
(),
new
SaveCoinviewRule
()
new
SaveCoinviewRule
(),
new
DeStreamBlockFeeRule
()
};
};
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Sources/Stratis.Bitcoin.Features.Consensus/Rules/CommonRules/DeStreamBlockFeeRule.cs
View file @
775402e3
...
@@ -3,6 +3,7 @@ using System.Collections.Generic;
...
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using
System.Linq
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
NBitcoin
;
using
NBitcoin
;
using
Stratis.Bitcoin.Consensus
;
using
Stratis.Bitcoin.Consensus.Rules
;
using
Stratis.Bitcoin.Consensus.Rules
;
namespace
Stratis.Bitcoin.Features.Consensus.Rules.CommonRules
namespace
Stratis.Bitcoin.Features.Consensus.Rules.CommonRules
...
@@ -10,32 +11,41 @@ namespace Stratis.Bitcoin.Features.Consensus.Rules.CommonRules
...
@@ -10,32 +11,41 @@ namespace Stratis.Bitcoin.Features.Consensus.Rules.CommonRules
/// <summary>
/// <summary>
/// A rule that verifies fee is charged from all spent funds and transferred to <see cref="Network.DeStreamWallet"/>
/// A rule that verifies fee is charged from all spent funds and transferred to <see cref="Network.DeStreamWallet"/>
/// </summary>
/// </summary>
[
ExecutionRule
]
public
class
DeStreamBlockFeeRule
:
FullValidationConsensusRule
public
class
DeStreamBlockFeeRule
:
ConsensusRule
{
{
private
DeStreamNetwork
DeStreamNetwork
{
get
{
if
(!(
this
.
Parent
.
Network
is
DeStreamNetwork
))
throw
new
NotSupportedException
(
$"Network must be
{
nameof
(
NBitcoin
.
DeStreamNetwork
)}
"
);
return
(
DeStreamNetwork
)
this
.
Parent
.
Network
;
}
}
public
override
Task
RunAsync
(
RuleContext
context
)
public
override
Task
RunAsync
(
RuleContext
context
)
{
{
// Actual fee is funds that are transferred to fee wallet in mined/staked block
// Actual fee is funds that are transferred to fee wallet in mined/staked block
long
actualFee
=
this
.
GetActualFee
(
context
.
ValidationContext
.
Block
);
long
actualFee
=
this
.
GetActualFee
(
context
.
ValidationContext
.
Block
ToValidate
);
// Expected fee is charged from all moved funds (not change)
// Expected fee is charged from all moved funds (not change)
long
expectedFee
;
long
expectedFee
;
switch
(
context
)
switch
(
context
)
{
{
case
DeStreamPowRuleContext
deStreamPowRuleContext
:
case
DeStreamPowRuleContext
deStreamPowRuleContext
:
expectedFee
=
this
.
GetExpectedFee
(
context
.
ValidationContext
.
Block
,
deStreamPowRuleContext
.
TotalIn
,
expectedFee
=
this
.
GetExpectedFee
(
context
.
ValidationContext
.
Block
ToValidate
,
deStreamPowRuleContext
.
TotalIn
,
deStreamPowRuleContext
.
InputScriptPubKeys
);
deStreamPowRuleContext
.
InputScriptPubKeys
);
break
;
break
;
case
DeStreamRuleContext
deStreamPosRuleContext
:
case
DeStream
Pos
RuleContext
deStreamPosRuleContext
:
expectedFee
=
this
.
GetExpectedFee
(
context
.
ValidationContext
.
Block
,
deStreamPosRuleContext
.
TotalIn
,
expectedFee
=
this
.
GetExpectedFee
(
context
.
ValidationContext
.
Block
ToValidate
,
deStreamPosRuleContext
.
TotalIn
,
deStreamPosRuleContext
.
InputScriptPubKeys
);
deStreamPosRuleContext
.
InputScriptPubKeys
);
break
;
break
;
default
:
default
:
throw
new
NotSupportedException
(
throw
new
NotSupportedException
(
$"Rule context must be
{
nameof
(
DeStreamPowRuleContext
)}
or
{
nameof
(
DeStreamRuleContext
)}
"
);
$"Rule context must be
{
nameof
(
DeStreamPowRuleContext
)}
or
{
nameof
(
DeStream
Pos
RuleContext
)}
"
);
}
}
this
.
Parent
.
Network
.
SplitFee
(
expectedFee
,
out
long
expectedDeStreamFee
,
out
long
_
);
this
.
DeStream
Network
.
SplitFee
(
expectedFee
,
out
long
expectedDeStreamFee
,
out
long
_
);
if
(
actualFee
<
expectedDeStreamFee
)
if
(
actualFee
<
expectedDeStreamFee
)
ConsensusErrors
.
BadTransactionFeeOutOfRange
.
Throw
();
ConsensusErrors
.
BadTransactionFeeOutOfRange
.
Throw
();
...
@@ -46,8 +56,8 @@ namespace Stratis.Bitcoin.Features.Consensus.Rules.CommonRules
...
@@ -46,8 +56,8 @@ namespace Stratis.Bitcoin.Features.Consensus.Rules.CommonRules
private
long
GetActualFee
(
Block
block
)
private
long
GetActualFee
(
Block
block
)
{
{
IList
<
TxOut
>
outputsToFeeWallet
=
block
.
Transactions
[
BlockStake
.
IsProofOfStake
(
block
)
?
1
:
0
].
Outputs
IList
<
TxOut
>
outputsToFeeWallet
=
block
.
Transactions
[
BlockStake
.
IsProofOfStake
(
block
)
?
1
:
0
].
Outputs
.
Where
(
p
=>
this
.
Parent
.
Network
.
IsDeStreamAddress
(
p
.
ScriptPubKey
.
Where
(
p
=>
this
.
DeStream
Network
.
IsDeStreamAddress
(
p
.
ScriptPubKey
.
GetDestinationAddress
(
this
.
Parent
.
Network
)?.
ToString
())).
ToList
();
.
GetDestinationAddress
(
this
.
DeStream
Network
)?.
ToString
())).
ToList
();
if
(
outputsToFeeWallet
.
Count
!=
1
)
if
(
outputsToFeeWallet
.
Count
!=
1
)
ConsensusErrors
.
BadBlockNoFeeOutput
.
Throw
();
ConsensusErrors
.
BadBlockNoFeeOutput
.
Throw
();
...
@@ -71,7 +81,7 @@ namespace Stratis.Bitcoin.Features.Consensus.Rules.CommonRules
...
@@ -71,7 +81,7 @@ namespace Stratis.Bitcoin.Features.Consensus.Rules.CommonRules
{
{
long
feeInTransaction
=
Convert
.
ToInt64
(
transaction
.
Outputs
long
feeInTransaction
=
Convert
.
ToInt64
(
transaction
.
Outputs
.
Where
(
p
=>
!
changeScriptPubKeys
.
Contains
(
p
.
ScriptPubKey
))
.
Where
(
p
=>
!
changeScriptPubKeys
.
Contains
(
p
.
ScriptPubKey
))
.
Sum
(
p
=>
p
.
Value
)
*
this
.
Parent
.
Network
.
FeeRate
);
.
Sum
(
p
=>
p
.
Value
)
*
this
.
DeStream
Network
.
FeeRate
);
if
(
Math
.
Abs
(
totalIn
.
Satoshi
-
transaction
.
TotalOut
.
Satoshi
-
feeInTransaction
)
>
1
)
if
(
Math
.
Abs
(
totalIn
.
Satoshi
-
transaction
.
TotalOut
.
Satoshi
-
feeInTransaction
)
>
1
)
ConsensusErrors
.
BadTransactionFeeOutOfRange
.
Throw
();
ConsensusErrors
.
BadTransactionFeeOutOfRange
.
Throw
();
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment