mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-18 02:07:43 +00:00
update fusion.dart to get to runround stage
This commit is contained in:
parent
e91ac3d355
commit
387e4ba99c
1 changed files with 52 additions and 43 deletions
|
@ -204,7 +204,7 @@ class Fusion {
|
||||||
Map<int, int> safety_exess_fees = {};
|
Map<int, int> safety_exess_fees = {};
|
||||||
Map<int, List<int>> tierOutputs ={}; // not sure if this should be using outputs class.
|
Map<int, List<int>> tierOutputs ={}; // not sure if this should be using outputs class.
|
||||||
|
|
||||||
int inactiveTimeLimit = 0;
|
int inactiveTimeLimit = 600000; // this is in ms... equates to 10 minutes.
|
||||||
int tier = 0;
|
int tier = 0;
|
||||||
int covertPort = 0;
|
int covertPort = 0;
|
||||||
bool covertSSL = false;
|
bool covertSSL = false;
|
||||||
|
@ -322,18 +322,13 @@ class Fusion {
|
||||||
await registerAndWait(socketwrapper);
|
await registerAndWait(socketwrapper);
|
||||||
|
|
||||||
|
|
||||||
print ("FUSION DEBUG 273");
|
|
||||||
print ("RETURNING early in fusion_run....");
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
|
||||||
// launch the covert submitter
|
// launch the covert submitter
|
||||||
CovertSubmitter covert = await start_covert();
|
CovertSubmitter covert = await startCovert();
|
||||||
try {
|
try {
|
||||||
// Pool started. Keep running rounds until fail or complete.
|
// Pool started. Keep running rounds until fail or complete.
|
||||||
while (true) {
|
while (true) {
|
||||||
roundcount += 1;
|
roundcount += 1;
|
||||||
if (await run_round(covert)) {
|
if (await runRound(covert)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -344,6 +339,9 @@ class Fusion {
|
||||||
(await connection)?.close();
|
(await connection)?.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print ("RETURNING early in fusion_run....");
|
||||||
|
return;
|
||||||
|
|
||||||
for (int i = 0; i < 60; i++) {
|
for (int i = 0; i < 60; i++) {
|
||||||
if (stopping) {
|
if (stopping) {
|
||||||
break; // not an error
|
break; // not an error
|
||||||
|
@ -389,20 +387,6 @@ class Fusion {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Future<CovertSubmitter> start_covert() async {
|
|
||||||
// Function implementation here...
|
|
||||||
|
|
||||||
// For now, just return a new instance of CovertSubmitter
|
|
||||||
return CovertSubmitter("dummy",0,true,"some_host",0,0,0,0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Future<bool> run_round(CovertSubmitter covert) async {
|
|
||||||
// function implementation here...
|
|
||||||
|
|
||||||
// placeholder return statement
|
|
||||||
return Future.value(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void notify_server_status(bool b, {Tuple? tup}) {
|
void notify_server_status(bool b, {Tuple? tup}) {
|
||||||
// Function implementation goes here
|
// Function implementation goes here
|
||||||
|
@ -823,7 +807,7 @@ static double nextDoubleNonZero(Random rng) {
|
||||||
|
|
||||||
Future<void> registerAndWait(SocketWrapper socketwrapper) async {
|
Future<void> registerAndWait(SocketWrapper socketwrapper) async {
|
||||||
|
|
||||||
print ("DEBUG register and wait top.");
|
var stopwatch = Stopwatch()..start();
|
||||||
// msg can be different classes depending on which protobuf msg is sent.
|
// msg can be different classes depending on which protobuf msg is sent.
|
||||||
dynamic? msg;
|
dynamic? msg;
|
||||||
|
|
||||||
|
@ -865,11 +849,10 @@ static double nextDoubleNonZero(Random rng) {
|
||||||
var tiersStrings = {for (var entry in tierOutputs.entries) entry.key: (entry.key * 1e-8).toStringAsFixed(8).replaceAll(RegExp(r'0+$'), '')};
|
var tiersStrings = {for (var entry in tierOutputs.entries) entry.key: (entry.key * 1e-8).toStringAsFixed(8).replaceAll(RegExp(r'0+$'), '')};
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
print ("RECEIVE LOOP 870............DEBUG");
|
msg = await recv2(socketwrapper,['tierstatusupdate', 'fusionbegin'], timeout: Duration(seconds: 10));
|
||||||
var msg = await recv2(socketwrapper,['tierstatusupdate', 'fusionbegin'], timeout: Duration(seconds: 10));
|
|
||||||
|
|
||||||
var fieldInfoFusionBegin = msg.info_.byName["fusionbegin"];
|
var fieldInfoFusionBegin = msg.info_.byName["fusionbegin"];
|
||||||
if (fieldInfoFusionBegin != null && msg.hasField(fieldInfoFusionBegin.tagNumber)) {
|
if (fieldInfoFusionBegin != null && msg.hasField(fieldInfoFusionBegin.tagNumber)) {
|
||||||
|
print ("DEBUG 867 Fusion Begin message...");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -886,7 +869,7 @@ static double nextDoubleNonZero(Random rng) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool messageIsTierStatusUpdate = msg.hasField(fieldInfo.tagNumber);
|
bool messageIsTierStatusUpdate = msg.hasField(fieldInfo.tagNumber);
|
||||||
|
print ("DEBUG 889 getting tier update.");
|
||||||
|
|
||||||
if (!messageIsTierStatusUpdate) {
|
if (!messageIsTierStatusUpdate) {
|
||||||
throw FusionError('Expected a TierStatusUpdate message');
|
throw FusionError('Expected a TierStatusUpdate message');
|
||||||
|
@ -915,12 +898,8 @@ static double nextDoubleNonZero(Random rng) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var fieldInfoTimeRemaining = entry.value.info_.byName["timeRemaining"];
|
var fieldInfoTimeRemaining = entry.value.info_.byName["timeRemaining"];
|
||||||
if (fieldInfoTimeRemaining == null) {
|
|
||||||
throw FusionError('Expected field not found in message: timeRemaining');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entry.value.hasField(fieldInfoTimeRemaining.tagNumber)) {
|
if (entry.value.hasField(fieldInfoTimeRemaining.tagNumber)) {
|
||||||
|
|
||||||
int tr = entry.value.timeRemaining.toInt();
|
int tr = entry.value.timeRemaining.toInt();
|
||||||
if (besttime == null || tr < besttime) {
|
if (besttime == null || tr < besttime) {
|
||||||
besttime = tr;
|
besttime = tr;
|
||||||
|
@ -933,7 +912,9 @@ static double nextDoubleNonZero(Random rng) {
|
||||||
var displayBest = <String>[];
|
var displayBest = <String>[];
|
||||||
var displayMid = <String>[];
|
var displayMid = <String>[];
|
||||||
var displayQueued = <String>[];
|
var displayQueued = <String>[];
|
||||||
|
|
||||||
for (var tier in tiersSorted) {
|
for (var tier in tiersSorted) {
|
||||||
|
|
||||||
if (statuses.containsKey(tier)) {
|
if (statuses.containsKey(tier)) {
|
||||||
var tierStr = tiersStrings[tier];
|
var tierStr = tiersStrings[tier];
|
||||||
if (tierStr == null) {
|
if (tierStr == null) {
|
||||||
|
@ -951,6 +932,7 @@ static double nextDoubleNonZero(Random rng) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var parts = <String>[];
|
var parts = <String>[];
|
||||||
if (displayBest.isNotEmpty || displayMid.isNotEmpty) {
|
if (displayBest.isNotEmpty || displayMid.isNotEmpty) {
|
||||||
parts.add("Tiers: ${displayBest.join(', ')} ${displayMid.join(', ')}");
|
parts.add("Tiers: ${displayBest.join(', ')} ${displayMid.join(', ')}");
|
||||||
|
@ -961,11 +943,16 @@ static double nextDoubleNonZero(Random rng) {
|
||||||
var tiersString = parts.join(' ');
|
var tiersString = parts.join(' ');
|
||||||
|
|
||||||
if (besttime == null && inactiveTimeLimit != null) {
|
if (besttime == null && inactiveTimeLimit != null) {
|
||||||
if (DateTime.now().millisecondsSinceEpoch > inactiveTimeLimit) {
|
if (stopwatch.elapsedMilliseconds > inactiveTimeLimit) {
|
||||||
throw FusionError('stopping due to inactivity');
|
throw FusionError('stopping due to inactivity');
|
||||||
|
} else {
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (besttime != null) {
|
if (besttime != null) {
|
||||||
status = Tuple<String, String>('waiting', 'Starting in ${besttime}s. $tiersString');
|
status = Tuple<String, String>('waiting', 'Starting in ${besttime}s. $tiersString');
|
||||||
} else if (maxfraction >= 1) {
|
} else if (maxfraction >= 1) {
|
||||||
|
@ -977,35 +964,47 @@ static double nextDoubleNonZero(Random rng) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var fieldInfoFusionBegin = msg.info_.byName["fusionbegin"];
|
var fieldInfoFusionBegin = msg.info_.byName["fusionbegin"];
|
||||||
|
|
||||||
|
// Check if fieldInfoFusionBegin is null
|
||||||
if (fieldInfoFusionBegin == null) {
|
if (fieldInfoFusionBegin == null) {
|
||||||
throw FusionError('Expected field not found in message: fusionbegin');
|
throw FusionError('Expected field not found in message: fusionbegin');
|
||||||
}
|
}
|
||||||
|
|
||||||
bool messageIsFusionBegin = msg.hasField(fieldInfoFusionBegin.tagNumber);
|
bool messageIsFusionBegin = msg.hasField(fieldInfoFusionBegin.tagNumber);
|
||||||
|
|
||||||
|
// Print whether the message is FusionBegin or not
|
||||||
if (!messageIsFusionBegin) {
|
if (!messageIsFusionBegin) {
|
||||||
throw FusionError('Expected a FusionBegin message');
|
throw FusionError('Expected a FusionBegin message');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
t_fusionBegin = DateTime.now();
|
t_fusionBegin = DateTime.now();
|
||||||
|
|
||||||
|
FusionBegin fusionBeginMsg = msg.fusionbegin;
|
||||||
|
|
||||||
var clockMismatch = msg.serverTime - DateTime.now().millisecondsSinceEpoch / 1000;
|
var elapsedSeconds = (stopwatch.elapsedMilliseconds / 1000).toInt();
|
||||||
if (clockMismatch.abs() > Protocol.MAX_CLOCK_DISCREPANCY) {
|
var clockMismatch = fusionBeginMsg.serverTime.toInt() - DateTime.now().millisecondsSinceEpoch / 1000;
|
||||||
throw FusionError("Clock mismatch too large: ${clockMismatch.toStringAsFixed(3)}.");
|
|
||||||
|
|
||||||
|
|
||||||
|
if (clockMismatch.abs().toDouble() > Protocol.MAX_CLOCK_DISCREPANCY) {
|
||||||
|
throw FusionError("Clock mismatch too large: ${(clockMismatch.toDouble()).toStringAsFixed(3)}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
tier = msg.tier;
|
|
||||||
|
tier = fusionBeginMsg.tier.toInt();
|
||||||
|
|
||||||
if (msg is FusionBegin) {
|
if (msg is FusionBegin) {
|
||||||
covertDomainB = Uint8List.fromList(msg.covertDomain);
|
covertDomainB = Uint8List.fromList(msg.covertDomain);
|
||||||
}
|
}
|
||||||
|
|
||||||
covertPort = msg.covertPort;
|
covertPort = fusionBeginMsg.covertPort;
|
||||||
covertSSL = msg.covertSSL;
|
covertSSL = fusionBeginMsg.covertSsl;
|
||||||
beginTime = msg.serverTime;
|
beginTime = fusionBeginMsg.serverTime.toDouble();
|
||||||
|
|
||||||
lastHash = Util.calcInitialHash(tier, covertDomainB, covertPort, covertSSL, beginTime);
|
lastHash = Util.calcInitialHash(tier, covertDomainB, covertPort, covertSSL, beginTime);
|
||||||
|
|
||||||
|
@ -1021,8 +1020,11 @@ static double nextDoubleNonZero(Random rng) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<CovertSubmitter> startCovert() async {
|
Future<CovertSubmitter> startCovert() async {
|
||||||
|
|
||||||
|
print ("DEBUG START COVERT!");
|
||||||
status = Tuple('running', 'Setting up Tor connections');
|
status = Tuple('running', 'Setting up Tor connections');
|
||||||
|
|
||||||
|
|
||||||
String covertDomain;
|
String covertDomain;
|
||||||
try {
|
try {
|
||||||
covertDomain = utf8.decode(covertDomainB);
|
covertDomain = utf8.decode(covertDomainB);
|
||||||
|
@ -1047,6 +1049,8 @@ static double nextDoubleNonZero(Random rng) {
|
||||||
connectTimeout: Protocol.COVERT_CONNECT_TIMEOUT.toInt()
|
connectTimeout: Protocol.COVERT_CONNECT_TIMEOUT.toInt()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
print ("DEBUG return early from covert");
|
||||||
|
return covert;
|
||||||
|
|
||||||
// loop until a just a bit before we're expecting startRound, watching for status updates
|
// loop until a just a bit before we're expecting startRound, watching for status updates
|
||||||
final tend = t_fusionBegin.add(Duration(seconds: (Protocol.WARMUP_TIME - Protocol.WARMUP_SLOP - 1).round()));
|
final tend = t_fusionBegin.add(Duration(seconds: (Protocol.WARMUP_TIME - Protocol.WARMUP_SLOP - 1).round()));
|
||||||
|
@ -1074,7 +1078,9 @@ static double nextDoubleNonZero(Random rng) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void runRound(CovertSubmitter covert) async {
|
Future<bool> runRound(CovertSubmitter covert) async {
|
||||||
|
print ("START OF RUN ROUND");
|
||||||
|
|
||||||
status = Tuple('running', 'Starting round ${roundcount.toString()}');
|
status = Tuple('running', 'Starting round ${roundcount.toString()}');
|
||||||
int timeoutInSeconds = (2 * Protocol.WARMUP_SLOP + Protocol.STANDARD_TIMEOUT).toInt();
|
int timeoutInSeconds = (2 * Protocol.WARMUP_SLOP + Protocol.STANDARD_TIMEOUT).toInt();
|
||||||
var msg = await recv(['startround'], timeout: Duration(seconds: timeoutInSeconds));
|
var msg = await recv(['startround'], timeout: Duration(seconds: timeoutInSeconds));
|
||||||
|
@ -1158,6 +1164,9 @@ static double nextDoubleNonZero(Random rng) {
|
||||||
final blindSigRequests = blindNoncePoints.map((e) => Schnorr.BlindSignatureRequest(roundPubKey, e, sha256(myComponents.elementAt(e)))).toList();
|
final blindSigRequests = blindNoncePoints.map((e) => Schnorr.BlindSignatureRequest(roundPubKey, e, sha256(myComponents.elementAt(e)))).toList();
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
print ("RETURNING EARLY FROM run round .....");
|
||||||
|
return true;
|
||||||
|
|
||||||
final randomNumber = Util.getRandomBytes(32);
|
final randomNumber = Util.getRandomBytes(32);
|
||||||
covert.checkOk();
|
covert.checkOk();
|
||||||
check_stop();
|
check_stop();
|
||||||
|
@ -1581,8 +1590,8 @@ static double nextDoubleNonZero(Random rng) {
|
||||||
// itself needs to check blockchain.
|
// itself needs to check blockchain.
|
||||||
await recv(['restartround'], timeout: Duration(seconds: 2 * (Protocol.STANDARD_TIMEOUT.round() + Protocol.BLAME_VERIFY_TIME.round())));
|
await recv(['restartround'], timeout: Duration(seconds: 2 * (Protocol.STANDARD_TIMEOUT.round() + Protocol.BLAME_VERIFY_TIME.round())));
|
||||||
|
|
||||||
|
return true;
|
||||||
} // end of run_round() function.
|
} // end of runRound() function.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue