@@ -29,6 +29,7 @@ use url::form_urlencoded;
29
29
use { serde, serde_json} ;
30
30
31
31
use crate :: burnchains:: Txid ;
32
+ use crate :: chainstate:: nakamoto:: NakamotoChainState ;
32
33
use crate :: chainstate:: stacks:: db:: StacksChainState ;
33
34
use crate :: chainstate:: stacks:: { Error as ChainError , StacksTransaction } ;
34
35
use crate :: core:: mempool:: { decode_tx_stream, MemPoolDB , MemPoolSyncData } ;
@@ -89,8 +90,8 @@ pub struct StacksMemPoolStream {
89
90
pub num_txs : u64 ,
90
91
/// maximum we can visit in the query
91
92
pub max_txs : u64 ,
92
- /// height of the chain at time of query
93
- pub height : u64 ,
93
+ /// coinbase height of the chain at time of query
94
+ pub coinbase_height : u64 ,
94
95
/// Are we done sending transactions, and are now in the process of sending the trailing page
95
96
/// ID?
96
97
pub corked : bool ,
@@ -105,7 +106,7 @@ impl StacksMemPoolStream {
105
106
mempool_db : DBConn ,
106
107
tx_query : MemPoolSyncData ,
107
108
max_txs : u64 ,
108
- height : u64 ,
109
+ coinbase_height : u64 ,
109
110
page_id_opt : Option < Txid > ,
110
111
) -> Self {
111
112
let last_randomized_txid = page_id_opt. unwrap_or_else ( || {
@@ -118,7 +119,7 @@ impl StacksMemPoolStream {
118
119
last_randomized_txid : last_randomized_txid,
119
120
num_txs : 0 ,
120
121
max_txs : max_txs,
121
- height : height ,
122
+ coinbase_height ,
122
123
corked : false ,
123
124
finished : false ,
124
125
mempool_db,
@@ -159,7 +160,7 @@ impl HttpChunkGenerator for StacksMemPoolStream {
159
160
MemPoolDB :: static_find_next_missing_transactions (
160
161
& self . mempool_db ,
161
162
& self . tx_query ,
162
- self . height ,
163
+ self . coinbase_height ,
163
164
& self . last_randomized_txid ,
164
165
1 ,
165
166
remaining,
@@ -275,12 +276,18 @@ impl RPCRequestHandler for RPCMempoolQueryRequestHandler {
275
276
let page_id = self . page_id . take ( ) ;
276
277
277
278
let stream_res = node. with_node_state ( |network, sortdb, chainstate, mempool, _rpc_args| {
278
- let height = self . get_stacks_chain_tip ( & preamble, sortdb, chainstate) . map ( |hdr| hdr. anchored_header . height ( ) ) . unwrap_or ( 0 ) ;
279
+ let header = self . get_stacks_chain_tip ( & preamble, sortdb, chainstate)
280
+ . map_err ( |e| StacksHttpResponse :: new_error ( & preamble, & HttpServerError :: new ( format ! ( "Failed to load chain tip: {:?}" , & e) ) ) ) ?;
281
+
282
+ let coinbase_height = NakamotoChainState :: get_coinbase_height ( & mut chainstate. index_conn ( ) , & header. index_block_hash ( ) )
283
+ . map_err ( |e| StacksHttpResponse :: new_error ( & preamble, & HttpServerError :: new ( format ! ( "Failed to load coinbase height: {:?}" , & e) ) ) ) ?
284
+ . unwrap_or ( 0 ) ;
285
+
279
286
let max_txs = network. connection_opts . mempool_max_tx_query ;
280
287
debug ! (
281
288
"Begin mempool query" ;
282
289
"page_id" => %page_id. map( |txid| format!( "{}" , & txid) ) . unwrap_or( "(none" . to_string( ) ) ,
283
- "block_height " => height ,
290
+ "coinbase_height " => coinbase_height ,
284
291
"max_txs" => max_txs
285
292
) ;
286
293
@@ -291,7 +298,7 @@ impl RPCRequestHandler for RPCMempoolQueryRequestHandler {
291
298
}
292
299
} ;
293
300
294
- Ok ( StacksMemPoolStream :: new ( mempool_db, mempool_query, max_txs, height , page_id) )
301
+ Ok ( StacksMemPoolStream :: new ( mempool_db, mempool_query, max_txs, coinbase_height , page_id) )
295
302
} ) ;
296
303
297
304
let stream = match stream_res {
0 commit comments