Skip to content

Commit

Permalink
Change version label
Browse files Browse the repository at this point in the history
  • Loading branch information
ironbeer committed Aug 26, 2024
2 parents 7076770 + f30864e commit 759f454
Show file tree
Hide file tree
Showing 33 changed files with 1,504 additions and 1,075 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
build/_workspace
build/_bin
tests/testdata
tmp/
166 changes: 62 additions & 104 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,138 +8,96 @@ on:
jobs:
build:
name: Build
strategy:
matrix:
os: [linux]
arch: [amd64, arm64]
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
submodules: true

- name: Set up a Git safe directory
run: git config --global --add safe.directory ${{ github.workspace }}
- name: Setup QEMU
uses: docker/setup-qemu-action@v3

- name: Build Binary - ${{ matrix.os }} ${{ matrix.arch }}
if: matrix.arch == 'amd64'
run: |
docker run --rm -t \
-v ${{ github.workspace }}:${{ github.workspace }} \
-w ${{ github.workspace }} \
-e GOOS=${{ matrix.os }} \
-e GOARCH=${{ matrix.arch }} \
golang:1.20.14-bookworm sh -c "git config --global --add safe.directory ${{ github.workspace }} && make geth"
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build Binary - ${{ matrix.os }} ${{ matrix.arch }}
if: matrix.arch == 'arm64'
run: |
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker run --rm -t \
-v ${{ github.workspace }}:${{ github.workspace }} \
-w ${{ github.workspace }} \
-e GOOS=${{ matrix.os }} \
-e GOARCH=${{ matrix.arch }} \
arm64v8/golang:1.20.14-bookworm sh -c "git config --global --add safe.directory ${{ github.workspace }} && make geth"
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Cache Docker Layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx
restore-keys: ${{ runner.os }}-buildx-

- name: Build and Push
uses: docker/bake-action@v4
env:
REGISTRY: ghcr.io
REPOSITORY: ${{ github.repository }}
GIT_COMMIT: ${{ github.sha }}
GIT_VERSION: ${{ github.ref_name }}
IMAGE_TAGS: ${{ github.ref_name }}
with:
files: docker-bake.hcl
push: true
set: |
*.platform=linux/amd64,linux/arm64
*.cache-from=type=local,src=/tmp/.buildx-cache
*.cache-to=type=local,dest=/tmp/.buildx-cache,mode=max
binaries.output=type=local,dest=./binaries
- name: Check version label
if: matrix.arch == 'amd64'
run: './build/bin/geth version | grep -q "Version: $(echo ${{ github.ref_name }} | cut -c 2-10)"'
run: 'binaries/linux_amd64/geth version | grep -q "Version: $(echo ${{ github.ref_name }} | cut -c 2-10)"'

- name: Compress Binary
run: zip -j geth-${{ github.ref_name }}-${{ matrix.os }}-${{ matrix.arch }}.zip ./build/bin/geth
- name: Compress Binaries
run: |
(cd binaries/linux_amd64 && zip -q - geth) > geth-${{ github.ref_name }}-linux-amd64.zip
(cd binaries/linux_arm64 && zip -q - geth) > geth-${{ github.ref_name }}-linux-arm64.zip
- name: Create genesis.zip
run: zip -r genesis.zip genesis

- name: Upload Artifact
uses: actions/upload-artifact@v2
- name: Create setup.sh
run: |
sed -e 's#__REPOSITORY__#${{ github.repository }}#' .github/setup_template.sh | \
sed -e 's#__RELEASE__#${{ github.ref_name }}#' > setup.sh
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ github.ref_name }}
path: geth-${{ github.ref_name }}-${{ matrix.os }}-${{ matrix.arch }}.zip
path: |
geth-*.zip
genesis.zip
setup.sh
release:
name: Release
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Download Artifact
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: ${{ github.ref_name }}
path: artifacts

- name: Archive genesis.json
run: zip -r genesis.zip genesis

- name: Create setup.sh
run: |
sed -e 's#__REPOSITORY__#${{ github.repository }}#' .github/setup_template.sh | \
sed -e 's#__RELEASE__#${{ github.ref_name }}#' > setup.sh
- name: Create sha256sums.txt
run: |
sha256sum genesis.zip > sha256sums.txt
sha256sum setup.sh >> sha256sums.txt
(cd artifacts && sha256sum *) >> sha256sums.txt
run: (cd artifacts && sha256sum *) > sha256sums.txt

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: softprops/action-gh-release@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag_name: ${{ github.ref_name }}
release_name: Release ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
draft: true

