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

Correct several stratum/pooled mining issues. #220

Merged
merged 1 commit into from
Oct 12, 2023

Conversation

davecgh
Copy link
Member

@davecgh davecgh commented Oct 10, 2023

This updates the code to properly support pooled mining via stratum.

In particular:

  • The extra nonce provided by the pool is now correctly set and used
  • The length for the second extra nonce provided by the pool is now validated
  • The second extra nonce length now respects the provided length
  • The mining code now uses the correct offset within the serialized work data for the second extra nonce to ensure the pool properly reconstructs the header
  • The provided timestamp is now updated locally as the mining process is underway and the final timestamp is submitted along with the share as expected
  • The correct network parameters for the active network are now passed into the stratum code so the right difficulties are used
  • The stratum fields that represent numbers are now consistently in little endian per the stratum "spec" (such that it is)
  • The "second generation tx" field is now ignored because it does not apply to Decred

Finally, various loggging messages have been cleaned up and the job id is no longer incorrectly expected to be numeric when logging it.

w := work.NewWork(workData, bigTarget, givenTs, uint32(time.Now().Unix()), true)

const isGetWork = true
timestamp := binary.LittleEndian.Uint32(workData[128+4*work.TimestampWord:])
Copy link
Member

Choose a reason for hiding this comment

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

I'm struggling to understand why the upper bound of the slice has been removed here. Given that timestamp is not the last item in the bytes (per the serialization format provided here), isn't removing the upper bound going to select the timestamp and everything after it?

Copy link
Member Author

@davecgh davecgh Oct 11, 2023

Choose a reason for hiding this comment

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

All of the little/big endian byte conversions are necessarily automatically sized by the type in question. A Uint32 is always 4 bytes. As a result, 4 bytes, and only 4 bytes, from the slice are always used.

Uint32 source code for proof.

stratum/stratum.go Outdated Show resolved Hide resolved
stratum/stratum.go Outdated Show resolved Hide resolved
stratum/stratum.go Outdated Show resolved Hide resolved
This updates the code to properly support pooled mining via stratum.

In particular:

- The extra nonce provided by the pool is now correctly set and used
- The length for the second extra nonce provided by the pool is now
  validated
- The second extra nonce length now respects the provided length
- The mining code now uses the correct offset within the serialized work
  data for the second extra nonce to ensure the pool properly
  reconstructs the header
- The provided timestamp is now updated locally as the mining process is
  underway and the final timestamp is submitted along with the share as
  expected
- The correct network parameters for the active network are now passed
  into the stratum code so the right difficulties are used
- The stratum fields that represent numbers are now consistently in
  little endian per the stratum "spec" (such that it is)
- The "second generation tx" field is now ignored because it does not
  apply to Decred

Finally, various loggging messages have been cleaned up and the job id
is no longer incorrectly expected to be numeric when logging it.
@davecgh davecgh merged commit 2e7c33a into decred:master Oct 12, 2023
2 checks passed
@davecgh davecgh deleted the correct_stratum_support branch October 12, 2023 15:07
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.

None yet

2 participants