Skip to content

Commit

Permalink
GH-1941 Remove v1/chain/get_block_header_state
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Dec 21, 2023
1 parent fffbe1e commit b5c6cc0
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 88 deletions.
24 changes: 0 additions & 24 deletions plugins/chain_api_plugin/chain.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -186,30 +186,6 @@ paths:
schema:
description: Returns Nothing

/get_block_header_state:
post:
description: Retrieves the glock header state
operationId: get_block_header_state
requestBody:
content:
application/json:
schema:
type: object
required:
- block_num_or_id
properties:
block_num_or_id:
type: string
description: Provide a block_number or a block_id

responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "https://docs.eosnetwork.com/openapi/v2.0/BlockHeaderState.yaml"

/get_abi:
post:
description: Retrieves the ABI for a contract based on its account name
Expand Down
1 change: 0 additions & 1 deletion plugins/chain_api_plugin/chain_api_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ void chain_api_plugin::plugin_startup() {
CHAIN_RO_CALL(get_activated_protocol_features, 200, http_params_types::possible_no_params),
CHAIN_RO_CALL_POST(get_block, fc::variant, 200, http_params_types::params_required), // _POST because get_block() returns a lambda to be executed on the http thread pool
CHAIN_RO_CALL(get_block_info, 200, http_params_types::params_required),
CHAIN_RO_CALL(get_block_header_state, 200, http_params_types::params_required),
CHAIN_RO_CALL_POST(get_account, chain_apis::read_only::get_account_results, 200, http_params_types::params_required),
CHAIN_RO_CALL(get_code, 200, http_params_types::params_required),
CHAIN_RO_CALL(get_code_hash, 200, http_params_types::params_required),
Expand Down
23 changes: 0 additions & 23 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2011,29 +2011,6 @@ fc::variant read_only::get_block_info(const read_only::get_block_info_params& pa
("ref_block_prefix", ref_block_prefix);
}

fc::variant read_only::get_block_header_state(const get_block_header_state_params& params, const fc::time_point&) const {
block_state_legacy_ptr b;
std::optional<uint64_t> block_num;
std::exception_ptr e;
try {
block_num = fc::to_uint64(params.block_num_or_id);
} catch( ... ) {}

if( block_num ) {
b = db.fetch_block_state_by_number(*block_num);
} else {
try {
b = db.fetch_block_state_by_id(fc::variant(params.block_num_or_id).as<block_id_type>());
} EOS_RETHROW_EXCEPTIONS(chain::block_id_type_exception, "Invalid block ID: ${block_num_or_id}", ("block_num_or_id", params.block_num_or_id))
}

EOS_ASSERT( b, unknown_block_exception, "Could not find reversible block: ${block}", ("block", params.block_num_or_id));

fc::variant vo;
fc::to_variant( static_cast<const block_header_state_legacy&>(*b), vo );
return vo;
}

void read_write::push_block(read_write::push_block_params&& params, next_function<read_write::push_block_results> next) {
try {
app().get_method<incoming::methods::block_sync>()(std::make_shared<signed_block>( std::move(params) ), std::optional<block_id_type>{}, block_state_legacy_ptr{});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,12 +409,6 @@ class read_only : public api_base {

fc::variant get_block_info(const get_block_info_params& params, const fc::time_point& deadline) const;

struct get_block_header_state_params {
string block_num_or_id;
};

fc::variant get_block_header_state(const get_block_header_state_params& params, const fc::time_point& deadline) const;

struct get_table_rows_params {
bool json = false;
name code;
Expand Down Expand Up @@ -1067,7 +1061,6 @@ FC_REFLECT(eosio::chain_apis::read_only::get_activated_protocol_features_params,
FC_REFLECT(eosio::chain_apis::read_only::get_activated_protocol_features_results, (activated_protocol_features)(more) )
FC_REFLECT(eosio::chain_apis::read_only::get_raw_block_params, (block_num_or_id))
FC_REFLECT(eosio::chain_apis::read_only::get_block_info_params, (block_num))
FC_REFLECT(eosio::chain_apis::read_only::get_block_header_state_params, (block_num_or_id))
FC_REFLECT(eosio::chain_apis::read_only::get_block_header_params, (block_num_or_id)(include_extensions))
FC_REFLECT(eosio::chain_apis::read_only::get_block_header_result, (id)(signed_block_header)(block_extensions))

Expand Down
1 change: 0 additions & 1 deletion programs/cleos/httpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ namespace eosio { namespace client { namespace http {
const string get_raw_block_func = chain_func_base + "/get_raw_block";
const string get_block_header_func = chain_func_base + "/get_block_header";
const string get_block_info_func = chain_func_base + "/get_block_info";
const string get_block_header_state_func = chain_func_base + "/get_block_header_state";
const string get_account_func = chain_func_base + "/get_account";
const string get_table_func = chain_func_base + "/get_table_rows";
const string get_table_by_scope_func = chain_func_base + "/get_table_by_scope";
Expand Down
7 changes: 2 additions & 5 deletions programs/cleos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3016,15 +3016,14 @@ int main( int argc, char** argv ) {
get_block_params params;
auto getBlock = get->add_subcommand("block", localized("Retrieve a full block from the blockchain"));
getBlock->add_option("block", params.blockArg, localized("The number or ID of the block to retrieve"))->required();
getBlock->add_flag("--header-state", params.get_bhs, localized("Get block header state from fork database instead") );
getBlock->add_flag("--info", params.get_binfo, localized("Get block info from the blockchain by block num only") );
getBlock->add_flag("--raw", params.get_braw, localized("Get raw block from the blockchain") );
getBlock->add_flag("--header", params.get_bheader, localized("Get block header from the blockchain") );
getBlock->add_flag("--header-with-extensions", params.get_bheader_extensions, localized("Get block header with block exntesions from the blockchain") );

getBlock->callback([&params] {
int num_flags = params.get_bhs + params.get_binfo + params.get_braw + params.get_bheader + params.get_bheader_extensions;
EOSC_ASSERT( num_flags <= 1, "ERROR: Only one of the following flags can be set: --header-state, --info, --raw, --header, --header-with-extensions." );
EOSC_ASSERT( num_flags <= 1, "ERROR: Only one of the following flags can be set: --info, --raw, --header, --header-with-extensions." );
if (params.get_binfo) {
std::optional<int64_t> block_num;
try {
Expand All @@ -3037,9 +3036,7 @@ int main( int argc, char** argv ) {
std::cout << fc::json::to_pretty_string(call(get_block_info_func, arg)) << std::endl;
} else {
const auto arg = fc::variant_object("block_num_or_id", params.blockArg);
if (params.get_bhs) {
std::cout << fc::json::to_pretty_string(call(get_block_header_state_func, arg)) << std::endl;
} else if (params.get_braw) {
if (params.get_braw) {
std::cout << fc::json::to_pretty_string(call(get_raw_block_func, arg)) << std::endl;
} else if (params.get_bheader || params.get_bheader_extensions) {
std::cout << fc::json::to_pretty_string(
Expand Down
19 changes: 0 additions & 19 deletions tests/plugin_http_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,25 +336,6 @@ def test_ChainApi(self) :
ret_json = self.nodeos.processUrllibRequest(resource, command, payload, endpoint=endpoint)
self.assertEqual(ret_json["payload"]["block_num"], 1)

# get_block_header_state with empty parameter
command = "get_block_header_state"
ret_json = self.nodeos.processUrllibRequest(resource, command, endpoint=endpoint)
self.assertEqual(ret_json["code"], 400)
self.assertEqual(ret_json["error"]["code"], 3200006)
# get_block_header_state with empty content parameter
ret_json = self.nodeos.processUrllibRequest(resource, command, self.empty_content_dict, endpoint=endpoint)
self.assertEqual(ret_json["code"], 400)
self.assertEqual(ret_json["error"]["code"], 3200006)
# get_block_header_state with invalid parameter
ret_json = self.nodeos.processUrllibRequest(resource, command, self.http_post_invalid_param, endpoint=endpoint)
self.assertEqual(ret_json["code"], 400)
self.assertEqual(ret_json["error"]["code"], 3200006)
# get_block_header_state with valid parameter, the irreversible is not available, unknown block number
payload = {"block_num_or_id":1}
ret_json = self.nodeos.processUrllibRequest(resource, command, payload, endpoint=endpoint)
self.assertEqual(ret_json["code"], 400)
self.assertEqual(ret_json["error"]["code"], 3100002)

# get_account with empty parameter
command = "get_account"
ret_json = self.nodeos.processUrllibRequest(resource, command, endpoint=endpoint)
Expand Down
8 changes: 0 additions & 8 deletions unittests/chain_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,6 @@ BOOST_AUTO_TEST_CASE( signal_validated_blocks ) try {
const auto& [ block, id ] = t;
auto block_num = block->block_num();
BOOST_CHECK(block);
const auto& bsp_by_id = chain.control->fetch_block_state_by_id(id);
BOOST_CHECK(bsp_by_id->block_num() == block_num);
const auto& bsp_by_number = chain.control->fetch_block_state_by_number(block_num); // verify it can be found (has to be validated)
BOOST_CHECK(bsp_by_number->id() == id);
BOOST_CHECK(chain.control->fetch_block_by_id(id) == block);
BOOST_CHECK(chain.control->fetch_block_by_number(block_num) == block);
BOOST_REQUIRE(chain.control->fetch_block_header_by_number(block_num));
Expand All @@ -175,10 +171,6 @@ BOOST_AUTO_TEST_CASE( signal_validated_blocks ) try {
const auto& [ block, id ] = t;
auto block_num = block->block_num();
BOOST_CHECK(block);
const auto& bsp_by_id = validator.control->fetch_block_state_by_id(id);
BOOST_CHECK(bsp_by_id->block_num() == block_num);
const auto& bsp_by_number = validator.control->fetch_block_state_by_number(block_num); // verify it can be found (has to be validated)
BOOST_CHECK(bsp_by_number->id() == id);
BOOST_CHECK(validator.control->fetch_block_by_id(id) == block);
BOOST_CHECK(validator.control->fetch_block_by_number(block_num) == block);
BOOST_REQUIRE(validator.control->fetch_block_header_by_number(block_num));
Expand Down

0 comments on commit b5c6cc0

Please sign in to comment.