Skip to content

Commit

Permalink
Added nft module, gas meter keeper
Browse files Browse the repository at this point in the history
moved blzjs to curium, fixed test imports

added blzjs not as git submodule

barebones nft module project structured, added uploadNft endpoint

added nft type, added store helpers

added genesis config

rename type files, install torrent and bencode dependencies

added nftKeeper to app, missing torrent client and curium dependencies

fixed imports, fixed DefaultGenesisState() in genesis.go

added torrent client module

added empty curium-submodule for broadcast code, filename cleanup

updated cosmos-sdk for hmac/blzcli keyring errors, removed nft module from app

added nft module to app.go, successful local node deploy

added uploadFile endpoint, store in .blzd, with tests

added vendor to upload url, vendor subdirectories

added vendor and userId to nft struct

scaffolded curium module, app.go

revisioned curium module broadcast code, polling

added 20s timeout in broadcast polling

added curium module to app.go, pass to nft keeper

added nft-keeper helper functions

added MsgCreateNft to nft module, with vendor and user id

added getNft query, and rest query

added PublishFile msg, not broadcasted

readded broadcaster of MsgPublishFile kicked by MsgCreate

added gas meter interface, updated ante handlers

added charging to curium endblocker, fixed nft imports

backported gas meter interface

added MsgRegisterPeer, added vendor and userId to metadata

fixed publish file/keyring bug, file replicated and .info includes userid and vendor

files replicated to vendor subdirectories

reverted to single-directory for replication

reverted all vendorDir instances, file replication working

added ensureNftDirExists, file replication and metainfo files created

removed getHomeDir and getKeyringDir used in local testing

renamed reader to keyringReader, use url for ip address lookup

poll with contet deadline in broadcaster

removed Users directory from project

added IsDevelopment helper

fixed IsDevelopment() helper, use DEVEL,BLZD,BLZCLI env vars

refactored tax module, enforced min-gas-price, replication/broadcaster broken

fixed MsgBroadcaster with gas/fee antehandler changes, tx builder use fee not gas price

fixed gas-price calculation, use Dec, reverted MsgBroadcaster changes

removed io/fs import

added catch-all in NewMsgBroadcaster

prefixed replicated id files with vendor

added endpoints for getting replicated files

fixed rest endpoints

removed catch-all logger in NewMsgBroadcaster

removed append flag when creating file

added hack to check nft funding in end blcoker, before register peer

readded catch-all in new msgbroadcaster, return error

added nil nft address check in new msg broadcaster

added print breaks in new msg broadcaster

moved break 5 to isolate tx builder

prints for tx builder

add check for account exists

added check if r is nil

added defer to outer func

prints for tracking get address

small log change

isoalte keyring.get in getAccountAddress

check result is not nil

fixed close error, wait for response before closing the channel

added logs to get account

gas price logs

removed catch all

account msg

added panic in returnError

removed test panic

added print for address in do broadcaster

logging in getNftHandler endpoint

try changing clicontext home dir to .blzd

hardcoded .blzd home dir to get nft handlers, fix uploadNft

removed broadcaster prints, added prints to publish handler

more publish and broadcast prints

put append back to assemble file, remove uploads if file exists

removed print statements, basic tests passed
  • Loading branch information
avendauz committed Aug 3, 2021
1 parent 8d3024b commit b487f79
Show file tree
Hide file tree
Showing 104 changed files with 5,766 additions and 398 deletions.
43 changes: 0 additions & 43 deletions app/ante/DummyGasMeter.go

This file was deleted.

69 changes: 0 additions & 69 deletions app/ante/LoggingGasMeter.go

This file was deleted.

42 changes: 42 additions & 0 deletions app/ante/MempoolFeeDecorator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ante

import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
)

type MempoolFeeDecorator struct{}

func NewMempoolFeeDecorator() MempoolFeeDecorator {
return MempoolFeeDecorator{}
}

func (mfd MempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
feeTx, ok := tx.(ante.FeeTx)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx")
}

feeCoins := feeTx.GetFee()
gas := feeTx.GetGas()

// Ensure that the provided fees meet a minimum threshold for the validator,
// if this is a CheckTx. This is only for local mempool purposes, and thus
// is only ran on check tx.
if ctx.IsCheckTx() && !simulate {
specifiedGasPrice := sdk.NewDecCoinsFromCoins(feeCoins[0]).QuoDec(sdk.NewDec(int64(gas)))[0]
minGasPrice := ctx.MinGasPrices()[0]

if specifiedGasPrice.IsLT(minGasPrice) {
return ctx, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "gas price too low; got: %s required: %s", specifiedGasPrice, minGasPrice)
}

if gas == 0 {
return ctx, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "max gas cannot be 0")
}

}

return next(ctx, tx, simulate)
}
105 changes: 0 additions & 105 deletions app/ante/NewDeductFeeDecorator.go

This file was deleted.

65 changes: 54 additions & 11 deletions app/ante/NewSetUpContextDecorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package ante

