Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop to 3.19.0 #1902

Merged
merged 42 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
d03ca0f
Merge pull request #1824 from skalenetwork/develop
DmytroNazarenko Feb 17, 2024
ac87d8e
1856_checkout_external_gas
kladkogex Apr 10, 2024
f3b977a
1856 fix clang format
kladkogex Apr 10, 2024
622187a
Merge pull request #1867 from skalenetwork/1856_checkout_external_gas
kladkogex Apr 11, 2024
c12ddd9
#1859 added test contract
kladkogex Apr 22, 2024
6da373d
#1859 added test contract
kladkogex Apr 22, 2024
4a912bf
#1859 added test contract
kladkogex Apr 22, 2024
335b66e
#1859 added test contract
kladkogex Apr 22, 2024
9215805
#1859 added test contract
kladkogex Apr 22, 2024
7eaa960
#1859 added test contract
kladkogex Apr 22, 2024
d62cfc8
#1859 added test contract
kladkogex Apr 22, 2024
a3c26d7
#1859 added test contract
kladkogex Apr 22, 2024
a203036
#1859 added test contract
kladkogex Apr 22, 2024
f3eb1a1
#1859 added test contract
kladkogex Apr 22, 2024
9b538c7
#1859 added test contract
kladkogex Apr 22, 2024
961fff1
#1859 added test contract
kladkogex Apr 22, 2024
b1a0519
#1859 added test contract
kladkogex Apr 23, 2024
46627eb
#1859 added test contract
kladkogex Apr 23, 2024
2f588b4
#1859 added test contract
kladkogex Apr 23, 2024
f98c5e0
#1859 added test contract
kladkogex Apr 23, 2024
86fc325
#1859 added test contract
kladkogex Apr 23, 2024
ab1679f
#1859 added test contract
kladkogex Apr 23, 2024
aeceb04
#1859 added test contract
kladkogex Apr 23, 2024
d66c3fd
#1859 added test contract
kladkogex Apr 23, 2024
a8f1f97
#1859 added test contract
kladkogex Apr 23, 2024
94a859a
#1859 added test contract
kladkogex Apr 23, 2024
80685dd
#1859 added test contract
kladkogex Apr 23, 2024
7e5335a
#1859 added test contract
kladkogex Apr 23, 2024
c0da15e
#1859 added test contract
kladkogex Apr 23, 2024
b8d4e83
#1859 added test contract
kladkogex Apr 23, 2024
d702d90
#1859 added test contract
kladkogex Apr 23, 2024
567659f
#1859 added test contract
kladkogex Apr 23, 2024
de3973a
Merge pull request #1875 from skalenetwork/1859_trace_failed_transaction
kladkogex Apr 29, 2024
2fc8164
Merge branch 'beta' into develop
kladkogex Apr 29, 2024
c344e42
Merge pull request #1881 from skalenetwork/develop
kladkogex Apr 29, 2024
c578e59
#1890 add more logs for archive node
olehnikolaiev May 13, 2024
156c18e
#1890 fix build
olehnikolaiev May 13, 2024
0c6b994
#1890 format
olehnikolaiev May 13, 2024
c56e96a
#1890 format
olehnikolaiev May 14, 2024
9e957ae
Merge pull request #1895 from skalenetwork/enhancement/1890-add-logs
olehnikolaiev May 14, 2024
1b54222
Merge branch 'beta' into develop
DmytroNazarenko May 14, 2024
9d1d3cd
Merge branch 'v3.19.0' into develop-to-3.19.0
olehnikolaiev May 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libdevcore/LevelDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class LevelDB : public DatabaseFace {
static std::atomic< uint64_t > g_keyDeletesStats;
// count of the keys that are scheduled to be deleted but are not yet deleted
static std::atomic< uint64_t > g_keysToBeDeletedStats;
static uint64_t getCurrentTimeMs();

private:
std::unique_ptr< leveldb::DB > m_db;
Expand Down Expand Up @@ -123,7 +124,6 @@ class LevelDB : public DatabaseFace {
}
};
void openDBInstanceUnsafe();
uint64_t getCurrentTimeMs();
void reopenDataBaseIfNeeded();
};

