@@ -8,6 +8,7 @@ const process = require("node:process");
88const test = require ( "node:test" ) ;
99
1010const loadRegistry = require ( "../../../lib/coins/core/registry.js" ) ;
11+ const createMinerJobs = require ( "../../../lib/pool/jobs.js" ) ;
1112const {
1213 MAIN_PORT ,
1314 createBaseTemplate,
@@ -150,7 +151,7 @@ test("BlockTemplate keeps main-template nonce layout stable across nextBlobHex c
150151 ) ;
151152} ) ;
152153
153- test ( "BlockTemplate keeps XTM-T pool nonce in the Tari nonce prefix " , ( ) => {
154+ test ( "BlockTemplate keeps XTM-T pool/proxy nonce inside RandomXT pow_data " , ( ) => {
154155 const coinFuncs = global . coinFuncs . __realCoinFuncs ;
155156 const blob = Buffer . concat ( [
156157 Buffer . alloc ( 3 ) ,
@@ -165,7 +166,7 @@ test("BlockTemplate keeps XTM-T pool nonce in the Tari nonce prefix", () => {
165166 difficulty : 1 ,
166167 height : 302 ,
167168 port : 18146 ,
168- reserved_offset : 35 ,
169+ reserved_offset : 44 ,
169170 reward : 1 ,
170171 seed_hash : "22" . repeat ( 32 ) ,
171172 xtm_block : { header : { nonce : "0" , pow : { pow_data : [ ] } } }
@@ -174,9 +175,99 @@ test("BlockTemplate keeps XTM-T pool nonce in the Tari nonce prefix", () => {
174175 const nextBlob = Buffer . from ( blockTemplate . nextBlobHex ( ) , "hex" ) ;
175176
176177 assert . equal ( blockTemplate . extraNonce , 1 ) ;
177- assert . equal ( nextBlob . readUInt32BE ( 35 ) , 1 ) ;
178+ assert . equal ( nextBlob . subarray ( 35 , 43 ) . equals ( Buffer . alloc ( 8 ) ) , true ) ;
178179 assert . equal ( nextBlob [ 43 ] , 0x02 ) ;
179- assert . equal ( nextBlob . subarray ( 44 ) . equals ( Buffer . alloc ( 32 ) ) , true ) ;
180+ assert . equal ( nextBlob . readUInt32BE ( 44 ) , 1 ) ;
181+ assert . equal ( blockTemplate . disableProxyNonce , false ) ;
182+ assert . equal ( blockTemplate . clientPoolLocation , 52 ) ;
183+ assert . equal ( blockTemplate . clientNonceLocation , 56 ) ;
184+ } ) ;
185+
186+ test ( "proxy miners use standard jobs when proxy nonce layout is disabled" , ( ) => {
187+ const originalGetPoolProfile = global . coinFuncs . getPoolProfile ;
188+ const calls = [ ] ;
189+ const validJobs = [ ] ;
190+ const poolSettings = {
191+ sharedTemplateNonces : false ,
192+ disableProxyNonce : true ,
193+ useEthJobId : false ,
194+ buildJobPayload ( ctx ) {
195+ calls . push ( "standard" ) ;
196+ assert . equal ( ctx . newJob . usesProxyNonce , false ) ;
197+ return { blob : ctx . blobHex , job_id : ctx . newJob . id } ;
198+ } ,
199+ buildProxyJobPayload ( ) {
200+ calls . push ( "proxy" ) ;
201+ return { } ;
202+ }
203+ } ;
204+ const miner = {
205+ proxy : true ,
206+ jobLastBlockHash : null ,
207+ newDiffToSet : null ,
208+ newDiffRecommendation : null ,
209+ difficulty : 50 ,
210+ curr_coin_hash_factor : 1 ,
211+ curr_coin_min_diff : 1 ,
212+ cachedJob : null ,
213+ validJobs : {
214+ enq ( job ) {
215+ validJobs . push ( job ) ;
216+ }
217+ }
218+ } ;
219+ let nextBlobCalls = 0 ;
220+ let childBlobCalls = 0 ;
221+ const blockTemplate = {
222+ idHash : "xtm-t-no-proxy" ,
223+ difficulty : 100 ,
224+ height : 302 ,
225+ seed_hash : "22" . repeat ( 32 ) ,
226+ port : 18146 ,
227+ block_version : 0 ,
228+ extraNonce : 0 ,
229+ disableProxyNonce : true ,
230+ clientPoolLocation : 43 ,
231+ clientNonceLocation : 47 ,
232+ nextBlobHex ( ) {
233+ nextBlobCalls += 1 ;
234+ this . extraNonce += 1 ;
235+ return "aa" ;
236+ } ,
237+ nextBlobWithChildNonceHex ( ) {
238+ childBlobCalls += 1 ;
239+ return "bb" ;
240+ }
241+ } ;
242+
243+ try {
244+ global . coinFuncs . getPoolProfile = function getPoolProfile ( ) {
245+ return { blobType : 106 , pool : poolSettings } ;
246+ } ;
247+ createMinerJobs ( { } ) ( miner , {
248+ protoVersion : 1 ,
249+ getCoinJobParams ( ) { } ,
250+ getNewId ( ) { return "job-1" ; } ,
251+ getNewEthJobId ( ) { return "eth-job-1" ; } ,
252+ getTargetHex ( ) { return "00" . repeat ( 32 ) ; } ,
253+ getRavenTargetHex ( ) { return "00" . repeat ( 32 ) ; } ,
254+ toBigInt ( value ) { return BigInt ( value ) ; } ,
255+ divideBaseDiff ( ) { return 1 ; }
256+ } ) ;
257+
258+ const payload = miner . getCoinJob ( "XTM-T" , { bt : blockTemplate , algo_name : "rx/0" , coinHashFactor : 1 } ) ;
259+
260+ assert . deepEqual ( payload , { blob : "aa" , job_id : "job-1" } ) ;
261+ assert . deepEqual ( calls , [ "standard" ] ) ;
262+ assert . equal ( nextBlobCalls , 1 ) ;
263+ assert . equal ( childBlobCalls , 0 ) ;
264+ assert . equal ( validJobs . length , 1 ) ;
265+ assert . equal ( validJobs [ 0 ] . usesProxyNonce , false ) ;
266+ assert . equal ( validJobs [ 0 ] . clientPoolLocation , undefined ) ;
267+ assert . equal ( validJobs [ 0 ] . clientNonceLocation , undefined ) ;
268+ } finally {
269+ global . coinFuncs . getPoolProfile = originalGetPoolProfile ;
270+ }
180271} ) ;
181272
182273test ( "BlockTemplate uses the SAL blob marker when daemon reserved offset is stale" , ( ) => {
0 commit comments