MCPcopy Create free account
hub / github.com/ethstorage/es-node / hashimoto

Function hashimoto

ethstorage/miner/algorithm.go:18–33  ·  view source on GitHub ↗
(kvEntriesBits, kvSizeBits, sampleSizeBits, shardIdx, randomChecks uint64, sampleReader SampleReader, hash0 common.Hash)

Source from the content-addressed store, hash-verified

16type SampleReader func(uint64, uint64) (common.Hash, error)
17
18func hashimoto(kvEntriesBits, kvSizeBits, sampleSizeBits, shardIdx, randomChecks uint64, sampleReader SampleReader, hash0 common.Hash) (common.Hash, []uint64, error) {
19 var sampleIdxs []uint64
20 rowBits := kvEntriesBits + kvSizeBits - sampleSizeBits
21 for i := uint64(0); i < randomChecks; i++ {
22 parent := big.NewInt(0)
23 parent.Mod(new(big.Int).SetBytes(hash0.Bytes()), big.NewInt(1<<rowBits))
24 sampleIdx := parent.Uint64() + shardIdx<<rowBits
25 encodedSample, err := sampleReader(shardIdx, sampleIdx)
26 if err != nil {
27 return common.Hash{}, nil, err
28 }
29 hash0 = crypto.Keccak256Hash(hash0.Bytes(), encodedSample.Bytes())
30 sampleIdxs = append(sampleIdxs, sampleIdx)
31 }
32 return hash0, sampleIdxs, nil
33}
34
35func initHash(miner common.Address, mixedHash common.Hash, nonce uint64) common.Hash {
36 return crypto.Keccak256Hash(

Callers 1

computeHashMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected