Skip to content

Commit

Permalink
Merge branch 'main' into 2170
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurav-11018 authored Jul 26, 2023
2 parents 42555b6 + af1a07a commit 7cc5885
Show file tree
Hide file tree
Showing 97 changed files with 2,679 additions and 1,597 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Version Release
uses: celestiaorg/.github/.github/actions/[email protected].0
uses: celestiaorg/.github/.github/actions/[email protected].2
with:
github-token: ${{secrets.GITHUB_TOKEN}}
version-bump: ${{inputs.version}}
10 changes: 9 additions & 1 deletion .github/workflows/docker-build-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ jobs:
permissions:
contents: write
packages: write
uses: celestiaorg/.github/.github/workflows/[email protected].1 # yamllint disable-line rule:line-length
uses: celestiaorg/.github/.github/workflows/[email protected].2 # yamllint disable-line rule:line-length
with:
dockerfile: Dockerfile

docker-txsim-build:
permissions:
contents: write
packages: write
uses: celestiaorg/.github/.github/workflows/[email protected]
with:
dockerfile: docker/Dockerfile_txsim
2 changes: 1 addition & 1 deletion .github/workflows/housekeeping.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
jobs:
pr-assignment:
name: PR Auto Assignment
uses: celestiaorg/.github/.github/workflows/[email protected].0 # yamllint disable-line rule:line-length
uses: celestiaorg/.github/.github/workflows/[email protected].2 # yamllint disable-line rule:line-length
secrets: inherit
# write access for issues and pull requests is needed because the called
# workflow requires write access to issues and pull requests and the
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ jobs:

# hadolint lints the Dockerfile
hadolint:
uses: celestiaorg/.github/.github/workflows/[email protected].0 # yamllint disable-line rule:line-length
uses: celestiaorg/.github/.github/workflows/[email protected].2 # yamllint disable-line rule:line-length

yamllint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: celestiaorg/.github/.github/actions/[email protected].0
- uses: celestiaorg/.github/.github/actions/[email protected].2

markdown-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: celestiaorg/.github/.github/actions/[email protected].0
- uses: celestiaorg/.github/.github/actions/[email protected].2
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# stage 1 Generate celestia-appd Binary
FROM docker.io/golang:1.20.5-alpine3.17 as builder
FROM docker.io/golang:1.20.6-alpine3.17 as builder
# hadolint ignore=DL3018
RUN apk update && apk add --no-cache \
gcc \
git \
# linux-headers are needed for Ledger support
linux-headers \
make \
musl-dev
COPY . /celestia-app
Expand Down
66 changes: 64 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,42 @@ DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bu
IMAGE := ghcr.io/tendermint/docker-build-proto:latest
DOCKER_PROTO_BUILDER := docker run -v $(shell pwd):/workspace --workdir /workspace $(IMAGE)
PROJECTNAME=$(shell basename "$(PWD)")
LEDGER_ENABLED ?= true


# process build tags
build_tags =
ifeq ($(LEDGER_ENABLED),true)
ifeq ($(OS),Windows_NT)
GCCEXE = $(shell where gcc.exe 2> NUL)
ifeq ($(GCCEXE),)
$(error gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
build_tags += ledger
endif
else
UNAME_S = $(shell uname -s)
ifeq ($(UNAME_S),OpenBSD)
$(warning OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988))
else
GCC = $(shell command -v gcc 2> /dev/null)
ifeq ($(GCC),)
$(error gcc not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
build_tags += ledger
endif
endif
endif
endif
build_tags := $(strip $(build_tags))

empty :=
whitespace := $(empty) $(empty)
comma := ,

# convert build_tags from a whitespace seperated list to a comma seperated list
build_tags_comma_sep := $(subst $(whitespace),$(comma),$(build_tags))


# process linker flags
ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=celestia-app \
Expand All @@ -14,7 +50,7 @@ ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=celestia-app \
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)"
ldflags += $(LDFLAGS)

BUILD_FLAGS := -ldflags '$(ldflags)'
BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'

## help: Get more info on make commands.
help: Makefile
Expand Down Expand Up @@ -99,7 +135,7 @@ fmt:
@markdownlint --fix --quiet --config .markdownlint.yaml .
.PHONY: fmt

## test: Run unit tests.
## test: Run tests.
test:
@echo "--> Running tests"
@go test -mod=readonly -timeout 30m ./...
Expand All @@ -111,6 +147,12 @@ test-short:
@go test -mod=readonly ./... -short
.PHONY: test-short

## test-e2e: Run end to end tests via knuu.
test-e2e:
@echo "--> Running e2e tests"
@KNUU_NAMESPACE=celestia-app E2E=true go test -mod=readonly ./test/e2e/... -timeout 30m
.PHONY: test-e2e

