Skip to content

Commit

Permalink
chore: review feedback improvements
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Olshansky <[email protected]>
  • Loading branch information
bryanchriswhite and Olshansk committed Nov 17, 2023
1 parent a2c4b7b commit c2476a6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/relayer/miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (mnr *miner) mapMineRelay(
relayHash := mnr.hash(relayBz)

// The relay IS NOT volume / reward applicable
if protocol.MustCountDifficultyBits(relayHash) >= defaultRelayDifficultyBits {
if protocol.MustCountDifficultyBits(relayHash) < defaultRelayDifficultyBits {
return either.Success[*relayer.MinedRelay](nil), true
}

Expand Down
12 changes: 7 additions & 5 deletions pkg/relayer/protocol/difficulty.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ func CountDifficultyBits(bz []byte) (int, error) {
bzLen := len(bz)

var zeroBits int
for i, b := range bz {
if b != 0 {
zeroBits = bits.LeadingZeros8(b)
for byteIdx, byteValue := range bz {
if byteValue != 0 {
zeroBits = bits.LeadingZeros8(byteValue)
if zeroBits == 8 {
// we already checked that b != 0.
// we already checked that byteValue != 0.
return 0, ErrDifficulty.Wrap("impossible code path")
}

return (i)*8 + zeroBits, nil
// We have byteIdx bytes that are all 0s and one byte that has
// zeroBits number of leading 0 bits.
return (byteIdx)*8 + zeroBits, nil
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/relayer/protocol/difficulty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestCountDifficultyBits(t *testing.T) {
}

for _, tt := range tests {
t.Run(fmt.Sprintf("difficulty_%d", tt.difficulty), func(t *testing.T) {
t.Run(fmt.Sprintf("difficulty_%d_zero_bits", tt.difficulty), func(t *testing.T) {
actualDifficulty, err := protocol.CountDifficultyBits(tt.bz)
require.NoError(t, err)
require.Equal(t, tt.difficulty, actualDifficulty)
Expand Down

0 comments on commit c2476a6

Please sign in to comment.