Skip to content

Commit

Permalink
Change HIVE_MAX_TIME_UNTIL_RUNTIME_EXPIRATION -> `HIVE_MAX_TIME_UNT…
Browse files Browse the repository at this point in the history
…IL_SIGNATURE_EXPIRATION` + don't allow redefine runtime_expiration
  • Loading branch information
Mariusz-Trela committed Oct 25, 2024
1 parent f111240 commit 140c34b
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 51 deletions.
33 changes: 18 additions & 15 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4336,26 +4336,29 @@ void database::validate_transaction(const std::shared_ptr<full_transaction_type>
{
fc::time_point_sec now = head_block_time();

if( has_hardfork( HIVE_HARDFORK_1_28_EXPIRATION_TIME ) )
if( full_transaction->get_runtime_expiration() == fc::time_point_sec::min() )
{
HIVE_ASSERT(now < trx.expiration, transaction_expiration_exception, "", (now)(trx.expiration));

HIVE_ASSERT(trx.expiration <= now + fc::seconds(HIVE_MAX_TIME_UNTIL_RUNTIME_EXPIRATION), transaction_expiration_exception,
"", (trx.expiration)(now)("max_til_exp", HIVE_MAX_TIME_UNTIL_RUNTIME_EXPIRATION));
if( has_hardfork( HIVE_HARDFORK_1_28_EXPIRATION_TIME ) )
{
HIVE_ASSERT(now < trx.expiration, transaction_expiration_exception, "", (now)(trx.expiration));

full_transaction->set_runtime_expiration( now + std::min( fc::seconds( HIVE_MAX_TIME_UNTIL_EXPIRATION ), trx.expiration - now ) );
}
else
{
HIVE_ASSERT(trx.expiration <= now + fc::seconds(HIVE_MAX_TIME_UNTIL_EXPIRATION), transaction_expiration_exception,
"", (trx.expiration)(now)("max_til_exp", HIVE_MAX_TIME_UNTIL_EXPIRATION));
HIVE_ASSERT(trx.expiration <= now + fc::seconds(HIVE_MAX_TIME_UNTIL_SIGNATURE_EXPIRATION), transaction_expiration_exception,
"", (trx.expiration)(now)("max_til_exp", HIVE_MAX_TIME_UNTIL_SIGNATURE_EXPIRATION));

if (has_hardfork(HIVE_HARDFORK_0_9)) // Simple solution to pending trx bug when now == trx.expiration
HIVE_ASSERT(now < trx.expiration, transaction_expiration_exception, "", (now)(trx.expiration));
full_transaction->set_runtime_expiration( now + std::min( fc::seconds( HIVE_MAX_TIME_UNTIL_EXPIRATION ), trx.expiration - now ) );
}
else
HIVE_ASSERT(now <= trx.expiration, transaction_expiration_exception, "", (now)(trx.expiration));
{
HIVE_ASSERT(trx.expiration <= now + fc::seconds(HIVE_MAX_TIME_UNTIL_EXPIRATION), transaction_expiration_exception,
"", (trx.expiration)(now)("max_til_exp", HIVE_MAX_TIME_UNTIL_EXPIRATION));

full_transaction->set_runtime_expiration( trx.expiration );
if (has_hardfork(HIVE_HARDFORK_0_9)) // Simple solution to pending trx bug when now == trx.expiration
HIVE_ASSERT(now < trx.expiration, transaction_expiration_exception, "", (now)(trx.expiration));
else
HIVE_ASSERT(now <= trx.expiration, transaction_expiration_exception, "", (now)(trx.expiration));

full_transaction->set_runtime_expiration( trx.expiration );
}
}

if (!(skip & skip_tapos_check))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ DEFINE_API_IMPL( transaction_status_api_impl, find_transaction )

// Check if the expiration is before our earliest tracked block plus maximum transaction expiration
fc::time_point_sec earliest_timestamp = _tsp.get_earliest_tracked_block_timestamp();
auto _expiration = _db.has_hardfork( HIVE_HARDFORK_1_28_EXPIRATION_TIME ) ? HIVE_MAX_TIME_UNTIL_RUNTIME_EXPIRATION : HIVE_MAX_TIME_UNTIL_EXPIRATION;
auto _expiration = _db.has_hardfork( HIVE_HARDFORK_1_28_EXPIRATION_TIME ) ? HIVE_MAX_TIME_UNTIL_SIGNATURE_EXPIRATION : HIVE_MAX_TIME_UNTIL_EXPIRATION;
if (expiration < earliest_timestamp + _expiration)
return {
.status = transaction_status::too_old
Expand Down
2 changes: 1 addition & 1 deletion libraries/protocol/include/hive/protocol/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ using namespace hive::protocol::testnet_blockchain_configuration;

#define HIVE_HARDFORK_REQUIRED_WITNESSES 17 // 17 of the 21 dpos witnesses (20 elected and 1 virtual time) required for hardfork. This guarantees 75% participation on all subsequent rounds.
#define HIVE_MAX_TIME_UNTIL_EXPIRATION (60*60) // seconds, aka: 1 hour
#define HIVE_MAX_TIME_UNTIL_RUNTIME_EXPIRATION (24*60*60) // seconds, aka: 1 day
#define HIVE_MAX_TIME_UNTIL_SIGNATURE_EXPIRATION (24*60*60) // seconds, aka: 1 day
#define HIVE_MAX_MEMO_SIZE 2048
#define HIVE_MAX_PROXY_RECURSION_DEPTH 4
#define HIVE_VESTING_WITHDRAW_INTERVALS_PRE_HF_16 104
Expand Down
2 changes: 1 addition & 1 deletion libraries/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ class wallet_api_impl

void set_transaction_expiration( uint32_t tx_expiration_seconds, bool is_hive_hardfork_1_28 )
{
FC_ASSERT( tx_expiration_seconds < ( is_hive_hardfork_1_28 ? HIVE_MAX_TIME_UNTIL_RUNTIME_EXPIRATION : HIVE_MAX_TIME_UNTIL_EXPIRATION ) );
FC_ASSERT( tx_expiration_seconds < ( is_hive_hardfork_1_28 ? HIVE_MAX_TIME_UNTIL_SIGNATURE_EXPIRATION : HIVE_MAX_TIME_UNTIL_EXPIRATION ) );
_tx_expiration_seconds = tx_expiration_seconds;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"HIVE_MAX_SIG_CHECK_ACCOUNTS": 125,
"HIVE_MAX_SIG_CHECK_DEPTH": 2,
"HIVE_MAX_TIME_UNTIL_EXPIRATION": 3600,
"HIVE_MAX_TIME_UNTIL_RUNTIME_EXPIRATION": 86400,
"HIVE_MAX_TIME_UNTIL_SIGNATURE_EXPIRATION": 86400,
"HIVE_MAX_TRANSACTION_SIZE": 65536,
"HIVE_MAX_UNDO_HISTORY": 10000,
"HIVE_MAX_URL_LENGTH": 127,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"HIVE_MAX_SIG_CHECK_ACCOUNTS": 125,
"HIVE_MAX_SIG_CHECK_DEPTH": 2,
"HIVE_MAX_TIME_UNTIL_EXPIRATION": 3600,
"HIVE_MAX_TIME_UNTIL_RUNTIME_EXPIRATION": 86400,
"HIVE_MAX_TIME_UNTIL_SIGNATURE_EXPIRATION": 86400,
"HIVE_MAX_TRANSACTION_SIZE": 65536,
"HIVE_MAX_UNDO_HISTORY": 10000,
"HIVE_MAX_URL_LENGTH": 127,
Expand Down
18 changes: 9 additions & 9 deletions tests/python/hive-local-tools/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/python/hive-local-tools/test-tools
Submodule test-tools updated 2 files
+9 −9 poetry.lock
+1 −1 pyproject.toml
28 changes: 14 additions & 14 deletions tests/unit/plugin_tests/witness_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ BOOST_AUTO_TEST_CASE( witness_basic_with_runtime_expiration_00_test )
{
try
{
expiration = HIVE_MAX_TIME_UNTIL_RUNTIME_EXPIRATION;
expiration = HIVE_MAX_TIME_UNTIL_SIGNATURE_EXPIRATION;
witness_basic();
}
FC_LOG_AND_RETHROW()
Expand All @@ -327,7 +327,7 @@ BOOST_AUTO_TEST_CASE( witness_basic_with_runtime_expiration_01_test )
{
try
{
expiration = HIVE_MAX_TIME_UNTIL_RUNTIME_EXPIRATION;
expiration = HIVE_MAX_TIME_UNTIL_SIGNATURE_EXPIRATION;

initialize();
bool test_passed = false;
Expand Down Expand Up @@ -364,7 +364,7 @@ BOOST_AUTO_TEST_CASE( witness_basic_with_runtime_expiration_01_test )
saved_block_num = current_block_num;

schedule_transfer( "alice", "bob", ASSET( "0.100 TBD" ), "", HIVE_MAX_TIME_UNTIL_EXPIRATION );
schedule_transfer( "alice", "bob", ASSET( "0.100 TBD" ), "", HIVE_MAX_TIME_UNTIL_RUNTIME_EXPIRATION );
schedule_transfer( "alice", "bob", ASSET( "0.100 TBD" ), "", HIVE_MAX_TIME_UNTIL_SIGNATURE_EXPIRATION );

db->with_read_lock( [&]()
{
Expand All @@ -391,7 +391,7 @@ BOOST_AUTO_TEST_CASE( witness_basic_with_runtime_expiration_02_test )
{
try
{
expiration = HIVE_MAX_TIME_UNTIL_RUNTIME_EXPIRATION;
expiration = HIVE_MAX_TIME_UNTIL_SIGNATURE_EXPIRATION;

initialize();
bool test_passed = false;
Expand Down Expand Up @@ -446,7 +446,7 @@ BOOST_AUTO_TEST_CASE( witness_basic_with_runtime_expiration_02_test )
if( msg_duplicate )
BOOST_REQUIRE( ex.to_string().find( "Duplicate transaction check failed" ) != std::string::npos );
else
BOOST_REQUIRE( ex.to_string().find( "trx.expiration <= now + fc::seconds(HIVE_MAX_TIME_UNTIL_RUNTIME_EXPIRATION)" ) != std::string::npos );
BOOST_REQUIRE( ex.to_string().find( "trx.expiration <= now + fc::seconds(HIVE_MAX_TIME_UNTIL_SIGNATURE_EXPIRATION)" ) != std::string::npos );
}
};

Expand All @@ -467,23 +467,23 @@ BOOST_AUTO_TEST_CASE( witness_basic_with_runtime_expiration_02_test )
}

{
_scheduling( HIVE_MAX_TIME_UNTIL_RUNTIME_EXPIRATION );
_scheduling( HIVE_MAX_TIME_UNTIL_SIGNATURE_EXPIRATION );
db->with_read_lock( [&]()
{
BOOST_REQUIRE_EQUAL( get_hbd_balance( "bob" ).amount.value, 1002 );
} );
}

{
_scheduling( HIVE_MAX_TIME_UNTIL_RUNTIME_EXPIRATION / 2 );
_scheduling( HIVE_MAX_TIME_UNTIL_SIGNATURE_EXPIRATION / 2 );
db->with_read_lock( [&]()
{
BOOST_REQUIRE_EQUAL( get_hbd_balance( "bob" ).amount.value, 1003 );
} );
}

{
_scheduling( HIVE_MAX_TIME_UNTIL_RUNTIME_EXPIRATION + 1, false/*pass*/, false/*msg_duplicate*/ );
_scheduling( HIVE_MAX_TIME_UNTIL_SIGNATURE_EXPIRATION + 1, false/*pass*/, false/*msg_duplicate*/ );
db->with_read_lock( [&]()
{
BOOST_REQUIRE_EQUAL( get_hbd_balance( "bob" ).amount.value, 1003 );
Expand All @@ -510,7 +510,7 @@ BOOST_AUTO_TEST_CASE( witness_basic_with_runtime_expiration_03_test )
{
try
{
expiration = HIVE_MAX_TIME_UNTIL_RUNTIME_EXPIRATION;
expiration = HIVE_MAX_TIME_UNTIL_SIGNATURE_EXPIRATION;

initialize();
bool test_passed = false;
Expand Down Expand Up @@ -565,18 +565,18 @@ BOOST_AUTO_TEST_CASE( witness_basic_with_runtime_expiration_03_test )
}
{
auto _trx_00 = schedule_transfer( "alice", "bob", ASSET( "0.001 TBD" ), "",
HIVE_MAX_TIME_UNTIL_RUNTIME_EXPIRATION - 12 * HIVE_BLOCK_INTERVAL, false/*accept_transaction*/ );
HIVE_MAX_TIME_UNTIL_SIGNATURE_EXPIRATION - 12 * HIVE_BLOCK_INTERVAL, false/*accept_transaction*/ );

auto _trx_01 = schedule_transfer( "alice", "bob", ASSET( "0.001 TBD" ), "",
HIVE_MAX_TIME_UNTIL_RUNTIME_EXPIRATION - 8 * HIVE_BLOCK_INTERVAL, false/*accept_transaction*/ );
HIVE_MAX_TIME_UNTIL_SIGNATURE_EXPIRATION - 8 * HIVE_BLOCK_INTERVAL, false/*accept_transaction*/ );

auto _trx_01_a = schedule_transfer( "alice", "bob", ASSET( "0.002 TBD" ), "",
HIVE_MAX_TIME_UNTIL_RUNTIME_EXPIRATION - 8 * HIVE_BLOCK_INTERVAL, false/*accept_transaction*/ );
HIVE_MAX_TIME_UNTIL_SIGNATURE_EXPIRATION - 8 * HIVE_BLOCK_INTERVAL, false/*accept_transaction*/ );

auto _trx_02 = schedule_transfer( "alice", "bob", ASSET( "0.001 TBD" ), "",
HIVE_MAX_TIME_UNTIL_RUNTIME_EXPIRATION - 4 * HIVE_BLOCK_INTERVAL, false/*accept_transaction*/ );
HIVE_MAX_TIME_UNTIL_SIGNATURE_EXPIRATION - 4 * HIVE_BLOCK_INTERVAL, false/*accept_transaction*/ );

schedule_blocks( HIVE_MAX_TIME_UNTIL_RUNTIME_EXPIRATION / HIVE_BLOCK_INTERVAL - 12 );
schedule_blocks( HIVE_MAX_TIME_UNTIL_SIGNATURE_EXPIRATION / HIVE_BLOCK_INTERVAL - 12 );

bool _accept_transaction_passed = false;
try
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/tests/hf28_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,11 +615,11 @@ BOOST_AUTO_TEST_CASE( basic_expiration_test )
_op.memo = "";

{
BOOST_TEST_MESSAGE( "0) Test with expiration: `HIVE_MAX_TIME_UNTIL_RUNTIME_EXPIRATION`" );
BOOST_TEST_MESSAGE( "0) Test with expiration: `HIVE_MAX_TIME_UNTIL_SIGNATURE_EXPIRATION`" );

signed_transaction _trx;
_trx.operations.push_back( _op );
_trx.set_expiration( executor->db->head_block_time() + HIVE_MAX_TIME_UNTIL_RUNTIME_EXPIRATION );
_trx.set_expiration( executor->db->head_block_time() + HIVE_MAX_TIME_UNTIL_SIGNATURE_EXPIRATION );

if( _statuses[_test_cnt] )
executor->push_transaction( _trx, alice_private_key );
Expand All @@ -628,11 +628,11 @@ BOOST_AUTO_TEST_CASE( basic_expiration_test )
++_test_cnt;
}
{
BOOST_TEST_MESSAGE( "1) Test with expiration: `HIVE_MAX_TIME_UNTIL_RUNTIME_EXPIRATION` - 1" );
BOOST_TEST_MESSAGE( "1) Test with expiration: `HIVE_MAX_TIME_UNTIL_SIGNATURE_EXPIRATION` - 1" );

signed_transaction _trx;
_trx.operations.push_back( _op );
_trx.set_expiration( executor->db->head_block_time() + HIVE_MAX_TIME_UNTIL_RUNTIME_EXPIRATION - 1 );
_trx.set_expiration( executor->db->head_block_time() + HIVE_MAX_TIME_UNTIL_SIGNATURE_EXPIRATION - 1 );

if( _statuses[_test_cnt] )
executor->push_transaction( _trx, alice_private_key );
Expand All @@ -641,11 +641,11 @@ BOOST_AUTO_TEST_CASE( basic_expiration_test )
++_test_cnt;
}
{
BOOST_TEST_MESSAGE( "2) Test with expiration: `HIVE_MAX_TIME_UNTIL_RUNTIME_EXPIRATION` + 1" );
BOOST_TEST_MESSAGE( "2) Test with expiration: `HIVE_MAX_TIME_UNTIL_SIGNATURE_EXPIRATION` + 1" );

signed_transaction _trx;
_trx.operations.push_back( _op );
_trx.set_expiration( executor->db->head_block_time() + HIVE_MAX_TIME_UNTIL_RUNTIME_EXPIRATION + 1 );
_trx.set_expiration( executor->db->head_block_time() + HIVE_MAX_TIME_UNTIL_SIGNATURE_EXPIRATION + 1 );

if( _statuses[_test_cnt] )
executor->push_transaction( _trx, alice_private_key );
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/tests/tx_status_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ BOOST_AUTO_TEST_CASE( failure_during_fork_switch )
check.expect( expectation::pending_transaction( expectation::PRE_TX ) );
check.expect( expectation::pending_transaction( expectation::PRE_TX ) );
/*
Before `HIVE_MAX_TIME_UNTIL_RUNTIME_EXPIRATION` was introduced
Before `HIVE_MAX_TIME_UNTIL_SIGNATURE_EXPIRATION` was introduced
last transaction (from block 2) has its expiration too far into the future, so it fails prior to notification
After:
last transaction wasn't expired
Expand Down

0 comments on commit 140c34b

Please sign in to comment.