public override void Awake(JToken jd = null) { style = jd["style"]?.ToString(); float.TryParse(jd["serviceFee"]?.ToString(), out serviceFee); serviceFee = MathF.Max(0, MathF.Min(1, serviceFee)); if (style == "PPLNS") { string db_path = jd["db_path"]?.ToString(); var DatabasePath = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), db_path); PoolDBStore.Init(DatabasePath); } if (jd["OutTimeDBMiner"] != null) { long.TryParse(jd["OutTimeDBMiner"]?.ToString(), out OutTimeDBMiner); } if (jd["OutTimeDBCounted"] != null) { long.TryParse(jd["OutTimeDBCounted"]?.ToString(), out OutTimeDBCounted); } if (jd["RewardInterval"] != null) { long.TryParse(jd["RewardInterval"]?.ToString(), out RewardInterval); } httpPool = Entity.Root.GetComponentInChild <HttpPool>(); transferProcess = Entity.Root.AddComponent <TransferProcess>(); }
public override void Awake(JToken jd = null) { string db_path = jd["db_path"]?.ToString(); var DatabasePath = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), db_path); PoolDBStore.Init(DatabasePath); style = jd["style"]?.ToString(); float.TryParse(jd["serviceFee"]?.ToString(), out serviceFee); serviceFee = MathF.Max(0, MathF.Min(0.3f, serviceFee)); if (jd["registerPool"] != null) { bool.TryParse(jd["registerPool"]?.ToString(), out registerPool); } if (jd["OutTimeDBMiner"] != null) { long.TryParse(jd["OutTimeDBMiner"]?.ToString(), out OutTimeDBMiner); } if (jd["OutTimeDBCounted"] != null) { long.TryParse(jd["OutTimeDBCounted"]?.ToString(), out OutTimeDBCounted); } if (jd["RewardInterval"] != null) { long.TryParse(jd["RewardInterval"]?.ToString(), out RewardInterval); } if (registerPool) { Log.Info($"Pool.registerPool=true --> Pool.style=SOLO"); style = "SOLO"; RewardInterval = Math.Max(8, Math.Min(32, RewardInterval)); } else if (style == "PPLNS") { #if RELEASE RewardInterval = Math.Max(120, Math.Min(240 * 24, RewardInterval)); #else RewardInterval = Math.Max(32, RewardInterval); #endif } Log.Info($"HttpPool.style = {style}"); Log.Info($"HttpPool.registerPool = {registerPool}"); Log.Info($"HttpPool.RewardInterval = {RewardInterval}"); httpPool = Entity.Root.GetComponentInChild <HttpPool>(); transferProcess = Entity.Root.AddComponent <TransferProcess>(); }
static public void MakeSnapshot(Dictionary <string, string> param) { Console.WriteLine($"levelDB.Init {param["db"]}"); LevelDBStore levelDB = new LevelDBStore(); levelDB.Init(param["db"]); if (param.ContainsKey("height") && long.TryParse(param["height"], out long height)) { levelDB.UndoTransfers(height); } long.TryParse(levelDB.Get("UndoHeight"), out long transferHeight); Console.WriteLine($"transferHeight: {transferHeight}"); var DatabasePath = $"./Data/LevelDB_Snapshot_{transferHeight}"; if (Directory.Exists(DatabasePath)) { Console.WriteLine($"Directory LevelDB_Snapshot Exists"); return; } LevelDBStore snapshotDB = new LevelDBStore(); snapshotDB.Init(DatabasePath); int count = 0; using (var it = levelDB.db.CreateIterator()) { for (it.SeekToFirst(); it.IsValid(); it.Next(), count++) { //Log.Info($"Value as string: {it.KeyAsString()}"); if (it.KeyAsString().IndexOf("_undo_") == -1 && it.KeyAsString().IndexOf("Blocks") != 0 && it.KeyAsString().IndexOf("BlockChain") != 0 && it.KeyAsString().IndexOf("Queue") != 0 && it.KeyAsString().IndexOf("List") != 0 && it.KeyAsString().IndexOf("Heights") != 0 && it.KeyAsString().IndexOf("Undos___") != 0) { if (it.KeyAsString().IndexOf("Trans___") == 0) { var slice = JsonHelper.FromJson <DbCache <BlockSub> .Slice>(it.ValueAsString()); if (slice != null && slice.obj.height != 0) { snapshotDB.Put(it.KeyAsString(), $"{{\"obj\":{{\"height\":{slice.obj.height}}}}}"); Console.WriteLine($"Processed tran: {it.KeyAsString()}"); } } else if (it.KeyAsString().IndexOf("Snap___") == 0) { if (it.KeyAsString().IndexOf("Snap___Rule_") == 0) { var key = it.KeyAsString(); var pos1 = "Snap___Rule_".Length; var pos2 = key.Length; var hegihtTemp1 = key.Substring(pos1, pos2 - pos1); var hegihtTemp2 = long.Parse(hegihtTemp1); if (hegihtTemp2 > transferHeight - 5 && hegihtTemp2 < transferHeight + 5) { snapshotDB.Put(it.KeyAsString(), it.ValueAsString()); Console.WriteLine($"Processed key: {it.KeyAsString()}"); } } else if (it.KeyAsString().IndexOf("_Reward") != -1) { var key = it.KeyAsString(); var pos1 = "Snap___".Length; var pos2 = key.IndexOf("_Reward"); var hegihtTemp1 = key.Substring(pos1, pos2 - pos1); var hegihtTemp2 = long.Parse(hegihtTemp1); if (hegihtTemp2 > transferHeight - 5 && hegihtTemp2 < transferHeight + 5) { snapshotDB.Put(it.KeyAsString(), it.ValueAsString()); Console.WriteLine($"Processed key: {it.KeyAsString()}"); } } else { snapshotDB.Put(it.KeyAsString(), it.ValueAsString()); Console.WriteLine($"Processed key: {it.KeyAsString()}"); } } else { snapshotDB.Put(it.KeyAsString(), it.ValueAsString()); Console.WriteLine($"Processed key: {it.KeyAsString()}"); } } if (count % 1000000 == 0) { Console.WriteLine($"Processed Count:{count}"); } } } using (DbSnapshot dbNew = snapshotDB.GetSnapshot(0, true)) using (DbSnapshot dbOld = levelDB.GetSnapshot()) { for (long ii = transferHeight - 3; ii <= transferHeight + 2; ii++) { Console.WriteLine($"Processed height: {ii}"); var heights = dbOld.Heights.Get(ii.ToString()); for (int jj = 0; jj < heights.Count; jj++) { dbNew.Blocks.Add(heights[jj], dbOld.Blocks.Get(heights[jj])); } dbNew.Heights.Add(ii.ToString(), heights); dbNew.BlockChains.Add(ii.ToString(), dbOld.BlockChains.Get(ii.ToString())); } dbNew.Commit(); } Console.WriteLine($"MakeSnapshot Complete"); while (true) { System.Threading.Thread.Sleep(1000); } }