Skip to content
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

Optimize PoW #419

Merged
merged 1 commit into from
Oct 6, 2023
Merged

Optimize PoW #419

merged 1 commit into from
Oct 6, 2023

Conversation

poszu
Copy link
Contributor

@poszu poszu commented Oct 5, 2023

Part of #416
Optimizes the proof of work:

Single hash benchmark:

BenchmarkPowHash-20    	 2889742	       394.6 ns/op	     152 B/op	       3 allocs/op
↓
BenchmarkPowHash-20    	 3915529	       302.4 ns/op	       0 B/op	       0 allocs/op

Finding PoW benchmark:

BenchmarkFindSubmitPowNonce/difficulty=20-20                   2         625033028 ns/op        243352568 B/op   4802780 allocs/op
↓
BenchmarkFindSubmitPowNonce/difficulty=20-20                   3         348184603 ns/op              416 B/op         6 allocs/op

@codecov
Copy link

codecov bot commented Oct 5, 2023

Codecov Report

Merging #419 (4bba71d) into develop (4bc1a3b) will increase coverage by 0.0%.
The diff coverage is 88.0%.

@@           Coverage Diff           @@
##           develop    #419   +/-   ##
=======================================
  Coverage     75.1%   75.1%           
=======================================
  Files           23      24    +1     
  Lines         1917    1926    +9     
=======================================
+ Hits          1440    1448    +8     
  Misses         359     359           
- Partials       118     119    +1     
Files Coverage Δ
registration/pow_verifier.go 96.1% <100.0%> (ø)
shared/shared.go 69.7% <ø> (-1.8%) ⬇️
shared/pow.go 87.8% <87.8%> (ø)

... and 1 file with indirect coverage changes

Copy link
Member

@fasmat fasmat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

}

func NewPowHasher(inputs ...[]byte) *powHasher {
h := &powHasher{h: ripemd.New256(), input: []byte{}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: h.input does not need to be initialized to append bytes to it

Suggested change
h := &powHasher{h: ripemd.New256(), input: []byte{}}
h := &powHasher{h: ripemd.New256()}


nonce, err := shared.FindSubmitPowNonce(context.Background(), challenge, poetChallenge, nodeID, difficulty)
require.NoError(t, err)
require.EqualValues(t, 143, nonce)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: EqualValues ignores typing; I think this assertion should fail if someone accidentally changes the type of nonce:

Suggested change
require.EqualValues(t, 143, nonce)
require.Equal(t, uint64(143), nonce)

Merged via the queue into develop with commit f13d351 Oct 6, 2023
11 checks passed
@fasmat fasmat deleted the optimize-pow branch May 14, 2024 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants