Skip to content

Commit

Permalink
open the plugin for docker and travis ,revise opinions
Browse files Browse the repository at this point in the history
  • Loading branch information
lelecommit committed Sep 5, 2019
1 parent 33fa8ca commit 35a77a8
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 45 deletions.
15 changes: 14 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,20 @@ sudo: true

install:
- sudo apt-get install --allow-unauthenticated libboost-thread-dev libboost-iostreams-dev libboost-date-time-dev libboost-system-dev libboost-filesystem-dev libboost-program-options-dev libboost-chrono-dev libboost-test-dev libboost-context-dev libboost-regex-dev libboost-coroutine-dev cmake parallel

- wget https://github.com/google/leveldb/archive/v1.20.tar.gz
- tar xvf v1.20.tar.gz
- rm -f v1.20.tar.gz
- cd leveldb-1.20
- make
- sudo cp -r out-static/lib* out-shared/lib* "/usr/local/lib"
- cd include
- sudo cp -r leveldb /usr/local/include
- sudo ldconfig
- git clone https://github.com/google/snappy.git
- cd snappy
- mkdir build
- cd build && cmake ../
- sudo make install
addons:
sonarcloud:
organization: "flwyiq7go36p6lipr64tbesy5jayad3q"
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ else()
set( CMAKE_CXX_EXTENSIONS OFF )
endif()

option(LOAD_QUERY_TXID_PLUGIN "Build with query_txid plugin." OFF)
option(LOAD_QUERY_TXID_PLUGIN "Build with query_txid plugin." ON)
if(${LOAD_QUERY_TXID_PLUGIN} STREQUAL "ON")
add_definitions(-DQUERY_TXID_PLUGIN_ABLE)
set( QUERY_TXID graphene_query_txid)
Expand Down
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ RUN \
fish \
&& \
apt-get clean && \
wget https://github.com/google/leveldb/archive/v1.20.tar.gz && \
tar xvf v1.20.tar.gz && \
rm -f v1.20.tar.gz && \
cd leveldb-1.20 && \
make && \
sudo cp -r out-static/lib* out-shared/lib* "/usr/local/lib" && \
cd include && \
sudo cp -r leveldb /usr/local/include && \
sudo ldconfig && \
git clone https://github.com/google/snappy.git && \
cd snappy && \
mkdir build && \
cd build && cmake ../ &&\
sudo make install &&\
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ADD . /bitshares-core
Expand Down
35 changes: 12 additions & 23 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1879,7 +1879,7 @@ std::string database_api::get_transaction_hex(const signed_transaction& trx)cons
{
return my->get_transaction_hex( trx );
}
optional<processed_transaction> database_api::get_transaction_by_txid(transaction_id_type txid)const
optional<query_trx_info> database_api::get_transaction_by_txid(transaction_id_type txid)const
{
return my->get_transaction_by_txid(txid);
}
Expand All @@ -1893,38 +1893,27 @@ std::string database_api::get_transaction_hex_without_sig(
{
return my->get_transaction_hex_without_sig(trx);
}
optional<processed_transaction> database_api_impl::get_transaction_by_txid(transaction_id_type txid)const
optional<query_trx_info> database_api_impl::get_transaction_by_txid(transaction_id_type txid)const
{
#ifdef QUERY_TXID_PLUGIN_ABLE
auto &txid_index = _db.get_index_type<trx_entry_index>().indices().get<by_txid>();
auto itor = txid_index.find(txid);
auto trx_entry = *itor;
if (itor == txid_index.end()) {
std::string txid_str(txid);
auto result = query_txid::query_txid_plugin::query_trx_by_id(txid_str);
if (result) {
const auto &trx_entry = *result;
auto opt_block = _db.fetch_block_by_number(trx_entry.block_num);
FC_ASSERT(opt_block);
FC_ASSERT(opt_block->transactions.size() > trx_entry.trx_in_block);
optional<processed_transaction> res = opt_block->transactions[trx_entry.trx_in_block];
return res;
trx_entry = *result;
}
return {};
} else {
const auto &dpo = _db.get_dynamic_global_properties();
if (itor->block_num <= dpo.last_irreversible_block_num) {
const auto &trx_entry = *itor;
auto opt_block = _db.fetch_block_by_number(trx_entry.block_num);
FC_ASSERT(opt_block);
FC_ASSERT(opt_block->transactions.size() > trx_entry.trx_in_block);
optional<processed_transaction> res = opt_block->transactions[trx_entry.trx_in_block];
return res;
} else {
return {};
}
}
}
auto opt_block = _db.fetch_block_by_number(trx_entry.block_num);
FC_ASSERT(opt_block);
FC_ASSERT(opt_block->transactions.size() > trx_entry.trx_in_block);
optional<query_trx_info> res = opt_block->transactions[trx_entry.trx_in_block];
res->query_txid_block_number = trx_entry.block_num;
res->query_txid_trx_in_block = trx_entry.trx_in_block;
return res;
#endif
return {};
}