import (
"fmt"
"github.com/bluzelle/curium/app/ante/gasmeter"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
acctypes "github.com/cosmos/cosmos-sdk/x/auth/keeper"
"github.com/cosmos/cosmos-sdk/x/auth/types"
"strings"
banktypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)

var (
Expand All @@ -23,10 +26,20 @@ type GasTx interface {
// on gas provided and gas used.
// CONTRACT: Must be first decorator in the chain
// CONTRACT: Tx must implement GasTx interface
type SetUpContextDecorator struct{}
type SetUpContextDecorator struct{
gasMeterKeeper *gasmeter.GasMeterKeeper
supplyKeeper banktypes.SupplyKeeper
accountKeeper acctypes.AccountKeeper
minGasPriceCoins sdk.DecCoins
}

func NewSetUpContextDecorator() SetUpContextDecorator {
return SetUpContextDecorator{}
func NewSetUpContextDecorator(gasMeterKeeper *gasmeter.GasMeterKeeper, supplyKeeper banktypes.SupplyKeeper, accountKeeper acctypes.AccountKeeper, minGasPriceCoins sdk.DecCoins) SetUpContextDecorator {
return SetUpContextDecorator{
gasMeterKeeper: gasMeterKeeper,
supplyKeeper: supplyKeeper,
accountKeeper: accountKeeper,
minGasPriceCoins: minGasPriceCoins,
}
}

func (sud SetUpContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
Expand All @@ -38,11 +51,15 @@ func (sud SetUpContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
if !ok {
// Set a gas meter with limit 0 as to prevent an infinite gas meter attack
// during runTx.
newCtx = SetGasMeter(simulate, ctx, 0, tx)
newCtx, _ = SetGasMeter(simulate, ctx, 0, tx, sud.gasMeterKeeper, sud.supplyKeeper, sud.accountKeeper, sud.minGasPriceCoins)
return newCtx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be GasTx")
}

newCtx = SetGasMeter(simulate, ctx, gasTx.GetGas(), tx)
newCtx, err = SetGasMeter(simulate, ctx, gasTx.GetGas(), tx, sud.gasMeterKeeper, sud.supplyKeeper, sud.accountKeeper, sud.minGasPriceCoins)

if err != nil {
return ctx, err
}

// Decorator will catch an OutOfGasPanic caused in the next antehandler
// AnteHandlers must have their own defer/recover in order for the BaseApp
Expand All @@ -68,15 +85,41 @@ func (sud SetUpContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
}

// SetGasMeter returns a new context with a gas meter set from a given context.
func SetGasMeter(simulate bool, ctx sdk.Context, gasLimit uint64, tx sdk.Tx) sdk.Context {
func SetGasMeter(simulate bool, ctx sdk.Context, gasLimit uint64, tx sdk.Tx, gk *gasmeter.GasMeterKeeper, supplyKeeper banktypes.SupplyKeeper, accountKeeper acctypes.AccountKeeper, minGasPriceCoins sdk.DecCoins) (sdk.Context, error) {
// In various cases such as simulation and during the genesis block, we do not
// meter any gas utilization.
if simulate || ctx.BlockHeight() == 0 {
return ctx.WithGasMeter(sdk.NewInfiniteGasMeter())
return ctx.WithGasMeter(sdk.NewInfiniteGasMeter()), nil
}

if strings.HasPrefix(tx.GetMsgs()[0].Type(), "oracle") {
return ctx.WithGasMeter(NewDummyGasMeter())
feeTx := tx.(ante.FeeTx)
maxGas := feeTx.GetGas()

maxGasInt := sdk.NewIntFromUint64(maxGas).ToDec()
feeInt := feeTx.GetFee().AmountOf("ubnt").ToDec()


gasPrice := feeInt.Quo(maxGasInt)
gasPriceCoin := sdk.NewDecCoinFromDec("ubnt", gasPrice)
gasPriceCoins := sdk.NewDecCoins(gasPriceCoin)

feePayer := feeTx.FeePayer()

if gasPriceCoins.AmountOf("ubnt").LT(minGasPriceCoins.AmountOf("ubnt")) {
return ctx, sdkerrors.New("curium", 2, "Specified gas price too low")
}
return ctx.WithGasMeter(sdk.NewGasMeter(gasLimit))

msgModule := tx.GetMsgs()[0].Route()

if msgModule == "crud" && !simulate && !ctx.IsCheckTx() { //TODO msg module for nft
gm := gasmeter.NewChargingGasMeter(supplyKeeper, accountKeeper, gasLimit, feePayer, gasPriceCoins)

gk.AddGasMeter(&gm)
return ctx.WithGasMeter(gm), nil
}

gm := gasmeter.NewFreeGasMeter(gasLimit)
gk.AddGasMeter(&gm)

return ctx.WithGasMeter(gm), nil
}
Loading

0 comments on commit b487f79

Please sign in to comment.