-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Hashcash
algorithm configurable
#1352
Conversation
Hashcash
algorithm configurableHashcash
algorithm configurable
Codecov Report
@@ Coverage Diff @@
## main #1352 +/- ##
==========================================
- Coverage 86.03% 77.19% -8.84%
==========================================
Files 361 256 -105
Lines 32457 17257 -15200
==========================================
- Hits 27925 13322 -14603
- Misses 2747 3371 +624
+ Partials 1785 564 -1221
|
de3d68e
to
704c285
Compare
@@ -211,10 +214,13 @@ public void DetectInvalidProtocolVersion() | |||
new Transaction<DumbAction>[] { }, | |||
protocolVersion: -1 | |||
); | |||
Assert.Throws<InvalidBlockProtocolVersionException>(() => block.Validate(now)); | |||
Assert.Throws<InvalidBlockProtocolVersionException>( | |||
() => block.Validate(_fx.GetHashAlgorithm(_fx.Next.Index), now) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may need ValidationContext
to consolidate the hash algorithm and DateTime... 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As HashAlgorithmGetter
is usually from IBlockPolicy.GetHashAlgorithm
, even if we make a new data type its construction would be unnatural IMHO.
704c285
to
72b8f89
Compare
72b8f89
to
d4bc53f
Compare
d4bc53f
to
5448b39
Compare
5448b39
to
cc8faa8
Compare
1cb5963
to
8dc9f89
Compare
This patch enables blockchain to consist of blocks with heterogeneous hash algorithms. Few points:
IBlockPolicy<T>.GetHashAlgorithm(long blockIndex)
determines a hash algorithm for a block atblockIndex
.BlockPolicy<T>()
constructor takes an optionalhashAlgorithmGetter
which configures the above method. If omitted SHA-256 is used for every block in the chain.HashAlgorithmTable.ToHashAlgoirthmGetter()
extension method can be useful to describe a simple rule to determine hash algorithms by block indices. E.g.,new Dictionary<long, HashAlgorithmType> { [0] = HashAlgorithmType.Of<SHA256>(), [1000] = HashAlgorithmType.Of<SHA512>() }.ToHashAlgorithmGetter()
is equivalent to(idx) => idx >= 1000 ? HashAlgorithmType.Of<SHA512>() : HashAlgorithmType.Of<SHA256>()
.HashAlgorithmType
is a type for comparing hash algorithms.Of<T>()
method, likeHashAlgorithmType.Of<SHA256>()
.HashAlgorithmType.Of<SHA256>() != HashAlgorithmType.Of<SHA1>()
,HashAlgorithmType.Of<SHA256>().Equals(HashAlgorithmType.Of<SHA256>())
. Also can be elements ofISet<T>
/IImmutableSet<T>
or keys ofIDictionary<TKey, TValue>
/IImmutableDictionary<TKey, TValue>
.Block<T>.Hash
, butBlock<T>.PreEvaluationHash
,BlockHash
became fixed-size (32 bytes).Block<T>.PreEvaluationHash
became represented as variable-lengthImmutableArray<byte>
(instead ofBlockHash
, which was misleading).