-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
97 changed files
with
2,679 additions
and
1,597 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} |
Oops, something went wrong.