std::string database_api_impl::get_transaction_hex_without_sig(
Expand Down
2 changes: 1 addition & 1 deletion libraries/app/database_api_impl.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
map<uint32_t, optional<block_header>> get_block_header_batch(const vector<uint32_t> block_nums)const;
optional<signed_block> get_block(uint32_t block_num)const;
processed_transaction get_transaction( uint32_t block_num, uint32_t trx_in_block )const;
optional<processed_transaction> get_transaction_by_txid(transaction_id_type txid)const;
optional<query_trx_info> get_transaction_by_txid(transaction_id_type txid)const;
// Globals
chain_property_object get_chain_properties()const;
global_property_object get_global_properties()const;
Expand Down
6 changes: 4 additions & 2 deletions libraries/app/include/graphene/app/database_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
#include <fc/variant_object.hpp>

#include <fc/network/ip.hpp>
#include <graphene/chain/transaction_entry_object.hpp>
#ifdef QUERY_TXID_PLUGIN_ABLE
#include <graphene/query_txid/transaction_entry_object.hpp>
#endif
#include <boost/container/flat_set.hpp>

#include <functional>
Expand Down Expand Up @@ -177,7 +179,7 @@ class database_api
* @return the transaction at the given position
*/
processed_transaction get_transaction( uint32_t block_num, uint32_t trx_in_block )const;
optional<processed_transaction> get_transaction_by_txid(transaction_id_type txid)const;
optional<query_trx_info> get_transaction_by_txid(transaction_id_type txid)const;

/**
* If the transaction has not expired, this method will return the transaction for the given ID or
Expand Down
3 changes: 1 addition & 2 deletions libraries/chain/include/graphene/chain/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,4 @@ GRAPHENE_DEFINE_IDS(chain, implementation_ids, impl_,
(special_authority)
(buyback)
(fba_accumulator)
(collateral_bid)
(trx_entry_history))
(collateral_bid))
1 change: 1 addition & 0 deletions libraries/plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ Folder | Name | Description
[market_history](market_history) | Market History | Save market history data | Market data | Stable | 5
[snapshot](snapshot) | Snapshot | Get a json of all objects in blockchain at a specificed time or block | Debug | Stable |
[witness](witness) | Witness | Generate and sign blocks | Block producer | Stable |
[query_txid](query_txid) | Query_txid | Get the transaction data by transaction id | Data | Experimental | 8
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
#pragma once
#include <graphene/app/plugin.hpp>
#include <graphene/chain/transaction_entry_object.hpp>
#include <graphene/query_txid/transaction_entry_object.hpp>
#include <graphene/chain/database.hpp>
namespace graphene
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,28 @@

namespace graphene { namespace chain {

struct query_trx_info : public graphene::protocol::processed_transaction
{
query_trx_info( const signed_transaction& trx = signed_transaction())
: processed_transaction(trx){}

virtual ~query_trx_info() = default;

uint64_t query_txid_block_number = 0;
uint64_t query_txid_trx_in_block = 0;
};
#ifndef QUERY_TXID_SPACE_ID
#define QUERY_TXID_SPACE_ID 8
#endif
enum query_txid_object_type
{
transaction_position_object_type = 0
};
class trx_entry_object : public abstract_object<trx_entry_object>
{
public:
static const uint8_t space_id = implementation_ids;
static const uint8_t type_id = impl_trx_entry_history_object_type;

static const uint8_t space_id = QUERY_TXID_SPACE_ID;
static const uint8_t type_id = transaction_position_object_type;
trx_entry_object(){}

transaction_id_type txid;
Expand All @@ -60,3 +76,5 @@ namespace graphene { namespace chain {

FC_REFLECT_DERIVED( graphene::chain::trx_entry_object, (graphene::chain::object),
(txid)(block_num)(trx_in_block))
FC_REFLECT_DERIVED( graphene::chain::query_trx_info, (graphene::protocol::processed_transaction),
(query_txid_block_number)(query_txid_trx_in_block))
18 changes: 7 additions & 11 deletions libraries/plugins/query_txid/query_txid_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
#include <graphene/query_txid/query_txid_plugin.hpp>
#include <fc/io/fstream.hpp>
#include <graphene/chain/transaction_entry_object.hpp>
#include <graphene/query_txid/transaction_entry_object.hpp>
#include <queue>
#include <thread>
#include <mutex>
Expand Down Expand Up @@ -58,11 +58,8 @@ class query_txid_plugin_impl
static optional<trx_entry_object> query_trx_by_id(std::string txid);
std::string db_path = "trx_entry.db";
uint64_t limit_batch = 1000;

private:
query_txid_plugin &_self;

fc::signal<void()> sig_db_write;
fc::signal<void(const uint64_t)> sig_remove;

static leveldb::DB *leveldb;
Expand All @@ -76,9 +73,9 @@ void query_txid_plugin_impl::init()
try {
leveldb::Options options;
options.create_if_missing = true;
db_path = database().get_data_dir().string() + db_path;
leveldb::Status s = leveldb::DB::Open(options, db_path, &leveldb);
sig_db_write.connect([&]() { consume_block(); });
sig_remove.connect([&](const uint64_t trx_entry_id) { remove_trx_index(trx_entry_id); });
sig_remove.connect([this](const uint64_t trx_entry_id) { remove_trx_index(trx_entry_id); });
}
FC_LOG_AND_RETHROW()
}
Expand All @@ -90,8 +87,7 @@ optional<trx_entry_object> query_txid_plugin_impl::query_trx_by_id(std::string t
leveldb::Status s = leveldb->Get(leveldb::ReadOptions(), txid, &value);
if (!s.ok()) return optional<trx_entry_object>();
std::vector<char> data(value.begin(), value.end());
auto result = fc::raw::unpack<trx_entry_object>(data);
return result;
return fc::raw::unpack<trx_entry_object>(data);
}
FC_LOG_AND_RETHROW()
}
Expand All @@ -100,13 +96,13 @@ void query_txid_plugin_impl::collect_txid_index(const signed_block &b)
try {
graphene::chain::database &db = database();
for (unsigned int idx = 0; idx < b.transactions.size(); idx++) {
db.create<trx_entry_object>([&](trx_entry_object &obj) {
db.create<trx_entry_object>([&b,&idx](trx_entry_object &obj) {
obj.txid = b.transactions[idx].id();
obj.block_num = b.block_num();
obj.trx_in_block = idx;
});
}
sig_db_write();
consume_block();
}
FC_LOG_AND_RETHROW()
}
Expand Down Expand Up @@ -200,7 +196,7 @@ void query_txid_plugin::plugin_initialize(const boost::program_options::variable
try {
ilog("query_txid plugin initialized");
database().add_index<primary_index<trx_entry_index>>();
database().applied_block.connect([&](const signed_block &b) { my->collect_txid_index(b); });
database().applied_block.connect([this](const signed_block &b) { my->collect_txid_index(b); });
if (options.count("query-txid-path")) {
my->db_path = options["query-txid-path"].as<std::string>();
if (!fc::exists(my->db_path))
Expand Down

0 comments on commit 35a77a8

Please sign in to comment.