Skip to content

Commit

Permalink
Steem can now be compiled in a low memory mode with cmake option LOW_…
Browse files Browse the repository at this point in the history
…MEMORY_NODE=ON. This prevents lengthy object fields not needed for consensus from being saved to the local database.
  • Loading branch information
Michael Vandeberg committed Apr 6, 2016
1 parent c8c3b5f commit c1436b6
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 26 deletions.
18 changes: 17 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ LIST(APPEND BOOST_COMPONENTS thread
SET( Boost_USE_STATIC_LIBS ON CACHE STRING "ON or OFF" )

OPTION( BUILD_STEEM_TESTNET "Build source for test network (ON OR OFF)" OFF )
MESSAGE( STATUS "BUILD_STEEM_TESTNET: ${BUILD_STEEM_TESTNET}" )
MESSAGE( STATUS "BUILD_STEEM_TESTNET: ${BUILD_STEEM_TESTNET}" )
if( BUILD_STEEM_TESTNET )
MESSAGE( STATUS " " )
MESSAGE( STATUS " CONFIGURING FOR TEST NET " )
Expand All @@ -59,6 +59,16 @@ if( BUILD_STEEM_TESTNET )
SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DIS_TEST_NET" )
endif()

OPTION( LOW_MEMORY_NODE "Build source for low memory node (ON OR OFF)" OFF )
MESSAGE( STATUS "LOW_MEMORY_NODE: ${LOW_MEMORY_NODE}" )
if( LOW_MEMORY_NODE )
MESSAGE( STATUS " " )
MESSAGE( STATUS " CONFIGURING FOR LOW MEMORY NODE " )
MESSAGE( STATUS " " )
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DIS_LOW_MEM" )
SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DIS_LOW_MEM" )
endif()

IF( WIN32 )
SET(BOOST_ROOT $ENV{BOOST_ROOT})
set(Boost_USE_MULTITHREADED ON)
Expand Down Expand Up @@ -220,4 +230,10 @@ else()
MESSAGE( STATUS "\n\n CONFIGURED FOR STEEM NETWORK \n\n" )
endif()

if( LOW_MEMORY_NODE )
MESSAGE( STATUS "\n\n CONFIGURED FOR LOW MEMORY NODE \n\n" )
else()
MESSAGE( STATUS "\n\n CONFIGURED FOR FULL NODE \n\n" )
endif()


2 changes: 1 addition & 1 deletion libraries/chain/include/steemit/chain/account_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace steemit { namespace chain {
authority active; ///< used for all monetary operations, can set active or posting
authority posting; ///< used for voting and posting
public_key_type memo_key;
string json_metadata;
string json_metadata = "";
string proxy;

time_point_sec created;
Expand Down
6 changes: 3 additions & 3 deletions libraries/chain/include/steemit/chain/comment_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ namespace steemit { namespace chain {
string author;
string permlink;

string title;
string body;
string json_metadata;
string title = "";
string body = "";
string json_metadata = "";
time_point_sec last_update;
time_point_sec created;

Expand Down
28 changes: 20 additions & 8 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,12 @@ void account_create_evaluator::do_apply( const account_create_operation& o )
acc.active = o.active;
acc.posting = o.posting;
acc.memo_key = o.memo_key;
acc.json_metadata = o.json_metadata;
acc.created = props.time;
acc.last_vote_time = props.time;

#ifndef IS_LOW_MEM
acc.json_metadata = o.json_metadata;
#endif
});

if( o.fee.amount > 0 )
Expand All @@ -85,7 +88,10 @@ void account_update_evaluator::do_apply( const account_update_operation& o )
if( o.active ) acc.active = *o.active;
if( o.posting ) acc.posting = *o.posting;
acc.memo_key = o.memo_key;
acc.json_metadata = o.json_metadata;

#ifndef IS_LOW_MEM
acc.json_metadata = o.json_metadata;
#endif
});
}

Expand Down Expand Up @@ -132,12 +138,15 @@ void comment_evaluator::do_apply( const comment_operation& o )