## test-race: Run unit tests in race mode.
test-race:
@echo "--> Running tests in race mode"
Expand All @@ -129,6 +171,26 @@ test-coverage:
@export VERSION=$(VERSION); bash -x scripts/test_cover.sh
.PHONY: test-coverage

## txsim-install: Install the tx simulator.
txsim-install:
@echo "--> Installing tx simulator"
@go install -mod=readonly $(BUILD_FLAGS) ./test/cmd/txsim
.PHONY: txsim-install

## txsim-build: Build the tx simulator binary into the ./build directory.
txsim-build:
@echo "--> Building tx simulator"
@cd ./test/cmd/txsim
@mkdir -p build/
@go build $(BUILD_FLAGS) -o build/ ./test/cmd/txsim
@go mod tidy -compat=1.20
.PHONY: txsim-build

## txsim-build-docker: Build the tx simulator Docker image. Requires Docker.
txsim-build-docker:
docker build -t ghcr.io/celestiaorg/txsim -f docker/Dockerfile_txsim .
.PHONY: txsim-build-docker

## adr-gen: Download the ADR template from the celestiaorg/.github repo. Ex. `make adr-gen`
adr-gen:
@echo "--> Downloading ADR template"
Expand Down
8 changes: 8 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
minttypes "github.com/celestiaorg/celestia-app/x/mint/types"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
Expand Down Expand Up @@ -676,6 +677,9 @@ func (app *App) RegisterAPIRoutes(apiSvr *api.Server, _ config.APIConfig) {
// Register new tendermint queries routes from grpc-gateway.
tmservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// Register node gRPC service for grpc-gateway.
nodeservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// Register the
ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
}
Expand All @@ -690,6 +694,10 @@ func (app *App) RegisterTendermintService(clientCtx client.Context) {
tmservice.RegisterTendermintService(clientCtx, app.BaseApp.GRPCQueryRouter(), app.interfaceRegistry, nil)
}

func (app *App) RegisterNodeService(clientCtx client.Context) {
nodeservice.RegisterNodeService(clientCtx, app.GRPCQueryRouter())
}

func (app *App) setPostHanders() {
postHandler, err := posthandler.NewPostHandler(
posthandler.HandlerOptions{},
Expand Down
80 changes: 80 additions & 0 deletions app/errors/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package errors

import (
"errors"
"fmt"
"regexp"
"strconv"

sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

var (
// This is relatively brittle. It would be better if going below the min gas price
// had a specific error type.
regexpMinGasPrice = regexp.MustCompile(`insufficient fees; got: \d+utia required: \d+utia`)
regexpInt = regexp.MustCompile(`[0-9]+`)
)

// ParseInsufficientMinGasPrice checks if the error is due to the gas price being too low.
// Given the previous gas price and gas limit, it returns the new minimum gas price that
// the node should accept.
// If the error is not due to the gas price being too low, it returns 0, nil
func ParseInsufficientMinGasPrice(err error, gasPrice float64, gasLimit uint64) (float64, error) {
// first work out if the error is ErrInsufficientFunds
if err == nil || !sdkerrors.ErrInsufficientFee.Is(err) {
return 0, nil
}

// As there are multiple cases of ErrInsufficientFunds, we need to check the error message
// matches the regexp
substr := regexpMinGasPrice.FindAllString(err.Error(), -1)
if len(substr) != 1 {
return 0, nil
}

// extract the first and second numbers from the error message (got and required)
numbers := regexpInt.FindAllString(substr[0], -1)
if len(numbers) != 2 {
return 0, fmt.Errorf("expected two numbers in error message got %d", len(numbers))
}

// attempt to parse them into float64 values
got, err := strconv.ParseFloat(numbers[0], 64)
if err != nil {
return 0, err
}
required, err := strconv.ParseFloat(numbers[1], 64)
if err != nil {
return 0, err
}

// catch rare condition that required is zero. This should theoretically
// never happen as a min gas price of zero should always be accepted.
if required == 0 {
return 0, errors.New("unexpected case: required gas price is zero (why was an error returned)")
}

// calculate the actual min gas price of the node based on the difference
// between the got and required values. If gas price was zero, we need to use
// the gasLimit to infer this.
if gasPrice == 0 || got == 0 {
if gasLimit == 0 {
return 0, fmt.Errorf("gas limit and gas price cannot be zero")
}
return required / float64(gasLimit), nil
}
return required / got * gasPrice, nil
}

// IsInsufficientMinGasPrice checks if the error is due to the gas price being too low.
func IsInsufficientMinGasPrice(err error) bool {
// first work out if the error is ErrInsufficientFunds
if err == nil || !sdkerrors.ErrInsufficientFee.Is(err) {
return false
}

// As there are multiple cases of ErrInsufficientFunds, we need to check the error message
// matches the regexp
return regexpMinGasPrice.MatchString(err.Error())
}
Loading

0 comments on commit 7cc5885

Please sign in to comment.