From 7d63bc3ee796ae7ef0b3ac3a2272e1be71fde933 Mon Sep 17 00:00:00 2001 From: Leon177_7 Date: Mon, 9 Feb 2026 00:32:16 +0100 Subject: [PATCH 1/3] pow: use shared fishhash context pointer --- domain/consensus/utils/pow/pow.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/domain/consensus/utils/pow/pow.go b/domain/consensus/utils/pow/pow.go index b8771b8e12..33580472f8 100644 --- a/domain/consensus/utils/pow/pow.go +++ b/domain/consensus/utils/pow/pow.go @@ -24,7 +24,7 @@ type State struct { Target big.Int prePowHash externalapi.DomainHash //cache cache - context fishhashContext + context *fishhashContext blockVersion uint16 } @@ -102,7 +102,7 @@ func NewState(header externalapi.MutableBlockHeader, generatedag bool) *State { mat: *generateMatrix(prePowHash), Timestamp: timestamp, Nonce: nonce, - context: *getContext(generatedag, log), + context: getContext(generatedag, log), blockVersion: header.Version(), } } @@ -114,7 +114,7 @@ func GetHashingAlgoVersion() string { // IsContextReady checks the readiness of the context func (state *State) IsContextReady() bool { - if state != nil { + if state != nil && state.context != nil { return state.context.ready } return false @@ -149,7 +149,7 @@ func (state *State) CalculateProofOfWorkValue() *big.Int { finalHash = state.mat.HeavyHash(powHash) } else { log.Debugf("Using khashv2 %d %d", state.blockVersion, constants.BlockVersionKHashV2) - middleHash := fishHashPlus(&state.context, powHash) + middleHash := fishHashPlus(state.context, powHash) writer2 := hashes.NewPoWHashWriter() writer2.InfallibleWrite(middleHash.ByteSlice()) finalHash = writer2.Finalize() From 928e884a4dc41fb562ac60f966490b09cfaea687 Mon Sep 17 00:00:00 2001 From: Leon177_7 Date: Mon, 9 Feb 2026 21:29:25 +0100 Subject: [PATCH 2/3] pow: generate mat for KHashV1 only --- domain/consensus/utils/pow/pow.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/domain/consensus/utils/pow/pow.go b/domain/consensus/utils/pow/pow.go index 33580472f8..ec3ff276c0 100644 --- a/domain/consensus/utils/pow/pow.go +++ b/domain/consensus/utils/pow/pow.go @@ -18,7 +18,7 @@ const hashingAlgoVersion = "fishhash-kls-0.0.2" // State is an intermediate data structure with pre-computed values to speed up mining. type State struct { - mat matrix + mat *matrix // can be nil Timestamp int64 Nonce uint64 Target big.Int @@ -95,11 +95,17 @@ func NewState(header externalapi.MutableBlockHeader, generatedag bool) *State { log.Debugf("BlueWork[%s] BlueScore[%d] DAAScore[%d] Version[%d]", header.BlueWork(), header.BlueScore(), header.DAAScore(), header.Version()) + var mat *matrix + // only generate matrix if using khashv1 + if header.Version() == constants.BlockVersionKHashV1 { + mat = generateMatrix(prePowHash) + } + return &State{ Target: *target, prePowHash: *prePowHash, //will remove matrix opow - mat: *generateMatrix(prePowHash), + mat: mat, // nil for v2 Timestamp: timestamp, Nonce: nonce, context: getContext(generatedag, log), From 7f3442026fdc074f38491b5f225665e8f2919b4f Mon Sep 17 00:00:00 2001 From: Leon177_7 Date: Wed, 11 Feb 2026 18:49:04 +0100 Subject: [PATCH 3/3] avoid allocating full khashv2 dataset --- domain/consensus/utils/pow/pow.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/domain/consensus/utils/pow/pow.go b/domain/consensus/utils/pow/pow.go index ec3ff276c0..3e96b40b3b 100644 --- a/domain/consensus/utils/pow/pow.go +++ b/domain/consensus/utils/pow/pow.go @@ -53,7 +53,10 @@ func getContext(full bool, log *logger.Logger) *fishhashContext { log.Debugf("getContext object 42 : %x", lightCache[42]) log.Debugf("getContext object 100 : %x", lightCache[100]) - fullDataset := make([]hash1024, fullDatasetNumItems) + var fullDataset []hash1024 + if full { + fullDataset = make([]hash1024, fullDatasetNumItems) + } sharedContext = &fishhashContext{ ready: false,