Skip to content

Commit

Permalink
IS 1074 fix externalGas calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
olehnikolaiev committed Sep 19, 2024
1 parent b723683 commit 44dafae
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
9 changes: 8 additions & 1 deletion libethereum/Transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,14 @@ void Transaction::checkOutExternalGas( const ChainParams& _cp, time_t _committed
u256 const& difficulty = _cp.externalGasDifficulty;
assert( difficulty > 0 );
if ( ( _force || !m_externalGasIsChecked ) && !isInvalid() ) {
h256 hash = dev::sha3( sender().ref() ) ^ dev::sha3( nonce() ) ^ dev::sha3( gasPrice() );
// reset externalGas value
// we may face patch activation after txn was added to the queue but before it was executed
// therefore we need to recalculate externalGas
if ( m_externalGasIsChecked && hasExternalGas() )
m_externalGas = 0;

h256 hash = dev::sha3( sender().ref() ) ^ dev::sha3( nonce() ) ^
dev::sha3( TransactionBase::gasPrice() );
if ( !hash ) {
hash = h256( 1 );
}
Expand Down
31 changes: 30 additions & 1 deletion test/unittests/libweb3jsonrpc/jsonrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1987,6 +1987,35 @@ BOOST_AUTO_TEST_CASE( simplePoWTransaction ) {
BOOST_REQUIRE_EQUAL(receipt["status"], "0x1");
}

BOOST_AUTO_TEST_CASE( recalculateExternalGas ) {
std::string _config = c_genesisConfigString;
Json::Value ret;
Json::Reader().parse( _config, ret );

// Set chainID = 2192608523748315
std::string chainID = "0x7ca2a743083db";
ret["params"]["chainID"] = chainID;
time_t eip1559PatchActivationTimestamp = time(nullptr);
ret["skaleConfig"]["sChain"]["EIP1559TransactionsPatchTimestamp"] = eip1559PatchActivationTimestamp;

Json::FastWriter fastWriter;
std::string config = fastWriter.write( ret );
JsonRpcFixture fixture( config );
dev::eth::simulateMining( *( fixture.client ), 20 );

fixture.rpcClient->eth_sendRawTransaction( "0x02f8ae8707ca2a743083db8080a0d7d2692231d351eab7d73269effb12393260eb38d11e81085a995dbfffeb4d4b830103ae9403f7c171a32e275c712fe6f32612ad21b485728180a40c11dedd000000000000000000000000229a61f480631a331ffde0dff312d06c087f818dc001a084bb73dbd78dbb45040982a5425c110ff217acb6b04d2e5366c0b75fbdadd450a001fef7f8c83e7472e51fae99dda30e7d0318d5a78487121a69642ca77763c02d" );

auto pendingTransactions = fixture.rpcClient->eth_pendingTransactions();
BOOST_REQUIRE( pendingTransactions.size() == 1 );

auto t = fixture.client->pending().front();

BOOST_REQUIRE( t.hasExternalGas() );
BOOST_REQUIRE( t.getExternalGas() == 92966 );
t.checkOutExternalGas( fixture.chainParams, 1, 0, true );
BOOST_REQUIRE( t.getExternalGas() == 92966 );
}

BOOST_AUTO_TEST_CASE( transactionWithoutFunds ) {
JsonRpcFixture fixture;
dev::eth::simulateMining( *( fixture.client ), 1 );
Expand Down Expand Up @@ -2924,7 +2953,7 @@ BOOST_AUTO_TEST_CASE( powTxnGasLimit ) {
txPOW2["gasPrice"] = "0xc5002ab03e1e7e196b3d0ffa9801e783fcd48d4c6d972f1389ab63f4e2d0bef0"; // gas 1m
txPOW2["value"] = 100;
BOOST_REQUIRE_THROW( fixture.rpcClient->eth_sendTransaction( txPOW2 ), jsonrpc::JsonRpcException ); // block gas limit reached
}
}

BOOST_AUTO_TEST_CASE( EIP1898Calls ) {
JsonRpcFixture fixture;
Expand Down

0 comments on commit 44dafae

Please sign in to comment.