Merge branch 'develop' into local_test_block_events
This commit is contained in:
commit
ed9ffc4a39
27 changed files with 1093 additions and 423 deletions
|
|
@ -9,6 +9,7 @@ stages:
|
||||||
- build
|
- build
|
||||||
- test
|
- test
|
||||||
- dockerize
|
- dockerize
|
||||||
|
- python-test
|
||||||
|
|
||||||
build-mainnet:
|
build-mainnet:
|
||||||
stage: build
|
stage: build
|
||||||
|
|
@ -48,6 +49,7 @@ dockerize-mainnet:
|
||||||
IMAGE: $CI_REGISTRY_IMAGE/mainnet/$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA
|
IMAGE: $CI_REGISTRY_IMAGE/mainnet/$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA
|
||||||
before_script:
|
before_script:
|
||||||
- docker info
|
- docker info
|
||||||
|
- docker builder prune -a -f
|
||||||
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
|
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
|
||||||
script:
|
script:
|
||||||
- docker build --no-cache -t $IMAGE .
|
- docker build --no-cache -t $IMAGE .
|
||||||
|
|
@ -56,8 +58,6 @@ dockerize-mainnet:
|
||||||
- docker rmi $IMAGE
|
- docker rmi $IMAGE
|
||||||
tags:
|
tags:
|
||||||
- builder
|
- builder
|
||||||
when:
|
|
||||||
manual
|
|
||||||
timeout:
|
timeout:
|
||||||
3h
|
3h
|
||||||
|
|
||||||
|
|
@ -119,3 +119,32 @@ dockerize-testnet:
|
||||||
manual
|
manual
|
||||||
timeout:
|
timeout:
|
||||||
3h
|
3h
|
||||||
|
|
||||||
|
test-e2e:
|
||||||
|
stage: python-test
|
||||||
|
variables:
|
||||||
|
IMAGE: $CI_REGISTRY_IMAGE/mainnet/$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA
|
||||||
|
before_script:
|
||||||
|
- docker info
|
||||||
|
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
|
||||||
|
script:
|
||||||
|
- git clone https://gitlab.com/PBSA/tools-libs/peerplays-utils.git
|
||||||
|
- cd peerplays-utils/peerplays-qa-environment
|
||||||
|
- git checkout origin/feature/python-e2e-tests-for-CI
|
||||||
|
- cd e2e-tests/
|
||||||
|
- python3 -m venv venv
|
||||||
|
- source venv/bin/activate
|
||||||
|
- pip3 install -r requirements.txt
|
||||||
|
- python3 main.py --stop
|
||||||
|
- docker ps -a
|
||||||
|
- docker pull $IMAGE
|
||||||
|
- docker tag $IMAGE peerplays-base:latest
|
||||||
|
- docker image ls -a
|
||||||
|
- python3 main.py --start all
|
||||||
|
- docker ps -a
|
||||||
|
- python3 -m pytest test_btc_init_state.py test_hive_inital_state.py test_pp_inital_state.py
|
||||||
|
- python3 main.py --stop
|
||||||
|
- deactivate
|
||||||
|
- docker ps -a
|
||||||
|
tags:
|
||||||
|
- python-tests
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,7 @@ RUN \
|
||||||
RUN \
|
RUN \
|
||||||
git clone https://github.com/libbitcoin/libbitcoin-build.git && \
|
git clone https://github.com/libbitcoin/libbitcoin-build.git && \
|
||||||
cd libbitcoin-build && \
|
cd libbitcoin-build && \
|
||||||
|
git reset --hard 92c215fc1ffa272bab4d485d369d0306db52d69d && \
|
||||||
./generate3.sh && \
|
./generate3.sh && \
|
||||||
cd ../libbitcoin-explorer && \
|
cd ../libbitcoin-explorer && \
|
||||||
./install.sh && \
|
./install.sh && \
|
||||||
|
|
@ -189,7 +190,6 @@ ADD . peerplays
|
||||||
RUN \
|
RUN \
|
||||||
cd peerplays && \
|
cd peerplays && \
|
||||||
git submodule update --init --recursive && \
|
git submodule update --init --recursive && \
|
||||||
git symbolic-ref --short HEAD && \
|
|
||||||
git log --oneline -n 5 && \
|
git log --oneline -n 5 && \
|
||||||
mkdir build && \
|
mkdir build && \
|
||||||
cd build && \
|
cd build && \
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,7 @@ RUN \
|
||||||
RUN \
|
RUN \
|
||||||
git clone https://github.com/libbitcoin/libbitcoin-build.git && \
|
git clone https://github.com/libbitcoin/libbitcoin-build.git && \
|
||||||
cd libbitcoin-build && \
|
cd libbitcoin-build && \
|
||||||
|
git reset --hard 92c215fc1ffa272bab4d485d369d0306db52d69d && \
|
||||||
./generate3.sh && \
|
./generate3.sh && \
|
||||||
cd ../libbitcoin-explorer && \
|
cd ../libbitcoin-explorer && \
|
||||||
./install.sh && \
|
./install.sh && \
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,7 @@ libbitcoin-explorer setup:
|
||||||
```
|
```
|
||||||
git clone https://github.com/libbitcoin/libbitcoin-build.git
|
git clone https://github.com/libbitcoin/libbitcoin-build.git
|
||||||
cd libbitcoin-build
|
cd libbitcoin-build
|
||||||
|
git reset --hard 92c215fc1ffa272bab4d485d369d0306db52d69d
|
||||||
./generate3.sh
|
./generate3.sh
|
||||||
cd ../libbitcoin-explorer
|
cd ../libbitcoin-explorer
|
||||||
sudo ./install.sh
|
sudo ./install.sh
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,54 @@ void verify_authority_accounts( const database& db, const authority& a )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void verify_account_votes( const database& db, const account_options& options )
|
// Overwrites the num_son values from the origin to the destination for those sidechains which are found in the origin.
|
||||||
|
// Keeps the values of num_son for the sidechains which are found in the destination, but not in the origin.
|
||||||
|
// Returns false if an error is detected.
|
||||||
|
bool merge_num_sons( flat_map<sidechain_type, uint16_t>& destination,
|
||||||
|
const flat_map<sidechain_type, uint16_t>& origin,
|
||||||
|
fc::optional<time_point_sec> head_block_time = {})
|
||||||
|
{
|
||||||
|
const auto active_sidechains = head_block_time.valid() ? active_sidechain_types(*head_block_time) : all_sidechain_types;
|
||||||
|
bool success = true;
|
||||||
|
|
||||||
|
for (const auto &ns : origin)
|
||||||
|
{
|
||||||
|
destination[ns.first] = ns.second;
|
||||||
|
if (active_sidechains.find(ns.first) == active_sidechains.end())
|
||||||
|
{
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
flat_map<sidechain_type, uint16_t> count_SON_votes_per_sidechain( const flat_set<vote_id_type>& votes )
|
||||||
|
{
|
||||||
|
flat_map<sidechain_type, uint16_t> SON_votes_per_sidechain = account_options::ext::empty_num_son();
|
||||||
|
|
||||||
|
for (const auto &vote : votes)
|
||||||
|
{
|
||||||
|
switch (vote.type())
|
||||||
|
{
|
||||||
|
case vote_id_type::son_bitcoin:
|
||||||
|
SON_votes_per_sidechain[sidechain_type::bitcoin]++;
|
||||||
|
break;
|
||||||
|
case vote_id_type::son_hive:
|
||||||
|
SON_votes_per_sidechain[sidechain_type::hive]++;
|
||||||
|
break;
|
||||||
|
case vote_id_type::son_ethereum:
|
||||||
|
SON_votes_per_sidechain[sidechain_type::ethereum]++;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return SON_votes_per_sidechain;
|
||||||
|
}
|
||||||
|
|
||||||
|
void verify_account_votes( const database& db, const account_options& options, fc::optional<account_object> account = {} )
|
||||||
{
|
{
|
||||||
// ensure account's votes satisfy requirements
|
// ensure account's votes satisfy requirements
|
||||||
// NB only the part of vote checking that requires chain state is here,
|
// NB only the part of vote checking that requires chain state is here,
|
||||||
|
|
@ -69,14 +116,40 @@ void verify_account_votes( const database& db, const account_options& options )
|
||||||
FC_ASSERT( options.num_committee <= chain_params.maximum_committee_count,
|
FC_ASSERT( options.num_committee <= chain_params.maximum_committee_count,
|
||||||
"Voted for more committee members than currently allowed (${c})", ("c", chain_params.maximum_committee_count) );
|
"Voted for more committee members than currently allowed (${c})", ("c", chain_params.maximum_committee_count) );
|
||||||
FC_ASSERT( chain_params.extensions.value.maximum_son_count.valid() , "Invalid maximum son count" );
|
FC_ASSERT( chain_params.extensions.value.maximum_son_count.valid() , "Invalid maximum son count" );
|
||||||
|
|
||||||
|
flat_map<sidechain_type, uint16_t> merged_num_sons = account_options::ext::empty_num_son();
|
||||||
|
|
||||||
|
// Merge with existing account if exists
|
||||||
|
if ( account.valid() && account->options.extensions.value.num_son.valid())
|
||||||
|
{
|
||||||
|
merge_num_sons( merged_num_sons, *account->options.extensions.value.num_son, db.head_block_time() );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply update operation on top
|
||||||
if ( options.extensions.value.num_son.valid() )
|
if ( options.extensions.value.num_son.valid() )
|
||||||
{
|
{
|
||||||
for(const auto& num_sons : *options.extensions.value.num_son)
|
merge_num_sons( merged_num_sons, *options.extensions.value.num_son, db.head_block_time() );
|
||||||
{
|
|
||||||
FC_ASSERT( num_sons.second <= *chain_params.extensions.value.maximum_son_count,
|
|
||||||
"Voted for more sons than currently allowed (${c})", ("c", *chain_params.extensions.value.maximum_son_count) );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(const auto& num_sons : merged_num_sons)
|
||||||
|
{
|
||||||
|
FC_ASSERT( num_sons.second <= *chain_params.extensions.value.maximum_son_count,
|
||||||
|
"Voted for more sons than currently allowed (${c})", ("c", *chain_params.extensions.value.maximum_son_count) );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count the votes for SONs and confirm that the account did not vote for less SONs than num_son
|
||||||
|
flat_map<sidechain_type, uint16_t> SON_votes_per_sidechain = count_SON_votes_per_sidechain(options.votes);
|
||||||
|
|
||||||
|
for (const auto& number_of_votes : SON_votes_per_sidechain)
|
||||||
|
{
|
||||||
|
// Number of votes of account_options are also checked in account_options::do_evaluate,
|
||||||
|
// but there we are checking the value before merging num_sons, so the values should be checked again
|
||||||
|
const auto sidechain = number_of_votes.first;
|
||||||
|
FC_ASSERT( number_of_votes.second >= merged_num_sons[sidechain],
|
||||||
|
"Voted for less sons than specified in num_son (votes ${v} < num_son ${ns}) for sidechain ${s}",
|
||||||
|
("v", number_of_votes.second) ("ns", merged_num_sons[sidechain]) ("s", sidechain) );
|
||||||
|
}
|
||||||
|
|
||||||
FC_ASSERT( db.find_object(options.voting_account), "Invalid proxy account specified." );
|
FC_ASSERT( db.find_object(options.voting_account), "Invalid proxy account specified." );
|
||||||
|
|
||||||
uint32_t max_vote_id = gpo.next_available_vote_id;
|
uint32_t max_vote_id = gpo.next_available_vote_id;
|
||||||
|
|
@ -191,9 +264,10 @@ object_id_type account_create_evaluator::do_apply( const account_create_operatio
|
||||||
obj.active = o.active;
|
obj.active = o.active;
|
||||||
obj.options = o.options;
|
obj.options = o.options;
|
||||||
|
|
||||||
if (!obj.options.extensions.value.num_son.valid())
|
obj.options.extensions.value.num_son = account_options::ext::empty_num_son();
|
||||||
|
if ( o.options.extensions.value.num_son.valid() )
|
||||||
{
|
{
|
||||||
obj.options.extensions.value = account_options::ext();
|
merge_num_sons( *obj.options.extensions.value.num_son, *o.options.extensions.value.num_son );
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.statistics = d.create<account_statistics_object>([&obj](account_statistics_object& s){
|
obj.statistics = d.create<account_statistics_object>([&obj](account_statistics_object& s){
|
||||||
|
|
@ -295,7 +369,7 @@ void_result account_update_evaluator::do_evaluate( const account_update_operatio
|
||||||
acnt = &o.account(d);
|
acnt = &o.account(d);
|
||||||
|
|
||||||
if( o.new_options.valid() )
|
if( o.new_options.valid() )
|
||||||
verify_account_votes( d, *o.new_options );
|
verify_account_votes( d, *o.new_options, *acnt );
|
||||||
|
|
||||||
return void_result();
|
return void_result();
|
||||||
} FC_CAPTURE_AND_RETHROW( (o) ) }
|
} FC_CAPTURE_AND_RETHROW( (o) ) }
|
||||||
|
|
@ -334,7 +408,31 @@ void_result account_update_evaluator::do_apply( const account_update_operation&
|
||||||
a.active = *o.active;
|
a.active = *o.active;
|
||||||
a.top_n_control_flags = 0;
|
a.top_n_control_flags = 0;
|
||||||
}
|
}
|
||||||
if( o.new_options ) a.options = *o.new_options;
|
|
||||||
|
// New num_son structure initialized to 0
|
||||||
|
flat_map<sidechain_type, uint16_t> new_num_son = account_options::ext::empty_num_son();
|
||||||
|
|
||||||
|
// If num_son of existing object is valid, we should merge the existing data
|
||||||
|
if ( a.options.extensions.value.num_son.valid() )
|
||||||
|
{
|
||||||
|
merge_num_sons( new_num_son, *a.options.extensions.value.num_son );
|
||||||
|
}
|
||||||
|
|
||||||
|
// If num_son of the operation are valid, they should merge the existing data
|
||||||
|
if ( o.new_options )
|
||||||
|
{
|
||||||
|
const auto new_options = *o.new_options;
|
||||||
|
|
||||||
|
if ( new_options.extensions.value.num_son.valid() )
|
||||||
|
{
|
||||||
|
merge_num_sons( new_num_son, *new_options.extensions.value.num_son );
|
||||||
|
}
|
||||||
|
|
||||||
|
a.options = *o.new_options;
|
||||||
|
}
|
||||||
|
|
||||||
|
a.options.extensions.value.num_son = new_num_son;
|
||||||
|
|
||||||
if( o.extensions.value.owner_special_authority.valid() )
|
if( o.extensions.value.owner_special_authority.valid() )
|
||||||
{
|
{
|
||||||
a.owner_special_authority = *(o.extensions.value.owner_special_authority);
|
a.owner_special_authority = *(o.extensions.value.owner_special_authority);
|
||||||
|
|
|
||||||
|
|
@ -36,21 +36,28 @@ namespace graphene { namespace chain {
|
||||||
bool is_cheap_name( const string& n );
|
bool is_cheap_name( const string& n );
|
||||||
|
|
||||||
/// These are the fields which can be updated by the active authority.
|
/// These are the fields which can be updated by the active authority.
|
||||||
struct account_options
|
struct account_options
|
||||||
{
|
{
|
||||||
struct ext
|
struct ext
|
||||||
{
|
{
|
||||||
/// The number of active son members this account votes the blockchain should appoint
|
/// The number of active son members this account votes the blockchain should appoint
|
||||||
/// Must not exceed the actual number of son members voted for in @ref votes
|
/// Must not exceed the actual number of son members voted for in @ref votes
|
||||||
optional< flat_map<sidechain_type, uint16_t> > num_son = []{
|
optional< flat_map<sidechain_type, uint16_t> > num_son;
|
||||||
|
|
||||||
|
/// Returns and empty num_son map with all sidechains
|
||||||
|
static flat_map<sidechain_type, uint16_t> empty_num_son()
|
||||||
|
{
|
||||||
flat_map<sidechain_type, uint16_t> num_son;
|
flat_map<sidechain_type, uint16_t> num_son;
|
||||||
for(const auto& active_sidechain_type : all_sidechain_types){
|
for(const auto& active_sidechain_type : all_sidechain_types)
|
||||||
|
{
|
||||||
num_son[active_sidechain_type] = 0;
|
num_son[active_sidechain_type] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return num_son;
|
return num_son;
|
||||||
}();
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// The memo key is the key this account will typically use to encrypt/sign transaction memos and other non-
|
/// The memo key is the key this account will typically use to encrypt/sign transaction memos and other non-
|
||||||
/// validated account activities. This field is here to prevent confusion if the active authority has zero or
|
/// validated account activities. This field is here to prevent confusion if the active authority has zero or
|
||||||
/// multiple keys in it.
|
/// multiple keys in it.
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ namespace graphene
|
||||||
// Buyer purchasing lottery tickets
|
// Buyer purchasing lottery tickets
|
||||||
account_id_type buyer;
|
account_id_type buyer;
|
||||||
// count of tickets to buy
|
// count of tickets to buy
|
||||||
uint64_t tickets_to_buy;
|
share_type tickets_to_buy;
|
||||||
// amount that can spent
|
// amount that can spent
|
||||||
asset amount;
|
asset amount;
|
||||||
|
|
||||||
|
|
@ -83,4 +83,4 @@ FC_REFLECT(graphene::chain::nft_lottery_reward_operation::fee_parameters_type, (
|
||||||
FC_REFLECT(graphene::chain::nft_lottery_end_operation::fee_parameters_type, (fee))
|
FC_REFLECT(graphene::chain::nft_lottery_end_operation::fee_parameters_type, (fee))
|
||||||
FC_REFLECT(graphene::chain::nft_lottery_token_purchase_operation, (fee)(lottery_id)(buyer)(tickets_to_buy)(amount)(extensions))
|
FC_REFLECT(graphene::chain::nft_lottery_token_purchase_operation, (fee)(lottery_id)(buyer)(tickets_to_buy)(amount)(extensions))
|
||||||
FC_REFLECT(graphene::chain::nft_lottery_reward_operation, (fee)(lottery_id)(winner)(amount)(win_percentage)(is_benefactor_reward)(winner_ticket_id)(extensions))
|
FC_REFLECT(graphene::chain::nft_lottery_reward_operation, (fee)(lottery_id)(winner)(amount)(win_percentage)(is_benefactor_reward)(winner_ticket_id)(extensions))
|
||||||
FC_REFLECT(graphene::chain::nft_lottery_end_operation, (fee)(lottery_id)(extensions))
|
FC_REFLECT(graphene::chain::nft_lottery_end_operation, (fee)(lottery_id)(extensions))
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,15 @@ namespace graphene { namespace chain {
|
||||||
deposit_address(""),
|
deposit_address(""),
|
||||||
withdraw_public_key(""),
|
withdraw_public_key(""),
|
||||||
withdraw_address("") {}
|
withdraw_address("") {}
|
||||||
|
|
||||||
|
inline string get_deposit_address() const {
|
||||||
|
if(sidechain_type::ethereum != sidechain)
|
||||||
|
return deposit_address;
|
||||||
|
|
||||||
|
auto deposit_address_lower = deposit_address;
|
||||||
|
std::transform(deposit_address_lower.begin(), deposit_address_lower.end(), deposit_address_lower.begin(), ::tolower);
|
||||||
|
return deposit_address_lower;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct by_account;
|
struct by_account;
|
||||||
|
|
@ -76,7 +85,7 @@ namespace graphene { namespace chain {
|
||||||
ordered_non_unique< tag<by_sidechain_and_deposit_address_and_expires>,
|
ordered_non_unique< tag<by_sidechain_and_deposit_address_and_expires>,
|
||||||
composite_key<sidechain_address_object,
|
composite_key<sidechain_address_object,
|
||||||
member<sidechain_address_object, sidechain_type, &sidechain_address_object::sidechain>,
|
member<sidechain_address_object, sidechain_type, &sidechain_address_object::sidechain>,
|
||||||
member<sidechain_address_object, string, &sidechain_address_object::deposit_address>,
|
const_mem_fun<sidechain_address_object, string, &sidechain_address_object::get_deposit_address>,
|
||||||
member<sidechain_address_object, time_point_sec, &sidechain_address_object::expires>
|
member<sidechain_address_object, time_point_sec, &sidechain_address_object::expires>
|
||||||
>
|
>
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ namespace graphene
|
||||||
|
|
||||||
auto lottery_options = lottery_md_obj.lottery_data->lottery_options;
|
auto lottery_options = lottery_md_obj.lottery_data->lottery_options;
|
||||||
FC_ASSERT(lottery_options.ticket_price.asset_id == op.amount.asset_id);
|
FC_ASSERT(lottery_options.ticket_price.asset_id == op.amount.asset_id);
|
||||||
FC_ASSERT((double)op.amount.amount.value / lottery_options.ticket_price.amount.value == (double)op.tickets_to_buy);
|
FC_ASSERT(op.tickets_to_buy * lottery_options.ticket_price.amount.value == op.amount.amount.value);
|
||||||
return void_result();
|
return void_result();
|
||||||
}
|
}
|
||||||
FC_CAPTURE_AND_RETHROW((op))
|
FC_CAPTURE_AND_RETHROW((op))
|
||||||
|
|
@ -142,4 +142,4 @@ namespace graphene
|
||||||
FC_CAPTURE_AND_RETHROW((op))
|
FC_CAPTURE_AND_RETHROW((op))
|
||||||
}
|
}
|
||||||
} // namespace chain
|
} // namespace chain
|
||||||
} // namespace graphene
|
} // namespace graphene
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -18,10 +18,40 @@
|
||||||
|
|
||||||
namespace graphene { namespace peerplays_sidechain {
|
namespace graphene { namespace peerplays_sidechain {
|
||||||
|
|
||||||
rpc_client::rpc_client(std::string _url, std::string _user, std::string _password, bool _debug_rpc_calls) :
|
struct rpc_reply {
|
||||||
url(_url),
|
uint16_t status;
|
||||||
user(_user),
|
std::string body;
|
||||||
password(_password),
|
};
|
||||||
|
|
||||||
|
class rpc_connection {
|
||||||
|
public:
|
||||||
|
rpc_connection(const rpc_credentials &_credentials, bool _debug_rpc_calls);
|
||||||
|
|
||||||
|
std::string send_post_request(std::string method, std::string params, bool show_log);
|
||||||
|
std::string get_url() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
rpc_credentials credentials;
|
||||||
|
bool debug_rpc_calls;
|
||||||
|
|
||||||
|
std::string protocol;
|
||||||
|
std::string host;
|
||||||
|
std::string port;
|
||||||
|
std::string target;
|
||||||
|
std::string authorization;
|
||||||
|
|
||||||
|
uint32_t request_id;
|
||||||
|
|
||||||
|
private:
|
||||||
|
rpc_reply send_post_request(std::string body, bool show_log);
|
||||||
|
|
||||||
|
boost::beast::net::io_context ioc;
|
||||||
|
boost::beast::net::ip::tcp::resolver resolver;
|
||||||
|
boost::asio::ip::basic_resolver_results<boost::asio::ip::tcp> results;
|
||||||
|
};
|
||||||
|
|
||||||
|
rpc_connection::rpc_connection(const rpc_credentials &_credentials, bool _debug_rpc_calls) :
|
||||||
|
credentials(_credentials),
|
||||||
debug_rpc_calls(_debug_rpc_calls),
|
debug_rpc_calls(_debug_rpc_calls),
|
||||||
request_id(0),
|
request_id(0),
|
||||||
resolver(ioc) {
|
resolver(ioc) {
|
||||||
|
|
@ -31,7 +61,7 @@ rpc_client::rpc_client(std::string _url, std::string _user, std::string _passwor
|
||||||
|
|
||||||
boost::xpressive::smatch sm;
|
boost::xpressive::smatch sm;
|
||||||
|
|
||||||
if (boost::xpressive::regex_search(url, sm, sr)) {
|
if (boost::xpressive::regex_search(credentials.url, sm, sr)) {
|
||||||
protocol = sm["Protocol"];
|
protocol = sm["Protocol"];
|
||||||
if (protocol.empty()) {
|
if (protocol.empty()) {
|
||||||
protocol = "http";
|
protocol = "http";
|
||||||
|
|
@ -52,15 +82,19 @@ rpc_client::rpc_client(std::string _url, std::string _user, std::string _passwor
|
||||||
target = "/";
|
target = "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
authorization = "Basic " + base64_encode(user + ":" + password);
|
authorization = "Basic " + base64_encode(credentials.user + ":" + credentials.password);
|
||||||
|
|
||||||
results = resolver.resolve(host, port);
|
results = resolver.resolve(host, port);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
elog("Invalid URL: ${url}", ("url", url));
|
elog("Invalid URL: ${url}", ("url", credentials.url));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string rpc_connection::get_url() const {
|
||||||
|
return credentials.url;
|
||||||
|
}
|
||||||
|
|
||||||
std::string rpc_client::retrieve_array_value_from_reply(std::string reply_str, std::string array_path, uint32_t idx) {
|
std::string rpc_client::retrieve_array_value_from_reply(std::string reply_str, std::string array_path, uint32_t idx) {
|
||||||
if (reply_str.empty()) {
|
if (reply_str.empty()) {
|
||||||
wlog("RPC call ${function}, empty reply string", ("function", __FUNCTION__));
|
wlog("RPC call ${function}, empty reply string", ("function", __FUNCTION__));
|
||||||
|
|
@ -125,7 +159,7 @@ std::string rpc_client::retrieve_value_from_reply(std::string reply_str, std::st
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string rpc_client::send_post_request(std::string method, std::string params, bool show_log) {
|
std::string rpc_connection::send_post_request(std::string method, std::string params, bool show_log) {
|
||||||
std::stringstream body;
|
std::stringstream body;
|
||||||
|
|
||||||
request_id = request_id + 1;
|
request_id = request_id + 1;
|
||||||
|
|
@ -164,7 +198,7 @@ std::string rpc_client::send_post_request(std::string method, std::string params
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
rpc_reply rpc_client::send_post_request(std::string body, bool show_log) {
|
rpc_reply rpc_connection::send_post_request(std::string body, bool show_log) {
|
||||||
|
|
||||||
// These object is used as a context for ssl connection
|
// These object is used as a context for ssl connection
|
||||||
boost::asio::ssl::context ctx(boost::asio::ssl::context::tlsv12_client);
|
boost::asio::ssl::context ctx(boost::asio::ssl::context::tlsv12_client);
|
||||||
|
|
@ -239,7 +273,7 @@ rpc_reply rpc_client::send_post_request(std::string body, bool show_log) {
|
||||||
reply.body = rbody;
|
reply.body = rbody;
|
||||||
|
|
||||||
if (show_log) {
|
if (show_log) {
|
||||||
ilog("### Request URL: ${url}", ("url", url));
|
ilog("### Request URL: ${url}", ("url", credentials.url));
|
||||||
ilog("### Request: ${body}", ("body", body));
|
ilog("### Request: ${body}", ("body", body));
|
||||||
ilog("### Response: ${rbody}", ("rbody", rbody));
|
ilog("### Response: ${rbody}", ("rbody", rbody));
|
||||||
}
|
}
|
||||||
|
|
@ -247,4 +281,113 @@ rpc_reply rpc_client::send_post_request(std::string body, bool show_log) {
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rpc_client::rpc_client(sidechain_type _sidechain, const std::vector<rpc_credentials> &_credentials, bool _debug_rpc_calls, bool _simulate_connection_reselection) :
|
||||||
|
sidechain(_sidechain),
|
||||||
|
debug_rpc_calls(_debug_rpc_calls),
|
||||||
|
simulate_connection_reselection(_simulate_connection_reselection) {
|
||||||
|
FC_ASSERT(_credentials.size());
|
||||||
|
for (size_t i = 0; i < _credentials.size(); i++)
|
||||||
|
connections.push_back(new rpc_connection(_credentials[i], _debug_rpc_calls));
|
||||||
|
n_active_conn = 0;
|
||||||
|
if (connections.size() > 1)
|
||||||
|
schedule_connection_selection();
|
||||||
|
}
|
||||||
|
|
||||||
|
void rpc_client::schedule_connection_selection() {
|
||||||
|
fc::time_point now = fc::time_point::now();
|
||||||
|
static const int64_t time_to_next_conn_selection = 10 * 1000 * 1000; // 10 sec
|
||||||
|
fc::time_point next_wakeup = now + fc::microseconds(time_to_next_conn_selection);
|
||||||
|
connection_selection_task = fc::schedule([this] {
|
||||||
|
select_connection();
|
||||||
|
},
|
||||||
|
next_wakeup, "SON RPC connection selection");
|
||||||
|
}
|
||||||
|
|
||||||
|
void rpc_client::select_connection() {
|
||||||
|
FC_ASSERT(connections.size() > 1);
|
||||||
|
|
||||||
|
const std::lock_guard<std::mutex> lock(conn_mutex);
|
||||||
|
|
||||||
|
static const int t_limit = 5 * 1000 * 1000, // 5 sec
|
||||||
|
quality_diff_threshold = 10 * 1000; // 10 ms
|
||||||
|
|
||||||
|
int best_n = -1;
|
||||||
|
int best_quality = -1;
|
||||||
|
|
||||||
|
std::vector<uint64_t> head_block_numbers;
|
||||||
|
head_block_numbers.resize(connections.size());
|
||||||
|
|
||||||
|
std::vector<int> qualities;
|
||||||
|
qualities.resize(connections.size());
|
||||||
|
|
||||||
|
for (size_t n = 0; n < connections.size(); n++) {
|
||||||
|
rpc_connection &conn = *connections[n];
|
||||||
|
int quality = 0;
|
||||||
|
head_block_numbers[n] = std::numeric_limits<uint64_t>::max();
|
||||||
|
|
||||||
|
// ping n'th node
|
||||||
|
if (debug_rpc_calls)
|
||||||
|
ilog("### Ping ${sidechain} node #${n}, ${url}", ("sidechain", fc::reflector<sidechain_type>::to_string(sidechain))("n", n)("url", conn.get_url()));
|
||||||
|
fc::time_point t_sent = fc::time_point::now();
|
||||||
|
uint64_t head_block_number = ping(conn);
|
||||||
|
fc::time_point t_received = fc::time_point::now();
|
||||||
|
int t = (t_received - t_sent).count();
|
||||||
|
|
||||||
|
// evaluate n'th node reply quality and switch to it if it's better
|
||||||
|
if (head_block_number != std::numeric_limits<uint64_t>::max()) {
|
||||||
|
if (simulate_connection_reselection)
|
||||||
|
t += rand() % 10;
|
||||||
|
FC_ASSERT(t != -1);
|
||||||
|
head_block_numbers[n] = head_block_number;
|
||||||
|
if (t < t_limit)
|
||||||
|
quality = t_limit - t; // the less time, the higher quality
|
||||||
|
|
||||||
|
// look for the best quality
|
||||||
|
if (quality > best_quality) {
|
||||||
|
best_n = n;
|
||||||
|
best_quality = quality;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
qualities[n] = quality;
|
||||||
|
}
|
||||||
|
|
||||||
|
FC_ASSERT(best_n != -1 && best_quality != -1);
|
||||||
|
if (best_n != n_active_conn) { // if the best client is not the current one, ...
|
||||||
|
uint64_t active_head_block_number = head_block_numbers[n_active_conn];
|
||||||
|
if ((active_head_block_number == std::numeric_limits<uint64_t>::max() // ...and the current one has no known head block...
|
||||||
|
|| head_block_numbers[best_n] >= active_head_block_number) // ...or the best client's head is more recent than the current, ...
|
||||||
|
&& best_quality > qualities[n_active_conn] + quality_diff_threshold) { // ...and the new client's quality exceeds current more than by threshold
|
||||||
|
n_active_conn = best_n; // ...then select new one
|
||||||
|
if (debug_rpc_calls)
|
||||||
|
ilog("### Reselected ${sidechain} node to #${n}, ${url}", ("sidechain", fc::reflector<sidechain_type>::to_string(sidechain))("n", n_active_conn)("url", connections[n_active_conn]->get_url()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
schedule_connection_selection();
|
||||||
|
}
|
||||||
|
|
||||||
|
rpc_connection &rpc_client::get_active_connection() const {
|
||||||
|
return *connections[n_active_conn];
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string rpc_client::send_post_request(std::string method, std::string params, bool show_log) {
|
||||||
|
const std::lock_guard<std::mutex> lock(conn_mutex);
|
||||||
|
return send_post_request(get_active_connection(), method, params, show_log);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string rpc_client::send_post_request(rpc_connection &conn, std::string method, std::string params, bool show_log) {
|
||||||
|
return conn.send_post_request(method, params, show_log);
|
||||||
|
}
|
||||||
|
|
||||||
|
rpc_client::~rpc_client() {
|
||||||
|
try {
|
||||||
|
if (connection_selection_task.valid())
|
||||||
|
connection_selection_task.cancel_and_wait(__FUNCTION__);
|
||||||
|
} catch (fc::canceled_exception &) {
|
||||||
|
//Expected exception. Move along.
|
||||||
|
} catch (fc::exception &e) {
|
||||||
|
edump((e.to_detail_string()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}} // namespace graphene::peerplays_sidechain
|
}} // namespace graphene::peerplays_sidechain
|
||||||
|
|
|
||||||
|
|
@ -137,8 +137,9 @@ std::string rlp_encoder::encode_length(int len, int offset) {
|
||||||
|
|
||||||
std::string rlp_encoder::hex2bytes(const std::string &s) {
|
std::string rlp_encoder::hex2bytes(const std::string &s) {
|
||||||
std::string dest;
|
std::string dest;
|
||||||
dest.resize(s.size() / 2);
|
const auto s_final = s.size() % 2 == 0 ? s : "0" + s;
|
||||||
hex2bin(s.c_str(), &dest[0]);
|
dest.resize(s_final.size() / 2);
|
||||||
|
hex2bin(s_final.c_str(), &dest[0]);
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,10 @@
|
||||||
|
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
typedef std::function<uint64_t()> get_fee_func_type;
|
typedef std::function<uint64_t()> get_fee_func_type;
|
||||||
|
|
|
||||||
|
|
@ -3,44 +3,52 @@
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include <fc/thread/future.hpp>
|
||||||
|
#include <fc/thread/thread.hpp>
|
||||||
|
|
||||||
#include <boost/asio/ip/tcp.hpp>
|
#include <boost/asio/ip/tcp.hpp>
|
||||||
#include <boost/beast/core.hpp>
|
#include <boost/beast/core.hpp>
|
||||||
|
|
||||||
|
#include <graphene/peerplays_sidechain/defs.hpp>
|
||||||
|
|
||||||
namespace graphene { namespace peerplays_sidechain {
|
namespace graphene { namespace peerplays_sidechain {
|
||||||
|
|
||||||
struct rpc_reply {
|
class rpc_connection;
|
||||||
uint16_t status;
|
|
||||||
std::string body;
|
struct rpc_credentials {
|
||||||
|
std::string url;
|
||||||
|
std::string user;
|
||||||
|
std::string password;
|
||||||
};
|
};
|
||||||
|
|
||||||
class rpc_client {
|
class rpc_client {
|
||||||
public:
|
public:
|
||||||
rpc_client(std::string _url, std::string _user, std::string _password, bool _debug_rpc_calls);
|
const sidechain_type sidechain;
|
||||||
|
|
||||||
|
rpc_client(sidechain_type _sidechain, const std::vector<rpc_credentials> &_credentials, bool _debug_rpc_calls, bool _simulate_connection_reselection);
|
||||||
|
~rpc_client();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string retrieve_array_value_from_reply(std::string reply_str, std::string array_path, uint32_t idx);
|
bool debug_rpc_calls;
|
||||||
std::string retrieve_value_from_reply(std::string reply_str, std::string value_path);
|
bool simulate_connection_reselection;
|
||||||
std::string send_post_request(std::string method, std::string params, bool show_log);
|
std::string send_post_request(std::string method, std::string params, bool show_log);
|
||||||
|
|
||||||
std::string url;
|
static std::string send_post_request(rpc_connection &conn, std::string method, std::string params, bool show_log);
|
||||||
std::string user;
|
|
||||||
std::string password;
|
|
||||||
bool debug_rpc_calls;
|
|
||||||
|
|
||||||
std::string protocol;
|
static std::string retrieve_array_value_from_reply(std::string reply_str, std::string array_path, uint32_t idx);
|
||||||
std::string host;
|
static std::string retrieve_value_from_reply(std::string reply_str, std::string value_path);
|
||||||
std::string port;
|
|
||||||
std::string target;
|
|
||||||
std::string authorization;
|
|
||||||
|
|
||||||
uint32_t request_id;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
rpc_reply send_post_request(std::string body, bool show_log);
|
std::vector<rpc_connection *> connections;
|
||||||
|
int n_active_conn;
|
||||||
|
fc::future<void> connection_selection_task;
|
||||||
|
std::mutex conn_mutex;
|
||||||
|
|
||||||
boost::beast::net::io_context ioc;
|
rpc_connection &get_active_connection() const;
|
||||||
boost::beast::net::ip::tcp::resolver resolver;
|
|
||||||
boost::asio::ip::basic_resolver_results<boost::asio::ip::tcp> results;
|
void select_connection();
|
||||||
|
void schedule_connection_selection();
|
||||||
|
virtual uint64_t ping(rpc_connection &conn) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}} // namespace graphene::peerplays_sidechain
|
}} // namespace graphene::peerplays_sidechain
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,10 @@
|
||||||
namespace graphene { namespace peerplays_sidechain {
|
namespace graphene { namespace peerplays_sidechain {
|
||||||
|
|
||||||
class sidechain_net_handler {
|
class sidechain_net_handler {
|
||||||
|
protected:
|
||||||
|
sidechain_net_handler(sidechain_type _sidechain, peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
sidechain_net_handler(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options);
|
|
||||||
virtual ~sidechain_net_handler();
|
virtual ~sidechain_net_handler();
|
||||||
|
|
||||||
sidechain_type get_sidechain() const;
|
sidechain_type get_sidechain() const;
|
||||||
|
|
@ -54,9 +56,9 @@ public:
|
||||||
virtual optional<asset> estimate_withdrawal_transaction_fee() const = 0;
|
virtual optional<asset> estimate_withdrawal_transaction_fee() const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
const sidechain_type sidechain;
|
||||||
peerplays_sidechain_plugin &plugin;
|
peerplays_sidechain_plugin &plugin;
|
||||||
graphene::chain::database &database;
|
graphene::chain::database &database;
|
||||||
sidechain_type sidechain;
|
|
||||||
|
|
||||||
bool debug_rpc_calls;
|
bool debug_rpc_calls;
|
||||||
bool use_bitcoind_client;
|
bool use_bitcoind_client;
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ protected:
|
||||||
class bitcoin_rpc_client : public bitcoin_client_base, public rpc_client {
|
class bitcoin_rpc_client : public bitcoin_client_base, public rpc_client {
|
||||||
public:
|
public:
|
||||||
public:
|
public:
|
||||||
bitcoin_rpc_client(std::string _url, std::string _user, std::string _password, bool _debug_rpc_calls);
|
bitcoin_rpc_client(const std::vector<rpc_credentials> &_credentials, bool _debug_rpc_calls, bool _simulate_connection_reselection);
|
||||||
|
|
||||||
uint64_t estimatesmartfee(uint16_t conf_target = 1);
|
uint64_t estimatesmartfee(uint16_t conf_target = 1);
|
||||||
std::vector<info_for_vin> getblock(const block_data &block, int32_t verbosity = 2);
|
std::vector<info_for_vin> getblock(const block_data &block, int32_t verbosity = 2);
|
||||||
|
|
@ -113,6 +113,8 @@ public:
|
||||||
std::string walletlock();
|
std::string walletlock();
|
||||||
bool walletpassphrase(const std::string &passphrase, uint32_t timeout = 60);
|
bool walletpassphrase(const std::string &passphrase, uint32_t timeout = 60);
|
||||||
|
|
||||||
|
virtual uint64_t ping(rpc_connection &conn) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string ip;
|
std::string ip;
|
||||||
std::string user;
|
std::string user;
|
||||||
|
|
@ -214,14 +216,11 @@ public:
|
||||||
virtual optional<asset> estimate_withdrawal_transaction_fee() const override;
|
virtual optional<asset> estimate_withdrawal_transaction_fee() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string bitcoin_node_ip;
|
std::vector<rpc_credentials> _rpc_credentials;
|
||||||
std::string libbitcoin_server_ip;
|
std::string libbitcoin_server_ip;
|
||||||
uint32_t libbitcoin_block_zmq_port;
|
uint32_t libbitcoin_block_zmq_port;
|
||||||
uint32_t libbitcoin_trx_zmq_port;
|
uint32_t libbitcoin_trx_zmq_port;
|
||||||
uint32_t bitcoin_node_zmq_port;
|
uint32_t bitcoin_node_zmq_port;
|
||||||
uint32_t rpc_port;
|
|
||||||
std::string rpc_user;
|
|
||||||
std::string rpc_password;
|
|
||||||
std::string wallet_name;
|
std::string wallet_name;
|
||||||
std::string wallet_password;
|
std::string wallet_password;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ namespace graphene { namespace peerplays_sidechain {
|
||||||
|
|
||||||
class ethereum_rpc_client : public rpc_client {
|
class ethereum_rpc_client : public rpc_client {
|
||||||
public:
|
public:
|
||||||
ethereum_rpc_client(const std::string &url, const std::string &user_name, const std::string &password, bool debug_rpc_calls);
|
ethereum_rpc_client(const std::vector<rpc_credentials> &credentials, bool debug_rpc_calls, bool simulate_connection_reselection);
|
||||||
|
|
||||||
std::string eth_blockNumber();
|
std::string eth_blockNumber();
|
||||||
std::string eth_get_block_by_number(std::string block_number, bool full_block);
|
std::string eth_get_block_by_number(std::string block_number, bool full_block);
|
||||||
|
|
@ -36,6 +36,8 @@ public:
|
||||||
std::string eth_send_raw_transaction(const std::string ¶ms);
|
std::string eth_send_raw_transaction(const std::string ¶ms);
|
||||||
std::string eth_get_transaction_receipt(const std::string ¶ms);
|
std::string eth_get_transaction_receipt(const std::string ¶ms);
|
||||||
std::string eth_get_transaction_by_hash(const std::string ¶ms);
|
std::string eth_get_transaction_by_hash(const std::string ¶ms);
|
||||||
|
|
||||||
|
virtual uint64_t ping(rpc_connection &conn) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class sidechain_net_handler_ethereum : public sidechain_net_handler {
|
class sidechain_net_handler_ethereum : public sidechain_net_handler {
|
||||||
|
|
@ -54,13 +56,9 @@ public:
|
||||||
virtual optional<asset> estimate_withdrawal_transaction_fee() const override;
|
virtual optional<asset> estimate_withdrawal_transaction_fee() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using bimap_type = boost::bimap<std::string, std::string>;
|
std::vector<rpc_credentials> _rpc_credentials;
|
||||||
|
|
||||||
private:
|
|
||||||
std::string rpc_url;
|
|
||||||
std::string rpc_user;
|
|
||||||
std::string rpc_password;
|
|
||||||
std::string wallet_contract_address;
|
std::string wallet_contract_address;
|
||||||
|
using bimap_type = boost::bimap<std::string, std::string>;
|
||||||
bimap_type erc20_addresses;
|
bimap_type erc20_addresses;
|
||||||
|
|
||||||
ethereum_rpc_client *rpc_client;
|
ethereum_rpc_client *rpc_client;
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ namespace graphene { namespace peerplays_sidechain {
|
||||||
|
|
||||||
class hive_rpc_client : public rpc_client {
|
class hive_rpc_client : public rpc_client {
|
||||||
public:
|
public:
|
||||||
hive_rpc_client(const std::string &url, const std::string &user_name, const std::string &password, bool debug_rpc_calls);
|
hive_rpc_client(const std::vector<rpc_credentials> &credentials, bool debug_rpc_calls, bool simulate_connection_reselection);
|
||||||
|
|
||||||
std::string account_history_api_get_transaction(std::string transaction_id);
|
std::string account_history_api_get_transaction(std::string transaction_id);
|
||||||
std::string block_api_get_block(uint32_t block_number);
|
std::string block_api_get_block(uint32_t block_number);
|
||||||
|
|
@ -30,6 +30,8 @@ public:
|
||||||
std::string get_head_block_time();
|
std::string get_head_block_time();
|
||||||
std::string get_is_test_net();
|
std::string get_is_test_net();
|
||||||
std::string get_last_irreversible_block_num();
|
std::string get_last_irreversible_block_num();
|
||||||
|
|
||||||
|
virtual uint64_t ping(rpc_connection &conn) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class sidechain_net_handler_hive : public sidechain_net_handler {
|
class sidechain_net_handler_hive : public sidechain_net_handler {
|
||||||
|
|
@ -48,9 +50,8 @@ public:
|
||||||
virtual optional<asset> estimate_withdrawal_transaction_fee() const override;
|
virtual optional<asset> estimate_withdrawal_transaction_fee() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string rpc_url;
|
std::vector<rpc_credentials> _rpc_credentials;
|
||||||
std::string rpc_user;
|
|
||||||
std::string rpc_password;
|
|
||||||
std::string wallet_account_name;
|
std::string wallet_account_name;
|
||||||
|
|
||||||
hive_rpc_client *rpc_client;
|
hive_rpc_client *rpc_client;
|
||||||
|
|
|
||||||
|
|
@ -175,13 +175,14 @@ void peerplays_sidechain_plugin_impl::plugin_set_program_options(
|
||||||
cli.add_options()("sidechain-retry-threshold", bpo::value<uint16_t>()->default_value(150), "Sidechain retry throttling threshold");
|
cli.add_options()("sidechain-retry-threshold", bpo::value<uint16_t>()->default_value(150), "Sidechain retry throttling threshold");
|
||||||
|
|
||||||
cli.add_options()("debug-rpc-calls", bpo::value<bool>()->default_value(false), "Outputs RPC calls to console");
|
cli.add_options()("debug-rpc-calls", bpo::value<bool>()->default_value(false), "Outputs RPC calls to console");
|
||||||
|
cli.add_options()("simulate-rpc-connection-reselection", bpo::value<bool>()->default_value(false), "Simulate RPC connection reselection by altering their response times by a random value");
|
||||||
|
|
||||||
cli.add_options()("bitcoin-sidechain-enabled", bpo::value<bool>()->default_value(false), "Bitcoin sidechain handler enabled");
|
cli.add_options()("bitcoin-sidechain-enabled", bpo::value<bool>()->default_value(false), "Bitcoin sidechain handler enabled");
|
||||||
|
cli.add_options()("bitcoin-node-ip", bpo::value<vector<string>>()->composing()->multitoken()->DEFAULT_VALUE_VECTOR("127.0.0.1"), "IP address of Bitcoin node");
|
||||||
cli.add_options()("use-bitcoind-client", bpo::value<bool>()->default_value(false), "Use bitcoind client instead of libbitcoin client");
|
cli.add_options()("use-bitcoind-client", bpo::value<bool>()->default_value(false), "Use bitcoind client instead of libbitcoin client");
|
||||||
cli.add_options()("libbitcoin-server-ip", bpo::value<string>()->default_value("127.0.0.1"), "Libbitcoin server IP address");
|
cli.add_options()("libbitcoin-server-ip", bpo::value<string>()->default_value("127.0.0.1"), "Libbitcoin server IP address");
|
||||||
cli.add_options()("libbitcoin-server-block-zmq-port", bpo::value<uint32_t>()->default_value(9093), "Block ZMQ port of libbitcoin server");
|
cli.add_options()("libbitcoin-server-block-zmq-port", bpo::value<uint32_t>()->default_value(9093), "Block ZMQ port of libbitcoin server");
|
||||||
cli.add_options()("libbitcoin-server-trx-zmq-port", bpo::value<uint32_t>()->default_value(9094), "Trx ZMQ port of libbitcoin server");
|
cli.add_options()("libbitcoin-server-trx-zmq-port", bpo::value<uint32_t>()->default_value(9094), "Trx ZMQ port of libbitcoin server");
|
||||||
cli.add_options()("bitcoin-node-ip", bpo::value<string>()->default_value("127.0.0.1"), "IP address of Bitcoin node");
|
|
||||||
cli.add_options()("bitcoin-node-zmq-port", bpo::value<uint32_t>()->default_value(11111), "ZMQ port of Bitcoin node");
|
cli.add_options()("bitcoin-node-zmq-port", bpo::value<uint32_t>()->default_value(11111), "ZMQ port of Bitcoin node");
|
||||||
cli.add_options()("bitcoin-node-rpc-port", bpo::value<uint32_t>()->default_value(8332), "RPC port of Bitcoin node");
|
cli.add_options()("bitcoin-node-rpc-port", bpo::value<uint32_t>()->default_value(8332), "RPC port of Bitcoin node");
|
||||||
cli.add_options()("bitcoin-node-rpc-user", bpo::value<string>()->default_value("1"), "Bitcoin RPC user");
|
cli.add_options()("bitcoin-node-rpc-user", bpo::value<string>()->default_value("1"), "Bitcoin RPC user");
|
||||||
|
|
@ -192,7 +193,7 @@ void peerplays_sidechain_plugin_impl::plugin_set_program_options(
|
||||||
"Tuple of [Bitcoin public key, Bitcoin private key] (may specify multiple times)");
|
"Tuple of [Bitcoin public key, Bitcoin private key] (may specify multiple times)");
|
||||||
|
|
||||||
cli.add_options()("ethereum-sidechain-enabled", bpo::value<bool>()->default_value(false), "Ethereum sidechain handler enabled");
|
cli.add_options()("ethereum-sidechain-enabled", bpo::value<bool>()->default_value(false), "Ethereum sidechain handler enabled");
|
||||||
cli.add_options()("ethereum-node-rpc-url", bpo::value<string>()->default_value("127.0.0.1:8545"), "Ethereum node RPC URL [http[s]://]host[:port]");
|
cli.add_options()("ethereum-node-rpc-url", bpo::value<vector<string>>()->composing()->multitoken()->DEFAULT_VALUE_VECTOR("127.0.0.1:8545"), "Ethereum node RPC URL [http[s]://]host[:port]");
|
||||||
cli.add_options()("ethereum-node-rpc-user", bpo::value<string>(), "Ethereum RPC user");
|
cli.add_options()("ethereum-node-rpc-user", bpo::value<string>(), "Ethereum RPC user");
|
||||||
cli.add_options()("ethereum-node-rpc-password", bpo::value<string>(), "Ethereum RPC password");
|
cli.add_options()("ethereum-node-rpc-password", bpo::value<string>(), "Ethereum RPC password");
|
||||||
cli.add_options()("ethereum-wallet-contract-address", bpo::value<string>(), "Ethereum wallet contract address");
|
cli.add_options()("ethereum-wallet-contract-address", bpo::value<string>(), "Ethereum wallet contract address");
|
||||||
|
|
@ -202,7 +203,7 @@ void peerplays_sidechain_plugin_impl::plugin_set_program_options(
|
||||||
"Tuple of [Ethereum public key, Ethereum private key] (may specify multiple times)");
|
"Tuple of [Ethereum public key, Ethereum private key] (may specify multiple times)");
|
||||||
|
|
||||||
cli.add_options()("hive-sidechain-enabled", bpo::value<bool>()->default_value(false), "Hive sidechain handler enabled");
|
cli.add_options()("hive-sidechain-enabled", bpo::value<bool>()->default_value(false), "Hive sidechain handler enabled");
|
||||||
cli.add_options()("hive-node-rpc-url", bpo::value<string>()->default_value("127.0.0.1:28090"), "Hive node RPC URL [http[s]://]host[:port]");
|
cli.add_options()("hive-node-rpc-url", bpo::value<vector<string>>()->composing()->multitoken()->DEFAULT_VALUE_VECTOR("127.0.0.1:28090"), "Hive node RPC URL [http[s]://]host[:port]");
|
||||||
cli.add_options()("hive-node-rpc-user", bpo::value<string>(), "Hive node RPC user");
|
cli.add_options()("hive-node-rpc-user", bpo::value<string>(), "Hive node RPC user");
|
||||||
cli.add_options()("hive-node-rpc-password", bpo::value<string>(), "Hive node RPC password");
|
cli.add_options()("hive-node-rpc-password", bpo::value<string>(), "Hive node RPC password");
|
||||||
cli.add_options()("hive-wallet-account-name", bpo::value<string>(), "Hive wallet account name");
|
cli.add_options()("hive-wallet-account-name", bpo::value<string>(), "Hive wallet account name");
|
||||||
|
|
@ -291,6 +292,9 @@ void peerplays_sidechain_plugin_impl::plugin_initialize(const boost::program_opt
|
||||||
if (sidechain_enabled_peerplays && !config_ready_peerplays) {
|
if (sidechain_enabled_peerplays && !config_ready_peerplays) {
|
||||||
wlog("Haven't set up Peerplays sidechain parameters");
|
wlog("Haven't set up Peerplays sidechain parameters");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.at("simulate-rpc-connection-reselection").as<bool>())
|
||||||
|
ilog("### RPC connection reselection will be simulated");
|
||||||
}
|
}
|
||||||
|
|
||||||
void peerplays_sidechain_plugin_impl::plugin_startup() {
|
void peerplays_sidechain_plugin_impl::plugin_startup() {
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,8 @@
|
||||||
|
|
||||||
namespace graphene { namespace peerplays_sidechain {
|
namespace graphene { namespace peerplays_sidechain {
|
||||||
|
|
||||||
sidechain_net_handler::sidechain_net_handler(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options) :
|
sidechain_net_handler::sidechain_net_handler(sidechain_type _sidechain, peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options) :
|
||||||
|
sidechain(_sidechain),
|
||||||
plugin(_plugin),
|
plugin(_plugin),
|
||||||
database(_plugin.database()) {
|
database(_plugin.database()) {
|
||||||
|
|
||||||
|
|
@ -679,7 +680,8 @@ void sidechain_net_handler::on_applied_block(const signed_block &b) {
|
||||||
const bool is_tracked_asset =
|
const bool is_tracked_asset =
|
||||||
((sidechain == sidechain_type::bitcoin) && (transfer_op.amount.asset_id == gpo.parameters.btc_asset())) ||
|
((sidechain == sidechain_type::bitcoin) && (transfer_op.amount.asset_id == gpo.parameters.btc_asset())) ||
|
||||||
((sidechain == sidechain_type::ethereum) && (transfer_op.amount.asset_id == gpo.parameters.eth_asset())) ||
|
((sidechain == sidechain_type::ethereum) && (transfer_op.amount.asset_id == gpo.parameters.eth_asset())) ||
|
||||||
(sidechain == sidechain_type::ethereum) ||
|
((sidechain == sidechain_type::ethereum) && (transfer_op.amount.asset_id != gpo.parameters.btc_asset())
|
||||||
|
&& (transfer_op.amount.asset_id != gpo.parameters.hbd_asset()) && (transfer_op.amount.asset_id != gpo.parameters.hive_asset())) ||
|
||||||
((sidechain == sidechain_type::hive) && (transfer_op.amount.asset_id == gpo.parameters.hbd_asset())) ||
|
((sidechain == sidechain_type::hive) && (transfer_op.amount.asset_id == gpo.parameters.hbd_asset())) ||
|
||||||
((sidechain == sidechain_type::hive) && (transfer_op.amount.asset_id == gpo.parameters.hive_asset()));
|
((sidechain == sidechain_type::hive) && (transfer_op.amount.asset_id == gpo.parameters.hive_asset()));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ namespace graphene { namespace peerplays_sidechain {
|
||||||
|
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
|
|
||||||
bitcoin_rpc_client::bitcoin_rpc_client(std::string _url, std::string _user, std::string _password, bool _debug_rpc_calls) :
|
bitcoin_rpc_client::bitcoin_rpc_client(const std::vector<rpc_credentials> &_credentials, bool _debug_rpc_calls, bool _simulate_connection_reselection) :
|
||||||
rpc_client(_url, _user, _password, _debug_rpc_calls) {
|
rpc_client(sidechain_type::bitcoin, _credentials, _debug_rpc_calls, _simulate_connection_reselection) {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t bitcoin_rpc_client::estimatesmartfee(uint16_t conf_target) {
|
uint64_t bitcoin_rpc_client::estimatesmartfee(uint16_t conf_target) {
|
||||||
|
|
@ -500,6 +500,13 @@ std::string bitcoin_libbitcoin_client::sendrawtransaction(const std::string &tx_
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t bitcoin_rpc_client::ping(rpc_connection &conn) const {
|
||||||
|
std::string str = send_post_request(conn, "getblockcount", "[]", debug_rpc_calls);
|
||||||
|
if (str.length() > 0)
|
||||||
|
return std::stoll(str);
|
||||||
|
return std::numeric_limits<uint64_t>::max();
|
||||||
|
}
|
||||||
|
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
|
|
||||||
zmq_listener::zmq_listener(std::string _ip, uint32_t _zmq_block_port, uint32_t _zmq_trx_port) :
|
zmq_listener::zmq_listener(std::string _ip, uint32_t _zmq_block_port, uint32_t _zmq_trx_port) :
|
||||||
|
|
@ -678,13 +685,19 @@ void zmq_listener_libbitcoin::handle_block() {
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
|
|
||||||
sidechain_net_handler_bitcoin::sidechain_net_handler_bitcoin(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options) :
|
sidechain_net_handler_bitcoin::sidechain_net_handler_bitcoin(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options) :
|
||||||
sidechain_net_handler(_plugin, options) {
|
sidechain_net_handler(sidechain_type::bitcoin, _plugin, options) {
|
||||||
sidechain = sidechain_type::bitcoin;
|
|
||||||
|
|
||||||
if (options.count("debug-rpc-calls")) {
|
if (options.count("debug-rpc-calls")) {
|
||||||
debug_rpc_calls = options.at("debug-rpc-calls").as<bool>();
|
debug_rpc_calls = options.at("debug-rpc-calls").as<bool>();
|
||||||
}
|
}
|
||||||
|
bool simulate_connection_reselection = options.at("simulate-rpc-connection-reselection").as<bool>();
|
||||||
|
|
||||||
|
std::vector<std::string> ips = options.at("bitcoin-node-ip").as<std::vector<std::string>>();
|
||||||
|
bitcoin_node_zmq_port = options.at("bitcoin-node-zmq-port").as<uint32_t>();
|
||||||
|
uint32_t rpc_port = options.at("bitcoin-node-rpc-port").as<uint32_t>();
|
||||||
|
std::string rpc_user = options.at("bitcoin-node-rpc-user").as<std::string>();
|
||||||
|
std::string rpc_password = options.at("bitcoin-node-rpc-password").as<std::string>();
|
||||||
|
|
||||||
if (options.count("use-bitcoind-client")) {
|
if (options.count("use-bitcoind-client")) {
|
||||||
use_bitcoind_client = options.at("use-bitcoind-client").as<bool>();
|
use_bitcoind_client = options.at("use-bitcoind-client").as<bool>();
|
||||||
}
|
}
|
||||||
|
|
@ -693,11 +706,6 @@ sidechain_net_handler_bitcoin::sidechain_net_handler_bitcoin(peerplays_sidechain
|
||||||
libbitcoin_block_zmq_port = options.at("libbitcoin-server-block-zmq-port").as<uint32_t>();
|
libbitcoin_block_zmq_port = options.at("libbitcoin-server-block-zmq-port").as<uint32_t>();
|
||||||
libbitcoin_trx_zmq_port = options.at("libbitcoin-server-trx-zmq-port").as<uint32_t>();
|
libbitcoin_trx_zmq_port = options.at("libbitcoin-server-trx-zmq-port").as<uint32_t>();
|
||||||
|
|
||||||
bitcoin_node_ip = options.at("bitcoin-node-ip").as<std::string>();
|
|
||||||
bitcoin_node_zmq_port = options.at("bitcoin-node-zmq-port").as<uint32_t>();
|
|
||||||
rpc_port = options.at("bitcoin-node-rpc-port").as<uint32_t>();
|
|
||||||
rpc_user = options.at("bitcoin-node-rpc-user").as<std::string>();
|
|
||||||
rpc_password = options.at("bitcoin-node-rpc-password").as<std::string>();
|
|
||||||
wallet_name = "";
|
wallet_name = "";
|
||||||
if (options.count("bitcoin-wallet-name")) {
|
if (options.count("bitcoin-wallet-name")) {
|
||||||
wallet_name = options.at("bitcoin-wallet-name").as<std::string>();
|
wallet_name = options.at("bitcoin-wallet-name").as<std::string>();
|
||||||
|
|
@ -720,17 +728,27 @@ sidechain_net_handler_bitcoin::sidechain_net_handler_bitcoin(peerplays_sidechain
|
||||||
}
|
}
|
||||||
|
|
||||||
if (use_bitcoind_client) {
|
if (use_bitcoind_client) {
|
||||||
std::string url = bitcoin_node_ip + ":" + std::to_string(rpc_port);
|
|
||||||
if (!wallet_name.empty()) {
|
for (size_t i = 0; i < ips.size(); i++) {
|
||||||
url = url + "/wallet/" + wallet_name;
|
std::string ip = ips[i];
|
||||||
|
std::string url = ip + ":" + std::to_string(rpc_port);
|
||||||
|
if (!wallet_name.empty()) {
|
||||||
|
url = url + "/wallet/" + wallet_name;
|
||||||
|
}
|
||||||
|
rpc_credentials creds;
|
||||||
|
creds.url = url;
|
||||||
|
creds.user = rpc_user;
|
||||||
|
creds.password = rpc_password;
|
||||||
|
_rpc_credentials.push_back(creds);
|
||||||
}
|
}
|
||||||
bitcoin_client = std::unique_ptr<bitcoin_rpc_client>(new bitcoin_rpc_client(url, rpc_user, rpc_password, debug_rpc_calls));
|
FC_ASSERT(!_rpc_credentials.empty());
|
||||||
|
|
||||||
|
bitcoin_client = std::unique_ptr<bitcoin_rpc_client>(new bitcoin_rpc_client(_rpc_credentials, debug_rpc_calls, simulate_connection_reselection));
|
||||||
if (!wallet_name.empty()) {
|
if (!wallet_name.empty()) {
|
||||||
bitcoin_client->loadwallet(wallet_name);
|
bitcoin_client->loadwallet(wallet_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
listener = std::unique_ptr<zmq_listener>(new zmq_listener(bitcoin_node_ip, bitcoin_node_zmq_port));
|
listener = std::unique_ptr<zmq_listener>(new zmq_listener(ips[0], bitcoin_node_zmq_port));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
bitcoin_client = std::unique_ptr<bitcoin_libbitcoin_client>(new bitcoin_libbitcoin_client(libbitcoin_server_ip));
|
bitcoin_client = std::unique_ptr<bitcoin_libbitcoin_client>(new bitcoin_libbitcoin_client(libbitcoin_server_ip));
|
||||||
|
|
||||||
|
|
@ -750,7 +768,6 @@ sidechain_net_handler_bitcoin::sidechain_net_handler_bitcoin(peerplays_sidechain
|
||||||
|
|
||||||
bitcoin_client->getnetworkinfo();
|
bitcoin_client->getnetworkinfo();
|
||||||
|
|
||||||
listener->start();
|
|
||||||
listener->block_event_received.connect([this](const block_data &block_event_data) {
|
listener->block_event_received.connect([this](const block_data &block_event_data) {
|
||||||
std::thread(&sidechain_net_handler_bitcoin::block_handle_event, this, block_event_data).detach();
|
std::thread(&sidechain_net_handler_bitcoin::block_handle_event, this, block_event_data).detach();
|
||||||
});
|
});
|
||||||
|
|
@ -759,6 +776,8 @@ sidechain_net_handler_bitcoin::sidechain_net_handler_bitcoin(peerplays_sidechain
|
||||||
std::thread(&sidechain_net_handler_bitcoin::trx_handle_event, this, trx_event_data).detach();
|
std::thread(&sidechain_net_handler_bitcoin::trx_handle_event, this, trx_event_data).detach();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
listener->start();
|
||||||
|
|
||||||
database.changed_objects.connect([this](const vector<object_id_type> &ids, const flat_set<account_id_type> &accounts) {
|
database.changed_objects.connect([this](const vector<object_id_type> &ids, const flat_set<account_id_type> &accounts) {
|
||||||
on_changed_objects(ids, accounts);
|
on_changed_objects(ids, accounts);
|
||||||
});
|
});
|
||||||
|
|
@ -778,7 +797,7 @@ sidechain_net_handler_bitcoin::~sidechain_net_handler_bitcoin() {
|
||||||
|
|
||||||
bool sidechain_net_handler_bitcoin::process_proposal(const proposal_object &po) {
|
bool sidechain_net_handler_bitcoin::process_proposal(const proposal_object &po) {
|
||||||
|
|
||||||
// ilog("Proposal to process: ${po}, SON id ${son_id}", ("po", po.id)("son_id", plugin.get_current_son_id(sidechain)));
|
ilog("Proposal to process: ${po}, SON id ${son_id}", ("po", po.id)("son_id", plugin.get_current_son_id(sidechain)));
|
||||||
|
|
||||||
bool should_approve = false;
|
bool should_approve = false;
|
||||||
|
|
||||||
|
|
@ -855,7 +874,7 @@ bool sidechain_net_handler_bitcoin::process_proposal(const proposal_object &po)
|
||||||
std::string op_tx_str = op_obj_idx_1.get<sidechain_transaction_create_operation>().transaction;
|
std::string op_tx_str = op_obj_idx_1.get<sidechain_transaction_create_operation>().transaction;
|
||||||
|
|
||||||
const auto &st_idx = database.get_index_type<sidechain_transaction_index>().indices().get<by_object_id>();
|
const auto &st_idx = database.get_index_type<sidechain_transaction_index>().indices().get<by_object_id>();
|
||||||
const auto st = st_idx.find(obj_id);
|
const auto st = st_idx.find(object_id);
|
||||||
if (st == st_idx.end()) {
|
if (st == st_idx.end()) {
|
||||||
|
|
||||||
std::string tx_str = "";
|
std::string tx_str = "";
|
||||||
|
|
@ -1075,6 +1094,10 @@ void sidechain_net_handler_bitcoin::process_primary_wallet() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!plugin.can_son_participate(sidechain, chain::operation::tag<chain::son_wallet_update_operation>::value, op_id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const chain::global_property_object &gpo = database.get_global_properties();
|
const chain::global_property_object &gpo = database.get_global_properties();
|
||||||
|
|
||||||
const auto &active_sons = gpo.active_sons.at(sidechain);
|
const auto &active_sons = gpo.active_sons.at(sidechain);
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@
|
||||||
|
|
||||||
namespace graphene { namespace peerplays_sidechain {
|
namespace graphene { namespace peerplays_sidechain {
|
||||||
|
|
||||||
ethereum_rpc_client::ethereum_rpc_client(const std::string &url, const std::string &user_name, const std::string &password, bool debug_rpc_calls) :
|
ethereum_rpc_client::ethereum_rpc_client(const std::vector<rpc_credentials> &credentials, bool debug_rpc_calls, bool simulate_connection_reselection) :
|
||||||
rpc_client(url, user_name, password, debug_rpc_calls) {
|
rpc_client(sidechain_type::ethereum, credentials, debug_rpc_calls, simulate_connection_reselection) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ethereum_rpc_client::eth_blockNumber() {
|
std::string ethereum_rpc_client::eth_blockNumber() {
|
||||||
|
|
@ -126,20 +126,29 @@ std::string ethereum_rpc_client::eth_get_transaction_by_hash(const std::string &
|
||||||
return send_post_request("eth_getTransactionByHash", "[\"" + params + "\"]", debug_rpc_calls);
|
return send_post_request("eth_getTransactionByHash", "[\"" + params + "\"]", debug_rpc_calls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t ethereum_rpc_client::ping(rpc_connection &conn) const {
|
||||||
|
std::string reply = send_post_request(conn, "eth_blockNumber", "", debug_rpc_calls);
|
||||||
|
if (!reply.empty())
|
||||||
|
return ethereum::from_hex<uint64_t>(retrieve_value_from_reply(reply, ""));
|
||||||
|
return std::numeric_limits<uint64_t>::max();
|
||||||
|
}
|
||||||
|
|
||||||
sidechain_net_handler_ethereum::sidechain_net_handler_ethereum(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options) :
|
sidechain_net_handler_ethereum::sidechain_net_handler_ethereum(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options) :
|
||||||
sidechain_net_handler(_plugin, options) {
|
sidechain_net_handler(sidechain_type::ethereum, _plugin, options) {
|
||||||
sidechain = sidechain_type::ethereum;
|
|
||||||
|
|
||||||
if (options.count("debug-rpc-calls")) {
|
if (options.count("debug-rpc-calls")) {
|
||||||
debug_rpc_calls = options.at("debug-rpc-calls").as<bool>();
|
debug_rpc_calls = options.at("debug-rpc-calls").as<bool>();
|
||||||
}
|
}
|
||||||
|
bool simulate_connection_reselection = options.at("simulate-rpc-connection-reselection").as<bool>();
|
||||||
|
|
||||||
rpc_url = options.at("ethereum-node-rpc-url").as<std::string>();
|
std::vector<std::string> rpc_urls = options.at("ethereum-node-rpc-url").as<std::vector<std::string>>();
|
||||||
|
std::string rpc_user;
|
||||||
if (options.count("ethereum-node-rpc-user")) {
|
if (options.count("ethereum-node-rpc-user")) {
|
||||||
rpc_user = options.at("ethereum-node-rpc-user").as<std::string>();
|
rpc_user = options.at("ethereum-node-rpc-user").as<std::string>();
|
||||||
} else {
|
} else {
|
||||||
rpc_user = "";
|
rpc_user = "";
|
||||||
}
|
}
|
||||||
|
std::string rpc_password;
|
||||||
if (options.count("ethereum-node-rpc-password")) {
|
if (options.count("ethereum-node-rpc-password")) {
|
||||||
rpc_password = options.at("ethereum-node-rpc-password").as<std::string>();
|
rpc_password = options.at("ethereum-node-rpc-password").as<std::string>();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -175,18 +184,27 @@ sidechain_net_handler_ethereum::sidechain_net_handler_ethereum(peerplays_sidecha
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rpc_client = new ethereum_rpc_client(rpc_url, rpc_user, rpc_password, debug_rpc_calls);
|
for (size_t i = 0; i < rpc_urls.size(); i++) {
|
||||||
|
rpc_credentials creds;
|
||||||
|
creds.url = rpc_urls[i];
|
||||||
|
creds.user = rpc_user;
|
||||||
|
creds.password = rpc_password;
|
||||||
|
_rpc_credentials.push_back(creds);
|
||||||
|
}
|
||||||
|
FC_ASSERT(!_rpc_credentials.empty());
|
||||||
|
|
||||||
|
rpc_client = new ethereum_rpc_client(_rpc_credentials, debug_rpc_calls, simulate_connection_reselection);
|
||||||
|
|
||||||
const std::string chain_id_str = rpc_client->get_chain_id();
|
const std::string chain_id_str = rpc_client->get_chain_id();
|
||||||
if (chain_id_str.empty()) {
|
if (chain_id_str.empty()) {
|
||||||
elog("No Ethereum node running at ${url}", ("url", rpc_url));
|
elog("No Ethereum node running at ${url}", ("url", _rpc_credentials[0].url));
|
||||||
FC_ASSERT(false);
|
FC_ASSERT(false);
|
||||||
}
|
}
|
||||||
chain_id = std::stoll(chain_id_str);
|
chain_id = std::stoll(chain_id_str);
|
||||||
|
|
||||||
const std::string network_id_str = rpc_client->get_network_id();
|
const std::string network_id_str = rpc_client->get_network_id();
|
||||||
if (network_id_str.empty()) {
|
if (network_id_str.empty()) {
|
||||||
elog("No Ethereum node running at ${url}", ("url", rpc_url));
|
elog("No Ethereum node running at ${url}", ("url", _rpc_credentials[0].url));
|
||||||
FC_ASSERT(false);
|
FC_ASSERT(false);
|
||||||
}
|
}
|
||||||
network_id = std::stoll(network_id_str);
|
network_id = std::stoll(network_id_str);
|
||||||
|
|
@ -205,6 +223,7 @@ sidechain_net_handler_ethereum::~sidechain_net_handler_ethereum() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sidechain_net_handler_ethereum::process_proposal(const proposal_object &po) {
|
bool sidechain_net_handler_ethereum::process_proposal(const proposal_object &po) {
|
||||||
|
|
||||||
ilog("Proposal to process: ${po}, SON id ${son_id}", ("po", po.id)("son_id", plugin.get_current_son_id(sidechain)));
|
ilog("Proposal to process: ${po}, SON id ${son_id}", ("po", po.id)("son_id", plugin.get_current_son_id(sidechain)));
|
||||||
|
|
||||||
bool should_approve = false;
|
bool should_approve = false;
|
||||||
|
|
@ -263,7 +282,7 @@ bool sidechain_net_handler_ethereum::process_proposal(const proposal_object &po)
|
||||||
const std::string op_tx_str = op_obj_idx_1.get<sidechain_transaction_create_operation>().transaction;
|
const std::string op_tx_str = op_obj_idx_1.get<sidechain_transaction_create_operation>().transaction;
|
||||||
|
|
||||||
const auto &st_idx = database.get_index_type<sidechain_transaction_index>().indices().get<by_object_id>();
|
const auto &st_idx = database.get_index_type<sidechain_transaction_index>().indices().get<by_object_id>();
|
||||||
const auto st = st_idx.find(obj_id);
|
const auto st = st_idx.find(object_id);
|
||||||
if (st == st_idx.end()) {
|
if (st == st_idx.end()) {
|
||||||
|
|
||||||
std::string tx_str = "";
|
std::string tx_str = "";
|
||||||
|
|
@ -665,13 +684,18 @@ std::string sidechain_net_handler_ethereum::send_sidechain_transaction(const sid
|
||||||
|
|
||||||
const ethereum::signature_encoder encoder{function_signature};
|
const ethereum::signature_encoder encoder{function_signature};
|
||||||
#ifdef SEND_RAW_TRANSACTION
|
#ifdef SEND_RAW_TRANSACTION
|
||||||
|
const auto data = encoder.encode(transactions);
|
||||||
|
const std::string params = "[{\"from\":\"" + ethereum::add_0x(public_key) + "\", \"to\":\"" + wallet_contract_address + "\", \"data\":\"" + data + "\"}]";
|
||||||
|
|
||||||
ethereum::raw_transaction raw_tr;
|
ethereum::raw_transaction raw_tr;
|
||||||
raw_tr.nonce = rpc_client->get_nonce(ethereum::add_0x(public_key));
|
raw_tr.nonce = rpc_client->get_nonce(ethereum::add_0x(public_key));
|
||||||
raw_tr.gas_price = rpc_client->get_gas_price();
|
raw_tr.gas_price = rpc_client->get_gas_price();
|
||||||
raw_tr.gas_limit = rpc_client->get_gas_limit();
|
raw_tr.gas_limit = rpc_client->get_estimate_gas(params);
|
||||||
|
if (raw_tr.gas_limit.empty())
|
||||||
|
raw_tr.gas_limit = rpc_client->get_gas_limit();
|
||||||
raw_tr.to = wallet_contract_address;
|
raw_tr.to = wallet_contract_address;
|
||||||
raw_tr.value = "";
|
raw_tr.value = "";
|
||||||
raw_tr.data = encoder.encode(transactions);
|
raw_tr.data = data;
|
||||||
raw_tr.chain_id = ethereum::add_0x(ethereum::to_hex(chain_id));
|
raw_tr.chain_id = ethereum::add_0x(ethereum::to_hex(chain_id));
|
||||||
|
|
||||||
const auto sign_tr = raw_tr.sign(get_private_key(public_key));
|
const auto sign_tr = raw_tr.sign(get_private_key(public_key));
|
||||||
|
|
@ -785,7 +809,7 @@ optional<asset> sidechain_net_handler_ethereum::estimate_withdrawal_transaction_
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto &public_key = son->sidechain_public_keys.at(sidechain);
|
const auto &public_key = son->sidechain_public_keys.at(sidechain);
|
||||||
const auto data = ethereum::withdrawal_encoder::encode(public_key, 1 * 10000000000, son_wallet_withdraw_id_type{0}.operator object_id_type().operator std::string());
|
const auto data = ethereum::withdrawal_encoder::encode(public_key, boost::multiprecision::uint256_t{1} * boost::multiprecision::uint256_t{10000000000}, "0");
|
||||||
const std::string params = "[{\"from\":\"" + ethereum::add_0x(public_key) + "\", \"to\":\"" + wallet_contract_address + "\", \"data\":\"" + data + "\"}]";
|
const std::string params = "[{\"from\":\"" + ethereum::add_0x(public_key) + "\", \"to\":\"" + wallet_contract_address + "\", \"data\":\"" + data + "\"}]";
|
||||||
|
|
||||||
const auto estimate_gas = ethereum::from_hex<int64_t>(rpc_client->get_estimate_gas(params));
|
const auto estimate_gas = ethereum::from_hex<int64_t>(rpc_client->get_estimate_gas(params));
|
||||||
|
|
@ -808,14 +832,14 @@ std::string sidechain_net_handler_ethereum::create_primary_wallet_transaction(co
|
||||||
|
|
||||||
std::string sidechain_net_handler_ethereum::create_withdrawal_transaction(const son_wallet_withdraw_object &swwo) {
|
std::string sidechain_net_handler_ethereum::create_withdrawal_transaction(const son_wallet_withdraw_object &swwo) {
|
||||||
if (swwo.withdraw_currency == "ETH") {
|
if (swwo.withdraw_currency == "ETH") {
|
||||||
return ethereum::withdrawal_encoder::encode(ethereum::remove_0x(swwo.withdraw_address), swwo.withdraw_amount.value * 10000000000, swwo.id.operator std::string());
|
return ethereum::withdrawal_encoder::encode(ethereum::remove_0x(swwo.withdraw_address), boost::multiprecision::uint256_t{swwo.withdraw_amount.value} * boost::multiprecision::uint256_t{10000000000}, swwo.id.operator std::string());
|
||||||
} else {
|
} else {
|
||||||
const auto it = erc20_addresses.left.find(swwo.withdraw_currency);
|
const auto it = erc20_addresses.left.find(swwo.withdraw_currency);
|
||||||
if (it == erc20_addresses.left.end()) {
|
if (it == erc20_addresses.left.end()) {
|
||||||
elog("No erc-20 token: ${symbol}", ("symbol", swwo.withdraw_currency));
|
elog("No erc-20 token: ${symbol}", ("symbol", swwo.withdraw_currency));
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return ethereum::withdrawal_erc20_encoder::encode(ethereum::remove_0x(it->second), ethereum::remove_0x(swwo.withdraw_address), swwo.withdraw_amount.value, swwo.id.operator std::string());
|
return ethereum::withdrawal_erc20_encoder::encode(ethereum::remove_0x(it->second), ethereum::remove_0x(swwo.withdraw_address), boost::multiprecision::uint256_t{swwo.withdraw_amount.value}, swwo.id.operator std::string());
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
|
|
@ -890,8 +914,9 @@ void sidechain_net_handler_ethereum::handle_event(const std::string &block_numbe
|
||||||
const boost::property_tree::ptree tx = tx_child.second;
|
const boost::property_tree::ptree tx = tx_child.second;
|
||||||
tx_idx = tx_idx + 1;
|
tx_idx = tx_idx + 1;
|
||||||
|
|
||||||
const std::string from = tx.get<std::string>("from");
|
|
||||||
const std::string to = tx.get<std::string>("to");
|
const std::string to = tx.get<std::string>("to");
|
||||||
|
std::string from = tx.get<std::string>("from");
|
||||||
|
std::transform(from.begin(), from.end(), from.begin(), ::tolower);
|
||||||
|
|
||||||
std::string cmp_to = to;
|
std::string cmp_to = to;
|
||||||
std::transform(cmp_to.begin(), cmp_to.end(), cmp_to.begin(), ::toupper);
|
std::transform(cmp_to.begin(), cmp_to.end(), cmp_to.begin(), ::toupper);
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,8 @@
|
||||||
|
|
||||||
namespace graphene { namespace peerplays_sidechain {
|
namespace graphene { namespace peerplays_sidechain {
|
||||||
|
|
||||||
hive_rpc_client::hive_rpc_client(const std::string &url, const std::string &user_name, const std::string &password, bool debug_rpc_calls) :
|
hive_rpc_client::hive_rpc_client(const std::vector<rpc_credentials> &credentials, bool debug_rpc_calls, bool simulate_connection_reselection) :
|
||||||
rpc_client(url, user_name, password, debug_rpc_calls) {
|
rpc_client(sidechain_type::hive, credentials, debug_rpc_calls, simulate_connection_reselection) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string hive_rpc_client::account_history_api_get_transaction(std::string transaction_id) {
|
std::string hive_rpc_client::account_history_api_get_transaction(std::string transaction_id) {
|
||||||
|
|
@ -112,20 +112,34 @@ std::string hive_rpc_client::get_last_irreversible_block_num() {
|
||||||
return retrieve_value_from_reply(reply_str, "last_irreversible_block_num");
|
return retrieve_value_from_reply(reply_str, "last_irreversible_block_num");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t hive_rpc_client::ping(rpc_connection &conn) const {
|
||||||
|
const std::string reply = send_post_request(conn, "database_api.get_dynamic_global_properties", "", debug_rpc_calls);
|
||||||
|
if (!reply.empty()) {
|
||||||
|
std::stringstream ss(reply);
|
||||||
|
boost::property_tree::ptree json;
|
||||||
|
boost::property_tree::read_json(ss, json);
|
||||||
|
if (json.count("result"))
|
||||||
|
return json.get<uint64_t>("result.head_block_number");
|
||||||
|
}
|
||||||
|
return std::numeric_limits<uint64_t>::max();
|
||||||
|
}
|
||||||
|
|
||||||
sidechain_net_handler_hive::sidechain_net_handler_hive(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options) :
|
sidechain_net_handler_hive::sidechain_net_handler_hive(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options) :
|
||||||
sidechain_net_handler(_plugin, options) {
|
sidechain_net_handler(sidechain_type::hive, _plugin, options) {
|
||||||
sidechain = sidechain_type::hive;
|
|
||||||
|
|
||||||
if (options.count("debug-rpc-calls")) {
|
if (options.count("debug-rpc-calls")) {
|
||||||
debug_rpc_calls = options.at("debug-rpc-calls").as<bool>();
|
debug_rpc_calls = options.at("debug-rpc-calls").as<bool>();
|
||||||
}
|
}
|
||||||
|
bool simulate_connection_reselection = options.at("simulate-rpc-connection-reselection").as<bool>();
|
||||||
|
|
||||||
rpc_url = options.at("hive-node-rpc-url").as<std::string>();
|
std::vector<std::string> rpc_urls = options.at("hive-node-rpc-url").as<std::vector<std::string>>();
|
||||||
|
std::string rpc_user;
|
||||||
if (options.count("hive-rpc-user")) {
|
if (options.count("hive-rpc-user")) {
|
||||||
rpc_user = options.at("hive-rpc-user").as<std::string>();
|
rpc_user = options.at("hive-rpc-user").as<std::string>();
|
||||||
} else {
|
} else {
|
||||||
rpc_user = "";
|
rpc_user = "";
|
||||||
}
|
}
|
||||||
|
std::string rpc_password;
|
||||||
if (options.count("hive-rpc-password")) {
|
if (options.count("hive-rpc-password")) {
|
||||||
rpc_password = options.at("hive-rpc-password").as<std::string>();
|
rpc_password = options.at("hive-rpc-password").as<std::string>();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -146,11 +160,20 @@ sidechain_net_handler_hive::sidechain_net_handler_hive(peerplays_sidechain_plugi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rpc_client = new hive_rpc_client(rpc_url, rpc_user, rpc_password, debug_rpc_calls);
|
for (size_t i = 0; i < rpc_urls.size(); i++) {
|
||||||
|
rpc_credentials creds;
|
||||||
|
creds.url = rpc_urls[i];
|
||||||
|
creds.user = rpc_user;
|
||||||
|
creds.password = rpc_password;
|
||||||
|
_rpc_credentials.push_back(creds);
|
||||||
|
}
|
||||||
|
FC_ASSERT(!_rpc_credentials.empty());
|
||||||
|
|
||||||
|
rpc_client = new hive_rpc_client(_rpc_credentials, debug_rpc_calls, simulate_connection_reselection);
|
||||||
|
|
||||||
const std::string chain_id_str = rpc_client->get_chain_id();
|
const std::string chain_id_str = rpc_client->get_chain_id();
|
||||||
if (chain_id_str.empty()) {
|
if (chain_id_str.empty()) {
|
||||||
elog("No Hive node running at ${url}", ("url", rpc_url));
|
elog("No Hive node running at ${url}", ("url", _rpc_credentials[0].url));
|
||||||
FC_ASSERT(false);
|
FC_ASSERT(false);
|
||||||
}
|
}
|
||||||
chain_id = chain_id_type(chain_id_str);
|
chain_id = chain_id_type(chain_id_str);
|
||||||
|
|
@ -180,7 +203,8 @@ sidechain_net_handler_hive::~sidechain_net_handler_hive() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sidechain_net_handler_hive::process_proposal(const proposal_object &po) {
|
bool sidechain_net_handler_hive::process_proposal(const proposal_object &po) {
|
||||||
//ilog("Proposal to process: ${po}, SON id ${son_id}", ("po", po.id)("son_id", plugin.get_current_son_id(sidechain)));
|
|
||||||
|
ilog("Proposal to process: ${po}, SON id ${son_id}", ("po", po.id)("son_id", plugin.get_current_son_id(sidechain)));
|
||||||
|
|
||||||
bool should_approve = false;
|
bool should_approve = false;
|
||||||
|
|
||||||
|
|
@ -238,7 +262,7 @@ bool sidechain_net_handler_hive::process_proposal(const proposal_object &po) {
|
||||||
std::string op_tx_str = op_obj_idx_1.get<sidechain_transaction_create_operation>().transaction;
|
std::string op_tx_str = op_obj_idx_1.get<sidechain_transaction_create_operation>().transaction;
|
||||||
|
|
||||||
const auto &st_idx = database.get_index_type<sidechain_transaction_index>().indices().get<by_object_id>();
|
const auto &st_idx = database.get_index_type<sidechain_transaction_index>().indices().get<by_object_id>();
|
||||||
const auto st = st_idx.find(obj_id);
|
const auto st = st_idx.find(object_id);
|
||||||
if (st == st_idx.end()) {
|
if (st == st_idx.end()) {
|
||||||
|
|
||||||
std::string tx_str = "";
|
std::string tx_str = "";
|
||||||
|
|
@ -499,6 +523,10 @@ void sidechain_net_handler_hive::process_primary_wallet() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!plugin.can_son_participate(sidechain, chain::operation::tag<chain::son_wallet_update_operation>::value, op_id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const chain::global_property_object &gpo = database.get_global_properties();
|
const chain::global_property_object &gpo = database.get_global_properties();
|
||||||
|
|
||||||
const auto &active_sons = gpo.active_sons.at(sidechain);
|
const auto &active_sons = gpo.active_sons.at(sidechain);
|
||||||
|
|
@ -577,7 +605,7 @@ void sidechain_net_handler_hive::process_primary_wallet() {
|
||||||
stc_op.object_id = op_id;
|
stc_op.object_id = op_id;
|
||||||
stc_op.sidechain = sidechain;
|
stc_op.sidechain = sidechain;
|
||||||
stc_op.transaction = tx_str;
|
stc_op.transaction = tx_str;
|
||||||
for (const auto &signer : gpo.active_sons.at(sidechain)) {
|
for (const auto &signer : signers) {
|
||||||
son_info si;
|
son_info si;
|
||||||
si.son_id = signer.son_id;
|
si.son_id = signer.son_id;
|
||||||
si.weight = signer.weight;
|
si.weight = signer.weight;
|
||||||
|
|
@ -639,6 +667,11 @@ void sidechain_net_handler_hive::process_sidechain_addresses() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sidechain_net_handler_hive::process_deposit(const son_wallet_deposit_object &swdo) {
|
bool sidechain_net_handler_hive::process_deposit(const son_wallet_deposit_object &swdo) {
|
||||||
|
|
||||||
|
if (proposal_exists(chain::operation::tag<chain::son_wallet_deposit_process_operation>::value, swdo.id)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const chain::global_property_object &gpo = database.get_global_properties();
|
const chain::global_property_object &gpo = database.get_global_properties();
|
||||||
|
|
||||||
price asset_price;
|
price asset_price;
|
||||||
|
|
@ -685,6 +718,11 @@ bool sidechain_net_handler_hive::process_deposit(const son_wallet_deposit_object
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sidechain_net_handler_hive::process_withdrawal(const son_wallet_withdraw_object &swwo) {
|
bool sidechain_net_handler_hive::process_withdrawal(const son_wallet_withdraw_object &swwo) {
|
||||||
|
|
||||||
|
if (proposal_exists(chain::operation::tag<chain::son_wallet_withdraw_process_operation>::value, swwo.id)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const chain::global_property_object &gpo = database.get_global_properties();
|
const chain::global_property_object &gpo = database.get_global_properties();
|
||||||
|
|
||||||
//=====
|
//=====
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,7 @@
|
||||||
namespace graphene { namespace peerplays_sidechain {
|
namespace graphene { namespace peerplays_sidechain {
|
||||||
|
|
||||||
sidechain_net_handler_peerplays::sidechain_net_handler_peerplays(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options) :
|
sidechain_net_handler_peerplays::sidechain_net_handler_peerplays(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options) :
|
||||||
sidechain_net_handler(_plugin, options) {
|
sidechain_net_handler(sidechain_type::peerplays, _plugin, options) {
|
||||||
sidechain = sidechain_type::peerplays;
|
|
||||||
//const auto &assets_by_symbol = database.get_index_type<asset_index>().indices().get<by_symbol>();
|
//const auto &assets_by_symbol = database.get_index_type<asset_index>().indices().get<by_symbol>();
|
||||||
//const auto get_asset_id = [&assets_by_symbol](const string &symbol) {
|
//const auto get_asset_id = [&assets_by_symbol](const string &symbol) {
|
||||||
// auto asset_itr = assets_by_symbol.find(symbol);
|
// auto asset_itr = assets_by_symbol.find(symbol);
|
||||||
|
|
|
||||||
|
|
@ -2773,12 +2773,21 @@ public:
|
||||||
FC_ASSERT(son_obj, "Account ${son} is not registered as a son", ("son", son));
|
FC_ASSERT(son_obj, "Account ${son} is not registered as a son", ("son", son));
|
||||||
FC_ASSERT(sidechain == sidechain_type::bitcoin || sidechain == sidechain_type::hive || sidechain == sidechain_type::ethereum, "Unexpected sidechain type");
|
FC_ASSERT(sidechain == sidechain_type::bitcoin || sidechain == sidechain_type::hive || sidechain == sidechain_type::ethereum, "Unexpected sidechain type");
|
||||||
|
|
||||||
|
bool update_vote_time = false;
|
||||||
if (approve)
|
if (approve)
|
||||||
{
|
{
|
||||||
FC_ASSERT(son_obj->get_sidechain_vote_id(sidechain).valid(), "Invalid vote id, sidechain: ${sidechain}, son: ${son}", ("sidechain", sidechain)("son", *son_obj));
|
FC_ASSERT(son_obj->get_sidechain_vote_id(sidechain).valid(), "Invalid vote id, sidechain: ${sidechain}, son: ${son}", ("sidechain", sidechain)("son", *son_obj));
|
||||||
|
account_id_type stake_account = get_account_id(voting_account);
|
||||||
|
const auto gpos_info = _remote_db->get_gpos_info(stake_account);
|
||||||
|
const auto vesting_subperiod = _remote_db->get_global_properties().parameters.gpos_subperiod();
|
||||||
|
const auto gpos_start_time = fc::time_point_sec(_remote_db->get_global_properties().parameters.gpos_period_start());
|
||||||
|
const auto subperiod_start_time = gpos_start_time.sec_since_epoch() + (gpos_info.current_subperiod - 1) * vesting_subperiod;
|
||||||
|
|
||||||
auto insert_result = voting_account_object.options.votes.insert(*son_obj->get_sidechain_vote_id(sidechain));
|
auto insert_result = voting_account_object.options.votes.insert(*son_obj->get_sidechain_vote_id(sidechain));
|
||||||
if (!insert_result.second)
|
if (!insert_result.second && (gpos_info.last_voted_time.sec_since_epoch() >= subperiod_start_time))
|
||||||
FC_THROW("Account ${account} has already voted for son ${son} for sidechain ${sidechain}", ("account", voting_account)("son", son)("sidechain", sidechain));
|
FC_THROW("Account ${account} was already voting for son ${son} in the current GPOS sub-period", ("account", voting_account)("son", son));
|
||||||
|
else
|
||||||
|
update_vote_time = true; //Allow user to vote in each sub-period(Update voting time, which is reference in calculating VF)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -2787,9 +2796,11 @@ public:
|
||||||
if (!votes_removed)
|
if (!votes_removed)
|
||||||
FC_THROW("Account ${account} has already unvoted for son ${son} for sidechain ${sidechain}", ("account", voting_account)("son", son)("sidechain", sidechain));
|
FC_THROW("Account ${account} has already unvoted for son ${son} for sidechain ${sidechain}", ("account", voting_account)("son", son)("sidechain", sidechain));
|
||||||
}
|
}
|
||||||
|
|
||||||
account_update_operation account_update_op;
|
account_update_operation account_update_op;
|
||||||
account_update_op.account = voting_account_object.id;
|
account_update_op.account = voting_account_object.id;
|
||||||
account_update_op.new_options = voting_account_object.options;
|
account_update_op.new_options = voting_account_object.options;
|
||||||
|
account_update_op.extensions.value.update_last_voting_time = update_vote_time;
|
||||||
|
|
||||||
signed_transaction tx;
|
signed_transaction tx;
|
||||||
tx.operations.push_back( account_update_op );
|
tx.operations.push_back( account_update_op );
|
||||||
|
|
|
||||||
|
|
@ -740,6 +740,19 @@ BOOST_AUTO_TEST_CASE( update_son_votes_test )
|
||||||
sidechain_type::ethereum, 0, true);
|
sidechain_type::ethereum, 0, true);
|
||||||
BOOST_CHECK(generate_maintenance_block());
|
BOOST_CHECK(generate_maintenance_block());
|
||||||
|
|
||||||
|
// Vote for less SONs than num_son (2 votes, but num_son is 3)
|
||||||
|
accepted.clear();
|
||||||
|
rejected.clear();
|
||||||
|
accepted.push_back("son1account");
|
||||||
|
accepted.push_back("son2account");
|
||||||
|
BOOST_CHECK_THROW(update_votes_tx = con.wallet_api_ptr->update_son_votes("nathan", accepted, rejected,
|
||||||
|
sidechain_type::bitcoin, 3, true), fc::exception);
|
||||||
|
BOOST_CHECK_THROW(update_votes_tx = con.wallet_api_ptr->update_son_votes("nathan", accepted, rejected,
|
||||||
|
sidechain_type::hive, 3, true), fc::exception);
|
||||||
|
BOOST_CHECK_THROW(update_votes_tx = con.wallet_api_ptr->update_son_votes("nathan", accepted, rejected,
|
||||||
|
sidechain_type::ethereum, 3, true), fc::exception);
|
||||||
|
generate_block();
|
||||||
|
|
||||||
// Verify the votes
|
// Verify the votes
|
||||||
son1_obj = con.wallet_api_ptr->get_son("son1account");
|
son1_obj = con.wallet_api_ptr->get_son("son1account");
|
||||||
son1_end_votes = son1_obj.total_votes;
|
son1_end_votes = son1_obj.total_votes;
|
||||||
|
|
|
||||||
|
|
@ -193,6 +193,34 @@ BOOST_AUTO_TEST_CASE(tickets_purchase_fail_test)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(tickets_purchase_overflow)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
nft_metadata_id_type test_nft_md_id = db.get_index<nft_metadata_object>().get_next_id();
|
||||||
|
INVOKE(create_lottery_nft_md_test);
|
||||||
|
auto &test_nft_md_obj = test_nft_md_id(db);
|
||||||
|
|
||||||
|
nft_lottery_token_purchase_operation tpo;
|
||||||
|
tpo.fee = asset();
|
||||||
|
tpo.buyer = account_id_type();
|
||||||
|
tpo.lottery_id = test_nft_md_obj.id;
|
||||||
|
tpo.tickets_to_buy = 9223372036854775800; // Large number so that the overall amount overflows
|
||||||
|
trx.operations.push_back(tpo);
|
||||||
|
BOOST_REQUIRE_THROW(PUSH_TX(db, trx, ~0), fc::overflow_exception);
|
||||||
|
trx.operations.clear();
|
||||||
|
|
||||||
|
tpo.tickets_to_buy = -2; // Negative value should also be rejected
|
||||||
|
trx.operations.push_back(tpo);
|
||||||
|
BOOST_REQUIRE_THROW(PUSH_TX(db, trx, ~0), fc::exception);
|
||||||
|
}
|
||||||
|
catch (fc::exception &e)
|
||||||
|
{
|
||||||
|
edump((e.to_detail_string()));
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(lottery_end_by_stage_test)
|
BOOST_AUTO_TEST_CASE(lottery_end_by_stage_test)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue