Skip to content

Commit c495726

Browse files
committed
Update Phihash to PhihashV2
1 parent f4b08b9 commit c495726

File tree

19 files changed

+968
-804
lines changed

19 files changed

+968
-804
lines changed

src/Miningcore/Blockchain/Progpow/ProgpowConstants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class TelestaiConstants
5656

5757
public class PhicoinConstants
5858
{
59-
public const int EpochLength = 2102400;
59+
public const int EpochLength = 30000;
6060
public static BigInteger BigMaxValue = BigInteger.Pow(2, 256);
6161
public static readonly BigInteger Diff1B = BigInteger.Parse("00000000ff000000000000000000000000000000000000000000000000000000", NumberStyles.AllowHexSpecifier, null);
6262
public static readonly BigInteger Diff1 = BigInteger.Parse("00000000ff000000000000000000000000000000000000000000000000000000", NumberStyles.HexNumber);

src/Miningcore/Crypto/Hashing/Progpow/Phihash/Cache.cs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,37 @@ public void Dispose()
3535
}
3636
}
3737

38-
public async Task GenerateAsync(ILogger logger)
38+
public async Task GenerateAsync(ILogger logger, CancellationToken ct)
3939
{
40-
await Task.Run(() =>
40+
if(handle == IntPtr.Zero)
4141
{
42-
lock(genLock)
42+
await Task.Run(() =>
4343
{
44-
if(!isGenerated)
44+
lock(genLock)
4545
{
46-
47-
var started = DateTime.Now;
48-
logger.Debug(() => $"Generating cache for epoch {Epoch}");
49-
50-
handle = PhiHash.CreateContext(Epoch);
51-
52-
logger.Debug(() => $"Done generating cache for epoch {Epoch} after {DateTime.Now - started}");
53-
isGenerated = true;
54-
55-
// get the seed hash for this epoch
56-
var res = PhiHash.calculate_epoch_seed(Epoch);
57-
SeedHash = res.bytes;
58-
logger.Info(() => $"Seed hash for epoch {Epoch} is {SeedHash.ToHexString()}");
46+
if(!isGenerated)
47+
{
48+
// re-check after obtaining lock
49+
if(handle != IntPtr.Zero)
50+
return;
51+
52+
var started = DateTime.Now;
53+
logger.Debug(() => $"Generating cache for epoch {Epoch}");
54+
55+
handle = PhiHash.CreateContext(Epoch);
56+
57+
logger.Debug(() => $"Done generating cache for epoch {Epoch} after {DateTime.Now - started}");
58+
59+
// get the seed hash for this epoch
60+
var res = PhiHash.calculate_epoch_seed(Epoch);
61+
SeedHash = res.bytes;
62+
logger.Info(() => $"Seed hash for epoch {Epoch} is {SeedHash.ToHexString()}");
63+
64+
isGenerated = true;
65+
}
5966
}
60-
}
61-
});
67+
}, ct);
68+
}
6269
}
6370

6471
public unsafe bool Compute(ILogger logger, int blockNumber, byte[] hash, ulong nonce, out byte[] mixDigest, out byte[] result)

src/Miningcore/Crypto/Hashing/Progpow/Phihash/PhihashLight.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ public async Task<IProgpowCache> GetCacheAsync(ILogger logger, int block, Cancel
7272
future = new Cache(epoch + 1);
7373

7474
#pragma warning disable 4014
75-
future.GenerateAsync(logger);
75+
future.GenerateAsync(logger, ct);
7676
#pragma warning restore 4014
7777
}
7878

7979
result.LastUsed = DateTime.Now;
8080
}
8181

8282
// get/generate current one
83-
await result.GenerateAsync(logger);
83+
await result.GenerateAsync(logger, ct);
8484

8585
return result;
8686
}

src/Native/libphihash/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ CXXFLAGS += -g -Wall -fPIC -fpermissive -O2 -Wno-char-subscripts -Wno-unused-var
33
LDFLAGS += -shared
44
TARGET = libphihash.so
55

6-
OBJECTS = ethash/ethash.o keccak/keccak.o keccak/keccakf800.o keccak/keccakf1600.o ethash/managed.o ethash/primes.o ethash/phihash.o
6+
OBJECTS = ethash/ethash.o keccak/keccak.o keccak/keccakf800.o keccak/keccakf1600.o ethash/managed.o ethash/primes.o ethash/phihash.o exports.o
77

88
all: $(TARGET)
99

src/Native/libphihash/attributes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@
3030
__attribute__((no_sanitize(sanitizer)))
3131
#else
3232
#define NO_SANITIZE(sanitizer)
33-
#endif
33+
#endif

src/Native/libphihash/dllmain.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,4 @@ BOOL APIENTRY DllMain( HMODULE hModule,
1515
break;
1616
}
1717
return TRUE;
18-
}
19-
18+
}

src/Native/libphihash/ethash/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
include(GNUInstallDirs)
66

77
add_library(
8-
ethash SHARED
8+
ethash
99
bit_manipulation.h
1010
builtins.h
1111
endianness.hpp
@@ -21,7 +21,6 @@ add_library(
2121
${include_dir}/ethash/phihash.hpp
2222
phihash.cpp
2323
)
24-
set_property(TARGET ethash PROPERTY POSITION_INDEPENDENT_CODE ON)
2524

2625
target_link_libraries(ethash PRIVATE keccak)
2726
target_include_directories(ethash PUBLIC $<BUILD_INTERFACE:${include_dir}>$<INSTALL_INTERFACE:include>)

src/Native/libphihash/ethash/endianness.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,4 @@ struct be
9494
};
9595

9696
#endif
97-
} // namespace ethash
97+
} // namespace ethash

0 commit comments

Comments
 (0)