Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
Breeze
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
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
Breeze
Commits
bb43fb28
Commit
bb43fb28
authored
Jun 02, 2017
by
Jeremy Bokobza
Committed by
GitHub
Jun 02, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #88 from bokobza/master
Tidying of Breeze's sync manager
parents
3a244ac5
c3beda01
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
167 additions
and
141 deletions
+167
-141
Program.cs
Breeze/src/Breeze.Daemon/Program.cs
+120
-119
launchSettings.json
Breeze/src/Breeze.Daemon/Properties/launchSettings.json
+3
-2
LightWalletFeature.cs
Breeze/src/Breeze.Wallet/LightWalletFeature.cs
+10
-13
LightWalletSyncManager.cs
Breeze/src/Breeze.Wallet/LightWalletSyncManager.cs
+34
-7
No files found.
Breeze/src/Breeze.Daemon/Program.cs
View file @
bb43fb28
...
...
@@ -25,125 +25,126 @@ namespace Breeze.Daemon
{
public
static
void
Main
(
string
[]
args
)
{
IFullNodeBuilder
fullNodeBuilder
=
null
;
if
(
args
.
Contains
(
"stratis"
))
{
// configure Full Node
Logs
.
Configure
(
Logs
.
GetLoggerFactory
(
args
));
if
(
NodeSettings
.
PrintHelp
(
args
,
Network
.
StratisMain
))
return
;
var
network
=
args
.
Contains
(
"-testnet"
)
?
InitStratisTest
()
:
Network
.
StratisMain
;
var
nodeSettings
=
NodeSettings
.
FromArguments
(
args
,
"stratis"
,
network
,
ProtocolVersion
.
ALT_PROTOCOL_VERSION
);
if
(
args
.
Contains
(
"light"
))
{
fullNodeBuilder
=
new
FullNodeBuilder
()
.
UseNodeSettings
(
nodeSettings
)
.
UseLightWallet
()
.
UseBlockNotification
()
.
UseTransactionNotification
()
.
UseApi
();
}
else
{
fullNodeBuilder
=
new
FullNodeBuilder
()
.
UseNodeSettings
(
nodeSettings
)
.
UseStratisConsensus
()
.
UseBlockStore
()
.
UseMempool
()
.
UseWallet
()
.
AddPowPosMining
()
.
UseApi
();
}
}
else
{
NodeSettings
nodeSettings
=
NodeSettings
.
FromArguments
(
args
);
if
(
args
.
Contains
(
"light"
))
{
fullNodeBuilder
=
new
FullNodeBuilder
()
.
UseNodeSettings
(
nodeSettings
)
.
UseLightWallet
()
.
UseBlockNotification
()
.
UseTransactionNotification
()
.
UseApi
();
}
else
{
fullNodeBuilder
=
new
FullNodeBuilder
()
.
UseNodeSettings
(
nodeSettings
)
.
UseConsensus
()
.
UseBlockStore
()
.
UseMempool
()
.
UseWallet
()
.
UseApi
();
}
}
// add the tumbler's settings
var
tumblerAddress
=
args
.
SingleOrDefault
(
arg
=>
arg
.
StartsWith
(
"-tumbler-uri="
));
if
(!
string
.
IsNullOrEmpty
(
tumblerAddress
))
{
tumblerAddress
=
tumblerAddress
.
Replace
(
"-tumbler-uri="
,
string
.
Empty
);
fullNodeBuilder
.
UseTumbleBit
(
new
Uri
(
tumblerAddress
));
}
var
node
=
fullNodeBuilder
.
Build
();
//start Full Node - this will also start the API
node
.
Run
();
IFullNodeBuilder
fullNodeBuilder
=
null
;
// configure logging
Logs
.
Configure
(
Logs
.
GetLoggerFactory
(
args
));
if
(
args
.
Contains
(
"stratis"
))
{
if
(
NodeSettings
.
PrintHelp
(
args
,
Network
.
StratisMain
))
return
;
var
network
=
args
.
Contains
(
"-testnet"
)
?
InitStratisTest
()
:
Network
.
StratisMain
;
var
nodeSettings
=
NodeSettings
.
FromArguments
(
args
,
"stratis"
,
network
,
ProtocolVersion
.
ALT_PROTOCOL_VERSION
);
if
(
args
.
Contains
(
"light"
))
{
fullNodeBuilder
=
new
FullNodeBuilder
()
.
UseNodeSettings
(
nodeSettings
)
.
UseLightWallet
()
.
UseBlockNotification
()
.
UseTransactionNotification
()
.
UseApi
();
}
else
{
fullNodeBuilder
=
new
FullNodeBuilder
()
.
UseNodeSettings
(
nodeSettings
)
.
UseStratisConsensus
()
.
UseBlockStore
()
.
UseMempool
()
.
UseWallet
()
.
AddPowPosMining
()
.
UseApi
();
}
}
else
{
NodeSettings
nodeSettings
=
NodeSettings
.
FromArguments
(
args
);
if
(
args
.
Contains
(
"light"
))
{
fullNodeBuilder
=
new
FullNodeBuilder
()
.
UseNodeSettings
(
nodeSettings
)
.
UseLightWallet
()
.
UseBlockNotification
()
.
UseTransactionNotification
()
.
UseApi
();
}
else
{
fullNodeBuilder
=
new
FullNodeBuilder
()
.
UseNodeSettings
(
nodeSettings
)
.
UseConsensus
()
.
UseBlockStore
()
.
UseMempool
()
.
UseWallet
()
.
UseApi
();
}
}
// add the tumbler's settings
var
tumblerAddress
=
args
.
SingleOrDefault
(
arg
=>
arg
.
StartsWith
(
"-tumbler-uri="
));
if
(!
string
.
IsNullOrEmpty
(
tumblerAddress
))
{
tumblerAddress
=
tumblerAddress
.
Replace
(
"-tumbler-uri="
,
string
.
Empty
);
fullNodeBuilder
.
UseTumbleBit
(
new
Uri
(
tumblerAddress
));
}
var
node
=
fullNodeBuilder
.
Build
();
//start Full Node - this will also start the API
node
.
Run
();
}
private
static
Network
InitStratisTest
()
{
Block
.
BlockSignature
=
true
;
Transaction
.
TimeStamp
=
true
;
var
consensus
=
Network
.
StratisMain
.
Consensus
.
Clone
();
consensus
.
PowLimit
=
new
Target
(
uint256
.
Parse
(
"0000ffff00000000000000000000000000000000000000000000000000000000"
));
// The message start string is designed to be unlikely to occur in normal data.
// The characters are rarely used upper ASCII, not valid as UTF-8, and produce
// a large 4-byte int at any alignment.
var
pchMessageStart
=
new
byte
[
4
];
pchMessageStart
[
0
]
=
0x71
;
pchMessageStart
[
1
]
=
0x31
;
pchMessageStart
[
2
]
=
0x21
;
pchMessageStart
[
3
]
=
0x11
;
var
magic
=
BitConverter
.
ToUInt32
(
pchMessageStart
,
0
);
//0x5223570;
var
genesis
=
Network
.
StratisMain
.
GetGenesis
().
Clone
();
genesis
.
Header
.
Time
=
1493909211
;
genesis
.
Header
.
Nonce
=
2433759
;
genesis
.
Header
.
Bits
=
consensus
.
PowLimit
;
consensus
.
HashGenesisBlock
=
genesis
.
GetHash
();
Guard
.
Assert
(
consensus
.
HashGenesisBlock
==
uint256
.
Parse
(
"0x00000e246d7b73b88c9ab55f2e5e94d9e22d471def3df5ea448f5576b1d156b9"
));
var
builder
=
new
NetworkBuilder
()
.
SetName
(
"StratisTest"
)
.
SetConsensus
(
consensus
)
.
SetMagic
(
magic
)
.
SetGenesis
(
genesis
)
.
SetPort
(
26178
)
.
SetRPCPort
(
26174
)
.
SetBase58Bytes
(
Base58Type
.
PUBKEY_ADDRESS
,
new
byte
[]
{
(
65
)
})
.
SetBase58Bytes
(
Base58Type
.
SCRIPT_ADDRESS
,
new
byte
[]
{
(
196
)
})
.
SetBase58Bytes
(
Base58Type
.
SECRET_KEY
,
new
byte
[]
{
(
65
+
128
)
})
.
SetBase58Bytes
(
Base58Type
.
ENCRYPTED_SECRET_KEY_NO_EC
,
new
byte
[]
{
0x01
,
0x42
})
.
SetBase58Bytes
(
Base58Type
.
ENCRYPTED_SECRET_KEY_EC
,
new
byte
[]
{
0x01
,
0x43
})
.
SetBase58Bytes
(
Base58Type
.
EXT_PUBLIC_KEY
,
new
byte
[]
{
(
0x04
),
(
0x88
),
(
0xB2
),
(
0x1E
)
})
.
SetBase58Bytes
(
Base58Type
.
EXT_SECRET_KEY
,
new
byte
[]
{
(
0x04
),
(
0x88
),
(
0xAD
),
(
0xE4
)
})
.
AddDNSSeeds
(
new
[]
{
new
DNSSeedData
(
"stratisplatform.com"
,
"testnode1.stratisplatform.com"
),
});
return
builder
.
BuildAndRegister
();
}
}
private
static
Network
InitStratisTest
()
{
Block
.
BlockSignature
=
true
;
Transaction
.
TimeStamp
=
true
;
var
consensus
=
Network
.
StratisMain
.
Consensus
.
Clone
();
consensus
.
PowLimit
=
new
Target
(
uint256
.
Parse
(
"0000ffff00000000000000000000000000000000000000000000000000000000"
));
// The message start string is designed to be unlikely to occur in normal data.
// The characters are rarely used upper ASCII, not valid as UTF-8, and produce
// a large 4-byte int at any alignment.
var
pchMessageStart
=
new
byte
[
4
];
pchMessageStart
[
0
]
=
0x71
;
pchMessageStart
[
1
]
=
0x31
;
pchMessageStart
[
2
]
=
0x21
;
pchMessageStart
[
3
]
=
0x11
;
var
magic
=
BitConverter
.
ToUInt32
(
pchMessageStart
,
0
);
//0x5223570;
var
genesis
=
Network
.
StratisMain
.
GetGenesis
().
Clone
();
genesis
.
Header
.
Time
=
1493909211
;
genesis
.
Header
.
Nonce
=
2433759
;
genesis
.
Header
.
Bits
=
consensus
.
PowLimit
;
consensus
.
HashGenesisBlock
=
genesis
.
GetHash
();
Guard
.
Assert
(
consensus
.
HashGenesisBlock
==
uint256
.
Parse
(
"0x00000e246d7b73b88c9ab55f2e5e94d9e22d471def3df5ea448f5576b1d156b9"
));
var
builder
=
new
NetworkBuilder
()
.
SetName
(
"StratisTest"
)
.
SetConsensus
(
consensus
)
.
SetMagic
(
magic
)
.
SetGenesis
(
genesis
)
.
SetPort
(
26178
)
.
SetRPCPort
(
26174
)
.
SetBase58Bytes
(
Base58Type
.
PUBKEY_ADDRESS
,
new
byte
[]
{
(
65
)
})
.
SetBase58Bytes
(
Base58Type
.
SCRIPT_ADDRESS
,
new
byte
[]
{
(
196
)
})
.
SetBase58Bytes
(
Base58Type
.
SECRET_KEY
,
new
byte
[]
{
(
65
+
128
)
})
.
SetBase58Bytes
(
Base58Type
.
ENCRYPTED_SECRET_KEY_NO_EC
,
new
byte
[]
{
0x01
,
0x42
})
.
SetBase58Bytes
(
Base58Type
.
ENCRYPTED_SECRET_KEY_EC
,
new
byte
[]
{
0x01
,
0x43
})
.
SetBase58Bytes
(
Base58Type
.
EXT_PUBLIC_KEY
,
new
byte
[]
{
(
0x04
),
(
0x88
),
(
0xB2
),
(
0x1E
)
})
.
SetBase58Bytes
(
Base58Type
.
EXT_SECRET_KEY
,
new
byte
[]
{
(
0x04
),
(
0x88
),
(
0xAD
),
(
0xE4
)
})
.
AddDNSSeeds
(
new
[]
{
new
DNSSeedData
(
"stratisplatform.com"
,
"testnode1.stratisplatform.com"
),
});
return
builder
.
BuildAndRegister
();
}
}
}
Breeze/src/Breeze.Daemon/Properties/launchSettings.json
View file @
bb43fb28
{
"profiles"
:
{
"Breeze.Daemon Main"
:
{
"commandName"
:
"Project"
"commandName"
:
"Project"
,
"commandLineArgs"
:
"light"
},
"Breeze.Daemon TestNet"
:
{
"commandName"
:
"Project"
,
"commandLineArgs"
:
"-testnet -tumbler-uri=http://localhost:5050"
"commandLineArgs"
:
"-testnet -tumbler-uri=http://localhost:5050
light -debug
"
}
}
}
\ No newline at end of file
Breeze/src/Breeze.Wallet/LightWalletFeature.cs
View file @
bb43fb28
using
Stratis.Bitcoin.Builder.Feature
;
using
Microsoft.Extensions.DependencyInjection
;
using
Stratis.Bitcoin.Builder
;
using
Stratis.Bitcoin.Logging
;
using
Microsoft.Extensions.Logging
;
using
Serilog
;
using
Stratis.Bitcoin.Wallet
;
using
Stratis.Bitcoin.Wallet.Controllers
;
...
...
@@ -11,16 +8,16 @@ namespace Breeze.Wallet
{
public
class
LightWalletFeature
:
FullNodeFeature
{
private
readonly
LightWalletSyncManager
lightW
alletSyncManager
;
private
readonly
IWalletSyncManager
w
alletSyncManager
;
public
LightWalletFeature
(
LightWalletSyncManager
lightW
alletSyncManager
)
{
this
.
lightWalletSyncManager
=
lightW
alletSyncManager
;
}
public
LightWalletFeature
(
IWalletSyncManager
w
alletSyncManager
)
{
this
.
walletSyncManager
=
w
alletSyncManager
;
}
public
override
void
Start
()
{
this
.
lightW
alletSyncManager
.
Initialize
();
this
.
w
alletSyncManager
.
Initialize
();
}
public
override
void
Stop
()
...
...
@@ -30,7 +27,7 @@ namespace Breeze.Wallet
}
public
static
class
LightWalletFeatureExtension
{
{
public
static
IFullNodeBuilder
UseLightWallet
(
this
IFullNodeBuilder
fullNodeBuilder
)
{
fullNodeBuilder
.
ConfigureFeature
(
features
=>
...
...
@@ -40,10 +37,10 @@ namespace Breeze.Wallet
.
FeatureServices
(
services
=>
{
services
.
AddSingleton
<
IWalletSyncManager
,
LightWalletSyncManager
>();
services
.
AddSingleton
<
IWalletManager
,
WalletManager
>();
services
.
AddSingleton
<
WalletController
>();
services
.
AddSingleton
<
IWalletManager
,
WalletManager
>();
services
.
AddSingleton
<
WalletController
>();
});
});
});
return
fullNodeBuilder
;
...
...
Breeze/src/Breeze.Wallet/LightWalletSyncManager.cs
View file @
bb43fb28
...
...
@@ -8,32 +8,46 @@ using Stratis.Bitcoin;
using
Stratis.Bitcoin.Notifications
;
using
Stratis.Bitcoin.Utilities
;
using
Stratis.Bitcoin.Wallet
;
using
Stratis.Bitcoin.Wallet.Notifications
;
namespace
Breeze.Wallet
{
public
class
LightWalletSyncManager
:
WalletSyncManager
public
class
LightWalletSyncManager
:
I
WalletSyncManager
{
private
readonly
WalletManager
walletManager
;
private
readonly
ConcurrentChain
chain
;
private
readonly
BlockNotification
blockNotification
;
private
readonly
CoinType
coinType
;
private
readonly
ILogger
logger
;
private
readonly
Signals
signals
;
public
LightWalletSyncManager
(
ILoggerFactory
loggerFactory
,
IWalletManager
walletManager
,
ConcurrentChain
chain
,
Network
network
,
BlockNotification
blockNotification
)
:
base
(
loggerFactory
,
walletManager
,
chain
,
network
)
public
LightWalletSyncManager
(
ILoggerFactory
loggerFactory
,
IWalletManager
walletManager
,
ConcurrentChain
chain
,
Network
network
,
BlockNotification
blockNotification
,
Signals
signals
)
//
:base(loggerFactory, walletManager, chain, network)
{
this
.
walletManager
=
walletManager
as
WalletManager
;
this
.
chain
=
chain
;
this
.
signals
=
signals
;
this
.
blockNotification
=
blockNotification
;
this
.
coinType
=
(
CoinType
)
network
.
Consensus
.
CoinType
;
this
.
logger
=
loggerFactory
.
CreateLogger
(
this
.
GetType
().
FullName
);
}
/// <inheritdoc />
public
override
void
Initialize
()
public
async
Task
Initialize
()
{
// get the chain headers. This needs to be up-to-date before we really do anything
this
.
WaitForChainDownloadAsync
().
GetAwaiter
().
GetResult
();
await
this
.
WaitForChainDownloadAsync
();
// subscribe to receiving blocks and transactions
BlockSubscriber
sub
=
new
BlockSubscriber
(
this
.
signals
.
Blocks
,
new
BlockObserver
(
this
.
chain
,
this
));
sub
.
Subscribe
();
TransactionSubscriber
txSub
=
new
TransactionSubscriber
(
this
.
signals
.
Transactions
,
new
TransactionObserver
(
this
));
txSub
.
Subscribe
();
// start syncing blocks
var
bestHeightForSyncing
=
this
.
FindBestHeightForSyncing
();
this
.
SyncFrom
(
bestHeightForSyncing
);
this
.
logger
.
LogInformation
(
$"Tracker initialized. Syncing from
{
bestHeightForSyncing
}
."
);
}
private
int
FindBestHeightForSyncing
()
...
...
@@ -75,7 +89,7 @@ namespace Breeze.Wallet
}
/// <inheritdoc />
public
override
void
SyncFrom
(
DateTime
date
)
public
void
SyncFrom
(
DateTime
date
)
{
int
blockSyncStart
=
this
.
chain
.
GetHeightAtTime
(
date
);
...
...
@@ -84,9 +98,22 @@ namespace Breeze.Wallet
}
/// <inheritdoc />
public
override
void
SyncFrom
(
int
height
)
public
void
SyncFrom
(
int
height
)
{
this
.
blockNotification
.
SyncFrom
(
this
.
chain
.
GetBlock
(
height
).
HashBlock
);
}
public
void
ProcessBlock
(
Block
block
)
{
var
hash
=
block
.
Header
.
GetHash
();
var
height
=
this
.
chain
.
GetBlock
(
hash
).
Height
;
this
.
walletManager
.
ProcessBlock
(
height
,
block
);
}
public
void
ProcessTransaction
(
Transaction
transaction
)
{
this
.
walletManager
.
ProcessTransaction
(
transaction
);
}
}
}
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