Skip to content

Commit

Permalink
Merge branch 'dev' into PROTO-2134
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandofcampos committed Aug 15, 2024
2 parents 21dca65 + 941fae0 commit 120e9ff
Show file tree
Hide file tree
Showing 51 changed files with 7,601 additions and 2,695 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build_push_docker_hub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ jobs:
IMAGE_TAG="${GITHUB_SHA:0:8}"
EXTRA_IMAGE_TAGS=$GIT_TAG
#! Add latest tag only if on named releases tag='v*'
if [[ ${GIT_TAG} == v* ]]; then
EXTRA_IMAGE_TAGS="${EXTRA_IMAGE_TAGS};latest"
EXTRA_IMAGE_TAGS="${EXTRA_IMAGE_TAGS}"
fi
# Build a docker container and push it to Docker Hub.
Expand Down
69 changes: 69 additions & 0 deletions .github/workflows/build_push_upgrader_docker_hub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Build and Push docker image to Docker Hub

# Trigger the workflow manually
on:
workflow_dispatch:
inputs:
tag:
description: 'Tag for the Docker image'
required: false
default: ''
allorad_current_version:
description: 'Current version of allorad'
required: true
default: 'v0.2.14'
allorad_upgrade_version:
description: 'Upgrade version of allorad'
required: true
default: 'v0.3.0'

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

jobs:
build-push:
name: Build and Push docker image
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Build, tag, and push upgrader image to Docker Hub
id: build-push-upgrader-image
env:
DOCKERHUB_USERNAME: alloranetwork
DOCKERHUB_REPOSITORY: ${{ github.event.repository.name }}
run: |
# Set the tag from the input or default to the SHA of the commit
GIT_TAG="${{ github.event.inputs.tag || github.sha }}"
ALLORAD_CURRENT_VERSION="${{ github.event.inputs.allorad_current_version }}"
ALLORAD_UPGRADE_VERSION="${{ github.event.inputs.allorad_upgrade_version }}"
IMAGE_TAG="${GITHUB_SHA:0:8}"
EXTRA_IMAGE_TAGS=$GIT_TAG

if [[ ${GIT_TAG} == v* ]]; then
EXTRA_IMAGE_TAGS="${EXTRA_IMAGE_TAGS}"
fi

# Build a docker container and push it to Docker Hub.
docker build --pull \
--build-arg "ALLORAD_CURRENT_VERSION=${ALLORAD_CURRENT_VERSION}" \
--build-arg "ALLORAD_UPGRADE_VERSION=${ALLORAD_UPGRADE_VERSION}" \
-f Dockerfile.cosmovisor -t $DOCKERHUB_USERNAME/$DOCKERHUB_REPOSITORY:$IMAGE_TAG .

docker push $DOCKERHUB_USERNAME/$DOCKERHUB_REPOSITORY:$IMAGE_TAG

# Build and PUSH additional tags
for tag in $(echo $EXTRA_IMAGE_TAGS | tr ";" "\n"); do
docker tag $DOCKERHUB_USERNAME/$DOCKERHUB_REPOSITORY:$IMAGE_TAG $DOCKERHUB_USERNAME/$DOCKERHUB_REPOSITORY:$tag
docker push $DOCKERHUB_USERNAME/$DOCKERHUB_REPOSITORY:$tag
done
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
<!-- ## v0.3.0 -->
* Refactors to adapt to single transaction insertions from workers and reputers.

### Added

Expand Down
40 changes: 13 additions & 27 deletions Dockerfile.cosmovisor
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,26 @@ ENV DASEL_VERSION="v2.8.1"
ADD https://github.com/TomWright/dasel/releases/download/${DASEL_VERSION}/dasel_linux_amd64 /usr/local/bin/dasel
RUN chmod a+x /usr/local/bin/dasel

