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
5c364b79
Commit
5c364b79
authored
Jun 15, 2017
by
Dan Gershony
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
LightSyncManager to inherit from base
parent
af016950
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
40 deletions
+19
-40
LightWalletFeature.cs
Breeze/src/Breeze.Wallet/LightWalletFeature.cs
+1
-1
LightWalletSyncManager.cs
Breeze/src/Breeze.Wallet/LightWalletSyncManager.cs
+18
-39
No files found.
Breeze/src/Breeze.Wallet/LightWalletFeature.cs
View file @
5c364b79
...
...
@@ -19,8 +19,8 @@ namespace Breeze.Wallet
public
override
void
Start
()
{
this
.
walletSyncManager
.
Initialize
();
this
.
walletManager
.
Initialize
();
this
.
walletSyncManager
.
Initialize
();
}
public
override
void
Stop
()
...
...
Breeze/src/Breeze.Wallet/LightWalletSyncManager.cs
View file @
5c364b79
...
...
@@ -13,7 +13,7 @@ using System.Collections.Generic;
namespace
Breeze.Wallet
{
public
class
LightWalletSyncManager
:
I
WalletSyncManager
public
class
LightWalletSyncManager
:
WalletSyncManager
{
private
readonly
WalletManager
walletManager
;
private
readonly
ConcurrentChain
chain
;
...
...
@@ -22,10 +22,8 @@ namespace Breeze.Wallet
private
readonly
ILogger
logger
;
private
readonly
Signals
signals
;
private
ChainedBlock
lastReceivedBlock
;
public
LightWalletSyncManager
(
ILoggerFactory
loggerFactory
,
IWalletManager
walletManager
,
ConcurrentChain
chain
,
Network
network
,
BlockNotification
blockNotification
,
Signals
signals
)
//
:base(loggerFactory, walletManager, chain, network)
BlockNotification
blockNotification
,
Signals
signals
)
:
base
(
loggerFactory
,
walletManager
,
chain
,
network
)
{
this
.
walletManager
=
walletManager
as
WalletManager
;
this
.
chain
=
chain
;
...
...
@@ -36,7 +34,7 @@ namespace Breeze.Wallet
}
/// <inheritdoc />
public
async
Task
Initialize
()
public
override
async
Task
Initialize
()
{
this
.
lastReceivedBlock
=
this
.
chain
.
GetBlock
(
this
.
walletManager
.
LastReceivedBlock
);
if
(
this
.
lastReceivedBlock
==
null
)
...
...
@@ -52,8 +50,9 @@ namespace Breeze.Wallet
txSub
.
Subscribe
();
// start syncing blocks
var
bestHeightForSyncing
=
this
.
FindBestHeightForSyncing
();
this
.
SyncFrom
(
bestHeightForSyncing
);
this
.
blockNotification
.
SyncFrom
(
this
.
chain
.
GetBlock
(
bestHeightForSyncing
).
HashBlock
);
this
.
logger
.
LogInformation
(
$"Tracker initialized. Syncing from
{
bestHeightForSyncing
}
."
);
}
...
...
@@ -96,22 +95,7 @@ namespace Breeze.Wallet
}
/// <inheritdoc />
public
void
SyncFrom
(
DateTime
date
)
{
int
blockSyncStart
=
this
.
chain
.
GetHeightAtTime
(
date
);
// start syncing blocks
this
.
SyncFrom
(
blockSyncStart
);
}
/// <inheritdoc />
public
void
SyncFrom
(
int
height
)
{
this
.
blockNotification
.
SyncFrom
(
this
.
chain
.
GetBlock
(
height
).
HashBlock
);
}
/// <inheritdoc />
public
void
ProcessBlock
(
Block
block
)
public
override
void
ProcessBlock
(
Block
block
)
{
// if the new block previous hash is the same as the
// wallet hash then just pass the block to the manager
...
...
@@ -125,35 +109,30 @@ namespace Breeze.Wallet
// the current wallet hash was not found on the main chain
// a reorg happenend so bring the wallet back top the last known fork
var
blockstoremove
=
new
List
<
uint256
>();
var
fork
=
this
.
lastReceivedBlock
;
// we walk back the chained block object to find the fork
while
(
this
.
chain
.
GetBlock
(
fork
.
HashBlock
)
==
null
)
{
blockstoremove
.
Add
(
fork
.
HashBlock
);
fork
=
fork
.
Previous
;
}
Guard
.
Assert
(
fork
.
HashBlock
==
block
.
Header
.
HashPrevBlock
);
this
.
walletManager
.
RemoveBlocks
(
fork
);
}
else
if
(
current
.
Height
>
this
.
lastReceivedBlock
.
Height
)
else
{
var
chainedBlock
=
this
.
chain
.
GetBlock
(
block
.
GetHash
());
if
(
chainedBlock
.
Height
>
this
.
lastReceivedBlock
.
Height
)
{
// the wallet is falling behind we need to catch up
this
.
logger
.
LogDebug
(
$"block received with height:
{
current
.
Height
}
and hash:
{
block
.
Header
.
GetHash
()}
is too far in advance. Ignoring
."
);
this
.
SyncFrom
(
this
.
lastReceivedBlock
.
Height
);
this
.
logger
.
LogDebug
(
$"block received with height:
{
current
.
Height
}
and hash:
{
block
.
Header
.
GetHash
()}
is too far in advance. put the pull back
."
);
this
.
blockNotification
.
SyncFrom
(
this
.
lastReceivedBlock
.
HashBlock
);
return
;
}
}
var
chainedBlock
=
this
.
chain
.
GetBlock
(
block
.
GetHash
());
this
.
walletManager
.
ProcessBlock
(
block
,
chainedBlock
);
}
/// <inheritdoc />
public
void
ProcessTransaction
(
Transaction
transaction
)
{
this
.
walletManager
.
ProcessTransaction
(
transaction
);
this
.
lastReceivedBlock
=
this
.
chain
.
GetBlock
(
block
.
GetHash
());
this
.
walletManager
.
ProcessBlock
(
block
,
this
.
lastReceivedBlock
);
}
}
}
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