Jordan Hrycaj 261c0b51a7
Redesign of BaseVMState descriptor (#923)
* Redesign of BaseVMState descriptor

why:
  BaseVMState provides an environment for executing transactions. The
  current descriptor also provides data that cannot generally be known
  within the execution environment, e.g. the total gasUsed which is
  available not before after all transactions have finished.

  Also, the BaseVMState constructor has been replaced by a constructor
  that does not need pre-initialised input of the account database.

also:
  Previous constructor and some fields are provided with a deprecated
  annotation (producing a lot of noise.)

* Replace legacy directives in production sources

* Replace legacy directives in unit test sources

* fix CI (missing premix update)

* Remove legacy directives

* chase CI problem

* rebased

* Re-introduce 'AccountsCache' constructor optimisation for 'BaseVmState' re-initialisation

why:
  Constructing a new 'AccountsCache' descriptor can be avoided sometimes
  when the current state root is properly positioned already. Such a
  feature existed already as the update function 'initStateDB()' for the
  'BaseChanDB' where the accounts cache was linked into this desctiptor.

  The function 'initStateDB()' was removed and re-implemented into the
  'BaseVmState' constructor without optimisation. The old version was of
  restricted use as a wrong accounts cache state would unconditionally
  throw an exception rather than conceptually ask for a remedy.

  The optimised 'BaseVmState' re-initialisation has been implemented for
  the 'persistBlocks()' function.

also:
  moved some test helpers to 'test/replay' folder

* Remove unused & undocumented fields from Chain descriptor

why:
  Reduces attack surface in general & improves reading the code.
2022-01-18 16:19:32 +00:00

298 lines
10 KiB
YAML

name: CI
on:
push:
paths-ignore: ['doc/**', 'docs/**', '**/*.md', 'hive_integration/**',
'fluffy/**', '.github/workflows/fluffy.yml']
# Disable `pull_request`. Experimenting with using only `push` for PRs.
#pull_request:
# paths-ignore: ['doc/**', 'docs/**', '**/*.md', 'hive_integration/**']
workflow_dispatch:
jobs:
build:
strategy:
fail-fast: false
max-parallel: 20
matrix:
target:
- os: linux
cpu: amd64
evmc: nimevm
- os: linux
cpu: i386
evmc: nimevm
- os: macos
cpu: amd64
evmc: nimevm
- os: windows
cpu: amd64
evmc: nimevm
- os: windows
cpu: i386
evmc: nimevm
- os: linux
cpu: amd64
evmc: evmc
- os: linux
cpu: i386
evmc: evmc
- os: macos
cpu: amd64
evmc: evmc
- os: windows
cpu: amd64
evmc: evmc
- os: windows
cpu: i386
evmc: evmc
# vm2
- os: linux
cpu: amd64
evmc: nimvm2
- os: linux
cpu: i386
evmc: nimvm2
- os: windows
cpu: amd64
evmc: nimvm2
- os: windows
cpu: i386
evmc: nimvm2
- os: macos
cpu: amd64
evmc: nimvm2
include:
- target:
os: linux
builder: ubuntu-18.04
shell: bash
- target:
os: macos
builder: macos-10.15
shell: bash
- target:
os: windows
builder: windows-latest
shell: msys2 {0}
defaults:
run:
shell: ${{ matrix.shell }}
name: '${{ matrix.target.os }}-${{ matrix.target.cpu }}-${{ matrix.target.evmc }}'
runs-on: ${{ matrix.builder }}
steps:
- name: Checkout nimbus-eth1
uses: actions/checkout@v2
- name: Derive environment variables
shell: bash
run: |
if [[ '${{ matrix.target.cpu }}' == 'amd64' ]]; then
PLATFORM=x64
GOARCH=amd64
USE_MIRACL=0
else
PLATFORM=x86
GOARCH=386
USE_MIRACL=1
fi
echo "PLATFORM=${PLATFORM}" >> $GITHUB_ENV
echo "GOARCH=${GOARCH}" >> $GITHUB_ENV
echo "USE_MIRACL=${USE_MIRACL}" >> $GITHUB_ENV
# libminiupnp / natpmp
if [[ '${{ runner.os }}' == 'Linux' && '${{ matrix.target.cpu }}' == 'i386' ]]; then
export CFLAGS="${CFLAGS} -m32 -mno-adx"
echo "CFLAGS=${CFLAGS}" >> $GITHUB_ENV
fi
ncpu=''
case '${{ runner.os }}' in
'Linux')
ncpu=$(nproc)
;;
'macOS')
ncpu=$(sysctl -n hw.ncpu)
;;
'Windows')
ncpu=${NUMBER_OF_PROCESSORS}
;;
esac
[[ -z "$ncpu" || $ncpu -le 0 ]] && ncpu=1
echo "ncpu=${ncpu}" >> $GITHUB_ENV
if [[ '${{ matrix.target.evmc }}' == 'evmc' ]]; then
echo "ENABLE_EVMC=1" >> $GITHUB_ENV
echo "ENABLE_VM2=0" >> $GITHUB_ENV
elif [[ '${{ matrix.target.evmc }}' == 'nimvm2' ]]; then
echo "ENABLE_EVMC=0" >> $GITHUB_ENV
echo "ENABLE_VM2=1" >> $GITHUB_ENV
case '${{ matrix.target.cpu }}:${{ runner.os }}' in
'i386:Windows')
# on a real win7/i386, there is only 64k optimiser space for gcc
echo "ENABLE_VM2LOWMEM=1" >> $GITHUB_ENV
esac
else
echo "ENABLE_EVMC=0" >> $GITHUB_ENV
echo "ENABLE_VM2=0" >> $GITHUB_ENV
fi
- name: Install build dependencies (Linux i386)
if: runner.os == 'Linux' && matrix.target.cpu == 'i386'
run: |
sudo dpkg --add-architecture i386
sudo apt-fast update -qq
sudo DEBIAN_FRONTEND='noninteractive' apt-fast install \
--no-install-recommends -yq gcc-multilib g++-multilib \
libz-dev:i386 libbz2-dev:i386 libssl-dev:i386 libpcre3-dev:i386
mkdir -p external/bin
cat << EOF > external/bin/gcc
#!/bin/bash
exec $(which gcc) -m32 "\$@"
EOF
cat << EOF > external/bin/g++
#!/bin/bash
exec $(which g++) -m32 "\$@"
EOF
chmod 755 external/bin/gcc external/bin/g++
echo '${{ github.workspace }}/external/bin' >> $GITHUB_PATH
- name: Restore rocksdb from cache (Macos/Linux)
if: runner.os != 'Windows'
id: rocksdb-cache
uses: actions/cache@v1
with:
path: rocks-db-cache-${{ matrix.target.cpu }}
key: 'rocksdb-v2-${{ matrix.target.os }}-${{ matrix.target.cpu }}'
- name: Build and install rocksdb (Linux i386)
# no librocksdb-dev:i386
if: runner.os == 'Linux' && matrix.target.cpu == 'i386'
run: |
curl -O -L -s -S https://raw.githubusercontent.com/status-im/nimbus-build-system/master/scripts/build_rocksdb.sh
bash build_rocksdb.sh rocks-db-cache-${{ matrix.target.cpu }}
- name: Install rocksdb (Linux amd64)
# mysterious illegal instruction error if we build our own librocksdb
if: runner.os == 'Linux' && matrix.target.cpu == 'amd64'
run: |
sudo apt-get -q update
sudo apt-get install -y librocksdb-dev libpcre3-dev
- name: Build and install rocksdb (Macos)
if: runner.os == 'Macos'
run: |
HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 brew install ccache
echo "/usr/local/opt/ccache/libexec" >> ${GITHUB_PATH}
curl -O -L -s -S https://raw.githubusercontent.com/status-im/nimbus-build-system/master/scripts/build_rocksdb.sh
bash build_rocksdb.sh rocks-db-cache-${{ matrix.target.cpu }}
- name: MSYS2 (Windows i386)
if: runner.os == 'Windows' && matrix.target.cpu == 'i386'
uses: msys2/setup-msys2@v2
with:
path-type: inherit
msystem: MINGW32
install: >-
base-devel
git
mingw-w64-i686-toolchain
- name: MSYS2 (Windows amd64)
if: runner.os == 'Windows' && matrix.target.cpu == 'amd64'
uses: msys2/setup-msys2@v2
with:
path-type: inherit
install: >-
base-devel
git
mingw-w64-x86_64-toolchain
- name: Restore Nim DLLs dependencies (Windows) from cache
if: runner.os == 'Windows'
id: windows-dlls-cache
uses: actions/cache@v2
with:
path: external/dlls-${{ matrix.target.cpu }}
# according to docu, idle caches are kept for up to 7 days
# so change dlls# to force new cache contents (for some number #)
key: dlls0-${{ matrix.target.cpu }}
- name: Install DLLs dependencies (Windows)
if: >
steps.windows-dlls-cache.outputs.cache-hit != 'true' &&
runner.os == 'Windows'
run: |
if [[ '${{ matrix.target.cpu }}' == 'amd64' ]]; then
ROCKSDBSUB=x64
else
ROCKSDBSUB=x86
fi
DLLPATH=external/dlls-${{ matrix.target.cpu }}
mkdir -p external
curl -L "https://nim-lang.org/download/windeps.zip" -o external/windeps.zip
7z x -y external/windeps.zip -o"$DLLPATH"
# ROCKSDB
curl -L "https://github.com/status-im/nimbus-deps/releases/download/nimbus-deps/nimbus-deps.zip" -o external/nimbus-deps.zip
7z x -y external/nimbus-deps.zip
cp "./$ROCKSDBSUB/librocksdb.dll" "$DLLPATH/librocksdb.dll"
- name: Path to cached dependencies (Windows)
if: >
runner.os == 'Windows'
run: |
echo '${{ github.workspace }}'"/external/dlls-${{ matrix.target.cpu }}" >> $GITHUB_PATH
- name: Get latest nimbus-build-system commit hash
id: versions
run: |
getHash() {
git ls-remote "https://github.com/$1" "${2:-HEAD}" | cut -f 1
}
nbsHash=$(getHash status-im/nimbus-build-system)
echo "::set-output name=nimbus_build_system::$nbsHash"
- name: Restore prebuilt Nim from cache
id: nim-cache
uses: actions/cache@v2
with:
path: NimBinaries
key: 'nim-${{ matrix.target.os }}-${{ matrix.target.cpu }}-${{ steps.versions.outputs.nimbus_build_system }}'
- name: Build Nim and Nimbus-eth1 dependencies
run: |
make -j${ncpu} ARCH_OVERRIDE=${PLATFORM} CI_CACHE=NimBinaries update
- name: Run nimbus-eth1 tests (Windows)
if: runner.os == 'Windows'
run: |
gcc --version
DEFAULT_MAKE_FLAGS="-j${ncpu} ENABLE_EVMC=${ENABLE_EVMC}"
mingw32-make ${DEFAULT_MAKE_FLAGS}
build/nimbus.exe --help
mingw32-make ${DEFAULT_MAKE_FLAGS} test
if [[ '${{ matrix.target.cpu }}' == 'amd64' ]]; then
mingw32-make ${DEFAULT_MAKE_FLAGS} test-reproducibility
fi
- name: Run nimbus-eth1 tests (Linux)
if: runner.os == 'Linux'
run: |
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/local/lib"
DEFAULT_MAKE_FLAGS="-j${ncpu} USE_MIRACL=${USE_MIRACL} ENABLE_EVMC=${ENABLE_EVMC}"
env CC=gcc make ${DEFAULT_MAKE_FLAGS}
build/nimbus --help
# CC, GOARCH, and CGO_ENABLED are needed to select correct compiler 32/64 bit
env CC=gcc GOARCH=${GOARCH} CXX=g++ CGO_ENABLED=1 make ${DEFAULT_MAKE_FLAGS} test test-reproducibility
- name: Run nimbus-eth1 tests (Macos)
if: runner.os == 'Macos'
run: |
DEFAULT_MAKE_FLAGS="-j${ncpu} ENABLE_EVMC=${ENABLE_EVMC}"
make ${DEFAULT_MAKE_FLAGS}
build/nimbus --help
# "-static" option will not work for osx unless static system libraries are provided
make ${DEFAULT_MAKE_FLAGS} test test-reproducibility