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

Add apply_discount_factor to gas_parameters #15

Merged
merged 10 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .cicd/defaults.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{

}
5 changes: 5 additions & 0 deletions .cicd/platforms.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"ubuntu22": {
"dockerfile": ".cicd/platforms/ubuntu22.Dockerfile"
}
}
9 changes: 9 additions & 0 deletions .cicd/platforms/ubuntu22.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM ubuntu:jammy
ENV TZ="America/New_York"
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get upgrade -y && \
apt-get install -y build-essential \
cmake \
gcc-11 \
g++-11 \
git
26 changes: 26 additions & 0 deletions .github/workflows/build-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
set -eo pipefail

# print and run a command
function ee()
{
echo "$ $*"
eval "$@"
}

# debug code
echo "CC='${CC}'"
echo "CXX='${CXX}'"
ee cmake --version

# build
ee mkdir build
ee pushd build
ee cmake -DEVMONE_TESTING=ON -DBUILD_SHARED_LIBS=OFF ..
ee make -j "$(nproc)"

# pack
ee popd
ee 'tar -czf build.tar.gz build/bin/*'

echo "Done! - ${0##*/}"
53 changes: 53 additions & 0 deletions .github/workflows/evmone.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# EOS EVM evmone CI
This GitHub Actions workflow builds all emvone modules

