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
f61773fd
Commit
f61773fd
authored
6 years ago
by
Sergei Zubov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge load coinview rule
parent
775402e3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
47 deletions
+21
-47
DeStreamFullNodeBuilderConsensusExtension.cs
...es.Consensus/DeStreamFullNodeBuilderConsensusExtension.cs
+2
-2
DeStreamLoadCoinviewRule.cs
...s.Consensus/Rules/CommonRules/DeStreamLoadCoinviewRule.cs
+19
-45
No files found.
Sources/Stratis.Bitcoin.Features.Consensus/DeStreamFullNodeBuilderConsensusExtension.cs
View file @
f61773fd
...
...
@@ -115,7 +115,7 @@ namespace Stratis.Bitcoin.Features.Consensus
new
SetActivationDeploymentsFullValidationRule
(),
// rules that require the store to be loaded (coinview)
new
LoadCoinviewRule
(),
new
DeStream
LoadCoinviewRule
(),
new
TransactionDuplicationActivationRule
(),
// implements BIP30
new
DeStreamPowCoinviewRule
(),
// implements BIP68, MaxSigOps and BlockReward calculation
new
SaveCoinviewRule
(),
...
...
@@ -173,7 +173,7 @@ namespace Stratis.Bitcoin.Features.Consensus
new
CheckDifficultyHybridRule
(),
// rules that require the store to be loaded (coinview)
new
LoadCoinviewRule
(),
new
DeStream
LoadCoinviewRule
(),
new
TransactionDuplicationActivationRule
(),
// implements BIP30
new
DeStreamPosCoinviewRule
(),
// implements BIP68, MaxSigOps and BlockReward calculation
// Place the PosColdStakingRule after the PosCoinviewRule to ensure that all input scripts have been evaluated
...
...
This diff is collapsed.
Click to expand it.
Sources/Stratis.Bitcoin.Features.Consensus/Rules/CommonRules/DeStreamLoadCoinviewRule.cs
View file @
f61773fd
...
...
@@ -4,74 +4,48 @@ using System.Linq;
using
System.Threading.Tasks
;
using
Microsoft.Extensions.Logging
;
using
NBitcoin
;
using
Stratis.Bitcoin.Consensus
;
using
Stratis.Bitcoin.Consensus.Rules
;
using
Stratis.Bitcoin.Features.Consensus.CoinViews
;
using
Stratis.Bitcoin.Utilities
;
namespace
Stratis.Bitcoin.Features.Consensus.Rules.CommonRules
{
[
ExecutionRule
]
public
class
DeStreamLoadCoinviewRule
:
LoadCoinviewRule
{
public
override
async
Task
RunAsync
(
RuleContext
context
)
{
var
utxoRuleContext
=
context
as
UtxoRuleContext
;
// Load the UTXO set of the current block. UTXO may be loaded from cache or from disk.
// The UTXO set is stored in the context.
this
.
Logger
.
LogTrace
(
"Loading UTXO set of the new block."
);
utxoRuleContext
.
UnspentOutputSet
=
new
DeStreamUnspentOutputSet
();
// Check that the current block has not been reorged.
// Catching a reorg at this point will not require a rewind.
if
(
context
.
ValidationContext
.
BlockToValidate
.
Header
.
HashPrevBlock
!=
this
.
Parent
.
ChainState
.
ConsensusTip
.
HashBlock
)
{
this
.
Logger
.
LogTrace
(
"Reorganization detected."
);
ConsensusErrors
.
InvalidPrevTip
.
Throw
();
}
var
utxoRuleContext
=
context
as
UtxoRuleContext
;
switch
(
utxoRuleContext
)
{
case
DeStreamPowRuleContext
deStreamPowRuleContext
:
deStreamPowRuleContext
.
InputScriptPubKeys
=
new
Dictionary
<
uint256
,
List
<
Script
>>();
break
;
case
DeStreamRuleContext
deStreamPosRuleContext
:
case
DeStream
Pos
RuleContext
deStreamPosRuleContext
:
deStreamPosRuleContext
.
InputScriptPubKeys
=
new
Dictionary
<
uint256
,
List
<
Script
>>();
break
;
default
:
throw
new
NotSupportedException
(
$"Rule context must be
{
nameof
(
DeStreamPowRuleContext
)}
or
{
nameof
(
DeStreamRuleContext
)}
"
);
}
using
(
new
StopwatchDisposable
(
o
=>
this
.
Parent
.
PerformanceCounter
.
AddUTXOFetchingTime
(
o
)))
{
uint256
[]
ids
=
this
.
GetIdsToFetch
(
context
.
ValidationContext
.
Block
,
context
.
Flags
.
EnforceBIP30
);
FetchCoinsResponse
coins
=
await
this
.
PowParent
.
UtxoSet
.
FetchCoinsAsync
(
ids
).
ConfigureAwait
(
false
);
utxoRuleContext
.
UnspentOutputSet
.
SetCoins
(
coins
.
UnspentOutputs
);
$"Rule context must be
{
nameof
(
DeStreamPowRuleContext
)}
or
{
nameof
(
DeStreamPosRuleContext
)}
"
);
}
// Attempt to load into the cache the next set of UTXO to be validated.
// The task is not awaited so will not stall main validation process.
this
.
TryPrefetchAsync
(
context
.
Flags
);
}
/// <inheritdoc />
protected
override
uint256
[]
GetIdsToFetch
(
Block
block
,
bool
enforceBIP30
)
{
this
.
Logger
.
LogTrace
(
"({0}:'{1}',{2}:{3})"
,
nameof
(
block
),
block
.
GetHash
(),
nameof
(
enforceBIP30
),
enforceBIP30
);
var
ids
=
new
HashSet
<
uint256
>();
foreach
(
Transaction
tx
in
block
.
Transactions
)
{
if
(
enforceBIP30
)
{
uint256
txId
=
tx
.
GetHash
();
ids
.
Add
(
txId
);
}
if
(
tx
.
IsCoinBase
)
continue
;
foreach
(
TxIn
input
in
tx
.
Inputs
.
RemoveChangePointer
())
{
ids
.
Add
(
input
.
PrevOut
.
Hash
);
}
}
// Load the UTXO set of the current block. UTXO may be loaded from cache or from disk.
// The UTXO set is stored in the context.
this
.
Logger
.
LogTrace
(
"Loading UTXO set of the new block."
);
utxoRuleContext
.
UnspentOutputSet
=
new
DeStreamUnspentOutputSet
();
uint256
[]
res
=
ids
.
ToArray
(
);
this
.
Logger
.
LogTrace
(
"(-):*.{0}={1}"
,
nameof
(
res
.
Length
),
res
.
Length
);
return
res
;
uint256
[]
ids
=
this
.
coinviewHelper
.
GetIdsToFetch
(
context
.
ValidationContext
.
BlockToValidate
,
context
.
Flags
.
EnforceBIP30
);
FetchCoinsResponse
coins
=
await
this
.
PowParent
.
UtxoSet
.
FetchCoinsAsync
(
ids
).
ConfigureAwait
(
false
);
utxoRuleContext
.
UnspentOutputSet
.
SetCoins
(
coins
.
UnspentOutputs
)
;
}
}
}
\ No newline at end of file
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