Skip to content

Commit

Permalink
Merge pull request #114 from peerplays-network/review-fixes
Browse files Browse the repository at this point in the history
Bring back all review fixes that were deleted with 50/50 merge
  • Loading branch information
pbattu123 authored Sep 6, 2019
2 parents a50da70 + e82a3db commit 62ddd67
Show file tree
Hide file tree
Showing 24 changed files with 214,855 additions and 8,365 deletions.
222,008 changes: 213,864 additions & 8,144 deletions genesis.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions libraries/app/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,14 @@ namespace graphene { namespace app {
void network_broadcast_api::broadcast_transaction(const signed_transaction& trx)
{
trx.validate();
_app.chain_database()->check_tansaction_for_duplicated_operations(trx);
database_api( *(_app.chain_database() ) ).check_transaction_for_duplicated_operations(trx);
_app.chain_database()->push_transaction(trx);
_app.p2p_node()->broadcast_transaction(trx);
}

fc::variant network_broadcast_api::broadcast_transaction_synchronous(const signed_transaction& trx)
{
_app.chain_database()->check_tansaction_for_duplicated_operations(trx);
database_api( *(_app.chain_database() ) ).check_transaction_for_duplicated_operations(trx);

fc::promise<fc::variant>::ptr prom( new fc::promise<fc::variant>() );
broadcast_transaction_with_callback( [=]( const fc::variant& v ){
Expand Down
39 changes: 35 additions & 4 deletions libraries/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,41 @@ namespace detail {
{
// t.me/peerplays #seednodes
vector<string> seeds = {
"ppy-beatrice-seed.blckchnd.com:6666",
"159.69.223.206:7777",
"51.38.237.243:9666",
"pbsa-beatrice.blockchainprojectsbv.com:9195"
"seed.ppy.blckchnd.com:6666", // blckchnd
"ppy.esteem.ws:7777", // good-karma
"peerplays.bitcoiner.me:9777", // bitcoiner
"peerplays.roelandp.nl:9777", // roelandp
"ppyseed.bacchist.me:42420", // bacchist-witness
"5.9.18.213:18828", // pfunk
"31.171.244.121:7777", // taconator
"seed.peerplaysdb.com:9777", // jesta
"ppy-seed.xeldal.com:19777", // xeldal
"seed.ppy.altcap.io:61388", // winner.winner.chicken.dinner
"seed.peerplaysnodes.com:9777", // wackou
"peerplays-seed.privex.io:7777", // someguy123/privex
"51.15.78.16:9777", // agoric.systems
"212.71.253.163:9777", // xtar
"51.15.35.96:9777", // lafona
"anyx.ca:9777", // anyx
"82.223.108.91:7777", // hiltos-witness
"seed.ppy.nuevax.com:9777", // nuevax
"peerplays.butler.net:9777", // billbutler-witness
"peerplays.bitcoiner.me:9777", // bitcoiner
"ppyseed.bacchist.me:42420", // bacchist-witness
"peerplays.bhuz.info:9777", // bhuz
"node.peerblock.trade:9777", // bitcoinsig
"peerplays.crypto.fans:9777", // sc-steemit
"54.38.193.20:9777", // royal-flush
"ppy001.bts-nodes.net:7777", // baxters-sports-witness
"ppy002.bts-nodes.net:7777", // baxters-sports-witness
"ppy003.bts-nodes.net:7777", // baxters-sports-witness
"ppy004.bts-nodes.net:7777", // baxters-sports-witness
"ppy.proxyhosts.info:7777", // baxters-sports-witness
"ppyseed.spacemx.tech:9777", // spacecrypt-witness
"peerplaysblockchain.net:9777", // houdini-witness
"54.37.235.164:7777", // melea-trust
"seed01.eifos.org:7777" // eifos
"peerplays-seed.lukestokes.info:7777" // lukestokes-witness
};

for( const string& endpoint_string : seeds )
Expand Down
72 changes: 72 additions & 0 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <fc/smart_ref_impl.hpp>

#include <fc/crypto/hex.hpp>
#include <fc/crypto/digest.hpp>

#include <boost/range/iterator_range.hpp>
#include <boost/rational.hpp>
Expand All @@ -45,6 +46,43 @@

typedef std::map< std::pair<graphene::chain::asset_id_type, graphene::chain::asset_id_type>, std::vector<fc::variant> > market_queue_type;

namespace {

struct proposed_operations_digest_accumulator
{
typedef void result_type;

void operator()(const graphene::chain::proposal_create_operation& proposal)
{
for (auto& operation: proposal.proposed_ops)
{
if( operation.op.which() != graphene::chain::operation::tag<graphene::chain::betting_market_group_create_operation>::value
&& operation.op.which() != graphene::chain::operation::tag<graphene::chain::betting_market_create_operation>::value )
proposed_operations_digests.push_back(fc::digest(operation.op));
}
}

//empty template method is needed for all other operation types
//we can ignore them, we are interested in only proposal_create_operation
template<class T>
void operator()(const T&)
{}

std::vector<fc::sha256> proposed_operations_digests;
};

std::vector<fc::sha256> gather_proposed_operations_digests(const graphene::chain::transaction& trx)
{
proposed_operations_digest_accumulator digest_accumulator;
for (auto& operation: trx.operations)
{
operation.visit(digest_accumulator);
}

return digest_accumulator.proposed_operations_digests;
}
}

namespace graphene { namespace app {

class database_api_impl;
Expand All @@ -70,6 +108,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;
void check_transaction_for_duplicated_operations(const signed_transaction& trx);

// Globals
chain_property_object get_chain_properties()const;
Expand Down Expand Up @@ -440,6 +479,39 @@ processed_transaction database_api_impl::get_transaction(uint32_t block_num, uin
return opt_block->transactions[trx_num];
}

void database_api::check_transaction_for_duplicated_operations(const signed_transaction& trx)
{
my->check_transaction_for_duplicated_operations(trx);
}

void database_api_impl::check_transaction_for_duplicated_operations(const signed_transaction& trx)
{
const auto& idx = _db.get_index_type<proposal_index>();
const auto& pidx = dynamic_cast<const primary_index<proposal_index>&>(idx);
const auto& raidx = pidx.get_secondary_index<graphene::chain::required_approval_index>();

auto acc_itr = raidx._account_to_proposals.find( GRAPHENE_WITNESS_ACCOUNT );
if( acc_itr != raidx._account_to_proposals.end() )
{
auto& p_set = acc_itr->second;

std::set<fc::sha256> existed_operations_digests;
for( auto p_itr = p_set.begin(); p_itr != p_set.end(); ++p_itr )
{
for( auto& operation : (*p_itr)(_db).proposed_transaction.operations )
{
existed_operations_digests.insert( fc::digest(operation) );
}
}

auto proposed_operations_digests = gather_proposed_operations_digests(trx);
for (auto& digest : proposed_operations_digests)
{
FC_ASSERT(existed_operations_digests.count(digest) == 0, "Proposed operation is already pending for apsproval.");
}
}
}

//////////////////////////////////////////////////////////////////////
// //
// Globals //
Expand Down
6 changes: 6 additions & 0 deletions libraries/app/include/graphene/app/database_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ class database_api
*/
optional<signed_transaction> get_recent_transaction_by_id( const transaction_id_type& id )const;

/**
* TODO
*
*/
void check_transaction_for_duplicated_operations(const signed_transaction& trx);

/////////////
// Globals //
/////////////
Expand Down
1 change: 0 additions & 1 deletion libraries/app/include/graphene/app/full_account.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ FC_REFLECT( graphene::app::full_account,
(limit_orders)
(call_orders)
(settle_orders)
(proposals)
(assets)
(withdraws)
(proposals)
Expand Down
51 changes: 26 additions & 25 deletions libraries/chain/asset_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,36 +58,37 @@ void_result asset_create_evaluator::do_evaluate( const asset_create_operation& o

if( d.head_block_time() > HARDFORK_385_TIME )
{

if( d.head_block_time() <= HARDFORK_409_TIME )
{
auto dotpos = op.symbol.find( '.' );
if( dotpos != std::string::npos )
if( d.head_block_time() <= HARDFORK_409_TIME )
{
auto prefix = op.symbol.substr( 0, dotpos );
auto asset_symbol_itr = asset_indx.find( op.symbol );
FC_ASSERT( asset_symbol_itr != asset_indx.end(), "Asset ${s} may only be created by issuer of ${p}, but ${p} has not been registered",
("s",op.symbol)("p",prefix) );
FC_ASSERT( asset_symbol_itr->issuer == op.issuer, "Asset ${s} may only be created by issuer of ${p}, ${i}",
("s",op.symbol)("p",prefix)("i", op.issuer(d).name) );
auto dotpos = op.symbol.find( '.' );
if( dotpos != std::string::npos )
{
auto prefix = op.symbol.substr( 0, dotpos );
auto asset_symbol_itr = asset_indx.find( op.symbol );
FC_ASSERT( asset_symbol_itr != asset_indx.end(),
"Asset ${s} may only be created by issuer of ${p}, but ${p} has not been registered",
("s",op.symbol)("p",prefix) );
FC_ASSERT( asset_symbol_itr->issuer == op.issuer,
"Asset ${s} may only be created by issuer of ${p}, ${i}",
("s",op.symbol)("p",prefix)("i", op.issuer(d).name) );
}
}
}
else
{
auto dotpos = op.symbol.rfind( '.' );
if( dotpos != std::string::npos )

else
{
auto prefix = op.symbol.substr( 0, dotpos );
auto asset_symbol_itr = asset_indx.find( prefix );
FC_ASSERT( asset_symbol_itr != asset_indx.end(), "Asset ${s} may only be created by issuer of ${p}, but ${p} has not been registered",
("s",op.symbol)("p",prefix) );
FC_ASSERT( asset_symbol_itr->issuer == op.issuer, "Asset ${s} may only be created by issuer of ${p}, ${i}",
("s",op.symbol)("p",prefix)("i", op.issuer(d).name) );
auto dotpos = op.symbol.rfind( '.' );
if( dotpos != std::string::npos )
{
auto prefix = op.symbol.substr( 0, dotpos );
auto asset_symbol_itr = asset_indx.find( prefix );
FC_ASSERT( asset_symbol_itr != asset_indx.end(),
"Asset ${s} may only be created by issuer of ${p}, but ${p} has not been registered",
("s",op.symbol)("p",prefix) );
FC_ASSERT( asset_symbol_itr->issuer == op.issuer,
"Asset ${s} may only be created by issuer of ${p}, ${i}",
("s",op.symbol)("p",prefix)("i", op.issuer(d).name) );
}
}
}

}
else
{
auto dotpos = op.symbol.find( '.' );
Expand Down
64 changes: 0 additions & 64 deletions libraries/chain/db_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,46 +43,6 @@

#include <fc/smart_ref_impl.hpp>

namespace {

struct proposed_operations_digest_accumulator
{
typedef void result_type;

void operator()(const graphene::chain::proposal_create_operation& proposal)
{
for (auto& operation: proposal.proposed_ops)
{
proposed_operations_digests.push_back(fc::digest(operation.op));
}
}

//empty template method is needed for all other operation types
//we can ignore them, we are interested in only proposal_create_operation
template<class T>
void operator()(const T&)
{}

std::vector<fc::sha256> proposed_operations_digests;
};

std::vector<fc::sha256> gather_proposed_operations_digests(const graphene::chain::transaction& trx)
{
proposed_operations_digest_accumulator digest_accumulator;

for (auto& operation: trx.operations)
{
if( operation.which() != graphene::chain::operation::tag<graphene::chain::betting_market_group_create_operation>::value
&& operation.which() != graphene::chain::operation::tag<graphene::chain::betting_market_create_operation>::value )
operation.visit(digest_accumulator);
else
edump( ("Found dup"));
}

return digest_accumulator.proposed_operations_digests;
}
}

namespace graphene { namespace chain {

bool database::is_known_block( const block_id_type& id )const
Expand Down Expand Up @@ -149,30 +109,6 @@ std::vector<block_id_type> database::get_block_ids_on_fork(block_id_type head_of
return result;
}

void database::check_tansaction_for_duplicated_operations(const signed_transaction& trx)
{
const auto& proposal_index = get_index<proposal_object>();
std::set<fc::sha256> existed_operations_digests;

proposal_index.inspect_all_objects( [&](const object& obj){
const proposal_object& proposal = static_cast<const proposal_object&>(obj);
auto proposed_operations_digests = gather_proposed_operations_digests( proposal.proposed_transaction );
existed_operations_digests.insert( proposed_operations_digests.begin(), proposed_operations_digests.end() );
});

for (auto& pending_transaction: _pending_tx)
{
auto proposed_operations_digests = gather_proposed_operations_digests(pending_transaction);
existed_operations_digests.insert(proposed_operations_digests.begin(), proposed_operations_digests.end());
}

auto proposed_operations_digests = gather_proposed_operations_digests(trx);
for (auto& digest: proposed_operations_digests)
{
FC_ASSERT(existed_operations_digests.count(digest) == 0, "Proposed operation is already pending for approval.");
}
}

/**
* Push block "may fail" in which case every partial change is unwound. After
* push block is successful the block is appended to the chain database on disk.
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/hardfork.d/1000.hf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#ifndef HARDFORK_1000_TIME
#define HARDFORK_1000_TIME (fc::time_point_sec( 1540000000 ))
#define HARDFORK_1000_TIME (fc::time_point_sec( 1550491200 ))
#endif
2 changes: 1 addition & 1 deletion libraries/chain/hardfork.d/1001.hf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// added delete sport and delete event group operations
#ifndef HARDFORK_1001_TIME
#define HARDFORK_1001_TIME (fc::time_point_sec( 1540000000 ))
#define HARDFORK_1001_TIME (fc::time_point_sec( 1550491200 ))
#endif
2 changes: 1 addition & 1 deletion libraries/chain/hardfork.d/999.hf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Placeholder HF for affiliate reward system
#ifndef HARDFORK_999_TIME
#define HARDFORK_999_TIME (fc::time_point_sec( 1540000000 ))
#define HARDFORK_999_TIME (fc::time_point_sec( 1550491200 ))
#endif
2 changes: 1 addition & 1 deletion libraries/chain/hardfork.d/CORE-429.hf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// bitshares-core #429 rounding issue when creating assets
#ifndef HARDFORK_CORE_429_TIME
#define HARDFORK_CORE_429_TIME (fc::time_point_sec( 1568167200 ))
#define HARDFORK_CORE_429_TIME (fc::time_point_sec( 1568340000 ))
#endif
2 changes: 1 addition & 1 deletion libraries/chain/hardfork.d/SWEEPS.hf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#ifndef HARDFORK_SWEEPS_TIME
#define HARDFORK_SWEEPS_TIME (fc::time_point_sec( 1568167200 ))
#define HARDFORK_SWEEPS_TIME (fc::time_point_sec( 1568340000 ))
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -718,8 +718,8 @@ inline Stream& operator>>( Stream& s, betting_market_group_object& betting_marke
} } // graphene::chain

FC_REFLECT_DERIVED( graphene::chain::betting_market_rules_object, (graphene::db::object), (name)(description) )
FC_REFLECT_DERIVED( graphene::chain::betting_market_group_object, (graphene::db::object), (description) )
FC_REFLECT_DERIVED( graphene::chain::betting_market_object, (graphene::db::object), (group_id) )
FC_REFLECT_DERIVED( graphene::chain::betting_market_group_object, (graphene::db::object), (description)(event_id)(rules_id)(asset_id)(total_matched_bets_amount)(never_in_play)(delay_before_settling)(settling_time) )
FC_REFLECT_DERIVED( graphene::chain::betting_market_object, (graphene::db::object), (group_id)(description)(payout_condition)(resolution) )
FC_REFLECT_DERIVED( graphene::chain::bet_object, (graphene::db::object), (bettor_id)(betting_market_id)(amount_to_bet)(backer_multiplier)(back_or_lay)(end_of_delay) )

FC_REFLECT_DERIVED( graphene::chain::betting_market_position_object, (graphene::db::object), (bettor_id)(betting_market_id)(pay_if_payout_condition)(pay_if_not_payout_condition)(pay_if_canceled)(pay_if_not_canceled)(fees_collected) )
8 changes: 4 additions & 4 deletions libraries/chain/include/graphene/chain/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
*/
#pragma once

#define GRAPHENE_SYMBOL "TEST"
#define GRAPHENE_ADDRESS_PREFIX "TEST"
#define GRAPHENE_SYMBOL "PPY"
#define GRAPHENE_ADDRESS_PREFIX "PPY"

#define GRAPHENE_MIN_ACCOUNT_NAME_LENGTH 1
#define GRAPHENE_MAX_ACCOUNT_NAME_LENGTH 63
Expand All @@ -43,7 +43,7 @@
#define GRAPHENE_MIN_BLOCK_INTERVAL 1 /* seconds */
#define GRAPHENE_MAX_BLOCK_INTERVAL 30 /* seconds */

#define GRAPHENE_DEFAULT_BLOCK_INTERVAL 3 /* seconds */
#define GRAPHENE_DEFAULT_BLOCK_INTERVAL 5 /* seconds */
#define GRAPHENE_DEFAULT_MAX_TRANSACTION_SIZE 2048
#define GRAPHENE_DEFAULT_MAX_BLOCK_SIZE (GRAPHENE_DEFAULT_MAX_TRANSACTION_SIZE*GRAPHENE_DEFAULT_BLOCK_INTERVAL*200000)
#define GRAPHENE_DEFAULT_MAX_TIME_UNTIL_EXPIRATION (60*60*24) // seconds, aka: 1 day
Expand Down Expand Up @@ -179,7 +179,7 @@

#define GRAPHENE_FBA_STEALTH_DESIGNATED_ASSET (asset_id_type(743))

#define GRAPHENE_DEFAULT_RAKE_FEE_PERCENTAGE (3*GRAPHENE_1_PERCENT)
#define GRAPHENE_DEFAULT_RAKE_FEE_PERCENTAGE (5*GRAPHENE_1_PERCENT)

/**
* Betting-related constants.
Expand Down
Loading

0 comments on commit 62ddd67

Please sign in to comment.