com.author = o.author;
com.permlink = o.permlink;
com.title = o.title;
com.body = o.body;
com.json_metadata = o.json_metadata;
com.last_update = db().head_block_time();
com.created = com.last_update;
com.cashout_time = com.last_update + fc::seconds(STEEMIT_CASHOUT_WINDOW_SECONDS);

#ifndef IS_LOW_MEM
com.title = o.title;
com.body = o.body;
com.json_metadata = o.json_metadata;
#endif
});
const category_object* cat = db().find_category( new_comment.category );
if( !cat ) {
Expand Down Expand Up @@ -181,13 +190,16 @@ void comment_evaluator::do_apply( const comment_operation& o )
FC_ASSERT( com.parent_permlink == o.parent_permlink );
}

com.title = o.title;
com.body = o.body;
com.json_metadata = o.json_metadata;
com.last_update = db().head_block_time();
com.net_rshares = std::min( com.net_rshares, share_type(0) );
com.abs_rshares = 0;
com.cashout_time = com.last_update + fc::seconds(STEEMIT_CASHOUT_WINDOW_SECONDS);

#ifndef IS_LOW_MEM
com.title = o.title;
com.body = o.body;
com.json_metadata = o.json_metadata;
#endif
});
}

Expand Down
37 changes: 24 additions & 13 deletions tests/tests/operation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ BOOST_AUTO_TEST_CASE( account_create_apply )
BOOST_REQUIRE_EQUAL( acct.balance.amount.value, ASSET( "0.000 TESTS" ).amount.value );
BOOST_REQUIRE_EQUAL( acct.sbd_balance.amount.value, ASSET( "0.000 TBD" ).amount.value );

#ifndef IS_LOW_MEM
BOOST_REQUIRE_EQUAL( acct.json_metadata, op.json_metadata );
#else
BOOST_REQUIRE_EQUAL( acct.json_metadata, "" );
#endif

/// because init_witness has created vesting shares and blocks have been produced, 100 STEEM is worth less than 100 vesting shares due to rounding
BOOST_REQUIRE_EQUAL( acct.vesting_shares.amount.value, ( op.fee * ( vest_shares / vests ) ).amount.value );
BOOST_REQUIRE_EQUAL( acct.vesting_withdraw_rate.amount.value, ASSET( "0.000000 VESTS" ).amount.value );
Expand Down Expand Up @@ -314,7 +320,13 @@ BOOST_AUTO_TEST_CASE( account_update_apply )
BOOST_REQUIRE( acct.owner == authority( 1, new_private_key.get_public_key(), 1 ) );
BOOST_REQUIRE( acct.active == authority( 2, new_private_key.get_public_key(), 2 ) );
BOOST_REQUIRE( acct.memo_key == new_private_key.get_public_key() );
BOOST_REQUIRE_EQUAL( acct.json_metadata, "{\"bar\":\"foo\"}" );

#ifndef IS_LOW_MEM
BOOST_REQUIRE_EQUAL( acct.json_metadata, "{\"bar\":\"foo\"}" );
#else
BOOST_REQUIRE_EQUAL( acct.json_metadata, "" );
#endif

validate_database();

BOOST_TEST_MESSAGE( "--- Test failure when updating a non-existent account" );
Expand Down Expand Up @@ -421,14 +433,22 @@ BOOST_AUTO_TEST_CASE( comment_apply )
BOOST_REQUIRE_EQUAL( alice_comment.author, op.author );
BOOST_REQUIRE_EQUAL( alice_comment.permlink, op.permlink );
BOOST_REQUIRE_EQUAL( alice_comment.parent_permlink, op.parent_permlink );
BOOST_REQUIRE_EQUAL( alice_comment.title, op.title );
BOOST_REQUIRE_EQUAL( alice_comment.body, op.body );
BOOST_REQUIRE_EQUAL( alice_comment.json_metadata, op.json_metadata );
BOOST_REQUIRE( alice_comment.last_update == db.head_block_time() );
BOOST_REQUIRE( alice_comment.created == db.head_block_time() );
BOOST_REQUIRE_EQUAL( alice_comment.net_rshares.value, 0 );
BOOST_REQUIRE_EQUAL( alice_comment.abs_rshares.value, 0 );
BOOST_REQUIRE( alice_comment.cashout_time == fc::time_point_sec( db.head_block_time() + fc::seconds( STEEMIT_CASHOUT_WINDOW_SECONDS ) ) );

