Skip to content

Commit

Permalink
Merge branch 'release/5.0' of github.com:AntelopeIO/leap into gh_2330…
Browse files Browse the repository at this point in the history
…_5.0
  • Loading branch information
greg7mdp committed Aug 20, 2024
2 parents 49079ab + 9fb5719 commit dbc6f0b
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 17 deletions.
4 changes: 2 additions & 2 deletions libraries/chain/snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void variant_snapshot_reader::validate() const {
"Variant snapshot version is not an integer");

EOS_ASSERT(version.as_uint64() == (uint64_t)current_snapshot_version, snapshot_validation_exception,
"Variant snapshot is an unsuppored version. Expected : ${expected}, Got: ${actual}",
"Variant snapshot is an unsupported version. Expected : ${expected}, Got: ${actual}",
("expected", current_snapshot_version)("actual",o["version"].as_uint64()));

EOS_ASSERT(o.contains("sections"), snapshot_validation_exception,
Expand Down Expand Up @@ -253,7 +253,7 @@ void istream_snapshot_reader::validate() const {
decltype(expected_version) actual_version;
snapshot.read((char*)&actual_version, sizeof(actual_version));
EOS_ASSERT(actual_version == expected_version, snapshot_exception,
"Binary snapshot is an unsuppored version. Expected : ${expected}, Got: ${actual}",
"Binary snapshot is an unsupported version. Expected : ${expected}, Got: ${actual}",
("expected", expected_version)("actual", actual_version));

while (validate_section()) {}
Expand Down
7 changes: 6 additions & 1 deletion libraries/chain/snapshot_scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ void snapshot_scheduler::set_db_path(fs::path db_path) {
_snapshot_db >> sr;
// if db read succeeded, clear/load
_snapshot_requests.get<by_snapshot_id>().clear();
_snapshot_requests.insert(sr.begin(), sr.end());
for(snapshot_schedule_information& ssi : sr) {
//fix up Leap v4's "forever" value of 0 to MAX
if(ssi.end_block_num == 0)
ssi.end_block_num = std::numeric_limits<uint32_t>::max();
_snapshot_requests.insert(ssi);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/libfc/libraries/bls12-381
Submodule bls12-381 updated 2 files
+14 −14 src/fp.cpp
+22 −22 src/g.cpp
2 changes: 1 addition & 1 deletion plugins/chain_api_plugin/chain.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ paths:

/get_block_header_state:
post:
description: Retrieves the glock header state
description: Retrieves the block header state
operationId: get_block_header_state
requestBody:
content:
Expand Down
2 changes: 1 addition & 1 deletion plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2552,7 +2552,7 @@ read_only::get_required_keys_result read_only::get_required_keys( const get_requ
}

void read_only::compute_transaction(compute_transaction_params params, next_function<compute_transaction_results> next) {
send_transaction_params_t gen_params { .return_failure_trace = false,
send_transaction_params_t gen_params { .return_failure_trace = true,
.retry_trx = false,
.retry_trx_num_blocks = std::nullopt,
.trx_type = transaction_metadata::trx_type::dry_run,
Expand Down
11 changes: 3 additions & 8 deletions plugins/net_plugin/net_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2400,7 +2400,7 @@ namespace eosio {
if (msg.known_blocks.ids.empty()) {
peer_wlog( c, "got a catch up with ids size = 0" );
} else {
const block_id_type& id = msg.known_blocks.ids.back();
const block_id_type& id = msg.known_blocks.ids.front();
peer_ilog( c, "notice_message, pending ${p}, blk_num ${n}, id ${id}...",
("p", msg.known_blocks.pending)("n", block_header::num_from_id(id))("id",id.str().substr(8,16)) );
if( !my_impl->dispatcher->have_block( id ) ) {
Expand Down Expand Up @@ -2690,12 +2690,7 @@ namespace eosio {
return;
}
if (msg.known_blocks.mode == normal) {
// known_blocks.ids is never > 1
if( !msg.known_blocks.ids.empty() ) {
if( msg.known_blocks.pending == 1 ) { // block id notify of 2.0.0, ignore
return;
}
}
return;
} else if (msg.known_blocks.mode != none) {
peer_wlog( c, "passed a notice_message with something other than a normal on none known_blocks" );
return;
Expand Down Expand Up @@ -3547,7 +3542,7 @@ namespace eosio {
}
if( msg.known_trx.mode != none ) {
if( logger.is_enabled( fc::log_level::debug ) ) {
const block_id_type& blkid = msg.known_blocks.ids.empty() ? block_id_type{} : msg.known_blocks.ids.back();
const block_id_type& blkid = msg.known_blocks.ids.empty() ? block_id_type{} : msg.known_blocks.ids.front();
peer_dlog( this, "this is a ${m} notice with ${n} pending blocks: ${num} ${id}...",
("m", modes_str( msg.known_blocks.mode ))("n", msg.known_blocks.pending)
("num", block_header::num_from_id( blkid ))("id", blkid.str().substr( 8, 16 )) );
Expand Down
3 changes: 3 additions & 0 deletions plugins/producer_plugin/producer_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1542,6 +1542,9 @@ producer_plugin::schedule_snapshot(const chain::snapshot_scheduler::snapshot_req
.end_block_num = srp.end_block_num ? *srp.end_block_num : std::numeric_limits<uint32_t>::max(),
.snapshot_description = srp.snapshot_description ? *srp.snapshot_description : ""
};
//treat a 0 end_block_num as max for compatibility with leap4 behavior
if(sri.end_block_num == 0)
sri.end_block_num = std::numeric_limits<uint32_t>::max();

return my->_snapshot_scheduler.schedule_snapshot(sri);
}
Expand Down
70 changes: 67 additions & 3 deletions tests/test_snapshot_scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <eosio/producer_plugin/producer_plugin.hpp>
#include <eosio/testing/tester.hpp>

#include <regex>

using namespace eosio;
using namespace eosio::chain;

Expand Down Expand Up @@ -110,6 +112,7 @@ BOOST_AUTO_TEST_CASE(snapshot_scheduler_test) {
BOOST_REQUIRE(validate_snapshot_request(0, 9, 8)); // snapshot #0 should have pending snapshot at block #9 (8 + 1) and it never expires
BOOST_REQUIRE(validate_snapshot_request(4, 12, 10, true)); // snapshot #4 should have pending snapshot at block # at the moment of scheduling (2) plus 10 = 12
BOOST_REQUIRE(validate_snapshot_request(5, 10, 10)); // snapshot #5 should have pending snapshot at block #10, #20 etc
BOOST_REQUIRE(validate_snapshot_request(6, 15, 15)); // snapshot #6 should have pending snapshot at block #15, #30 etc
}
});

Expand All @@ -127,6 +130,7 @@ BOOST_AUTO_TEST_CASE(snapshot_scheduler_test) {
snapshot_request_params sri4 = {.start_block_num = 1, .snapshot_description = "One time snapshot on first block"};
snapshot_request_params sri5 = {.block_spacing = 10, .snapshot_description = "Recurring every 10 blocks snapshot starting now"};
snapshot_request_params sri6 = {.block_spacing = 10, .start_block_num = 0, .snapshot_description = "Recurring every 10 blocks snapshot starting from 0"};
snapshot_request_params sri7 = {.block_spacing = 15, .start_block_num = 0, .end_block_num = 0, .snapshot_description = "similar to above but with end_block_num=0 to be treated as max"};

app->post(appbase::priority::medium_low, [&]() {
prod_plug->schedule_snapshot(sri1);
Expand All @@ -135,16 +139,17 @@ BOOST_AUTO_TEST_CASE(snapshot_scheduler_test) {
prod_plug->schedule_snapshot(sri4);
prod_plug->schedule_snapshot(sri5);
prod_plug->schedule_snapshot(sri6);
prod_plug->schedule_snapshot(sri7);

// all six snapshot requests should be present now
BOOST_CHECK_EQUAL(6u, prod_plug->get_snapshot_requests().snapshot_requests.size());
BOOST_CHECK_EQUAL(7u, prod_plug->get_snapshot_requests().snapshot_requests.size());
});

at_block_20_fut.get();

app->post(appbase::priority::medium_low, [&]() {
// two of the snapshots are done here and requests, corresponding to them should be deleted
BOOST_CHECK_EQUAL(4u, prod_plug->get_snapshot_requests().snapshot_requests.size());
BOOST_CHECK_EQUAL(5u, prod_plug->get_snapshot_requests().snapshot_requests.size());

// check whether no pending snapshots present for a snapshot with id 0
const auto& snapshot_requests = prod_plug->get_snapshot_requests().snapshot_requests;
Expand All @@ -164,12 +169,71 @@ BOOST_AUTO_TEST_CASE(snapshot_scheduler_test) {
std::vector<snapshot_scheduler::snapshot_schedule_information> ssi;
db.set_path(temp / "snapshots");
db >> ssi;
BOOST_CHECK_EQUAL(4u, ssi.size());
BOOST_CHECK_EQUAL(5u, ssi.size());
BOOST_CHECK_EQUAL(ssi.begin()->block_spacing, *sri1.block_spacing);
} catch(...) {
throw;
}
}
}

//created via a schedule_snapshot with {"block_spacing":5,"snapshot_description":"banana"} on leap4
static const std::string old_schedule_json = R"===(
{
"snapshot_requests": [
{
"snapshot_request_id": "0",
"snapshot_description": "banana",
"block_spacing": "5",
"start_block_num": "0",
"end_block_num": "0"
}
]
}
)===";

BOOST_AUTO_TEST_CASE(snapshot_scheduler_old_json) {
fc::temp_directory temp_dir;
const std::filesystem::path& temp = temp_dir.path();
appbase::scoped_app app;

{
std::filesystem::create_directory(temp / "snapshots");
std::ofstream ofs(temp / "snapshots" / "snapshot-schedule.json");
ofs << old_schedule_json;
}

std::promise<void> at_block_16;

std::thread app_thread([&]() {
try {
fc::logger::get(DEFAULT_LOGGER).set_log_level(fc::log_level::debug);
std::vector<const char*> argv =
{"test", "--data-dir", temp.c_str(), "--config-dir", temp.c_str(),
"-p", "eosio", "-e"};
app->initialize<chain_plugin, producer_plugin>(argv.size(), (char**) &argv[0]);
app->startup();

app->get_plugin<chain_plugin>().chain().block_start.connect([&](uint32_t bn) {
if(bn == 16u)
at_block_16.set_value();
});

app->exec();
return;
} FC_LOG_AND_DROP()
BOOST_CHECK(!"app threw exception see logged error");
});
auto stopit = fc::make_scoped_exit([&](){app->quit(); app_thread.join();});

at_block_16.get_future().get();

const std::regex snapshotfile_regex(".bin$");

unsigned found = 0;
for(const std::filesystem::directory_entry& dir_entry : std::filesystem::directory_iterator(temp / "snapshots"))
found += std::regex_search(dir_entry.path().filename().string(), snapshotfile_regex);
BOOST_REQUIRE_GE(found, 3);
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit dbc6f0b

Please sign in to comment.