Skip to content

Commit

Permalink
Merge pull request #9 from karlsen-network/mainnet_karlsenhashv2
Browse files Browse the repository at this point in the history
upstream merge
  • Loading branch information
okilisan authored Aug 29, 2024
2 parents 54812f1 + a133806 commit f098efb
Show file tree
Hide file tree
Showing 18 changed files with 105 additions and 225 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/SetPageFileSize.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#>

param(
[System.UInt64] $MinimumSize = 16gb ,
[System.UInt64] $MaximumSize = 16gb ,
[System.UInt64] $MinimumSize = 32gb ,
[System.UInt64] $MaximumSize = 32gb ,
[System.String] $DiskRoot = "D:"
)

Expand Down Expand Up @@ -193,4 +193,4 @@ namespace Util
Add-Type -TypeDefinition $source

# Set SetPageFileSize
[Util.PageFile]::SetPageFileSize($minimumSize, $maximumSize, $diskRoot)
[Util.PageFile]::SetPageFileSize($minimumSize, $maximumSize, $diskRoot)
48 changes: 0 additions & 48 deletions .github/workflows/race.yaml

This file was deleted.

36 changes: 26 additions & 10 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,36 @@ jobs:
if: runner.os == 'Windows'
run: powershell -command .github\workflows\SetPageFileSize.ps1

# Increase the swap size on Linux to aviod running out of memory
- name: Increase swap size on Linux
if: runner.os == 'Linux'
uses: thejerrybao/setup-swap-space@v1
with:
swap-size-gb: 12

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: 1.21

# Source: https://github.com/actions/cache/blob/main/examples.md#go---modules
- name: Go Cache
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Test
shell: bash
env:
NO_PARALLEL: 1
run: ./build_and_test.sh

stability-test-fast:
runs-on: ubuntu-latest
name: Fast stability tests
steps:

# Increase the swap size on Linux to aviod running out of memory
- name: Increase swap size on Linux
if: runner.os == 'Linux'
uses: thejerrybao/setup-swap-space@v1
with:
swap-size-gb: 12

- name: Setup Go
uses: actions/setup-go@v4
with:
Expand All @@ -71,6 +79,14 @@ jobs:
runs-on: ubuntu-latest
name: Produce code coverage
steps:

# Increase the swap size on Linux to aviod running out of memory
- name: Increase swap size on Linux
if: runner.os == 'Linux'
uses: thejerrybao/setup-swap-space@v1
with:
swap-size-gb: 12

- name: Check out code into the Go module directory
uses: actions/checkout@v4

Expand All @@ -83,7 +99,7 @@ jobs:
run: rm -r stability-tests

- name: Create coverage file
run: go test -v -covermode=atomic -coverpkg=./... -coverprofile coverage.txt ./...
run: go test -timeout 120m -parallel=1 -v -covermode=atomic -coverpkg=./... -coverprofile coverage.txt ./...

