Skip to content

Commit

Permalink
Merge branch 'v3.18.0' into enhancement/SKALED-1431-ftq-rpc-call
Browse files Browse the repository at this point in the history
  • Loading branch information
DmytroNazarenko authored Jan 10, 2024
2 parents 3372716 + a3dd9cc commit 1e79fdf
Show file tree
Hide file tree
Showing 18 changed files with 66 additions and 218 deletions.
1 change: 0 additions & 1 deletion libethcore/ChainOperationParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ struct SChain {
time_t precompiledConfigPatchTimestamp = 0;
time_t pushZeroPatchTimestamp = 0;
time_t skipInvalidTransactionsPatchTimestamp = 0;
time_t correctForkInPowPatchTimestamp = 0;

SChain() {
name = "TestChain";
Expand Down
5 changes: 3 additions & 2 deletions libethereum/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ pair< TransactionReceipts, bool > Block::sync(
// caller if we hit the limit

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

assert( _bc.currentHash() == m_currentBlock.parentHash() );
Expand Down Expand Up @@ -631,7 +631,8 @@ u256 Block::enact( VerifiedBlockRef const& _block, BlockChain const& _bc ) {
// << " (state #"
// << state().getNonce( tr.from() ) << ") value = " << tr.value() <<
// endl;
const_cast< Transaction& >( tr ).checkOutExternalGas( _bc.chainParams(), _bc.number() );
const_cast< Transaction& >( tr ).checkOutExternalGas(
_bc.chainParams().externalGasDifficulty );
execute( _bc.lastBlockHashes(), tr );
// cerr << "Now: "
// << "State #" << state().getNonce( tr.from() ) << endl;
Expand Down
5 changes: 0 additions & 5 deletions libethereum/ChainParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,6 @@ ChainParams ChainParams::loadConfig(
sChainObj.at( "skipInvalidTransactionsPatchTimestamp" ).get_int64() :
0;

s.correctForkInPowPatchTimestamp =
sChainObj.count( "correctForkInPowPatchTimestamp" ) ?
sChainObj.at( "correctForkInPowPatchTimestamp" ).get_int64() :
0;

if ( sChainObj.count( "nodeGroups" ) ) {
std::vector< NodeGroup > nodeGroups;
for ( const auto& nodeGroupConf : sChainObj["nodeGroups"].get_obj() ) {
Expand Down
19 changes: 4 additions & 15 deletions libethereum/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@

#include <libskale/ContractStorageLimitPatch.h>
#include <libskale/ContractStorageZeroValuePatch.h>
#include <libskale/CorrectForkInPowPatch.h>
#include <libskale/POWCheckPatch.h>
#include <libskale/PrecompiledConfigPatch.h>
#include <libskale/PushZeroPatch.h>
Expand Down Expand Up @@ -170,7 +169,6 @@ Client::Client( ChainParams const& _params, int _networkID,
SkipInvalidTransactionsPatch::setTimestamp(
this->chainParams().sChain.skipInvalidTransactionsPatchTimestamp );
PrecompiledConfigPatch::setTimestamp( chainParams().sChain.precompiledConfigPatchTimestamp );
CorrectForkInPowPatch::setTimestamp( chainParams().sChain.correctForkInPowPatchTimestamp );
}


Expand Down Expand Up @@ -602,10 +600,6 @@ size_t Client::importTransactionsAsBlock(
sealUnconditionally( false );
importWorkingBlock();

// this needs to be updated as soon as possible, as it's used in new transactions validation
CorrectForkInPowPatch::lastBlockTimestamp = blockChain().info().timestamp();
CorrectForkInPowPatch::lastBlockNumber = blockChain().number();

if ( !UnsafeRegion::isActive() ) {
LOG( m_loggerDetail ) << "Total unsafe time so far = "
<< std::chrono::duration_cast< std::chrono::seconds >(
Expand Down Expand Up @@ -674,9 +668,6 @@ size_t Client::syncTransactions(
PushZeroPatch::lastBlockTimestamp = blockChain().info().timestamp();
SkipInvalidTransactionsPatch::lastBlockTimestamp = blockChain().info().timestamp();
PrecompiledConfigPatch::lastBlockTimestamp = blockChain().info().timestamp();
CorrectForkInPowPatch::lastBlockTimestamp = blockChain().info().timestamp();
CorrectForkInPowPatch::lastBlockNumber = blockChain().number();


DEV_WRITE_GUARDED( x_working ) {
assert( !m_working.isSealed() );
Expand Down Expand Up @@ -1199,17 +1190,15 @@ h256 Client::importTransaction( Transaction const& _t ) {
// the latest block in the client's blockchain. This can throw but
// we'll catch the exception at the RPC level.

const_cast< Transaction& >( _t ).checkOutExternalGas( chainParams().externalGasDifficulty );

// throws in case of error
State state;
u256 gasBidPrice;

DEV_GUARDED( m_blockImportMutex ) {
state = this->state().createStateReadOnlyCopy();
gasBidPrice = this->gasBidPrice();

// We need to check external gas under mutex to be sure about current block bumber
// correctness
const_cast< Transaction& >( _t ).checkOutExternalGas( chainParams(), number() );
}

Executive::verifyTransaction( _t,
Expand Down Expand Up @@ -1266,7 +1255,7 @@ ExecutionResult Client::call( Address const& _from, u256 _value, Address _dest,
Transaction t( _value, gasPrice, gas, _dest, _data, nonce );
t.forceSender( _from );
t.forceChainId( chainParams().chainID );
t.ignoreExternalGas();
t.checkOutExternalGas( ~u256( 0 ) );
if ( _ff == FudgeFactor::Lenient ) {
historicBlock.mutableState().mutableHistoricState().addBalance(
_from, ( u256 )( t.gas() * t.gasPrice() + t.value() ) );
Expand All @@ -1291,7 +1280,7 @@ ExecutionResult Client::call( Address const& _from, u256 _value, Address _dest,
Transaction t( _value, gasPrice, gas, _dest, _data, nonce );
t.forceSender( _from );
t.forceChainId( chainParams().chainID );
t.ignoreExternalGas();
t.checkOutExternalGas( ~u256( 0 ) );
if ( _ff == FudgeFactor::Lenient )
temp.mutableState().addBalance( _from, ( u256 )( t.gas() * t.gasPrice() + t.value() ) );
ret = temp.execute( bc().lastBlockHashes(), t, skale::Permanence::Reverted );
Expand Down
11 changes: 3 additions & 8 deletions libethereum/ClientBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/

#include "ClientBase.h"
#include <libskale/CorrectForkInPowPatch.h>

#include <algorithm>
#include <utility>
Expand Down Expand Up @@ -90,7 +89,7 @@ std::pair< bool, ExecutionResult > ClientBase::estimateGasStep( int64_t _gas, Bl
t = Transaction( _value, _gasPrice, _gas, _data, nonce );
t.forceSender( _from );
t.forceChainId( chainId() );
t.ignoreExternalGas();
t.checkOutExternalGas( ~u256( 0 ) );
EnvInfo const env( _latestBlock.info(), bc().lastBlockHashes(), 0, _gas );
// Make a copy of state!! It will be deleted after step!
State tempState = _latestBlock.mutableState();
Expand All @@ -116,12 +115,8 @@ std::pair< u256, ExecutionResult > ClientBase::estimateGas( Address const& _from
int64_t upperBound = _maxGas;
if ( upperBound == Invalid256 || upperBound > c_maxGasEstimate )
upperBound = c_maxGasEstimate;
int64_t lowerBound =
CorrectForkInPowPatch::isEnabled() ?
Transaction::baseGasRequired( !_dest, &_data,
bc().sealEngine()->chainParams().scheduleForBlockNumber( bc().number() ) ) :
Transaction::baseGasRequired( !_dest, &_data, EVMSchedule() );

int64_t lowerBound = Transaction::baseGasRequired( !_dest, &_data,
bc().sealEngine()->chainParams().scheduleForBlockNumber( bc().number() ) );
Block bk = latestBlock();
if ( upperBound > bk.info().gasLimit() ) {
upperBound = bk.info().gasLimit().convert_to< int64_t >();
Expand Down
3 changes: 1 addition & 2 deletions libethereum/SkaleHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,6 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro
// TODO clear occasionally this cache?!
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(), m_client.number(), true );
out_txns.push_back( t );
LOG( m_debugLogger ) << "Dropping good txn " << sha << std::endl;
m_debugTracer.tracepoint( "drop_good" );
Expand All @@ -658,7 +657,7 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro
// ).detach();
} else {
Transaction t( data, CheckTransaction::Everything, true );
t.checkOutExternalGas( m_client.chainParams(), m_client.number() );
t.checkOutExternalGas( m_client.chainParams().externalGasDifficulty );
out_txns.push_back( t );
LOG( m_debugLogger ) << "Will import consensus-born txn";
m_debugTracer.tracepoint( "import_consensus_born" );
Expand Down
26 changes: 6 additions & 20 deletions libethereum/Transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <libdevcrypto/Common.h>
#include <libethcore/Exceptions.h>
#include <libevm/VMFace.h>
#include <libskale/CorrectForkInPowPatch.h>

using namespace std;
using namespace dev;
Expand Down Expand Up @@ -181,32 +180,19 @@ u256 Transaction::gasPrice() const {
}
}

void Transaction::checkOutExternalGas( const ChainParams& _cp, uint64_t _bn, bool _force ) {
u256 const& difficulty = _cp.externalGasDifficulty;
assert( difficulty > 0 );
if ( ( _force || !m_externalGasIsChecked ) && !isInvalid() ) {
void Transaction::checkOutExternalGas( u256 const& _difficulty ) {
assert( _difficulty > 0 );
if ( !m_externalGasIsChecked && !isInvalid() ) {
h256 hash = dev::sha3( sender().ref() ) ^ dev::sha3( nonce() ) ^ dev::sha3( gasPrice() );
if ( !hash ) {
hash = h256( 1 );
}
u256 externalGas = ~u256( 0 ) / u256( hash ) / difficulty;
u256 externalGas = ~u256( 0 ) / u256( hash ) / _difficulty;
if ( externalGas > 0 )
ctrace << "Mined gas: " << externalGas << endl;

EVMSchedule scheduleForUse = ConstantinopleSchedule;
if ( CorrectForkInPowPatch::isEnabled() )
scheduleForUse = _cp.scheduleForBlockNumber( _bn );

// never call checkOutExternalGas with non-last block
if ( _bn != CorrectForkInPowPatch::getLastBlockNumber() ) {
ctrace << _bn << " != " << CorrectForkInPowPatch::getLastBlockNumber();
BOOST_THROW_EXCEPTION( std::runtime_error(
"Internal error: checkOutExternalGas() has invalid block number" ) );
}

if ( externalGas >= baseGasRequired( scheduleForUse ) )
if ( externalGas >= baseGasRequired( ConstantinopleSchedule ) ) {
m_externalGas = externalGas;

}
m_externalGasIsChecked = true;
}
}
Expand Down
9 changes: 1 addition & 8 deletions libethereum/Transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
#include <libethcore/Common.h>
#include <libethcore/TransactionBase.h>

#include "ChainParams.h"

namespace dev {
namespace eth {

Expand Down Expand Up @@ -122,12 +120,7 @@ class Transaction : public TransactionBase {

u256 gasPrice() const;

void checkOutExternalGas( const ChainParams& _cp, uint64_t _bn, bool _force = false );

void ignoreExternalGas() {
m_externalGasIsChecked = true;
m_externalGas = 0;
}
void checkOutExternalGas( u256 const& _difficulty );

private:
bool m_externalGasIsChecked = false;
Expand Down
2 changes: 0 additions & 2 deletions libethereum/ValidationSchemes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,6 @@ void validateConfigJson( js::mObject const& _obj ) {
{ "skipInvalidTransactionsPatchTimestamp",
{ { js::int_type }, JsonFieldPresence::Optional } },
{ "precompiledConfigPatchTimestamp",
{ { js::int_type }, JsonFieldPresence::Optional } },
{ "correctForkInPowPatchTimestamp",
{ { js::int_type }, JsonFieldPresence::Optional } } } );

js::mArray const& nodes = sChain.at( "nodes" ).get_array();
Expand Down
2 changes: 0 additions & 2 deletions libskale/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ set(sources
PrecompiledConfigPatch.cpp
PushZeroPatch.cpp
SkipInvalidTransactionsPatch.cpp
CorrectForkInPowPatch.cpp
)

set(headers
Expand All @@ -45,7 +44,6 @@ set(headers
PrecompiledConfigPatch.h
OverlayFS.h
SkipInvalidTransactionsPatch.h
CorrectForkInPowPatch.h
)

add_library(skale ${sources} ${headers})
Expand Down
12 changes: 0 additions & 12 deletions libskale/CorrectForkInPowPatch.cpp

This file was deleted.

41 changes: 0 additions & 41 deletions libskale/CorrectForkInPowPatch.h

This file was deleted.

10 changes: 0 additions & 10 deletions test/tools/libtesteth/BlockChainHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
* that manage block/transaction import and test mining
*/

#include <libskale/CorrectForkInPowPatch.h>

#include <libdevcore/TransientDirectory.h>
#include <libethashseal/GenesisInfo.h>
#include <libethereum/Block.h>
Expand Down Expand Up @@ -475,10 +473,6 @@ void TestBlockChain::reset( TestBlock const& _genesisBlock ) {
}

bool TestBlockChain::addBlock( TestBlock const& _block ) {

CorrectForkInPowPatch::lastBlockTimestamp = m_blockChain->info().timestamp();
CorrectForkInPowPatch::lastBlockNumber = m_blockChain->number();

while ( true ) {
try {
_block.verify( *this ); // check that block header match TestBlock contents
Expand All @@ -500,10 +494,6 @@ bool TestBlockChain::addBlock( TestBlock const& _block ) {

State st( block.state() );
m_lastBlock.setState( st );

CorrectForkInPowPatch::lastBlockTimestamp = m_blockChain->info().timestamp();
CorrectForkInPowPatch::lastBlockNumber = m_blockChain->number();

return true;
}

Expand Down
Loading

0 comments on commit 1e79fdf

Please sign in to comment.