-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create new release v0.13.0
- Loading branch information
Showing
125 changed files
with
3,185 additions
and
2,684 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Publish Docker image | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
push_to_registry: | ||
name: Push Docker image to Docker Hub | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out the repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: Log in to the Container registry | ||
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 | ||
with: | ||
images: | | ||
ghcr.io/${{ github.repository }} | ||
- name: Build and push Docker images | ||
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} |
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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
FROM ubuntu:18.04 | ||
FROM golang:1.18 AS builder | ||
|
||
RUN apt-get update && \ | ||
apt-get -y upgrade && \ | ||
apt-get -y install curl jq file | ||
RUN apt-get update && apt-get install -y \ | ||
jq \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
VOLUME [ /nibid ] | ||
WORKDIR /nibid | ||
EXPOSE 26656 26657 | ||
ENTRYPOINT ["/usr/bin/docker-wrapper.sh"] | ||
CMD ["start"] | ||
STOPSIGNAL SIGTERM | ||
|
||
COPY scripts/docker-wrapper.sh /usr/bin/docker-wrapper.sh | ||
|
||
COPY . ./ | ||
RUN CGO_ENABLED=0 make build | ||
|
||
FROM alpine:latest | ||
RUN apk --no-cache add ca-certificates | ||
WORKDIR /root/ | ||
COPY --from=builder /nibid/build/nibid /usr/local/bin/nibid | ||
ENTRYPOINT ["nibid"] |
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,84 @@ | ||
package fee | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
"github.com/cosmos/cosmos-sdk/x/auth/ante" | ||
"github.com/cosmos/cosmos-sdk/x/auth/types" | ||
) | ||
|
||
// DeductFeeDecorator deducts fees from the first signer of the tx | ||
// If the first signer does not have the funds to pay for the fees, return with InsufficientFunds error | ||
// Call next AnteHandler if fees successfully deducted | ||
// CONTRACT: Tx must implement FeeTx interface to use DeductFeeDecorator | ||
type DeductFeeDecorator struct { | ||
ak ante.AccountKeeper | ||
bankKeeper types.BankKeeper | ||
feegrantKeeper ante.FeegrantKeeper | ||
} | ||
|
||
func NewDeductFeeDecorator(ak ante.AccountKeeper, bk types.BankKeeper, fk ante.FeegrantKeeper) DeductFeeDecorator { | ||
return DeductFeeDecorator{ | ||
ak: ak, | ||
bankKeeper: bk, | ||
feegrantKeeper: fk, | ||
} | ||
} | ||
|
||
func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { | ||
feeTx, ok := tx.(sdk.FeeTx) | ||
if !ok { | ||
return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") | ||
} | ||
|
||
if addr := dfd.ak.GetModuleAddress(types.FeeCollectorName); addr == nil { | ||
return ctx, fmt.Errorf("fee collector module account (%s) has not been set", types.FeeCollectorName) | ||
} | ||
|
||
fee := feeTx.GetFee() | ||
feePayer := feeTx.FeePayer() | ||
feeGranter := feeTx.FeeGranter() | ||
|
||
deductFeesFrom := feePayer | ||
|
||
// if feegranter set deduct fee from feegranter account. | ||
// this works with only when feegrant enabled. | ||
if feeGranter != nil { | ||
if dfd.feegrantKeeper == nil { | ||
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "fee grants are not enabled") | ||
} else if !feeGranter.Equals(feePayer) { | ||
err := dfd.feegrantKeeper.UseGrantedFees(ctx, feeGranter, feePayer, fee, tx.GetMsgs()) | ||
|
||
if err != nil { | ||
return ctx, sdkerrors.Wrapf(err, "%s not allowed to pay fees from %s", feeGranter, feePayer) | ||
} | ||
} | ||
|
||
deductFeesFrom = feeGranter | ||
} | ||
|
||
deductFeesFromAcc := dfd.ak.GetAccount(ctx, deductFeesFrom) | ||
if deductFeesFromAcc == nil { | ||
return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "fee payer address: %s does not exist", deductFeesFrom) | ||
} | ||
|
||
// Gas meter is set to 1 for gasless transactions. | ||
// Depends on GasLessDecorator for this to happen. | ||
if ctx.GasMeter().GasConsumed() == 1 { | ||
// do nothing | ||
} else if !feeTx.GetFee().IsZero() { | ||
err = ante.DeductFees(dfd.bankKeeper, ctx, deductFeesFromAcc, feeTx.GetFee()) | ||
if err != nil { | ||
return ctx, err | ||
} | ||
} | ||
|
||
events := sdk.Events{sdk.NewEvent(sdk.EventTypeTx, | ||
sdk.NewAttribute(sdk.AttributeKeyFee, feeTx.GetFee().String()), | ||
)} | ||
ctx.EventManager().EmitEvents(events) | ||
|
||
return next(ctx, tx, simulate) | ||
} |
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,54 @@ | ||
package fee_test | ||
|
||
import ( | ||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" | ||
"github.com/cosmos/cosmos-sdk/simapp" | ||
"github.com/cosmos/cosmos-sdk/testutil/testdata" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/NibiruChain/nibiru/app" | ||
"github.com/NibiruChain/nibiru/app/antedecorators/fee" | ||
) | ||
|
||
func (suite *AnteTestSuite) TestDeductFees() { | ||
suite.SetupTest(false) // setup | ||
suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder() | ||
|
||
// keys and addresses | ||
priv1, _, addr1 := testdata.KeyTestPubAddr() | ||
|
||
// msg and signatures | ||
msg := testdata.NewTestMsg(addr1) | ||
feeAmount := sdk.NewCoins(sdk.NewInt64Coin(app.BondDenom, 150)) | ||
gasLimit := testdata.NewTestGasLimit() | ||
suite.Require().NoError(suite.txBuilder.SetMsgs(msg)) | ||
suite.txBuilder.SetFeeAmount(feeAmount) | ||
suite.txBuilder.SetGasLimit(gasLimit) | ||
|
||
privs, accNums, accSeqs := []cryptotypes.PrivKey{priv1}, []uint64{0}, []uint64{0} | ||
tx, err := suite.CreateTestTx(privs, accNums, accSeqs, suite.ctx.ChainID()) | ||
suite.Require().NoError(err) | ||
|
||
// Set account with insufficient funds | ||
acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, addr1) | ||
suite.app.AccountKeeper.SetAccount(suite.ctx, acc) | ||
coins := sdk.NewCoins(sdk.NewCoin(app.BondDenom, sdk.NewInt(10))) | ||
err = simapp.FundAccount(suite.app.BankKeeper, suite.ctx, addr1, coins) | ||
suite.Require().NoError(err) | ||
|
||
dfd := fee.NewDeductFeeDecorator(suite.app.AccountKeeper, suite.app.BankKeeper, nil) | ||
antehandler := sdk.ChainAnteDecorators(dfd) | ||
|
||
_, err = antehandler(suite.ctx, tx, false) | ||
|
||
suite.Require().NotNil(err, "Tx did not error when fee payer had insufficient funds") | ||
|
||
// Set account with sufficient funds | ||
suite.app.AccountKeeper.SetAccount(suite.ctx, acc) | ||
err = simapp.FundAccount(suite.app.BankKeeper, suite.ctx, addr1, sdk.NewCoins(sdk.NewCoin(app.BondDenom, sdk.NewInt(200)))) | ||
suite.Require().NoError(err) | ||
|
||
_, err = antehandler(suite.ctx, tx, false) | ||
|
||
suite.Require().Nil(err, "Tx errored after account has been set with sufficient funds") | ||
} |
Oops, something went wrong.