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
9c01aab4
Commit
9c01aab4
authored
Jan 14, 2019
by
Sergei Zubov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge block fee rule
parent
59fe1daa
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 @
9c01aab4
...
...
@@ -118,7 +118,8 @@ namespace Stratis.Bitcoin.Features.Consensus
new
LoadCoinviewRule
(),
new
TransactionDuplicationActivationRule
(),
// implements BIP30
new
DeStreamPowCoinviewRule
(),
// implements BIP68, MaxSigOps and BlockReward calculation
new
SaveCoinviewRule
()
new
SaveCoinviewRule
(),
new
DeStreamBlockFeeRule
()
};
}
}
...
...
@@ -178,7 +179,8 @@ namespace Stratis.Bitcoin.Features.Consensus
// 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.
new
PosColdStakingRule
(),
new
SaveCoinviewRule
()
new
SaveCoinviewRule
(),
new
DeStreamBlockFeeRule
()
};
}
}
...
...
Sources/Stratis.Bitcoin.Features.Consensus/Rules/CommonRules/DeStreamBlockFeeRule.cs
View file @
9c01aab4
...
...
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using
System.Linq
;
using
System.Threading.Tasks
;
using
NBitcoin
;
using
Stratis.Bitcoin.Consensus
;
using
Stratis.Bitcoin.Consensus.Rules
;
namespace
Stratis.Bitcoin.Features.Consensus.Rules.CommonRules
...
...
@@ -10,32 +11,41 @@ namespace Stratis.Bitcoin.Features.Consensus.Rules.CommonRules
/// <summary>
/// A rule that verifies fee is charged from all spent funds and transferred to <see cref="Network.DeStreamWallet"/>
/// </summary>
[
ExecutionRule
]
public
class
DeStreamBlockFeeRule
:
ConsensusRule
public
class
DeStreamBlockFeeRule
:
FullValidationConsensusRule
{
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
)
{
// 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)
long
expectedFee
;
switch
(
context
)
{
case
DeStreamPowRuleContext
deStreamPowRuleContext
:
expectedFee
=
this
.
GetExpectedFee
(
context
.
ValidationContext
.
Block
,
deStreamPowRuleContext
.
TotalIn
,
expectedFee
=
this
.
GetExpectedFee
(
context
.
ValidationContext
.
Block
ToValidate
,
deStreamPowRuleContext
.
TotalIn
,
deStreamPowRuleContext
.
InputScriptPubKeys
);
break
;
case
DeStreamRuleContext
deStreamPosRuleContext
:
expectedFee
=
this
.
GetExpectedFee
(
context
.
ValidationContext
.
Block
,
deStreamPosRuleContext
.
TotalIn
,
case
DeStream
Pos
RuleContext
deStreamPosRuleContext
:
expectedFee
=
this
.
GetExpectedFee
(
context
.
ValidationContext
.
Block
ToValidate
,
deStreamPosRuleContext
.
TotalIn
,
deStreamPosRuleContext
.
InputScriptPubKeys
);
break
;
default
:
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
)
ConsensusErrors
.
BadTransactionFeeOutOfRange
.
Throw
();
...
...
@@ -46,8 +56,8 @@ namespace Stratis.Bitcoin.Features.Consensus.Rules.CommonRules
private
long
GetActualFee
(
Block
block
)
{
IList
<
TxOut
>
outputsToFeeWallet
=
block
.
Transactions
[
BlockStake
.
IsProofOfStake
(
block
)
?
1
:
0
].
Outputs
.
Where
(
p
=>
this
.
Parent
.
Network
.
IsDeStreamAddress
(
p
.
ScriptPubKey
.
GetDestinationAddress
(
this
.
Parent
.
Network
)?.
ToString
())).
ToList
();
.
Where
(
p
=>
this
.
DeStream
Network
.
IsDeStreamAddress
(
p
.
ScriptPubKey
.
GetDestinationAddress
(
this
.
DeStream
Network
)?.
ToString
())).
ToList
();
if
(
outputsToFeeWallet
.
Count
!=
1
)
ConsensusErrors
.
BadBlockNoFeeOutput
.
Throw
();
...
...
@@ -71,7 +81,7 @@ namespace Stratis.Bitcoin.Features.Consensus.Rules.CommonRules
{
long
feeInTransaction
=
Convert
.
ToInt64
(
transaction
.
Outputs
.
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
)
ConsensusErrors
.
BadTransactionFeeOutOfRange
.
Throw
();
...
...
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