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
f4f13dc1
Commit
f4f13dc1
authored
Jan 14, 2019
by
Sergei Zubov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge DBreeze CoinView
parent
ee6989c9
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
40 deletions
+22
-40
DBreezeCoinView.cs
...s.Bitcoin.Features.Consensus/CoinViews/DBreezeCoinView.cs
+5
-5
DeStreamDBreezeCoinView.cs
...n.Features.Consensus/CoinViews/DeStreamDBreezeCoinView.cs
+13
-31
DeStreamFullNodeBuilderConsensusExtension.cs
...es.Consensus/DeStreamFullNodeBuilderConsensusExtension.cs
+4
-4
No files found.
Sources/Stratis.Bitcoin.Features.Consensus/CoinViews/DBreezeCoinView.cs
View file @
f4f13dc1
...
@@ -24,10 +24,10 @@ namespace Stratis.Bitcoin.Features.Consensus.CoinViews
...
@@ -24,10 +24,10 @@ namespace Stratis.Bitcoin.Features.Consensus.CoinViews
private
static
readonly
byte
[]
blockHashKey
=
new
byte
[
0
];
private
static
readonly
byte
[]
blockHashKey
=
new
byte
[
0
];
/// <summary>Instance logger.</summary>
/// <summary>Instance logger.</summary>
pr
ivate
readonly
ILogger
logger
;
pr
otected
readonly
ILogger
logger
;
/// <summary>Specification of the network the node runs on - regtest/testnet/mainnet.</summary>
/// <summary>Specification of the network the node runs on - regtest/testnet/mainnet.</summary>
pr
ivate
readonly
Network
network
;
pr
otected
readonly
Network
network
;
/// <summary>Hash of the block which is currently the tip of the coinview.</summary>
/// <summary>Hash of the block which is currently the tip of the coinview.</summary>
private
uint256
blockHash
;
private
uint256
blockHash
;
...
@@ -78,7 +78,7 @@ namespace Stratis.Bitcoin.Features.Consensus.CoinViews
...
@@ -78,7 +78,7 @@ namespace Stratis.Bitcoin.Features.Consensus.CoinViews
/// <summary>
/// <summary>
/// Initializes the database tables used by the coinview.
/// Initializes the database tables used by the coinview.
/// </summary>
/// </summary>
public
Task
InitializeAsync
()
public
virtual
Task
InitializeAsync
()
{
{
Block
genesis
=
this
.
network
.
GetGenesis
();
Block
genesis
=
this
.
network
.
GetGenesis
();
...
@@ -164,7 +164,7 @@ namespace Stratis.Bitcoin.Features.Consensus.CoinViews
...
@@ -164,7 +164,7 @@ namespace Stratis.Bitcoin.Features.Consensus.CoinViews
/// </summary>
/// </summary>
/// <param name="transaction">Open dBreeze transaction.</param>
/// <param name="transaction">Open dBreeze transaction.</param>
/// <returns>Block header hash of the coinview's current tip.</returns>
/// <returns>Block header hash of the coinview's current tip.</returns>
pr
ivate
uint256
GetTipHash
(
DBreeze
.
Transactions
.
Transaction
transaction
)
pr
otected
uint256
GetTipHash
(
DBreeze
.
Transactions
.
Transaction
transaction
)
{
{
if
(
this
.
blockHash
==
null
)
if
(
this
.
blockHash
==
null
)
{
{
...
@@ -181,7 +181,7 @@ namespace Stratis.Bitcoin.Features.Consensus.CoinViews
...
@@ -181,7 +181,7 @@ namespace Stratis.Bitcoin.Features.Consensus.CoinViews
/// </summary>
/// </summary>
/// <param name="transaction">Open dBreeze transaction.</param>
/// <param name="transaction">Open dBreeze transaction.</param>
/// <param name="nextBlockHash">Hash of the block to become the new tip.</param>
/// <param name="nextBlockHash">Hash of the block to become the new tip.</param>
pr
ivate
void
SetBlockHash
(
DBreeze
.
Transactions
.
Transaction
transaction
,
uint256
nextBlockHash
)
pr
otected
void
SetBlockHash
(
DBreeze
.
Transactions
.
Transaction
transaction
,
uint256
nextBlockHash
)
{
{
this
.
blockHash
=
nextBlockHash
;
this
.
blockHash
=
nextBlockHash
;
transaction
.
Insert
<
byte
[],
uint256
>(
"BlockHash"
,
blockHashKey
,
nextBlockHash
);
transaction
.
Insert
<
byte
[],
uint256
>(
"BlockHash"
,
blockHashKey
,
nextBlockHash
);
...
...
Sources/Stratis.Bitcoin.Features.Consensus/CoinViews/DeStreamDBreezeCoinView.cs
View file @
f4f13dc1
using
System
;
using
System
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
Microsoft.Extensions.Logging
;
using
Microsoft.Extensions.Logging
;
using
NBitcoin
;
using
NBitcoin
;
using
Stratis.Bitcoin.Configuration
;
using
Stratis.Bitcoin.Configuration
;
using
Stratis.Bitcoin.Utilities
;
using
Stratis.Bitcoin.Utilities
;
using
Transaction
=
DBreeze
.
Transactions
.
Transaction
;
namespace
Stratis.Bitcoin.Features.Consensus.CoinViews
namespace
Stratis.Bitcoin.Features.Consensus.CoinViews
{
{
...
@@ -13,55 +11,39 @@ namespace Stratis.Bitcoin.Features.Consensus.CoinViews
...
@@ -13,55 +11,39 @@ namespace Stratis.Bitcoin.Features.Consensus.CoinViews
public
class
DeStreamDBreezeCoinView
:
DBreezeCoinView
,
IDisposable
public
class
DeStreamDBreezeCoinView
:
DBreezeCoinView
,
IDisposable
{
{
public
DeStreamDBreezeCoinView
(
Network
network
,
DataFolder
dataFolder
,
IDateTimeProvider
dateTimeProvider
,
public
DeStreamDBreezeCoinView
(
Network
network
,
DataFolder
dataFolder
,
IDateTimeProvider
dateTimeProvider
,
ILoggerFactory
loggerFactory
)
:
base
(
network
,
dataFolder
,
dateTimeProvider
,
loggerFactory
)
ILoggerFactory
loggerFactory
,
INodeStats
nodeStats
)
:
base
(
network
,
dataFolder
,
dateTimeProvider
,
loggerFactory
,
nodeStats
)
{
{
}
}
public
DeStreamDBreezeCoinView
(
Network
network
,
string
folder
,
IDateTimeProvider
dateTimeProvider
,
public
DeStreamDBreezeCoinView
(
Network
network
,
string
folder
,
IDateTimeProvider
dateTimeProvider
,
ILoggerFactory
loggerFactory
)
:
base
(
network
,
folder
,
dateTimeProvider
,
loggerFactory
)
ILoggerFactory
loggerFactory
,
INodeStats
nodeStats
)
:
base
(
network
,
folder
,
dateTimeProvider
,
loggerFactory
,
nodeStats
)
{
{
}
}
/// <inheritdoc />
/// <inheritdoc />
// Instead of ignoring genesis coins, add them to database
public
override
Task
InitializeAsync
()
public
override
Task
InitializeAsync
()
{
{
this
.
logger
.
LogTrace
(
"()"
);
var
genesis
=
network
.
GetGenesis
(
);
Block
genesis
=
this
.
network
.
GetGenesis
();
var
task
=
Task
.
Run
(()
=>
int
insertedEntities
=
0
;
Task
task
=
Task
.
Run
(()
=>
{
{
this
.
logger
.
LogTrace
(
"()"
);
using
(
var
transaction
=
CreateTransaction
())
using
(
Transaction
transaction
=
this
.
dbreeze
.
GetTransaction
())
{
{
transaction
.
ValuesLazyLoadingIsOn
=
false
;
transaction
.
ValuesLazyLoadingIsOn
=
false
;
transaction
.
SynchronizeTables
(
"BlockHash"
);
transaction
.
SynchronizeTables
(
"BlockHash"
);
if
(
this
.
GetCurrentHash
(
transaction
)
==
null
)
if
(
GetTipHash
(
transaction
)
!=
null
)
return
;
{
this
.
SetBlockHash
(
transaction
,
genesis
.
GetHash
());
// Genesis coin is spendable and added to the database.
SetBlockHash
(
transaction
,
genesis
.
GetHash
());
foreach
(
UnspentOutputs
unspentOutput
in
genesis
.
Transactions
.
Select
(
p
=>
new
UnspentOutputs
(
0
,
p
)))
{
transaction
.
Insert
(
"Coins"
,
unspentOutput
.
TransactionId
.
ToBytes
(
false
),
unspentOutput
.
ToCoins
());
}
insertedEntities
+=
genesis
.
Transactions
.
Count
;
// Genesis coin is spendable and included to database.
transaction
.
Commit
();
transaction
.
Commit
();
}
}
}
this
.
logger
.
LogTrace
(
"(-)"
);
});
});
this
.
PerformanceCounter
.
AddInsertedEntities
(
insertedEntities
);
this
.
logger
.
LogTrace
(
"(-)"
);
return
task
;
return
task
;
}
}
}
}
...
...
Sources/Stratis.Bitcoin.Features.Consensus/DeStreamFullNodeBuilderConsensusExtension.cs
View file @
f4f13dc1
...
@@ -22,7 +22,7 @@ namespace Stratis.Bitcoin.Features.Consensus
...
@@ -22,7 +22,7 @@ namespace Stratis.Bitcoin.Features.Consensus
/// </summary>
/// </summary>
public
static
class
DeStreamFullNodeBuilderConsensusExtension
public
static
class
DeStreamFullNodeBuilderConsensusExtension
{
{
public
static
IFullNodeBuilder
UsePowConsensus
(
this
IFullNodeBuilder
fullNodeBuilder
)
public
static
IFullNodeBuilder
Use
DeStream
PowConsensus
(
this
IFullNodeBuilder
fullNodeBuilder
)
{
{
LoggingConfiguration
.
RegisterFeatureNamespace
<
PowConsensusFeature
>(
"powconsensus"
);
LoggingConfiguration
.
RegisterFeatureNamespace
<
PowConsensusFeature
>(
"powconsensus"
);
...
@@ -33,7 +33,7 @@ namespace Stratis.Bitcoin.Features.Consensus
...
@@ -33,7 +33,7 @@ namespace Stratis.Bitcoin.Features.Consensus
.
FeatureServices
(
services
=>
.
FeatureServices
(
services
=>
{
{
services
.
AddSingleton
<
ConsensusOptions
,
ConsensusOptions
>();
services
.
AddSingleton
<
ConsensusOptions
,
ConsensusOptions
>();
services
.
AddSingleton
<
DBreezeCoinView
>();
services
.
AddSingleton
<
D
eStreamD
BreezeCoinView
>();
services
.
AddSingleton
<
ICoinView
,
CachedCoinView
>();
services
.
AddSingleton
<
ICoinView
,
CachedCoinView
>();
services
.
AddSingleton
<
ConsensusController
>();
services
.
AddSingleton
<
ConsensusController
>();
services
.
AddSingleton
<
IConsensusRuleEngine
,
PowConsensusRuleEngine
>();
services
.
AddSingleton
<
IConsensusRuleEngine
,
PowConsensusRuleEngine
>();
...
@@ -48,7 +48,7 @@ namespace Stratis.Bitcoin.Features.Consensus
...
@@ -48,7 +48,7 @@ namespace Stratis.Bitcoin.Features.Consensus
return
fullNodeBuilder
;
return
fullNodeBuilder
;
}
}
public
static
IFullNodeBuilder
UsePosConsensus
(
this
IFullNodeBuilder
fullNodeBuilder
)
public
static
IFullNodeBuilder
Use
DeStream
PosConsensus
(
this
IFullNodeBuilder
fullNodeBuilder
)
{
{
LoggingConfiguration
.
RegisterFeatureNamespace
<
PosConsensusFeature
>(
"posconsensus"
);
LoggingConfiguration
.
RegisterFeatureNamespace
<
PosConsensusFeature
>(
"posconsensus"
);
...
@@ -58,7 +58,7 @@ namespace Stratis.Bitcoin.Features.Consensus
...
@@ -58,7 +58,7 @@ namespace Stratis.Bitcoin.Features.Consensus
.
AddFeature
<
PosConsensusFeature
>()
.
AddFeature
<
PosConsensusFeature
>()
.
FeatureServices
(
services
=>
.
FeatureServices
(
services
=>
{
{
services
.
AddSingleton
<
DBreezeCoinView
>();
services
.
AddSingleton
<
D
eStreamD
BreezeCoinView
>();
services
.
AddSingleton
<
ICoinView
,
CachedCoinView
>();
services
.
AddSingleton
<
ICoinView
,
CachedCoinView
>();
services
.
AddSingleton
<
StakeChainStore
>().
AddSingleton
<
IStakeChain
,
StakeChainStore
>(
provider
=>
provider
.
GetService
<
StakeChainStore
>());
services
.
AddSingleton
<
StakeChainStore
>().
AddSingleton
<
IStakeChain
,
StakeChainStore
>(
provider
=>
provider
.
GetService
<
StakeChainStore
>());
services
.
AddSingleton
<
IStakeValidator
,
StakeValidator
>();
services
.
AddSingleton
<
IStakeValidator
,
StakeValidator
>();
...
...
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