Skip to content

Commit

Permalink
removed getblockbyhash
Browse files Browse the repository at this point in the history
  • Loading branch information
rdeioris committed Nov 19, 2024
1 parent ce533e0 commit 1e628f7
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 152 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
- Add `block_commit_delay_ms` to the config file to control the time to wait after seeing a new burn block, before submitting a block commit, to allow time for the first Nakamoto block of the new tenure to be mined, allowing this miner to avoid the need to RBF the block commit.
- Add `tenure_cost_limit_per_block_percentage` to the miner config file to control the percentage remaining tenure cost limit to consume per nakamoto block.
- Add `/v3/blockbyhash` and `/v3/blockbyheight` rpc endpoints
- Add `/v3/blocks/height/:block_height` rpc endpoint

## [3.0.0.0.1]

Expand Down
12 changes: 4 additions & 8 deletions docs/rpc-endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -503,20 +503,16 @@ data.

This will return 404 if the block does not exist.

### GET /v3/blockbyhash/[Block Hash]

Fetch a Nakamoto block given its block hash. This returns the raw block
data.

This will return 404 if the block does not exist.

### GET /v3/blockbyheight/[Block Height]
### GET /v3/blocks/height/[Block Height]

Fetch a Nakamoto block given its block height. This returns the raw block
data.

This will return 404 if the block does not exist.

This endpoint also accepts a querystring parameter `?tip=` which when supplied will return the
block relative to the specified tip.

### GET /v3/tenures/[Block ID]

Fetch a Nakamoto block and all of its ancestors in the same tenure, given its
Expand Down
19 changes: 0 additions & 19 deletions stackslib/src/chainstate/nakamoto/staging_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,25 +302,6 @@ impl<'a> NakamotoStagingBlocksConnRef<'a> {
.optional()?)
}

/// Get the block ID of a staging block from block hash.
/// Used for downloads
pub fn get_block_id_by_block_hash(
&self,
block_hash: &BlockHeaderHash,
) -> Result<Option<StacksBlockId>, ChainstateError> {
let sql = "SELECT index_block_hash FROM nakamoto_staging_blocks WHERE block_hash = ?1";
let args = params![block_hash];

let mut stmt = self.deref().prepare(sql)?;
Ok(stmt
.query_row(args, |row| {
let block_id: StacksBlockId = row.get(0)?;

Ok(block_id)
})
.optional()?)
}