- name: Upload coverage file
run: bash <(curl -s https://codecov.io/bash)
43 changes: 34 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,15 @@ miners. We will ensure long-term GPU-friendly mining.
### Hashing Function

We initially started with `kHeavyHash` and `blake3` modifications
on-top. This algorithm is called `KarlsenHashv1`. However `kHeavyHash`
and `blake3` are not future proof in ASIC resistence. Therefore we've
launched already our `testnet-1` with [FishHash](https://github.com/iron-fish/fish-hash/blob/main/FishHash.pdf).
It is the worlds first implementation of FishHash with Golang in a
1bps blockchain.
on-top. This algorithm is called `KarlsenHashv1`.

`KarlsenHashv1` is currently used in [mainnet](https://github.com/karlsen-network/karlsend/releases/tag/v1.1.0)
and can be mined using the following miners maintained by the Karlsen
developers:

* Built-in CPU miner from `karlsend`
* Karlsen [GPU miner](https://github.com/karlsen-network/karlsen-miner) as reference implementation of `kHeavyHash` with `blake3`.
* Karlsen [GPU miner](https://github.com/karlsen-network/karlsen-miner)
as reference implementation of `kHeavyHash` with `blake3`.

The following third-party miners are available and have added
`KarlsenHashv1`:
Expand All @@ -61,14 +58,42 @@ The following third-party miners are available and have added
* [Rigel](https://github.com/rigelminer/rigel)
* [GMiner](https://github.com/develsoftware/GMinerRelease)

`KarlsenHashv2` is currently being investigated and tested in [testnet-1](https://github.com/karlsen-network/karlsend/releases/tag/v2.0.0-testnet-1-fishhash)
`KarlsenHashv2` will become active via hardfork at DAA score `26.962.009`.
It is based on [FishHash](https://github.com/iron-fish/fish-hash/blob/main/FishHash.pdf)
written from scratch in our Golang node implementation. It is FPGA/ASIC
resistent. It is the worlds first implementation of FishHash with Golang
in `mainnet` in a 1bps blockchain.

`KarlsenHashv2` is currently used in [mainnet](https://github.com/karlsen-network/karlsend/releases/tag/v2.1.0)
and can be mined using the following miners maintained by the Karlsen
developers:

* Built-in CPU miner from `karlsend`
* Karlsen [GPU miner](https://github.com/wam-rd/karlsen-miner/releases/tag/v2.0.0-alpha) as bleeding edge and unoptimized reference implementation of FishHash.
* Karlsen [GPU miner](https://github.com/karlsen-network/karlsen-miner/releases/tag/v2.0.0)
as bleeding edge and unoptimized reference implementation of
`KarlsenHashv2`. Please follow the steps in the [README.md](https://github.com/karlsen-network/karlsen-miner/blob/main/README.md)
to generate a DAG file.

The following third-party miners are available and have added
`KarlsenHashv2`:

* [SRBMiner](https://github.com/doktor83/SRBMiner-Multi)

### DAG Generation

To start mining using the built-in CPU miner it needs a pre-generated
DAG file. `KarlsenHashv2` miner uses a 4GB DAG for efficient mining.
It generates this DAG with 8 CPU threads and saves it as `hashes.dat`
for faster subsequent runs.

* First Run: Generates a 4GB DAG using 8 CPU threads. This may take
time depending on your computer. Saves the DAG as `hashes.dat` for
future use.
* Next Runs: Loads `hashes.dat` to skip DAG generation, speeding up
startup.

There are no third-party miners available as of now.
If you need to regenerate the DAG, delete `hashes.dat` and run the
`karlsenminer` again.

## Smart Contracts

Expand Down
5 changes: 0 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ func (app *karlsendApp) main(startedChan chan<- struct{}) error {
// Show version at startup.
log.Infof("Version %s", version.Version())
log.Infof("Using KarlsenHashV2 impl: %s", pow.GetHashingAlgoVersion())
if !app.cfg.Testnet && !app.cfg.Devnet && !app.cfg.Simnet {
log.Warnf("You are trying to connect to Mainnet")
log.Errorf("This version is using KarlsenHashV2, please add --testnet parameter")
os.Exit(42)
}

// Enable http profiling server if requested.
if app.cfg.Profile != "" {
Expand Down
4 changes: 2 additions & 2 deletions build_and_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ go build -v -o karlsend .

# check if parallel tests are enabled.
[ -n "${NO_PARALLEL}" ] && {
go test -timeout 20m -parallel=1 -v ./...
go test -timeout 30m -parallel=1 -v ./...
} || {
go test -timeout 20m -v ./...
go test -timeout 30m -v ./...
}
2 changes: 1 addition & 1 deletion domain/consensus/processes/pruningmanager/pruning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestPruning(t *testing.T) {
dagconfig.MainnetParams.Name: "503",
dagconfig.TestnetParams.Name: "502",
dagconfig.DevnetParams.Name: "503",
dagconfig.SimnetParams.Name: "502",
dagconfig.SimnetParams.Name: "503",
},
}

Expand Down
2 changes: 1 addition & 1 deletion domain/consensus/utils/pow/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import (
"github.com/karlsen-network/karlsend/util/panics"
)

var log = logger.RegisterSubSystem("POW")
var log = logger.RegisterSubSystem("POWK")
var spawn = panics.GoroutineWrapperFunc(log)
6 changes: 3 additions & 3 deletions domain/consensus/utils/pow/pow.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func getContext(full bool, log *logger.Logger) *fishhashContext {

// SetLogger uses a specified Logger to output package logging info
func SetLogger(backend *logger.Backend, level logger.Level) {
const logSubsystem = "POW"
const logSubsystem = "POWK"
log = backend.Logger(logSubsystem)
log.SetLevel(level)
spawn = panics.GoroutineWrapperFunc(log)
Expand Down Expand Up @@ -145,10 +145,10 @@ func (state *State) CalculateProofOfWorkValue() *big.Int {
//log.Infof("Hash b3-1: %x", powHash.ByteSlice())
finalHash := powHash
if state.blockVersion == constants.BlockVersionKHashV1 {
log.Debugf("Using khashv1 %d %d\n", state.blockVersion, constants.BlockVersionKHashV1)
log.Debugf("Using khashv1 %d %d", state.blockVersion, constants.BlockVersionKHashV1)
finalHash = state.mat.HeavyHash(powHash)
} else {
log.Debugf("Using khashv2 %d %d\n", state.blockVersion, constants.BlockVersionKHashV1)
log.Debugf("Using khashv2 %d %d", state.blockVersion, constants.BlockVersionKHashV2)
middleHash := fishHashPlus(&state.context, powHash)
writer2 := hashes.NewPoWHashWriter()
writer2.InfallibleWrite(middleHash.ByteSlice())
Expand Down
2 changes: 1 addition & 1 deletion domain/dagconfig/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ var devnetGenesisBlock = externalapi.DomainBlock{
&externalapi.DomainHash{},
externalapi.NewDomainHashFromByteArray(muhash.EmptyMuHashHash.AsArray()),
0x11e9db49828,
525264379,
0x1f4ee5fb,
0x48e5e,
0,
0,
Expand Down
7 changes: 3 additions & 4 deletions domain/dagconfig/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,7 @@ var MainnetParams = Params{
// This means that any block that has a level lower or equal to genesis will be level 0.
MaxBlockLevel: 225,
MergeDepth: defaultMergeDepth,
// todo: define the fork date DAAscore
HFDAAScore: 42000042,
HFDAAScore: 26962009, // HF DAAscore to switch to khashv2 (Fri Sep 13 01:37:00 PM UTC 2024)
}

// TestnetParams defines the network parameters for the test Karlsen network.
Expand Down Expand Up @@ -344,8 +343,7 @@ var TestnetParams = Params{

MaxBlockLevel: 250,
MergeDepth: defaultMergeDepth,
// todo: define the fork date DAAscore
HFDAAScore: 6000000,
HFDAAScore: 6000000, // TODO: define the fork date DAAscore
}

// SimnetParams defines the network parameters for the simulation test Karlsen
Expand Down Expand Up @@ -412,6 +410,7 @@ var SimnetParams = Params{

MaxBlockLevel: 250,
MergeDepth: defaultMergeDepth,
HFDAAScore: 50,
}

// DevnetParams defines the network parameters for the development Karlsen network.
Expand Down
13 changes: 6 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,20 @@ require (
github.com/pkg/errors v0.9.1
github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d
github.com/tyler-smith/go-bip39 v1.1.0
golang.org/x/crypto v0.19.0
golang.org/x/crypto v0.26.0
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a
golang.org/x/term v0.17.0
golang.org/x/term v0.23.0
google.golang.org/grpc v1.61.1
google.golang.org/protobuf v1.32.0
google.golang.org/protobuf v1.34.2
lukechampine.com/blake3 v1.2.1
)

require (
github.com/golang/snappy v0.0.4 // indirect
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
)
Loading

0 comments on commit f098efb

Please sign in to comment.