Skip to content

Commit

Permalink
Merge pull request #380 from eosnetworkfoundation/elmato/perf-test
Browse files Browse the repository at this point in the history
Add scripts to measure EVM contract performance
  • Loading branch information
elmato authored Jun 10, 2023
2 parents 7d5695a + 022ce9c commit ad3ae54
Show file tree
Hide file tree
Showing 14 changed files with 2,501 additions and 1,401 deletions.
1 change: 1 addition & 0 deletions contract/src/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ void evm_contract::pushtx( eosio::name miner, const bytes& rlptx ) {

engine.finalize(ep.state(), ep.evm().block(), ep.evm().revision());
ep.state().write_to_db(ep.evm().block().header.number);
LOGTIME("EVM END");
}

void evm_contract::open(eosio::name owner) {
Expand Down
11 changes: 11 additions & 0 deletions tests/leap/nodeos_eos_evm_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@
# producer nodes will be mapped to 0 through totalProducerNodes-1, so the number totalProducerNodes will be the non-producing node
specificExtraNodeosArgs[totalProducerNodes]="--plugin eosio::test_control_api_plugin "
extraNodeosArgs="--contracts-console"
if useEosVmOC:
extraNodeosArgs += " --wasm-runtime eos-vm-jit --eos-vm-oc-enable"

Print("Stand up cluster")
if cluster.launch(topo="bridge", pnodes=totalProducerNodes,
Expand Down Expand Up @@ -410,6 +412,15 @@ def forward_request(req):
"jsonrpc": "2.0",
"result": '0x'+keccak(unhexlify(req['params'][0][2:])).hex()
}

if req['method'] == "eth_gasPrice":
gas_price=int(prodNode1.getTable(evmAcc.name, evmAcc.name, "config")['rows'][0]['gas_price'])
return {
"id": req['id'],
"jsonrpc": "2.0",
"result": f'{gas_price:#0x}'
}

return requests.post(readEndpoint, json.dumps(req), headers={"Content-Type":"application/json"}).json()

request_data = request.get_json()
Expand Down
144 changes: 144 additions & 0 deletions tests/leap/nodeos_eos_evm_server/PERFORMANCE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# Mesuring EVM contract performance

### Create working folder
```
mkdir ~/evmperf
cd ~/evmperf
```


### Build EVM contract
_set stack-size in src/CMakeList.txt to_ **16384** _before building_

```
cd ~/evmperf
git clone https://github.com/eosnetworkfoundation/eos-evm
cd eos-evm/contract
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DWITH_LOGTIME=ON ..
make -j4
```

### Build eos-evm-node and eos-evm-rpc
```
cd ~/evmperf/eos-evm
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j4 eos-evm-node eos-evm-rpc
```


### Build leap v3.2.2-logtime
```
cd ~/evmperf
git clone https://github.com/elmato/leap
cd leap
git checkout v3.2.2-logtime
git submodules update --init --recursive
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j4
```

### Setup nodeos_eos_evm_server.py python env
```
cd ~/evmperf/leap/build/tests
ln -s ~/evmperf/eos-evm/tests/leap/nodeos_eos_evm_server.py nodeos_eos_evm_server.py
sed -i 's/SYS/EOS/g' core_symbol.py
python3 -m venv venv
source venv/bin/activate
pip install 'web3<6' flask flask-cors
```


### Launch nodeos and deploy EVM contract
_use --use-eos-vm-oc=1 when launching **nodeos_eos_evm_server.py** if you want to measure OC performance_

```
cd ~/evmperf/leap/build/tests
source venv/bin/activate
cd ..
./tests/nodeos_eos_evm_server.py --leave-running --eos-evm-contract-root ~/evmperf/eos-evm/contract/build
```

(_wait until nodeos_eos_evm_server start listening at localhost:5000_)

### Launch eos-evm-node
```
cd ~/evmperf/eos-evm/build/cmd
rm -rf chaindata etl-temp config-dir
./eos-evm-node --plugin=blockchain_plugin --ship-endpoint=127.0.0.1:8999 --genesis-json=$HOME/evmperf/leap/build/eos-evm-genesis.json --verbosity=4
```

### Launch eos-evm-rpc
```
cd ~/evmperf/eos-evm/build/cmd
./eos-evm-rpc --eos-evm-node=127.0.0.1:8080 --http-port=0.0.0.0:8881 --chaindata=./ --api-spec=eth,debug,net,trace --verbosity=4
```

### Install scripts dependencies
```
cd ~/evmperf/eos-evm/tests/leap/nodeos_eos_evm_server
yarn install
```


### Deploy Uniswap V2
```
cd ~/evmperf/eos-evm/tests/leap/nodeos_eos_evm_server
npx hardhat run scripts/deploy-uniswap.js
```

### Deploy Recursive contract
```
cd ~/evmperf/eos-evm/tests/leap/nodeos_eos_evm_server
npx hardhat run scripts/deploy-recursive.js
```

### Allow Uniswap router to transfer AAA tokens
```
cd ~/evmperf/eos-evm/tests/leap/nodeos_eos_evm_server
npx hardhat approve --erc20 0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9 --router 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 --amount 10000
```

### Tail logs _(separate console)_
```
cd ~/evmperf/eos-evm/tests/leap/nodeos_eos_evm_server
./extract-logtime-cmd.sh ~/evmperf/leap/build/var/lib/node_01/stderr.txt
```

### Execute AAA=>BBB swaps
```
while true
do
npx hardhat swap --router 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 --path 0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9,0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9 --amount 0.5
done
```

### Execute AAA=>BBB=>CCC swaps
```
while true
do
npx hardhat swap --router 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 --path 0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9,0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9,0x5FC8d32690cc91D4c39d9d3abcBD16989F875707 --amount 0.5
done
```

### Execute erc20 transfers
```
while true
do
npx hardhat transfer --from 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --to 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 --contract 0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9 --amount 0.1
done
```

### Execute native transfers
```
while true
do
npx hardhat native-transfer --from 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --to 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 --amount 1
done
```
13 changes: 13 additions & 0 deletions tests/leap/nodeos_eos_evm_server/contracts/Recursive.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;

contract Recursive {

event Call(uint256 _value);
function start(uint256 _depth) public {
emit Call(_depth);
if( _depth == 0 )
return;
Recursive(this).start(_depth-1);
}
}
3 changes: 1 addition & 2 deletions tests/leap/nodeos_eos_evm_server/contracts/Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ pragma solidity >=0.7.0 <0.9.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract Token is ERC20 {

constructor () ERC20("Yuniper", "YUN") {
constructor (string memory _name, string memory _symbol) ERC20(_name, _symbol) {
_mint(msg.sender, 1000000 * (10 ** uint256(decimals())));
}
}
Loading

0 comments on commit ad3ae54

Please sign in to comment.