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
632d01da
Commit
632d01da
authored
Jun 09, 2017
by
Jeremy Bokobza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added the code to create and update tumblebit sessions
parent
ad0d8e76
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
118 additions
and
12 deletions
+118
-12
Breeze.TumbleBit.Client.csproj
...rc/Breeze.TumbleBit.Client/Breeze.TumbleBit.Client.csproj
+1
-0
IStateMachine.cs
Breeze/src/Breeze.TumbleBit.Client/IStateMachine.cs
+5
-0
TumbleBitManager.cs
Breeze/src/Breeze.TumbleBit.Client/TumbleBitManager.cs
+24
-6
TumblingState.cs
Breeze/src/Breeze.TumbleBit.Client/TumblingState.cs
+88
-6
No files found.
Breeze/src/Breeze.TumbleBit.Client/Breeze.TumbleBit.Client.csproj
View file @
632d01da
...
@@ -26,6 +26,7 @@
...
@@ -26,6 +26,7 @@
<ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\StratisBitcoinFullNode\Stratis.Bitcoin.Common\Stratis.Bitcoin.Common.csproj" />
<ProjectReference Include="..\..\..\..\StratisBitcoinFullNode\Stratis.Bitcoin.Common\Stratis.Bitcoin.Common.csproj" />
<ProjectReference Include="..\..\..\..\StratisBitcoinFullNode\Stratis.Bitcoin\Stratis.Bitcoin.csproj" />
<ProjectReference Include="..\..\..\..\StratisBitcoinFullNode\Stratis.Bitcoin\Stratis.Bitcoin.csproj" />
<ProjectReference Include="..\NTumbleBit.Common\NTumbleBit.Common.csproj" />
<ProjectReference Include="..\NTumbleBit\NTumbleBit.csproj" />
<ProjectReference Include="..\NTumbleBit\NTumbleBit.csproj" />
</ItemGroup>
</ItemGroup>
...
...
Breeze/src/Breeze.TumbleBit.Client/IStateMachine.cs
View file @
632d01da
...
@@ -17,5 +17,10 @@
...
@@ -17,5 +17,10 @@
/// Deletes the state of the current tumbling session..
/// Deletes the state of the current tumbling session..
/// </summary>
/// </summary>
void
Delete
();
void
Delete
();
/// <summary>
/// Updates this the state of the current tumbling session.
/// </summary>
void
Update
();
}
}
}
}
Breeze/src/Breeze.TumbleBit.Client/TumbleBitManager.cs
View file @
632d01da
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
;
...
@@ -22,11 +23,13 @@ namespace Breeze.TumbleBit.Client
...
@@ -22,11 +23,13 @@ namespace Breeze.TumbleBit.Client
private
readonly
Network
network
;
private
readonly
Network
network
;
private
TumblingState
tumblingState
;
private
TumblingState
tumblingState
;
private
IDisposable
blockReceiver
;
private
IDisposable
blockReceiver
;
int
lastCycleStarted
;
private
ClassicTumblerParameters
TumblerParameters
{
get
;
set
;
}
private
ClassicTumblerParameters
TumblerParameters
{
get
;
set
;
}
public
TumbleBitManager
(
ILoggerFactory
loggerFactory
,
IWalletManager
walletManager
,
ConcurrentChain
chain
,
Network
network
,
Signals
signals
)
public
TumbleBitManager
(
ILoggerFactory
loggerFactory
,
IWalletManager
walletManager
,
ConcurrentChain
chain
,
Network
network
,
Signals
signals
)
{
{
this
.
lastCycleStarted
=
0
;
this
.
walletManager
=
walletManager
;
this
.
walletManager
=
walletManager
;
this
.
chain
=
chain
;
this
.
chain
=
chain
;
this
.
signals
=
signals
;
this
.
signals
=
signals
;
...
@@ -115,12 +118,27 @@ namespace Breeze.TumbleBit.Client
...
@@ -115,12 +118,27 @@ namespace Breeze.TumbleBit.Client
this
.
logger
.
LogDebug
(
$"Receive block with height
{
height
}
"
);
this
.
logger
.
LogDebug
(
$"Receive block with height
{
height
}
"
);
// update the block height in the tumbling state
// update the block height in the tumbling state
if
(
this
.
tumblingState
.
LastBlockReceivedHeight
==
0
)
{
this
.
tumblingState
.
StartHeight
=
height
;
}
this
.
tumblingState
.
LastBlockReceivedHeight
=
height
;
this
.
tumblingState
.
LastBlockReceivedHeight
=
height
;
this
.
tumblingState
.
Save
();
this
.
tumblingState
.
Save
();
// get the next cycle to be started
var
cycle
=
this
.
TumblerParameters
.
CycleGenerator
.
GetRegistratingCycle
(
height
);
// check if we need to start a new session starting from the registration cycle
if
(
this
.
lastCycleStarted
!=
cycle
.
Start
)
{
this
.
lastCycleStarted
=
cycle
.
Start
;
this
.
logger
.
LogDebug
(
$"new registration cycle at
{
cycle
.
Start
}
"
);
if
(
this
.
tumblingState
.
Sessions
.
SingleOrDefault
(
s
=>
s
.
StartCycle
==
cycle
.
Start
)
==
null
)
{
this
.
tumblingState
.
CreateNewSession
(
cycle
.
Start
);
this
.
logger
.
LogDebug
(
$"new session created at
{
cycle
.
Start
}
"
);
}
}
// update the state of the tumbling session in this new block
this
.
tumblingState
.
Update
();
}
}
}
}
}
}
Breeze/src/Breeze.TumbleBit.Client/TumblingState.cs
View file @
632d01da
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.IO
;
using
System.Linq
;
using
System.Runtime.InteropServices
;
using
System.Runtime.InteropServices
;
using
Microsoft.Extensions.Logging
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json
;
using
NTumbleBit.ClassicTumbler
;
using
NTumbleBit.ClassicTumbler
;
using
NTumbleBit.PuzzlePromise
;
using
NTumbleBit.PuzzleSolver
;
namespace
Breeze.TumbleBit.Client
namespace
Breeze.TumbleBit.Client
{
{
...
@@ -16,15 +21,19 @@ namespace Breeze.TumbleBit.Client
...
@@ -16,15 +21,19 @@ namespace Breeze.TumbleBit.Client
[
JsonProperty
(
"tumblerUri"
)]
[
JsonProperty
(
"tumblerUri"
)]
public
Uri
TumblerUri
{
get
;
set
;
}
public
Uri
TumblerUri
{
get
;
set
;
}
[
JsonProperty
(
"startHeight"
)]
public
int
StartHeight
{
get
;
set
;
}
[
JsonProperty
(
"lastBlockReceivedHeight"
)]
[
JsonProperty
(
"lastBlockReceivedHeight"
)]
public
int
LastBlockReceivedHeight
{
get
;
set
;
}
public
int
LastBlockReceivedHeight
{
get
;
set
;
}
[
JsonProperty
(
"destinationWalletName"
)]
[
JsonProperty
(
"destinationWalletName"
)]
public
string
DestinationWalletName
{
get
;
set
;
}
public
string
DestinationWalletName
{
get
;
set
;
}
public
IList
<
Session
>
Sessions
{
get
;
set
;
}
public
TumblingState
()
{
this
.
Sessions
=
new
List
<
Session
>();
}
/// <inheritdoc />
/// <inheritdoc />
public
void
Save
()
public
void
Save
()
{
{
...
@@ -44,6 +53,55 @@ namespace Breeze.TumbleBit.Client
...
@@ -44,6 +53,55 @@ namespace Breeze.TumbleBit.Client
File
.
Delete
(
stateFilePath
);
File
.
Delete
(
stateFilePath
);
}
}
/// <inheritdoc />
public
void
Update
()
{
// get a list of cycles we expect to have at this height
var
cycles
=
this
.
TumblerParameters
.
CycleGenerator
.
GetCycles
(
this
.
LastBlockReceivedHeight
);
var
states
=
cycles
.
SelectMany
(
c
=>
this
.
Sessions
.
Where
(
s
=>
s
.
StartCycle
==
c
.
Start
)).
ToList
();
foreach
(
var
state
in
states
)
{
try
{
// create a new session to be updated
var
session
=
new
Session
();
if
(
state
.
NegotiationClientState
!=
null
)
{
session
.
StartCycle
=
state
.
NegotiationClientState
.
CycleStart
;
session
.
ClientChannelNegotiation
=
new
ClientChannelNegotiation
(
this
.
TumblerParameters
,
state
.
NegotiationClientState
);
}
if
(
state
.
PromiseClientState
!=
null
)
session
.
PromiseClientSession
=
new
PromiseClientSession
(
this
.
TumblerParameters
.
CreatePromiseParamaters
(),
state
.
PromiseClientState
);
if
(
state
.
SolverClientState
!=
null
)
session
.
SolverClientSession
=
new
SolverClientSession
(
this
.
TumblerParameters
.
CreateSolverParamaters
(),
state
.
SolverClientState
);
// update the session
session
.
Update
();
// replace the updated session in the list of existing sessions
int
index
=
this
.
Sessions
.
IndexOf
(
state
);
if
(
index
!=
-
1
)
{
this
.
Sessions
[
index
]
=
session
;
}
this
.
Save
();
}
catch
(
Exception
)
{
throw
;
}
}
}
public
void
CreateNewSession
(
int
start
)
{
this
.
Sessions
.
Add
(
new
Session
{
StartCycle
=
start
});
this
.
Save
();
}
/// <summary>
/// <summary>
/// Loads the saved state of the tumbling execution to the file system.
/// Loads the saved state of the tumbling execution to the file system.
/// </summary>
/// </summary>
...
@@ -81,4 +139,28 @@ namespace Breeze.TumbleBit.Client
...
@@ -81,4 +139,28 @@ namespace Breeze.TumbleBit.Client
return
Path
.
Combine
(
defaultFolderPath
,
StateFileName
);
return
Path
.
Combine
(
defaultFolderPath
,
StateFileName
);
}
}
}
}
public
class
Session
{
public
int
StartCycle
{
get
;
set
;
}
public
ClientChannelNegotiation
.
State
NegotiationClientState
{
get
;
set
;
}
public
PromiseClientSession
.
State
PromiseClientState
{
get
;
set
;
}
public
SolverClientSession
.
State
SolverClientState
{
get
;
set
;
}
public
ClientChannelNegotiation
ClientChannelNegotiation
{
get
;
set
;
}
public
SolverClientSession
SolverClientSession
{
get
;
set
;
}
public
PromiseClientSession
PromiseClientSession
{
get
;
set
;
}
public
void
Update
()
{
}
}
}
}
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