### Index
1. [Triggers](#triggers)
1. [Inputs](#inputs)
1. [Steps](#steps)
1. [Outputs](#outputs)
1. [See Also](#see-also)

## Triggers
This GitHub action will run under the following circumstances:
1. When code is pushed.
1. Workflow dispatch event, a manual CI run, which can be triggered by the "Workflow Dispatch" button in the Actions tab of the GitHub repository, among other means.

## Inputs
The inputs for this GitHub action are:
1. `GITHUB_TOKEN` - a GitHub Actions intrinsic used to access the repository and other public resources.
1. `TRUSTEVM_CI_APP_ID` - the app ID of the `trustevm-ci-submodule-checkout` GitHub App.
1. `TRUSTEVM_CI_APP_KEY` - the private key to the `trustevm-ci-submodule-checkout` GitHub App.
1. `upload-artifacts` - a boolean input that specifies whether or not to upload the artifacts of the build. The default value is `false`. This can be overridden in manual CI runs.

These inputs are used in various steps of the workflow to perform actions such as authentication, downloading artifacts, configuring the build, and uploading artifacts.

## Steps
This workflow performs the following steps:
1. Attach Documentation
1. Checkout the repo with no submodules.
1. Attach an annotation to the GitHub Actions build summary page containing CI documentation.
1. EOS EVM Siklworm Build
1. Authenticate to the `trustevm-ci-submodule-checkout` GitHub app using the [AntelopeIO/github-app-token-action](https://github.com/AntelopeIO/github-app-token-action) action to obtain an ephemeral token.
1. Checkout the repo and submodules using the ephemeral token.
1. Build using `cmake` and `make`.
1. Upload the test binaries to GitHub Actions if the `upload-artifacts` input is set to `true`.

## Outputs
This workflow produces the following outputs:
1. Build Artifacts - `build.tar.gz` containing the built artifacts of unit tests of the evmone project, if the `upload-artifacts` input is set to `true`. Note that only tests are included as we do not really care about other binaries for this repo.

> 💾️ Build artifacts are only attached on-demand for this pipeline because they are >117 MB each, but we only get 2 GB of cumulative artifact storage in GitHub Actions while eos-evm is a private repo. Obtain artifacts by performing a manual build with `upload-artifacts` set to `true`.

## See Also
- [github-app-token-action](https://github.com/AntelopeIO/github-app-token-action) GitHub action
- [EOS EVM Documentation](../../README.md)

For assistance with the CI system, please open an issue in this repo or reach out in the `#help-automation` channel via IM.

***
**_Legal notice_**
This document was generated in collaboration with ChatGPT from OpenAI, a machine learning algorithm or weak artificial intelligence (AI). At the time of this writing, the [OpenAI terms of service agreement](https://openai.com/terms) §3.a states:
> Your Content. You may provide input to the Services (“Input”), and receive output generated and returned by the Services based on the Input (“Output”). Input and Output are collectively “Content.” As between the parties and to the extent permitted by applicable law, you own all Input, and subject to your compliance with these Terms, OpenAI hereby assigns to you all its right, title and interest in and to Output.

This notice is required in some countries.
143 changes: 143 additions & 0 deletions .github/workflows/evmone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
name: EOS EVM evmone CI

on:
push:
branches:
- main
- release/*
pull_request:
workflow_dispatch:

defaults:
run:
shell: bash

jobs:
documentation:
name: Attach Documentation
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
with:
fetch-depth: 1
submodules: 'false'

- name: Attach Documentation
run: cat .github/workflows/evmone.md >> $GITHUB_STEP_SUMMARY

d:
name: Discover Platforms
runs-on: ubuntu-latest
outputs:
missing-platforms: ${{steps.discover.outputs.missing-platforms}}
p: ${{steps.discover.outputs.platforms}}
steps:
- name: Discover Platforms
id: discover
uses: AntelopeIO/discover-platforms-action@v1
with:
platform-file: .cicd/platforms.json
password: ${{secrets.GITHUB_TOKEN}}
package-name: builders-evmone

build-platforms:
name: Build Platforms
needs: d
if: needs.d.outputs.missing-platforms != '[]'
strategy:
fail-fast: false
matrix:
platform: ${{fromJSON(needs.d.outputs.missing-platforms)}}
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Login to Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{github.repository_owner}}
password: ${{secrets.GITHUB_TOKEN}}
- name: Build and push
uses: docker/build-push-action@v3
with:
push: true
tags: ${{fromJSON(needs.d.outputs.p)[matrix.platform].image}}
file: ${{fromJSON(needs.d.outputs.p)[matrix.platform].dockerfile}}

build:
name: EOS EVM evmone Build
needs: [d, build-platforms]
if: always() && needs.d.result == 'success' && (needs.build-platforms.result == 'success' || needs.build-platforms.result == 'skipped')
strategy:
fail-fast: false
matrix:
platform: [ ubuntu22 ]
runs-on: ubuntu-latest
container: ${{fromJSON(needs.d.outputs.p)[matrix.platform].image}}

steps:
- name: Checkout Repo
uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: 'recursive'
token: ${{secrets.GITHUB_TOKEN}}

- name: Build EOS EVM evmone
run: .github/workflows/build-tests.sh
env:
CC: gcc-11
CXX: g++-11

- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: build.tar.gz
path: build.tar.gz

unit-test:
name: EOS EVM evmone Unit Tests
needs: [d, build]
if: always() && needs.d.result == 'success' && needs.build.result == 'success'
strategy:
fail-fast: false
matrix:
platform: [ ubuntu22 ]
runs-on: ubuntu-latest
container: ${{fromJSON(needs.d.outputs.p)[matrix.platform].image}}
env:
CC: gcc-11
CXX: g++-11
DCMAKE_BUILD_TYPE: 'Release'

steps:
- name: Update Package Index & Upgrade Packages
run: |
apt-get update
apt-get upgrade -y
apt update
apt upgrade -y

- name: Download EOS EVM evmone builddir
uses: actions/download-artifact@v3
with:
name: build.tar.gz

- name: Extract EOS EVM evmone builddir
id: evm-evmone-build
run: |
mkdir evmone
mv build.tar.gz evmone/
pushd evmone
tar xvf build.tar.gz
pushd build
echo "EVM_EVMONE_BUILD=$(pwd)" >> "$GITHUB_OUTPUT"
popd

- name: Test evmone
run: |
cd ${{ steps.evm-evmone-build.outputs.EVM_EVMONE_BUILD }}/bin/
./evmone-unittests
28 changes: 19 additions & 9 deletions lib/evmone/execution_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ struct gas_parameters {
uint64_t G_codedeposit = 200;
uint64_t G_sset = 20000;

static gas_parameters apply_discount_factor(const intx::uint256& factor_num, const intx::uint256& factor_den, const evmone::gas_parameters& g) {
gas_parameters out;
out.G_txnewaccount = static_cast<uint64_t>((factor_num*g.G_txnewaccount)/factor_den);
out.G_newaccount = static_cast<uint64_t>((factor_num*g.G_newaccount)/factor_den);
out.G_txcreate = static_cast<uint64_t>((factor_num*g.G_txcreate)/factor_den);
out.G_codedeposit = static_cast<uint64_t>((factor_num*g.G_codedeposit)/factor_den);
out.G_sset = static_cast<uint64_t>((factor_num*g.G_sset)/factor_den);
return out;
}

const storage_cost_t& get_storage_cost(uint64_t version) {
if(!storage_cost.has_value()) {
storage_cost = generate_storage_cost_table(version);
Expand All @@ -162,7 +172,7 @@ struct gas_parameters {
storage_cost_t st;
if( version >= 3) {
int64_t cpu_gas_to_change_slot = reset - warm_access; //cpu cost of adding or removing or mutating a slot in the db
int64_t storage_gas_to_add_slot = set - reset; //storage cost of adding a new slot into the db
int64_t storage_gas_to_add_slot = set; //storage cost of adding a new slot into the db

st[EVMC_STORAGE_ASSIGNED] = { 0, 0};
st[EVMC_STORAGE_ADDED] = { cpu_gas_to_change_slot, storage_gas_to_add_slot};
Expand Down Expand Up @@ -223,8 +233,8 @@ struct gas_state_t {
int64_t apply_storage_gas_delta(int64_t storage_gas_delta){
if (eos_evm_version_ >= 3) {
int64_t d = storage_gas_delta - storage_gas_refund_;
storage_gas_refund_ = std::max(-d, 0l);
const auto gas_consumed = std::max(d, 0l);
storage_gas_refund_ = std::max(-d, int64_t{0});
const auto gas_consumed = std::max(d, int64_t{0});
storage_gas_consumed_ += gas_consumed;
return gas_consumed;
}
Expand All @@ -234,8 +244,8 @@ struct gas_state_t {
int64_t apply_speculative_cpu_gas_delta(int64_t cpu_gas_delta) {
if (eos_evm_version_ >= 3) {
int64_t d = cpu_gas_delta - cpu_gas_refund_;
cpu_gas_refund_ = std::max(-d, 0l);
const auto gas_consumed = std::max(d, 0l);
cpu_gas_refund_ = std::max(-d, int64_t{0});
const auto gas_consumed = std::max(d, int64_t{0});
speculative_cpu_gas_consumed_ += gas_consumed;
return gas_consumed;
}
Expand All @@ -262,13 +272,13 @@ struct gas_state_t {
int64_t collapse() {
const auto s = std::min(storage_gas_consumed_, storage_gas_refund_);
const auto x = storage_gas_consumed_ - storage_gas_refund_;
storage_gas_consumed_ = std::max(x, 0l);
storage_gas_refund_ = std::max(-x, 0l);
storage_gas_consumed_ = std::max(x, int64_t{0});
storage_gas_refund_ = std::max(-x, int64_t{0});

const auto c = std::min(speculative_cpu_gas_consumed_, cpu_gas_refund_);
const auto y = speculative_cpu_gas_consumed_ - cpu_gas_refund_;
speculative_cpu_gas_consumed_ = std::max(y, 0l);
cpu_gas_refund_ = std::max(-y, 0l);
speculative_cpu_gas_consumed_ = std::max(y, int64_t{0});
cpu_gas_refund_ = std::max(-y, int64_t{0});

return s + c;
}
Expand Down
Loading
Loading