/// Get a Nakamoto block by index block hash, as well as its size.
/// Verifies its integrity.
/// Returns Ok(Some(block, size)) if the block was present
Expand Down
2 changes: 0 additions & 2 deletions stackslib/src/net/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ pub mod getattachment;
pub mod getattachmentsinv;
pub mod getblock;
pub mod getblock_v3;
pub mod getblockbyhash;
pub mod getblockbyheight;
pub mod getconstantval;
pub mod getcontractabi;
Expand Down Expand Up @@ -94,7 +93,6 @@ impl StacksHttp {
self.register_rpc_endpoint(getattachmentsinv::RPCGetAttachmentsInvRequestHandler::new());
self.register_rpc_endpoint(getblock::RPCBlocksRequestHandler::new());
self.register_rpc_endpoint(getblock_v3::RPCNakamotoBlockRequestHandler::new());
self.register_rpc_endpoint(getblockbyhash::RPCNakamotoBlockByHashRequestHandler::new());
self.register_rpc_endpoint(getblockbyheight::RPCNakamotoBlockByHeightRequestHandler::new());
self.register_rpc_endpoint(getconstantval::RPCGetConstantValRequestHandler::new());
self.register_rpc_endpoint(getcontractabi::RPCGetContractAbiRequestHandler::new());
Expand Down
123 changes: 0 additions & 123 deletions testnet/stacks-node/src/tests/nakamoto_integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9303,129 +9303,6 @@ fn v3_signer_api_endpoint() {
run_loop_thread.join().unwrap();
}

/// Test `/v3/blockbyhash` API endpoint
///
/// This endpoint returns the block blob given a height
#[test]
#[ignore]
fn v3_blockbyhash_api_endpoint() {
if env::var("BITCOIND_TEST") != Ok("1".into()) {
return;
}

let (mut conf, _miner_account) = naka_neon_integration_conf(None);
let password = "12345".to_string();
conf.connection_options.auth_token = Some(password.clone());
conf.miner.wait_on_interim_blocks = Duration::from_secs(1);
let stacker_sk = setup_stacker(&mut conf);
let signer_sk = Secp256k1PrivateKey::new();
let signer_addr = tests::to_addr(&signer_sk);
let sender_sk = Secp256k1PrivateKey::new();
// setup sender + recipient for some test stx transfers
// these are necessary for the interim blocks to get mined at all
let sender_addr = tests::to_addr(&sender_sk);
let send_amt = 100;
let send_fee = 180;
conf.add_initial_balance(
PrincipalData::from(sender_addr).to_string(),
send_amt + send_fee,
);
conf.add_initial_balance(PrincipalData::from(signer_addr).to_string(), 100000);

// only subscribe to the block proposal events
test_observer::spawn();
test_observer::register(&mut conf, &[EventKeyType::BlockProposal]);

let mut btcd_controller = BitcoinCoreController::new(conf.clone());
btcd_controller
.start_bitcoind()
.expect("Failed starting bitcoind");
let mut btc_regtest_controller = BitcoinRegtestController::new(conf.clone(), None);
btc_regtest_controller.bootstrap_chain(201);

let mut run_loop = boot_nakamoto::BootRunLoop::new(conf.clone()).unwrap();
let run_loop_stopper = run_loop.get_termination_switch();
let Counters {
blocks_processed,
naka_submitted_commits: commits_submitted,
naka_proposed_blocks: proposals_submitted,
..
} = run_loop.counters();

let coord_channel = run_loop.coordinator_channels();

let run_loop_thread = thread::spawn(move || run_loop.start(None, 0));
let mut signers = TestSigners::new(vec![signer_sk]);
wait_for_runloop(&blocks_processed);
boot_to_epoch_3(
&conf,
&blocks_processed,
&[stacker_sk],
&[signer_sk],
&mut Some(&mut signers),
&mut btc_regtest_controller,
);

info!("------------------------- Reached Epoch 3.0 -------------------------");

blind_signer(&conf, &signers, proposals_submitted);

wait_for_first_naka_block_commit(60, &commits_submitted);

// Mine 1 nakamoto tenure
next_block_and_mine_commit(
&mut btc_regtest_controller,
60,
&coord_channel,
&commits_submitted,
)
.unwrap();

let burnchain = conf.get_burnchain();
let sortdb = burnchain.open_sortition_db(true).unwrap();
let (chainstate, _) = StacksChainState::open(
conf.is_mainnet(),
conf.burnchain.chain_id,
&conf.get_chainstate_path_str(),
None,
)
.unwrap();

info!("------------------------- Setup finished, run test -------------------------");

let http_origin = format!("http://{}", &conf.node.rpc_bind);

let get_v3_block_by_hash = |block_hash: &str| {
let url = &format!("{http_origin}/v3/blockbyhash/{block_hash}");
info!("Send request: GET {url}");
reqwest::blocking::get(url).unwrap_or_else(|e| panic!("GET request failed: {e}"))
};

let tip = NakamotoChainState::get_canonical_block_header(chainstate.db(), &sortdb)
.unwrap()
.unwrap();

let block_hash = tip
.anchored_header
.as_stacks_nakamoto()
.unwrap()
.block_hash()
.to_string();
let block_data = get_v3_block_by_hash(&block_hash);
assert!(block_data.status().is_success());
assert!(block_data.bytes().unwrap().len() > 0);

info!("------------------------- Test finished, clean up -------------------------");

coord_channel
.lock()
.expect("Mutex poisoned")
.stop_chains_coordinator();
run_loop_stopper.store(false, Ordering::SeqCst);

run_loop_thread.join().unwrap();
}

/// Test `/v3/blocks/height` API endpoint
///
/// This endpoint returns the block blob given a height
Expand Down

0 comments on commit 1e628f7

Please sign in to comment.