ENV COSMOVISOR_VERSION="v1.5.0"
#* See https://docs.cosmos.network/main/build/tooling/cosmovisor#setup for details
ENV DAEMON_HOME="/cosmovisor"
# ENV DAEMON_NAME=allorad
# ENV DAEMON_ALLOW_DOWNLOAD_BINARIES=false
# ENV DAEMON_DOWNLOAD_MUST_HAVE_CHECKSUM=false
# ENV DAEMON_RESTART_AFTER_UPGRADE=true
# ENV DAEMON_RESTART_DELAY=1s
# ENV DAEMON_POLL_INTERVAL=3s
# ENV UNSAFE_SKIP_BACKUP=true
# ENV DAEMON_PREUPGRADE_MAX_RETRIES=3
# ENV COSMOVISOR_DISABLE_LOGS=false
# ENV COSMOVISOR_COLOR_LOGS=true
ENV COSMOVISOR_VERSION="v1.5.0"
ENV INITIAL_COSMOVISOR_DIR="/cosmovisor"
ENV DAEMON_HOME="/data"
ENV DAEMON_NAME=allorad
ENV UNSAFE_SKIP_BACKUP=true

ADD https://github.com/cosmos/cosmos-sdk/releases/download/cosmovisor/${COSMOVISOR_VERSION}/cosmovisor-v1.5.0-linux-amd64.tar.gz /tmp/cosmovisor.tar.gz
RUN tar -xvf /tmp/cosmovisor.tar.gz -C /usr/local/bin/ && \
chmod +x /usr/local/bin/cosmovisor

ENV ALLORAD_CURRENT_VERSION="v0.2.14"
#* ALLORAD_UPGRADE_VERSIONS - Could be many versions, space separated
ENV ALLORAD_UPGRADE_VERSIONS="untagged-e66cf245a46ad9a6cef6"
ARG ALLORAD_CURRENT_VERSION="v0.2.14"
ARG ALLORAD_UPGRADE_VERSION="v0.3.0"

RUN mkdir -p ${DAEMON_HOME}/genesis/bin && \
curl -Lo ${DAEMON_HOME}/genesis/bin/allorad https://github.com/allora-network/allora-chain/releases/download/${ALLORAD_CURRENT_VERSION}/allorad_linux_amd64 && \
chmod +x ${DAEMON_HOME}/genesis/bin/allorad
RUN mkdir -p ${INITIAL_COSMOVISOR_DIR}/genesis/bin && \
curl -Lo ${INITIAL_COSMOVISOR_DIR}/genesis/bin/allorad https://github.com/allora-network/allora-chain/releases/download/${ALLORAD_CURRENT_VERSION}/allorad_linux_amd64 && \
chmod +x ${INITIAL_COSMOVISOR_DIR}/genesis/bin/allorad

# RUN for ver in "${ALLORAD_UPGRADE_VERSIONS}"; do \
# mkdir -p ${DAEMON_HOME}/upgrades/${ver}/bin && \
# curl -Lo ${DAEMON_HOME}/upgrades/${ver}/bin/allorad https://github.com/allora-network/allora-chain/releases/download/${ver}/allorad_linux_amd64 && \
# chmod +x ${DAEMON_HOME}/upgrades/${ver}/bin/allorad ; \
# done && \
# chown -R ${USERNAME}:${USERNAME} ${DAEMON_HOME}
ENV ver="v0.3.0"
RUN mkdir -p ${DAEMON_HOME}/upgrades/${ver}/bin
COPY allorad ${DAEMON_HOME}/upgrades/${ver}/bin/allorad
RUN mkdir -p ${INITIAL_COSMOVISOR_DIR}/upgrades/${ALLORAD_UPGRADE_VERSION}/bin && \
curl -Lo ${INITIAL_COSMOVISOR_DIR}/upgrades/${ALLORAD_UPGRADE_VERSION}/bin/allorad https://github.com/allora-network/allora-chain/releases/download/${ALLORAD_UPGRADE_VERSION}/allorad_linux_amd64