Expand Down
9 changes: 6 additions & 3 deletions libethereum/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,10 +674,13 @@ size_t Client::syncTransactions(
// Tell network about the new transactions.
m_skaleHost->noteNewTransactions();

ctrace << cc::debug( "Processed " ) << cc::size10( newPendingReceipts.size() )
<< cc::debug( " transactions in " ) << cc::size10( timer.elapsed() * 1000 )
<< cc::debug( "(" ) << ( bool ) m_syncTransactionQueue << cc::debug( ")" );
ctrace << "Processed " << newPendingReceipts.size() << " transactions in "
<< timer.elapsed() * 1000 << "(" << ( bool ) m_syncTransactionQueue << ")";

#ifdef HISTORIC_STATE
LOG( m_logger ) << "HSCT: "
<< m_working.mutableState().mutableHistoricState().getAndResetBlockCommitTime();
#endif
return goodReceipts;
}

Expand Down
1 change: 1 addition & 0 deletions libethereum/SkaleHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro
skaledTimeFinish - skaledTimeStart )
.count();
}

latestBlockTime = skaledTimeFinish;
LOG( m_debugLogger ) << "Successfully imported " << n_succeeded << " of " << out_txns.size()
<< " transactions";
Expand Down
22 changes: 13 additions & 9 deletions libevm/LegacyVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,25 +231,29 @@ void LegacyVM::interpretCases() {
//

CASE( CREATE2 ) {
// for CREATE and CREATE2 we call ON_OP in caseCreate, since it calculates
// correct gas cost
// ON_OP();
if ( !m_schedule->haveCreate2 )
if ( !m_schedule->haveCreate2 ) {
ON_OP();
throwBadInstruction();
if ( m_ext->staticCall )
}
if ( m_ext->staticCall ) {
ON_OP();
throwDisallowedStateChange();
}

// for CREATE and CREATE2 we call ON_OP in caseCreate, since it calculates
// correct gas cost
m_bounce = &LegacyVM::caseCreate;
}
BREAK

CASE( CREATE ) {
// for CREATE and CREATE2 we call ON_OP in caseCreate, since it calculates
// correct gas cost
// ON_OP();
if ( m_ext->staticCall )
if ( m_ext->staticCall ) {
ON_OP();
throwDisallowedStateChange();
}

// for CREATE and CREATE2 we call ON_OP in caseCreate, since it calculates
// correct gas cost
m_bounce = &LegacyVM::caseCreate;
}
BREAK
Expand Down
3 changes: 1 addition & 2 deletions libhistoric/AlethExecutive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,7 @@ bool AlethExecutive::go( OnOpFunc const& _onOp ) {
throw;
#ifdef HISTORIC_STATE
} catch ( VMTracingError const& _e ) {
cwarn << "Tracing error: " << *boost::get_error_info< errinfo_evmcStatusCode >( _e )
<< ")";
cerr << "VM tracing error:" << _e.message;
revert();
throw;
#endif
Expand Down
4 changes: 2 additions & 2 deletions libhistoric/AlethStandardTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ void AlethStandardTrace::setTopFunctionCall(

void AlethStandardTrace::recordFunctionReturned(
evmc_status_code _status, const vector< uint8_t >& _returnData, uint64_t _gasUsed ) {
STATE_CHECK( getLastOpRecord()->m_gasRemaining >= getLastOpRecord()->m_opGas )
// note that m_gas remaining can be less than m_opGas. This happens in case
// of out of gas revert
STATE_CHECK( m_currentlyExecutingFunctionCall )
STATE_CHECK( !m_isFinalized )

Expand Down Expand Up @@ -348,7 +349,6 @@ shared_ptr< OpExecutionRecord > AlethStandardTrace::createOpExecutionRecord( uin
opName = "KECCAK256";
}


auto executionRecord = std::make_shared< OpExecutionRecord >( ext.depth, _inst,
( uint64_t ) _gasRemaining, ( uint64_t ) _gasOpGas, _pc, ext.sub.refunds, opName );

Expand Down
7 changes: 7 additions & 0 deletions libhistoric/CallTracePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ void CallTracePrinter::printContractTransactionTrace(
// call trace on the top Solidity function call in the stack
// this will also recursively call printTrace on nested calls if exist
topFunctionCall->printTrace( _jsonTrace, _statePost, 0, m_trace.getOptions() );

// for the top function the gas limit that geth prints is the transaction gas limit
// and not the gas limit given to the top level function, which is smaller because of 21000
// transaction cost and potentially eth transfer cost
_jsonTrace["gas"] =
AlethStandardTrace::toGethCompatibleCompactHexPrefixed( m_trace.getGasLimit() );

// handle the case of a transaction that deploys a contract
// in this case geth prints transaction input data as input
// end prints to as newly created contract address
Expand Down
13 changes: 12 additions & 1 deletion libhistoric/HistoricState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ HistoricState::HistoricState( HistoricState const& _s )
m_unchangedCacheEntries( _s.m_unchangedCacheEntries ),
m_nonExistingAccountsCache( _s.m_nonExistingAccountsCache ),
m_unrevertablyTouched( _s.m_unrevertablyTouched ),
m_accountStartNonce( _s.m_accountStartNonce ) {}
m_accountStartNonce( _s.m_accountStartNonce ),
m_totalTimeSpentInStateCommitsPerBlock( _s.m_totalTimeSpentInStateCommitsPerBlock ) {}

OverlayDB HistoricState::openDB(
fs::path const& _basePath, h256 const& _genesisHash, WithExisting _we ) {
Expand Down Expand Up @@ -137,6 +138,7 @@ HistoricState& HistoricState::operator=( HistoricState const& _s ) {
m_nonExistingAccountsCache = _s.m_nonExistingAccountsCache;
m_unrevertablyTouched = _s.m_unrevertablyTouched;
m_accountStartNonce = _s.m_accountStartNonce;
m_totalTimeSpentInStateCommitsPerBlock = _s.m_totalTimeSpentInStateCommitsPerBlock;
return *this;
}

Expand Down Expand Up @@ -194,11 +196,20 @@ void HistoricState::clearCacheIfTooLarge() const {
}

void HistoricState::commitExternalChanges( AccountMap const& _accountMap ) {
auto historicStateStart = dev::db::LevelDB::getCurrentTimeMs();
commitExternalChangesIntoTrieDB( _accountMap, m_state );
m_state.db()->commit();
m_changeLog.clear();
m_cache.clear();
m_unchangedCacheEntries.clear();
auto historicStateFinish = dev::db::LevelDB::getCurrentTimeMs();
m_totalTimeSpentInStateCommitsPerBlock += historicStateFinish - historicStateStart;
}

uint64_t HistoricState::getAndResetBlockCommitTime() {
uint64_t retVal = m_totalTimeSpentInStateCommitsPerBlock;
m_totalTimeSpentInStateCommitsPerBlock = 0;
return retVal;
}


Expand Down
4 changes: 4 additions & 0 deletions libhistoric/HistoricState.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ class HistoricState {

void setRootFromDB();

uint64_t getAndResetBlockCommitTime();

private:
/// Turns all "touched" empty accounts into non-alive accounts.
void removeEmptyAccounts();
Expand Down Expand Up @@ -345,6 +347,8 @@ class HistoricState {

AddressHash commitExternalChangesIntoTrieDB(
AccountMap const& _cache, SecureTrieDB< Address, OverlayDB >& _state );

uint64_t m_totalTimeSpentInStateCommitsPerBlock = 0;
};

std::ostream& operator<<( std::ostream& _out, HistoricState const& _s );
Expand Down
157 changes: 157 additions & 0 deletions test/historicstate/hardhat/contracts/Erc20Custom.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
// SPDX-License-Identifier: AGPL-3.0-only

/**
* ERC20Custom.sol - SKALE Test tokens
* Copyright (C) 2022-Present SKALE Labs
* @author Artem Payvin
*
* SKALE IMA is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SKALE IMA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with SKALE IMA. If not, see <https://www.gnu.org/licenses/>.
*/

pragma solidity ^0.8.20;

contract ERC20Custom {

mapping (address => uint256) private _balances;

mapping (address => mapping (address => uint256)) private _allowances;

uint256 private _totalSupply;

string private _name;
string private _symbol;
uint8 private _decimals;

event Approval(address owner, address spender, uint256 amount);

event Transfer(address from, address to, uint256 amount);

constructor(string memory tokenName, string memory tokenSymbol) {
_name = tokenName;
_symbol = tokenSymbol;
_decimals = 18;

_mint(tx.origin, 10);
}

function mint(address account, uint256 amount) external returns (bool) {
_mint(account, amount);
return true;
}

/**
* @dev burn - destroys token on msg sender
*
* NEED TO HAVE THIS FUNCTION ON SKALE-CHAIN
*
* @param amount - amount of tokens
*/
function burn(uint256 amount) external {
_burn(msg.sender, amount);
}

function name() public view returns (string memory) {
return _name;
}

function symbol() public view returns (string memory) {
return _symbol;
}

function decimals() public view returns (uint8) {
return _decimals;
}

function totalSupply() public view returns (uint256) {
return _totalSupply;
}

function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}

function transfer(address recipient, uint256 amount) public virtual returns (bool) {
this._transfer1();
return true;
}

function allowance(address owner, address spender) public view virtual returns (uint256) {
return _allowances[owner][spender];
}

function approve(address spender, uint256 amount) public virtual returns (bool) {
_approve(msg.sender, spender, amount);
return true;
}

function transferFrom(address sender, address recipient, uint256 amount) public virtual returns (bool) {
_transfer(sender, recipient, amount);
_approve(
sender,
msg.sender,
_allowances[sender][msg.sender] - amount
);
return true;
}

function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender] + addedValue);
return true;
}

function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(
msg.sender,
spender,
_allowances[msg.sender][spender] - subtractedValue
);
return true;
}

function _transfer1() public {
}

function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");

_balances[sender] = _balances[sender] - amount;
_balances[recipient] = _balances[recipient] + amount;
emit Transfer(sender, recipient, amount);
}

function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");

_totalSupply = _totalSupply + amount;
_balances[account] = _balances[account] + amount;
emit Transfer(address(0), account, amount);
}

function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");

_balances[account] = _balances[account] - amount;
_totalSupply = _totalSupply - amount;
emit Transfer(account, address(0), amount);
}

function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");

_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
}
2 changes: 1 addition & 1 deletion test/historicstate/hardhat/run_geth.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def add_ether_to_account(address, amount):
return

# Unlock the default account (coinbase)
coinbase = w3.eth.coinbase
coinbase = w3.eth.accounts[0]
w3.geth.personal.unlock_account(coinbase, '', 0)

# Convert Ether to Wei
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"calls": [
{
"error": "out of gas",
"from": "ERC20Custom.address",
"gas": "0x51",
"gasUsed": "0x30d",
"input": "0x53bb9b8a",
"to": "ERC20Custom.address",
"type": "CALL"
}
],
"error": "out of gas",
"from": "OWNER.address",
"gas": "0x6239",
"gasUsed": "0x6239",
"input": "0xa9059cbb000000000000000000000000ce5c7ca85f8cb94fa284a303348ef42add23f5e70000000000000000000000000000000000000000000000000000000000000001",
"to": "ERC20Custom.address",
"type": "CALL",
"value": "0x0"
}
Loading
Loading