Skip to content

Commit

Permalink
IS 1074 remove force for checkOutExternalGas
Browse files Browse the repository at this point in the history
  • Loading branch information
olehnikolaiev committed Sep 24, 2024
1 parent bad0612 commit 13d7638
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 17 deletions.
5 changes: 2 additions & 3 deletions libethereum/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,7 @@ pair< TransactionReceipts, bool > Block::sync(
// caller if we hit the limit

for ( Transaction& transaction : transactions ) {
transaction.checkOutExternalGas(
_bc.chainParams(), _bc.info().timestamp(), _bc.number(), false );
transaction.checkOutExternalGas( _bc.chainParams(), _bc.info().timestamp(), _bc.number() );
}

assert( _bc.currentHash() == m_currentBlock.parentHash() );
Expand Down Expand Up @@ -633,7 +632,7 @@ u256 Block::enact( VerifiedBlockRef const& _block, BlockChain const& _bc ) {
// << state().getNonce( tr.from() ) << ") value = " << tr.value() <<
// endl;
const_cast< Transaction& >( tr ).checkOutExternalGas(
_bc.chainParams(), _bc.info().timestamp(), _bc.number(), false );
_bc.chainParams(), _bc.info().timestamp(), _bc.number() );
execute( _bc.lastBlockHashes(), tr );
// cerr << "Now: "
// << "State #" << state().getNonce( tr.from() ) << endl;
Expand Down
2 changes: 1 addition & 1 deletion libethereum/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ h256 Client::importTransaction( Transaction const& _t ) {
// We need to check external gas under mutex to be sure about current block number
// correctness
const_cast< Transaction& >( _t ).checkOutExternalGas(
chainParams(), bc().info().timestamp(), number(), false );
chainParams(), bc().info().timestamp(), number() );
}

Executive::verifyTransaction( _t, bc().info().timestamp(),
Expand Down
4 changes: 2 additions & 2 deletions libethereum/SkaleHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro
if ( m_m_transaction_cache.find( sha.asArray() ) != m_m_transaction_cache.cend() ) {
Transaction t = m_m_transaction_cache.at( sha.asArray() );
t.checkOutExternalGas(
m_client.chainParams(), latestInfo.timestamp(), m_client.number(), true );
m_client.chainParams(), latestInfo.timestamp(), m_client.number() );
out_txns.push_back( t );
LOG( m_debugLogger ) << "Dropping good txn " << sha << std::endl;
m_debugTracer.tracepoint( "drop_good" );
Expand All @@ -675,7 +675,7 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro
Transaction t( data, CheckTransaction::Everything, true,
EIP1559TransactionsPatch::isEnabledInWorkingBlock() );
t.checkOutExternalGas(
m_client.chainParams(), latestInfo.timestamp(), m_client.number(), false );
m_client.chainParams(), latestInfo.timestamp(), m_client.number() );
out_txns.push_back( t );
LOG( m_debugLogger ) << "Will import consensus-born txn";
m_debugTracer.tracepoint( "import_consensus_born" );
Expand Down
14 changes: 6 additions & 8 deletions libethereum/Transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,22 +195,20 @@ u256 Transaction::gasPrice() const {
}
}

void Transaction::checkOutExternalGas( const ChainParams& _cp, time_t _committedBlockTimestamp,
uint64_t _committedBlockNumber, bool _force ) {
void Transaction::checkOutExternalGas(
const ChainParams& _cp, time_t _committedBlockTimestamp, uint64_t _committedBlockNumber ) {
u256 const& difficulty = _cp.externalGasDifficulty;
assert( difficulty > 0 );
if ( ( _force || !m_externalGasIsChecked ) && !isInvalid() ) {
if ( !isInvalid() ) {
h256 hash;
if ( !ExternalGasPatch::isEnabledWhen( _committedBlockTimestamp ) ) {
hash = dev::sha3( sender().ref() ) ^ dev::sha3( nonce() ) ^ dev::sha3( gasPrice() );
} else {
// 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_externalGasIsChecked = false;
m_externalGas.reset();
}
// executed. therefore we need to recalculate externalGas
m_externalGasIsChecked = false;
m_externalGas.reset();
hash = dev::sha3( sender().ref() ) ^ dev::sha3( nonce() ) ^
dev::sha3( TransactionBase::gasPrice() );
}
Expand Down
4 changes: 2 additions & 2 deletions libethereum/Transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ class Transaction : public TransactionBase {

u256 gasPrice() const;

void checkOutExternalGas( const ChainParams& _cp, time_t _committedBlockTimestamp,
uint64_t _committedBlockNumber, bool _force );
void checkOutExternalGas(
const ChainParams& _cp, time_t _committedBlockTimestamp, uint64_t _committedBlockNumber );

void ignoreExternalGas() {
m_externalGasIsChecked = true;
Expand Down
2 changes: 1 addition & 1 deletion test/unittests/libethereum/SkaleHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ BOOST_AUTO_TEST_CASE( transactionDropQueue,

// 1st tx
Transaction tx1 = fixture.tx_from_json( json );
tx1.checkOutExternalGas( client->chainParams(), client->latestBlock().info().timestamp(), client->number(), false );
tx1.checkOutExternalGas( client->chainParams(), client->latestBlock().info().timestamp(), client->number() );

// submit it!
tq->import( tx1 );
Expand Down

0 comments on commit 13d7638

Please sign in to comment.