VOLUME ${APP_PATH}
WORKDIR ${APP_PATH}
Expand Down
9 changes: 5 additions & 4 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
services:
node:
container_name: sample_validator
image: "alloranetwork/allora-chain:v0.2.14"
image: "alloranetwork/allora-chain:v0.3.0-upgrader" # docker image without cosmovisor. use vx.x.x-upgrader for upgrade image
environment:
- NETWORK=allora-testnet-1
- MONIKER=sample_validator
- APP_HOME=/data
- HOME=/data
- STATE_SYNC_RPC1=https://allora-rpc.testnet-1.testnet.allora.network:443
- STATE_SYNC_RPC2=https://allora-rpc.testnet-1.testnet.allora.network:443
# - STATE_SYNC_RPC1=https://allora-rpc.testnet-1.testnet.allora.network:443
# - STATE_SYNC_RPC2=https://allora-rpc.testnet-1.testnet.allora.network:443
- UPGRADE=true # set this to true for chain upgrade runs
volumes:
- ./data_validator:/data
- ./data:/data
- ./scripts/:/scripts
ports:
- "26656-26657:26656-26657"
Expand Down
39 changes: 33 additions & 6 deletions math/dec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/json"
"fmt"
"math/big"
"math/bits"

"cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
Expand Down Expand Up @@ -39,6 +40,7 @@ var (
ErrUnexpectedRounding = errors.Register(mathCodespace, 2, "unexpected rounding")
ErrNonIntegeral = errors.Register(mathCodespace, 3, "value is non-integral")
ErrInfiniteString = errors.Register(mathCodespace, 4, "value is infinite")
ErrOverflow = errors.Register(mathCodespace, 5, "overflow")
)

// The number 0 encoded as Dec
Expand Down Expand Up @@ -389,6 +391,7 @@ func (x Dec) BigInt() (*big.Int, error) {
return z, nil
}

// Coeff copies x into a big int while minimizing trailing zeroes
func (x Dec) Coeff() big.Int {
y, _ := x.Reduce()
var r = y.dec.Coeff
Expand All @@ -408,19 +411,43 @@ func (x Dec) Coeff() big.Int {
return *r.MathBigInt()
}

// MaxBitLen defines the maximum bit length supported bit Int and Uint types.
const MaxBitLen = 256

// maxWordLen defines the maximum word length supported by Int and Uint types.
// We check overflow, by first doing a fast check if the word length is below maxWordLen
// and if not then do the slower full bitlen check.
// NOTE: If MaxBitLen is not a multiple of bits.UintSize, then we need to edit the used logic slightly.
const maxWordLen = MaxBitLen / bits.UintSize

// check if the big int is greater than the maximum word length
// of a sdk int (256 bits)
func bigIntOverflows(i *big.Int) bool {
// overflow is defined as i.BitLen() > MaxBitLen
// however this check can be expensive when doing many operations.
// So we first check if the word length is greater than maxWordLen.
// However the most significant word could be zero, hence we still do the bitlen check.
if len(i.Bits()) > maxWordLen {
return i.BitLen() > MaxBitLen
}
return false
}

// SdkIntTrim rounds decimal number to the integer towards zero and converts it to `sdkmath.Int`.
// Panics if x is bigger the SDK Int max value
func (x Dec) SdkIntTrim() sdkmath.Int {
// returns error if the Dec is not representable in an sdkmath.Int
func (x Dec) SdkIntTrim() (sdkmath.Int, error) {
var r = x.Coeff()
return sdkmath.NewIntFromBigInt(&r)
if bigIntOverflows(&r) {
return sdkmath.Int{}, errors.Wrap(ErrOverflow, "decimal is not representable as an sdkmath.Int")
}
return sdkmath.NewIntFromBigInt(&r), nil
}

// SdkLegacyDec converts Dec to `sdkmath.LegacyDec`
// can return nil if the value is not representable in a LegacyDec
func (x Dec) SdkLegacyDec() sdkmath.LegacyDec {
func (x Dec) SdkLegacyDec() (sdkmath.LegacyDec, error) {
stringRep := x.dec.Text('f')
y, _ := sdkmath.LegacyNewDecFromStr(stringRep)
return y
return sdkmath.LegacyNewDecFromStr(stringRep)
}

func (x Dec) String() string {
Expand Down
Loading

0 comments on commit 120e9ff

Please sign in to comment.