Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

refactor get_kv_table_rows #9964

Merged
merged 8 commits into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace eosio { namespace chain {
uint32_t* found_key_size, uint32_t* found_value_size) = 0;
virtual kv_it_stat kv_it_key(uint32_t offset, char* dest, uint32_t size, uint32_t& actual_size) = 0;
virtual kv_it_stat kv_it_value(uint32_t offset, char* dest, uint32_t size, uint32_t& actual_size) = 0;
virtual std::optional<name> kv_it_payer() = 0;
};

struct kv_resource_trace {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ namespace eosio { namespace chain {
int32_t kv_it_compare(const kv_iterator& rhs) override {
EOS_ASSERT(rhs.is_kv_chainbase_context_iterator(), kv_bad_iter, "Incompatible key-value iterators");
auto& r = static_cast<const kv_iterator_chainbase&>(rhs);

EOS_ASSERT(contract == r.contract, kv_bad_iter, "Incompatible key-value iterators");
EOS_ASSERT(!current || !tracker.is_removed(*current), kv_bad_iter, "Iterator to erased element");
EOS_ASSERT(!r.current || !tracker.is_removed(*r.current), kv_bad_iter, "Iterator to erased element");
Expand All @@ -69,6 +70,7 @@ namespace eosio { namespace chain {
if (!current) {
return 1;
}

return compare_blob(current->kv_key, r.current->kv_key);
}

Expand Down Expand Up @@ -137,6 +139,11 @@ namespace eosio { namespace chain {
actual_size = current->kv_value.size();
return kv_it_stat::iterator_ok;
}

std::optional<name> kv_it_payer() override {
if (!current) return {};
return current->payer;
}
}; // kv_iterator_chainbase

template<typename Resource_manager>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,17 @@ namespace eosio { namespace chain {
}
}

std::optional<name> kv_it_payer() override {
EOS_ASSERT(!kv_current.deleted(), kv_bad_iter, "Iterator to erased element");
if (kv_it_status() == kv_it_stat::iterator_ok) {
const auto& value = (*kv_current).second;
if (value) {
return backing_store::payer_payload(*value).payer;
}
}
return {};
}

private:
kv_it_stat get_current_key_value_sizes(uint32_t* found_key_size, uint32_t* found_value_size) {
auto status = kv_it_status();
Expand Down
915 changes: 414 additions & 501 deletions plugins/chain_plugin/chain_plugin.cpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,7 @@ class read_only {

get_table_rows_result get_table_rows( const get_table_rows_params& params )const;

constexpr uint32_t prefix_size() const { return 1 + 2 * sizeof(uint64_t); }
void convert_key(const string& index_type, const string& encode_type, const string& index_value, vector<char>& bin)const;
void make_prefix(eosio::name table_name, eosio::name index_name, uint8_t status, vector<char> &prefix)const;
get_table_rows_result get_kv_table_rows( const get_kv_table_rows_params& params )const;
get_table_rows_result get_kv_table_rows_context( const read_only::get_kv_table_rows_params& p, eosio::chain::kv_context &kv_context, const abi_def &abi )const;
void set_kv_next_key(const string& encode_type, const string& index_type, read_only::get_table_rows_result& result) const;

struct get_table_by_scope_params {
name code; // mandatory
Expand Down
36 changes: 17 additions & 19 deletions tests/get_kv_table_addr_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@
#define TESTER validating_tester
#endif

using namespace eosio;
BOOST_AUTO_TEST_SUITE(get_kv_table_addr_tests)

using namespace eosio::chain;
using namespace eosio::testing;
using namespace fc;

BOOST_AUTO_TEST_SUITE(get_kv_table_addr_tests)


BOOST_FIXTURE_TEST_CASE( get_kv_table_addr_test, TESTER ) try {
eosio::chain_apis::read_only::get_table_rows_result result;
auto chk_result = [&](int row, int data) {
Expand Down Expand Up @@ -111,19 +109,19 @@ BOOST_FIXTURE_TEST_CASE( get_kv_table_addr_test, TESTER ) try {
p.index_name = "accname"_n;
p.index_value = "john";
p.encode_type = "name";
p.lower_bound = "";
p.upper_bound = "";
p.lower_bound = {};
p.upper_bound = {};
p.json = true;
p.reverse = false;
result = plugin.read_only::get_kv_table_rows(p);
BOOST_REQUIRE_EQUAL(1u, result.rows.size());
chk_result(0, 2);

p.index_name = "accname"_n;
p.index_value = "";
p.index_value = {};
p.encode_type = "name";
p.lower_bound = "aaa";
p.upper_bound = "";
p.upper_bound = {};
p.reverse = false;
result = plugin.read_only::get_kv_table_rows(p);
BOOST_REQUIRE_EQUAL(4u, result.rows.size());
Expand All @@ -133,10 +131,10 @@ BOOST_FIXTURE_TEST_CASE( get_kv_table_addr_test, TESTER ) try {
chk_result(3, 4);

p.index_name = "accname"_n;
p.index_value = "";
p.index_value = {};
p.encode_type = "name";
p.lower_bound = "john";
p.upper_bound = "";
p.upper_bound = {};
p.reverse = false;
result = plugin.read_only::get_kv_table_rows(p);
BOOST_REQUIRE_EQUAL(3u, result.rows.size());
Expand All @@ -145,7 +143,7 @@ BOOST_FIXTURE_TEST_CASE( get_kv_table_addr_test, TESTER ) try {
chk_result(2, 4);

p.index_name = "accname"_n;
p.index_value = "";
p.index_value = {};
p.encode_type = "name";
p.lower_bound = "john";
p.upper_bound = "lois";
Expand All @@ -155,9 +153,9 @@ BOOST_FIXTURE_TEST_CASE( get_kv_table_addr_test, TESTER ) try {
chk_result(0, 2);

p.index_name = "accname"_n;
p.index_value = "";
p.index_value = {};
p.encode_type = "name";
p.lower_bound = "";
p.lower_bound = {};
p.upper_bound = "steve";
p.reverse = true;
result = plugin.read_only::get_kv_table_rows(p);
Expand All @@ -168,7 +166,7 @@ BOOST_FIXTURE_TEST_CASE( get_kv_table_addr_test, TESTER ) try {
chk_result(3, 1);

p.index_name = "accname"_n;
p.index_value = "";
p.index_value = {};
p.encode_type = "name";
p.lower_bound = "john";
p.upper_bound = "steve";
Expand All @@ -179,16 +177,16 @@ BOOST_FIXTURE_TEST_CASE( get_kv_table_addr_test, TESTER ) try {
chk_result(1, 3);

p.index_name = "accname"_n;
p.index_value = "";
p.index_value = {};
p.encode_type = "name";
p.lower_bound = "";
p.lower_bound = {};
p.upper_bound = "aaaa";
p.reverse = true;
result = plugin.read_only::get_kv_table_rows(p);
BOOST_REQUIRE_EQUAL(0u, result.rows.size());

p.index_name = "accname"_n;
p.index_value = "";
p.index_value = {};
p.encode_type = "name";
p.lower_bound = "steve";
p.upper_bound = "john";
Expand All @@ -197,9 +195,9 @@ BOOST_FIXTURE_TEST_CASE( get_kv_table_addr_test, TESTER ) try {
BOOST_REQUIRE_EQUAL(0u, result.rows.size());

p.index_name = "accname"_n;
p.index_value = "";
p.index_value = {};
p.encode_type = "name";
p.lower_bound = "";
p.lower_bound = {};
p.upper_bound = "john";
p.reverse = true;
result = plugin.read_only::get_kv_table_rows(p);
Expand Down
Loading