- name: Upload Asset - Linux amd64
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: artifacts/geth-${{ github.ref_name }}-linux-amd64.zip
asset_name: geth-${{ github.ref_name }}-linux-amd64.zip
asset_content_type: application/zip

- name: Upload Asset - Linux arm64
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: artifacts/geth-${{ github.ref_name }}-linux-arm64.zip
asset_name: geth-${{ github.ref_name }}-linux-arm64.zip
asset_content_type: application/zip

- name: Upload Asset - genesis.zip
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: genesis.zip
asset_name: genesis.zip
asset_content_type: application/zip

- name: Upload Asset - setup.sh
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: setup.sh
asset_name: setup.sh
asset_content_type: text/plain

- name: Upload Asset - sha256sums.txt
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: sha256sums.txt
asset_name: sha256sums.txt
asset_content_type: text/plain
files: |
artifacts/*
sha256sums.txt
20 changes: 12 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Build Geth in a stock Go builder container
FROM golang:1.20.14-bookworm as builder

# Support setting various labels on the final image
ARG COMMIT=""
ARG VERSION=""
ARG BUILDNUM=""

# Build Geth in a stock Go builder container
FROM golang:1.21-alpine as builder

RUN apk add --no-cache gcc musl-dev linux-headers git
RUN apt update && apt install -y git ca-certificates

# Get dependencies - will also be cached if we won't change go.mod/go.sum
COPY go.mod /go-ethereum/
Expand All @@ -16,11 +16,15 @@ RUN cd /go-ethereum && go mod download
ADD . /go-ethereum
RUN cd /go-ethereum && go run build/ci.go install -static ./cmd/geth

# Pull Geth into a second stage deploy alpine container
FROM alpine:latest
# Binary extraction stage
FROM scratch as binaries
COPY --from=builder /go-ethereum/build/bin/geth /geth

RUN apk add --no-cache ca-certificates
COPY --from=builder /go-ethereum/build/bin/geth /usr/local/bin/
# Final stage
FROM gcr.io/distroless/base-debian12
COPY --from=builder /go-ethereum/build/bin/geth /usr/local/bin/geth
COPY --from=builder /etc/ssl /etc/ssl
COPY --from=builder /usr/share/ca-certificates /usr/share/ca-certificates

EXPOSE 8545 8546 30303 30303/udp
ENTRYPOINT ["geth"]
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Automated builds are available for stable releases and the unstable master branc
archives are published at https://github.com/oasysgames/oasys-validator/releases.
## Running `geth` on Oasys

Read following manual on [**Oasys docs**](https://docs.oasys.games/docs/hub-validator/operate-validator/1-2-build-validator-node).
Read following manual on [**Oasys docs**](https://docs.oasys.games/docs/hub-validator/operate-validator/build-validator-node).

### Hardware Requirements

Expand Down Expand Up @@ -71,9 +71,9 @@ directory.
All validator need to process following steps.
All full node installation requires **only `1`** in steps.

1. [Run geth client](https://docs.oasys.games/docs/hub-validator/operate-validator/1-2-build-validator-node)
2. [Join PoS system & delegage](https://docs.oasys.games/docs/hub-validator/operate-validator/1-4-join-validator-web)
3. [Run verifier](https://docs.oasys.games/docs/hub-validator/operate-validator/1-5-setup-verifier)
1. [Run geth client](https://docs.oasys.games/docs/hub-validator/operate-validator/build-validator-node)
2. [Join PoS system & delegage](https://docs.oasys.games/docs/hub-validator/operate-validator/join-validator)
3. [Run verifier](https://docs.oasys.games/docs/hub-validator/operate-validator/setup-verifier)

### Programmatically interfacing `geth` nodes

Expand Down
68 changes: 3 additions & 65 deletions consensus/oasys/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,54 +150,6 @@ func (c chainContext) GetHeader(hash common.Hash, number uint64) *types.Header {
return c.Chain.GetHeader(hash, number)
}

// environmentValue
type environmentValue struct {
// Block and epoch to which this setting applies
StartBlock *big.Int
StartEpoch *big.Int
// Block generation interval(by seconds)
BlockPeriod *big.Int
// Number of blocks in epoch
EpochPeriod *big.Int
// Annual rate of staking reward
RewardRate *big.Int
// Validator commission rate
CommissionRate *big.Int
// Amount of tokens required to become a validator
ValidatorThreshold *big.Int
// Number of not sealed to jailing the validator
JailThreshold *big.Int
// Number of epochs to jailing the validator
JailPeriod *big.Int
}

func (p *environmentValue) IsEpoch(number uint64) bool {
return (number-p.StartBlock.Uint64())%p.EpochPeriod.Uint64() == 0
}

func (p *environmentValue) Epoch(number uint64) uint64 {
return p.StartEpoch.Uint64() + (number-p.StartBlock.Uint64())/p.EpochPeriod.Uint64()
}

func (p *environmentValue) GetFirstBlock(number uint64) uint64 {
elapsedEpoch := p.Epoch(number) - p.StartEpoch.Uint64()
return p.StartBlock.Uint64() + elapsedEpoch*p.EpochPeriod.Uint64()
}

func (p *environmentValue) Copy() *environmentValue {
return &environmentValue{
StartBlock: new(big.Int).Set(p.StartBlock),
StartEpoch: new(big.Int).Set(p.StartEpoch),
BlockPeriod: new(big.Int).Set(p.BlockPeriod),
EpochPeriod: new(big.Int).Set(p.EpochPeriod),
RewardRate: new(big.Int).Set(p.RewardRate),
CommissionRate: new(big.Int).Set(p.CommissionRate),
ValidatorThreshold: new(big.Int).Set(p.ValidatorThreshold),
JailThreshold: new(big.Int).Set(p.JailThreshold),
JailPeriod: new(big.Int).Set(p.JailPeriod),
}
}

// nextValidators
type nextValidators struct {
Owners []common.Address
Expand Down Expand Up @@ -228,20 +180,6 @@ func (p *nextValidators) Exists(validator common.Address) bool {
return false
}

func getInitialEnvironment(config *params.OasysConfig) *environmentValue {
return &environmentValue{
StartBlock: common.Big0,
StartEpoch: common.Big1,
BlockPeriod: big.NewInt(int64(config.Period)),
EpochPeriod: big.NewInt(int64(config.Epoch)),
RewardRate: big.NewInt(10),
CommissionRate: big.NewInt(10),
ValidatorThreshold: new(big.Int).Mul(big.NewInt(params.Ether), big.NewInt(10_000_000)),
JailThreshold: big.NewInt(500),
JailPeriod: big.NewInt(2),
}
}

// callmsg
type callmsg struct {
ethereum.CallMsg
Expand Down Expand Up @@ -303,7 +241,7 @@ func (c *Oasys) initializeSystemContracts(
if !environment.verifyCode(state) {
return errors.New("invalid contract code: Environment")
}
data, err := environment.abi.Pack("initialize", getInitialEnvironment(c.config))
data, err := environment.abi.Pack("initialize", params.InitialEnvironmentValue(c.config))
if err != nil {
return err
}
Expand Down Expand Up @@ -611,7 +549,7 @@ func getRewards(ethAPI blockchainAPI, hash common.Hash) (*big.Int, error) {
}

// Call the `Environment.nextValue` method.
func getNextEnvironmentValue(ethAPI blockchainAPI, hash common.Hash) (*environmentValue, error) {
func getNextEnvironmentValue(ethAPI blockchainAPI, hash common.Hash) (*params.EnvironmentValue, error) {
method := "nextValue"

ctx, cancel := context.WithCancel(context.Background())
Expand All @@ -638,7 +576,7 @@ func getNextEnvironmentValue(ethAPI blockchainAPI, hash common.Hash) (*environme
return nil, err
}

var recv struct{ Result environmentValue }
var recv struct{ Result params.EnvironmentValue }
if err := environment.abi.UnpackIntoInterface(&recv, method, rbytes); err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion consensus/oasys/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func TestGetRewards(t *testing.T) {
}

func TestGetNextEnvironmentValue(t *testing.T) {
want := &environmentValue{
want := &params.EnvironmentValue{
StartBlock: common.Big0,
StartEpoch: common.Big1,
BlockPeriod: big.NewInt(3),
Expand Down
Loading

0 comments on commit 759f454

Please sign in to comment.