#ifndef IS_LOW_MEM
BOOST_REQUIRE_EQUAL( alice_comment.title, op.title );
BOOST_REQUIRE_EQUAL( alice_comment.body, op.body );
BOOST_REQUIRE_EQUAL( alice_comment.json_metadata, op.json_metadata );
#else
BOOST_REQUIRE_EQUAL( alice_comment.title, "" );
BOOST_REQUIRE_EQUAL( alice_comment.body, "" );
BOOST_REQUIRE_EQUAL( alice_comment.json_metadata, "" );
#endif

validate_database();

BOOST_TEST_MESSAGE( "--- Test Bob posting a comment on a non-existent comment" );
Expand Down Expand Up @@ -458,9 +478,6 @@ BOOST_AUTO_TEST_CASE( comment_apply )
BOOST_REQUIRE_EQUAL( bob_comment.permlink, op.permlink );
BOOST_REQUIRE_EQUAL( bob_comment.parent_author, op.parent_author );
BOOST_REQUIRE_EQUAL( bob_comment.parent_permlink, op.parent_permlink );
BOOST_REQUIRE_EQUAL( bob_comment.title, op.title );
BOOST_REQUIRE_EQUAL( bob_comment.body, op.body );
BOOST_REQUIRE_EQUAL( bob_comment.json_metadata, op.json_metadata );
BOOST_REQUIRE( bob_comment.last_update == db.head_block_time() );
BOOST_REQUIRE( bob_comment.created == db.head_block_time() );
BOOST_REQUIRE_EQUAL( bob_comment.net_rshares.value, 0 );
Expand All @@ -487,9 +504,6 @@ BOOST_AUTO_TEST_CASE( comment_apply )
BOOST_REQUIRE_EQUAL( sam_comment.permlink, op.permlink );
BOOST_REQUIRE_EQUAL( sam_comment.parent_author, op.parent_author );
BOOST_REQUIRE_EQUAL( sam_comment.parent_permlink, op.parent_permlink );
BOOST_REQUIRE_EQUAL( sam_comment.title, op.title );
BOOST_REQUIRE_EQUAL( sam_comment.body, op.body );
BOOST_REQUIRE_EQUAL( sam_comment.json_metadata, op.json_metadata );
BOOST_REQUIRE( sam_comment.last_update == db.head_block_time() );
BOOST_REQUIRE( sam_comment.created == db.head_block_time() );
BOOST_REQUIRE_EQUAL( sam_comment.net_rshares.value, 0 );
Expand Down Expand Up @@ -523,9 +537,6 @@ BOOST_AUTO_TEST_CASE( comment_apply )
BOOST_REQUIRE_EQUAL( mod_sam_comment.permlink, op.permlink );
BOOST_REQUIRE_EQUAL( mod_sam_comment.parent_author, op.parent_author );
BOOST_REQUIRE_EQUAL( mod_sam_comment.parent_permlink, op.parent_permlink );
BOOST_REQUIRE_EQUAL( mod_sam_comment.title, op.title );
BOOST_REQUIRE_EQUAL( mod_sam_comment.body, op.body );
BOOST_REQUIRE_EQUAL( mod_sam_comment.json_metadata, op.json_metadata );
BOOST_REQUIRE( mod_sam_comment.last_update == db.head_block_time() );
BOOST_REQUIRE( mod_sam_comment.created == created );
BOOST_REQUIRE_EQUAL( mod_sam_comment.net_rshares.value, 0 );
Expand Down

0 comments on commit c1436b6

Please sign in to comment.