-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move stratum code into its own directory for cleaner 'mining.configure'
extensions in the future. Add a 'mining.configure' handler. Add a 'mining.configure' version-rolling extension handler. Modify submitted blocks with miner-provided version bits when version-rolling is negotiated successfully.
- Loading branch information
1 parent
54e4e35
commit 9d80e78
Showing
7 changed files
with
320 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const maxMaskHex = '1fffe000'; // See BIP-320 | ||
const maxMaskBits = parseInt(maxMaskHex, 16); | ||
|
||
// Validates a 4-byte hex-encoded string | ||
function validHex(hexChars) { | ||
const hexAlphabet = '0123456789aAbBcCdDeEfF'; | ||
return (typeof hexChars === 'string') | ||
&& (hexChars.length === 8) | ||
&& ([...hexChars].every((hexChar) => hexAlphabet.includes(hexChar))); | ||
} | ||
|
||
function validate(bitsHex, maskHex) { | ||
if (!validHex(bitsHex)) { | ||
return false; | ||
} | ||
|
||
const bits = parseInt(bitsHex, 16); | ||
const allowedBits = parseInt(maskHex, 16); | ||
return (bits & ~allowedBits) === 0; | ||
} | ||
|
||
function handle(params) { | ||
const response = {}; | ||
const requestMaskHex = params && params['version-rolling.mask']; | ||
|
||
if (!requestMaskHex) { | ||
response['version-rolling'] = true; | ||
response['version-rolling.mask'] = maxMaskHex; | ||
return response; | ||
} | ||
|
||
if (!validHex(requestMaskHex)) { | ||
response['version-rolling'] = 'Invalid version-rolling.mask parameter.'; | ||
return response; | ||
} | ||
|
||
const requestMaskBits = parseInt(requestMaskHex, 16); | ||
const responseMaskBits = requestMaskBits & maxMaskBits; | ||
const responseMaskHex = responseMaskBits.toString(16).padStart(8, '0'); | ||
|
||
response['version-rolling'] = true; | ||
response['version-rolling.mask'] = responseMaskHex; | ||
return response; | ||
} | ||
|
||
module.exports = { | ||
maxMaskHex, | ||
maxMaskBits, | ||
validHex, | ||
validate, | ||
handle | ||
}; |
Oops, something went wrong.