@@ -95,37 +95,53 @@ module.exports = function createShareBlockHelpers(deps) {
9595 return rows . map ( ( row ) => "\n" + row . label . padEnd ( labelWidth ) + ": " + formatDiff ( row . value ) . padStart ( valueWidth ) ) . join ( "" ) ;
9696 }
9797
98- function getLocalBlockCheck ( blockTemplate , blockData , resultBuff , job ) {
99- if ( ! Buffer . isBuffer ( blockData ) ) return null ;
98+ function getLocalBlockCheck ( blockTemplate , blockData , resultBuff , job , miner , callback ) {
99+ if ( ! Buffer . isBuffer ( blockData ) ) return callback ( null ) ;
100+ let convertedBlob ;
100101 try {
101- const convertedBlob = global . coinFuncs . convertBlob ( blockData , blockTemplate . port ) ;
102- const buff = convertedBlob ? global . coinFuncs . slowHashBuff ( convertedBlob , blockTemplate ) : null ;
103- if ( ! Buffer . isBuffer ( buff ) ) return null ;
102+ convertedBlob = global . coinFuncs . convertBlob ( blockData , blockTemplate . port ) ;
103+ } catch ( _error ) {
104+ return callback ( null ) ;
105+ }
106+ if ( ! convertedBlob ) return callback ( null ) ;
107+
108+ function finish ( buff ) {
109+ if ( ! Buffer . isBuffer ( buff ) ) return callback ( null ) ;
104110 let diff = hashBuffDiff ( buff ) ;
105111 if ( job && ( job . coin === "ETH" || job . coin === "ETC" || job . coin === "ERG" ) ) diff = hashEthBuffDiff ( buff ) ;
106112 else if ( job && ( job . coin === "RVN" || job . coin === "XNA" ) ) diff = hashRavenBuffDiff ( buff ) ;
107- return { diff, matchesSubmit : ! Buffer . isBuffer ( resultBuff ) || buff . equals ( resultBuff ) } ;
113+ return callback ( { diff, matchesSubmit : ! Buffer . isBuffer ( resultBuff ) || buff . equals ( resultBuff ) } ) ;
114+ }
115+
116+ if ( typeof global . coinFuncs . slowHashBuffAsync === "function" ) {
117+ return global . coinFuncs . slowHashBuffAsync ( convertedBlob , blockTemplate , miner && miner . payout , finish ) ;
118+ }
119+ if ( typeof global . coinFuncs . isHashVerifierEnabled === "function" && global . coinFuncs . isHashVerifierEnabled ( ) ) return callback ( null ) ;
120+
121+ try {
122+ return finish ( global . coinFuncs . slowHashBuff ( convertedBlob , blockTemplate ) ) ;
108123 } catch ( _error ) {
109- return null ;
124+ return callback ( null ) ;
110125 }
111126 }
112127
113- function getBlockSubmitDiffMessage ( blockTemplate , blockData , resultBuff , hashDiff , requiredDiff , job ) {
114- const localCheck = getLocalBlockCheck ( blockTemplate , blockData , resultBuff , job ) ;
128+ function getBlockSubmitDiffMessage ( blockTemplate , blockData , resultBuff , hashDiff , requiredDiff , job , miner , callback ) {
115129 const diffRows = [
116130 { label : "Submitted share difficulty" , value : hashDiff } ,
117131 { label : "Required block difficulty" , value : requiredDiff }
118132 ] ;
119- if ( localCheck !== null ) {
120- const localDiff = localCheck . diff ;
121- diffRows . push ( { label : "Locally verified difficulty" , value : localDiff } ) ;
122- let message = formatDiffRows ( diffRows ) ;
123- if ( ! localCheck . matchesSubmit || ( requiredDiff !== undefined && requiredDiff !== null && requiredDiff !== "" && ! ge ( localDiff , requiredDiff ) ) ) {
124- message += "\nLocal check says this was not block level; no action is needed for this submit failure." ;
133+ return getLocalBlockCheck ( blockTemplate , blockData , resultBuff , job , miner , function onLocalCheck ( localCheck ) {
134+ if ( localCheck !== null ) {
135+ const localDiff = localCheck . diff ;
136+ diffRows . push ( { label : "Locally verified difficulty" , value : localDiff } ) ;
137+ let message = formatDiffRows ( diffRows ) ;
138+ if ( ! localCheck . matchesSubmit || ( requiredDiff !== undefined && requiredDiff !== null && requiredDiff !== "" && ! ge ( localDiff , requiredDiff ) ) ) {
139+ message += "\nLocal check says this was not block level; no action is needed for this submit failure." ;
140+ }
141+ return callback ( message ) ;
125142 }
126- return message ;
127- }
128- return formatDiffRows ( diffRows ) ;
143+ return callback ( formatDiffRows ( diffRows ) ) ;
144+ } ) ;
129145 }
130146
131147 function submitBlock ( miner , job , blockTemplate , blockData , resultBuff , hashDiff , isTrustedShare , isParentBlock , portUsedToSubmit , submitBlockCB , submitParams , submitRetryCount ) {
@@ -153,11 +169,30 @@ module.exports = function createShareBlockHelpers(deps) {
153169 }
154170 }
155171
156- function shouldNotifySubmitFailure ( ) {
157- if ( ! ( isParentBlock && isTrustedShare && ! shouldSuppressBlockSubmitFailureEmail ( ) ) ) return true ;
158- const convertedBlob = global . coinFuncs . convertBlob ( blockData , blockTemplate . port ) ;
159- const buff = global . coinFuncs . slowHashBuff ( convertedBlob , blockTemplate ) ;
160- return Buffer . isBuffer ( buff ) && Buffer . isBuffer ( resultBuff ) && buff . equals ( resultBuff ) ;
172+ function shouldNotifySubmitFailure ( callback ) {
173+ if ( ! ( isParentBlock && isTrustedShare && ! shouldSuppressBlockSubmitFailureEmail ( ) ) ) return callback ( true ) ;
174+ let convertedBlob ;
175+ try {
176+ convertedBlob = global . coinFuncs . convertBlob ( blockData , blockTemplate . port ) ;
177+ } catch ( _error ) {
178+ return callback ( false ) ;
179+ }
180+ if ( ! convertedBlob ) return callback ( false ) ;
181+
182+ function finish ( buff ) {
183+ return callback ( Buffer . isBuffer ( buff ) && Buffer . isBuffer ( resultBuff ) && buff . equals ( resultBuff ) ) ;
184+ }
185+
186+ if ( typeof global . coinFuncs . slowHashBuffAsync === "function" ) {
187+ return global . coinFuncs . slowHashBuffAsync ( convertedBlob , blockTemplate , miner && miner . payout , finish ) ;
188+ }
189+ if ( typeof global . coinFuncs . isHashVerifierEnabled === "function" && global . coinFuncs . isHashVerifierEnabled ( ) ) return callback ( false ) ;
190+
191+ try {
192+ return finish ( global . coinFuncs . slowHashBuff ( convertedBlob , blockTemplate ) ) ;
193+ } catch ( _error ) {
194+ return callback ( false ) ;
195+ }
161196 }
162197
163198 function shouldRetryXmrSubmitFailure ( isDisplaySubmitPort ) {
@@ -183,7 +218,9 @@ module.exports = function createShareBlockHelpers(deps) {
183218 global . coinFuncs . getPortLastBlockHeader ( blockTemplate . port , function ( err , body ) {
184219 if ( err !== null ) return console . error ( getThreadName ( ) + formatPoolEvent ( "Header fetch failed" , { chain : formatCoinPort ( blockTemplate . coin , blockTemplate . port ) } ) ) ;
185220 if ( blockTemplate . height == body . height + 1 ) {
186- global . support . sendAdminFyi ( "pool:block-submit:" + reportCoinPort , "FYI: Can't submit " + reportCoinPort + " block to deamon" , "The pool server: " + global . config . hostname + " can't submit block to deamon on " + reportCoinPort + getDiffMessage ( ) + "\nInput: " + blockDataStr + "\n" + getThreadName ( ) + "Error submitting " + reportCoinPort + " block at " + reportHeight + " height from " + miner . logString + ", isTrustedShare: " + isTrustedShare + " error ): " + JSON . stringify ( rpcResult ) ) ;
221+ getDiffMessage ( function onDiffMessage ( diffMessage ) {
222+ global . support . sendAdminFyi ( "pool:block-submit:" + reportCoinPort , "FYI: Can't submit " + reportCoinPort + " block to deamon" , "The pool server: " + global . config . hostname + " can't submit block to deamon on " + reportCoinPort + diffMessage + "\nInput: " + blockDataStr + "\n" + getThreadName ( ) + "Error submitting " + reportCoinPort + " block at " + reportHeight + " height from " + miner . logString + ", isTrustedShare: " + isTrustedShare + " error ): " + JSON . stringify ( rpcResult ) ) ;
223+ } ) ;
187224 }
188225 } , true ) ;
189226 } , 2 * 1000 ) ;
@@ -204,8 +241,8 @@ module.exports = function createShareBlockHelpers(deps) {
204241 const replyFn = function ( rpcResult , rpcStatus , port , nextSubmitBlockCB , isDisplaySubmitPortOverride ) {
205242 const { activeHeight, isDisplaySubmitPort, reportCoinPort, reportDiff, reportHeight, reportPort } = buildSubmitReport ( port , isDisplaySubmitPortOverride ) ;
206243 const requiredBlockDiff = isMainPort && ! isDisplaySubmitPort && blockTemplate . xmr_difficulty ? blockTemplate . xmr_difficulty : reportDiff ;
207- const getDiffMessage = function ( ) {
208- return getBlockSubmitDiffMessage ( blockTemplate , blockData , resultBuff , hashDiff , requiredBlockDiff , job ) ;
244+ const getDiffMessage = function ( callback ) {
245+ return getBlockSubmitDiffMessage ( blockTemplate , blockData , resultBuff , hashDiff , requiredBlockDiff , job , miner , callback ) ;
209246 } ;
210247 const blockDataStr = Buffer . isBuffer ( blockData ) ? blockData . toString ( "hex" ) : JSON . stringify ( blockData ) ;
211248
@@ -222,24 +259,24 @@ module.exports = function createShareBlockHelpers(deps) {
222259 } ) + ", block hex: \n" + blockDataStr ) ;
223260 return retrySubmit ( port , nextSubmitBlockCB , SUBMIT_RETRY_DELAY_MS ) ;
224261 }
225- const isNotifyAdmin = shouldNotifySubmitFailure ( ) ;
226- console . error ( getThreadName ( ) + formatPoolEvent ( "Block submit failed" , {
227- chain : reportCoinPort ,
228- height : reportHeight ,
229- activeHeight,
230- miner : miner . logString ,
231- trusted : isTrustedShare ,
232- valid : isNotifyAdmin ,
233- rpcStatus,
234- error : rpcResult
235- } ) + ", block hex: \n" + blockDataStr ) ;
262+ return shouldNotifySubmitFailure ( function onSubmitFailureNotify ( isNotifyAdmin ) {
263+ console . error ( getThreadName ( ) + formatPoolEvent ( "Block submit failed" , {
264+ chain : reportCoinPort ,
265+ height : reportHeight ,
266+ activeHeight,
267+ miner : miner . logString ,
268+ trusted : isTrustedShare ,
269+ valid : isNotifyAdmin ,
270+ rpcStatus,
271+ error : rpcResult
272+ } ) + ", block hex: \n" + blockDataStr ) ;
236273
237- if ( isNotifyAdmin && ! shouldSuppressBlockSubmitFailureEmail ( ) ) {
238- sendSubmitFailureEmail ( reportCoinPort , reportHeight , blockDataStr , rpcResult , getDiffMessage ) ;
239- }
240- resetShareTrust ( ) ;
241- if ( nextSubmitBlockCB ) return nextSubmitBlockCB ( false ) ;
242- return ;
274+ if ( isNotifyAdmin && ! shouldSuppressBlockSubmitFailureEmail ( ) ) {
275+ sendSubmitFailureEmail ( reportCoinPort , reportHeight , blockDataStr , rpcResult , getDiffMessage ) ;
276+ }
277+ resetShareTrust ( ) ;
278+ if ( nextSubmitBlockCB ) return nextSubmitBlockCB ( false ) ;
279+ } ) ;
243280 }
244281
245282 if ( poolSettings . acceptSubmittedBlock ( {
@@ -307,7 +344,10 @@ module.exports = function createShareBlockHelpers(deps) {
307344 } ) + ", block hex: \n" + blockDataStr ) ;
308345 if ( ! shouldSuppressBlockSubmitFailureEmail ( ) ) {
309346 const submitCoinPort = formatCoinPort ( blockTemplate . coin , blockTemplate . port ) ;
310- global . support . sendAdminFyi ( "pool:block-submit-rpc:" + submitCoinPort , "FYI: Can't submit block to deamon on " + submitCoinPort , "Input: " + blockDataStr + "\nThe pool server: " + global . config . hostname + " can't submit block to deamon on " + submitCoinPort + getDiffMessage ( ) + "\nRPC Error. Please check logs for details" ) ;
347+ return getDiffMessage ( function onRpcErrorDiff ( diffMessage ) {
348+ global . support . sendAdminFyi ( "pool:block-submit-rpc:" + submitCoinPort , "FYI: Can't submit block to deamon on " + submitCoinPort , "Input: " + blockDataStr + "\nThe pool server: " + global . config . hostname + " can't submit block to deamon on " + submitCoinPort + diffMessage + "\nRPC Error. Please check logs for details" ) ;
349+ if ( nextSubmitBlockCB ) return nextSubmitBlockCB ( false ) ;
350+ } ) ;
311351 }
312352 if ( nextSubmitBlockCB ) return nextSubmitBlockCB ( false ) ;
313353 } ;
0 commit comments