@@ -324,7 +324,7 @@ function isPgConnectionError(error: any): string | false {
324
324
const TX_COLUMNS = `
325
325
-- required columns
326
326
tx_id, raw_tx, tx_index, index_block_hash, parent_index_block_hash, block_hash, parent_block_hash, block_height, burn_block_time, parent_burn_block_time,
327
- type_id, anchor_mode, status, canonical, post_conditions, nonce, fee_rate, sponsored, sponsor_address, sender_address, origin_hash_mode,
327
+ type_id, anchor_mode, status, canonical, post_conditions, nonce, fee_rate, sponsored, sponsor_nonce, sponsor_address, sender_address, origin_hash_mode,
328
328
microblock_canonical, microblock_sequence, microblock_hash,
329
329
330
330
-- token-transfer tx columns
@@ -355,7 +355,7 @@ const TX_COLUMNS = `
355
355
const MEMPOOL_TX_COLUMNS = `
356
356
-- required columns
357
357
pruned, tx_id, raw_tx, type_id, anchor_mode, status, receipt_time, receipt_block_height,
358
- post_conditions, nonce, fee_rate, sponsored, sponsor_address, sender_address, origin_hash_mode,
358
+ post_conditions, nonce, fee_rate, sponsored, sponsor_nonce, sponsor_address, sender_address, origin_hash_mode,
359
359
360
360
-- token-transfer tx columns
361
361
token_transfer_recipient_address, token_transfer_amount, token_transfer_memo,
@@ -416,6 +416,7 @@ function txColumns(tableName: string = 'txs'): string {
416
416
'fee_rate' ,
417
417
'sponsored' ,
418
418
'sponsor_address' ,
419
+ 'sponsor_nonce' ,
419
420
'sender_address' ,
420
421
'origin_hash_mode' ,
421
422
'microblock_canonical' ,
@@ -520,6 +521,7 @@ interface MempoolTxQueryResult {
520
521
tx_id : Buffer ;
521
522
522
523
nonce : number ;
524
+ sponsor_nonce ?: number ;
523
525
type_id : number ;
524
526
anchor_mode : number ;
525
527
status : number ;
@@ -571,6 +573,7 @@ interface TxQueryResult {
571
573
burn_block_time : number ;
572
574
parent_burn_block_time : number ;
573
575
nonce : number ;
576
+ sponsor_nonce ?: number ;
574
577
type_id : number ;
575
578
anchor_mode : number ;
576
579
status : number ;
@@ -2008,22 +2011,55 @@ export class PgDataStore
2008
2011
`
2009
2012
SELECT MAX(nonce) nonce
2010
2013
FROM txs
2011
- WHERE (( sender_address = $1 AND sponsored = false) OR (sponsor_address = $1 AND sponsored= true))
2014
+ WHERE sender_address = $1
2012
2015
AND canonical = true AND microblock_canonical = true
2013
2016
` ,
2014
2017
[ args . stxAddress ]
2015
2018
) ;
2019
+
2020
+ const executedTxSponsorNonce = await client . query < { nonce : number | null } > (
2021
+ `
2022
+ SELECT MAX(sponsor_nonce) nonce
2023
+ FROM txs
2024
+ WHERE sponsor_address = $1 AND sponsored = true
2025
+ AND canonical = true AND microblock_canonical = true
2026
+ ` ,
2027
+ [ args . stxAddress ]
2028
+ ) ;
2029
+
2016
2030
const mempoolTxNonce = await client . query < { nonce : number | null } > (
2017
2031
`
2018
2032
SELECT MAX(nonce) nonce
2019
2033
FROM mempool_txs
2020
- WHERE ((sender_address = $1 AND sponsored = false) OR (sponsor_address = $1 AND sponsored= true))
2034
+ WHERE sender_address = $1
2035
+ AND pruned = false
2036
+ ` ,
2037
+ [ args . stxAddress ]
2038
+ ) ;
2039
+
2040
+ const mempoolTxSponsorNonce = await client . query < { nonce : number | null } > (
2041
+ `
2042
+ SELECT MAX(sponsor_nonce) nonce
2043
+ FROM mempool_txs
2044
+ WHERE sponsor_address = $1 AND sponsored= true
2021
2045
AND pruned = false
2022
2046
` ,
2023
2047
[ args . stxAddress ]
2024
2048
) ;
2025
- const lastExecutedTxNonce = executedTxNonce . rows [ 0 ] ?. nonce ?? null ;
2026
- const lastMempoolTxNonce = mempoolTxNonce . rows [ 0 ] ?. nonce ?? null ;
2049
+
2050
+ let lastExecutedTxNonce = executedTxNonce . rows [ 0 ] ?. nonce ?? null ;
2051
+ const lastExecutedTxSponsorNonce = executedTxSponsorNonce . rows [ 0 ] ?. nonce ?? null ;
2052
+ if ( lastExecutedTxNonce != null || lastExecutedTxSponsorNonce != null ) {
2053
+ lastExecutedTxNonce = Math . max ( lastExecutedTxNonce ?? 0 , lastExecutedTxSponsorNonce ?? 0 ) ;
2054
+ }
2055
+
2056
+ let lastMempoolTxNonce = mempoolTxNonce . rows [ 0 ] ?. nonce ?? null ;
2057
+ const lastMempoolTxSponsorNonce = mempoolTxSponsorNonce . rows [ 0 ] ?. nonce ?? null ;
2058
+
2059
+ if ( lastMempoolTxNonce != null || lastMempoolTxSponsorNonce != null ) {
2060
+ lastMempoolTxNonce = Math . max ( lastMempoolTxNonce ?? 0 , lastMempoolTxSponsorNonce ?? 0 ) ;
2061
+ }
2062
+
2027
2063
let possibleNextNonce = 0 ;
2028
2064
if ( lastExecutedTxNonce !== null || lastMempoolTxNonce !== null ) {
2029
2065
possibleNextNonce = Math . max ( lastExecutedTxNonce ?? 0 , lastMempoolTxNonce ?? 0 ) + 1 ;
@@ -2041,7 +2077,12 @@ export class PgDataStore
2041
2077
`
2042
2078
SELECT nonce
2043
2079
FROM mempool_txs
2044
- WHERE ((sender_address = $1 AND sponsored = false) OR (sponsor_address = $1 AND sponsored= true)) AND nonce = ANY($2)
2080
+ WHERE sender_address = $1 AND nonce = ANY($2)
2081
+ AND pruned = false
2082
+ UNION
2083
+ SELECT sponsor_nonce as nonce
2084
+ FROM mempool_txs
2085
+ WHERE sponsor_address = $1 AND sponsored= true AND sponsor_nonce = ANY($2)
2045
2086
AND pruned = false
2046
2087
` ,
2047
2088
[ args . stxAddress , expectedNonces ]
@@ -3453,7 +3494,7 @@ export class PgDataStore
3453
3494
) values(
3454
3495
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19,
3455
3496
$20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35, $36, $37,
3456
- $38, $39, $40, $41, $42
3497
+ $38, $39, $40, $41, $42, $43
3457
3498
)
3458
3499
ON CONFLICT ON CONSTRAINT unique_tx_id_index_block_hash_microblock_hash DO NOTHING
3459
3500
` ,
@@ -3476,6 +3517,7 @@ export class PgDataStore
3476
3517
tx . nonce ,
3477
3518
tx . fee_rate ,
3478
3519
tx . sponsored ,
3520
+ tx . sponsor_nonce ,
3479
3521
tx . sponsor_address ,
3480
3522
tx . sender_address ,
3481
3523
tx . origin_hash_mode ,
@@ -3514,7 +3556,7 @@ export class PgDataStore
3514
3556
`
3515
3557
INSERT INTO mempool_txs(
3516
3558
${ MEMPOOL_TX_COLUMNS }
3517
- ) values($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26)
3559
+ ) values($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27 )
3518
3560
ON CONFLICT ON CONSTRAINT unique_tx_id
3519
3561
DO NOTHING
3520
3562
` ,
@@ -3531,6 +3573,7 @@ export class PgDataStore
3531
3573
tx . nonce ,
3532
3574
tx . fee_rate ,
3533
3575
tx . sponsored ,
3576
+ tx . sponsor_nonce ,
3534
3577
tx . sponsor_address ,
3535
3578
tx . sender_address ,
3536
3579
tx . origin_hash_mode ,
@@ -3587,6 +3630,7 @@ export class PgDataStore
3587
3630
pruned : result . pruned ,
3588
3631
tx_id : bufferToHexPrefixString ( result . tx_id ) ,
3589
3632
nonce : result . nonce ,
3633
+ sponsor_nonce : result . sponsor_nonce ?? undefined ,
3590
3634
raw_tx : result . raw_tx ,
3591
3635
type_id : result . type_id as DbTxTypeId ,
3592
3636
anchor_mode : result . anchor_mode as DbTxAnchorMode ,
@@ -3623,6 +3667,7 @@ export class PgDataStore
3623
3667
tx_id : bufferToHexPrefixString ( result . tx_id ) ,
3624
3668
tx_index : result . tx_index ,
3625
3669
nonce : result . nonce ,
3670
+ sponsor_nonce : result . sponsor_nonce ?? undefined ,
3626
3671
raw_tx : result . raw_tx ,
3627
3672
index_block_hash : bufferToHexPrefixString ( result . index_block_hash ) ,
3628
3673
parent_index_block_hash : bufferToHexPrefixString ( result . parent_index_block_hash ) ,
0 commit comments