Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
panic when account is missing
added good genesis.json
  • Loading branch information
ebruck committed Apr 20, 2020
1 parent 146d287 commit 2c36f7e
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ func NewAnteHandler(bk bank.Keeper, ak keeper.AccountKeeper, supplyKeeper types.
ante.NewSetPubKeyDecorator(ak), // SetPubKeyDecorator must be called before all signature verification decorators
ante.NewValidateSigCountDecorator(ak),
ante.NewDeductFeeDecorator(ak, supplyKeeper),
utilityfee.NewDeductFeeDecorator(bk, ak, supplyKeeper, DefaultNodeHome),
utilityfee.NewDeductFeeDecorator(bk, ak, supplyKeeper, DefaultNodeHome+"/config/genesis.json"),
ante.NewSigGasConsumeDecorator(ak, sigGasConsumer),
ante.NewSigVerificationDecorator(ak),
ante.NewIncrementSequenceDecorator(ak), // innermost AnteDecorator
Expand Down
175 changes: 175 additions & 0 deletions x/utilityfee/genesis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
{
"genesis_time": "2020-04-17T20:48:19.818894094Z",
"chain_id": "bluzelle",
"consensus_params": {
"block": {
"max_bytes": "22020096",
"max_gas": "-1",
"time_iota_ms": "1000"
},
"evidence": {
"max_age_num_blocks": "100000",
"max_age_duration": "172800000000000"
},
"validator": {
"pub_key_types": [
"ed25519"
]
}
},
"app_hash": "",
"app_state": {
"supply": {
"supply": []
},
"auth": {
"params": {
"max_memo_characters": "256",
"tx_sig_limit": "7",
"tx_size_cost_per_byte": "10",
"sig_verify_cost_ed25519": "590",
"sig_verify_cost_secp256k1": "1000"
},
"accounts": [
{
"type": "cosmos-sdk/Account",
"value": {
"address": "bluzelle15nez235z5wj4e84wnlea9yy45fyd4cc2xv8kym",
"coins": [
{
"denom": "ubnt",
"amount": "499999999999999"
}
],
"public_key": "",
"account_number": 0,
"sequence": 0
}
},
{
"type": "cosmos-sdk/Account",
"value": {
"address": "bluzelle1tfqzcch3dx9ly72nwtvqcn222a5d7yn65xdzkk",
"coins": [
{
"denom": "ubnt",
"amount": "1"
}
],
"public_key": "",
"account_number": 1,
"sequence": 0
}
}
]
},
"staking": {
"params": {
"unbonding_time": "1814400000000000",
"max_validators": 100,
"max_entries": 7,
"historical_entries": 0,
"bond_denom": "ubnt"
},
"last_total_power": "0",
"last_validator_powers": null,
"validators": null,
"delegations": null,
"unbonding_delegations": null,
"redelegations": null,
"exported": false
},
"genutil": {
"gentxs": [
{
"type": "cosmos-sdk/StdTx",
"value": {
"msg": [
{
"type": "cosmos-sdk/MsgCreateValidator",
"value": {
"description": {
"moniker": "curium00",
"identity": "",
"website": "",
"security_contact": "",
"details": ""
},
"commission": {
"rate": "0.100000000000000000",
"max_rate": "0.200000000000000000",
"max_change_rate": "0.010000000000000000"
},
"min_self_delegation": "1",
"delegator_address": "bluzelle15nez235z5wj4e84wnlea9yy45fyd4cc2xv8kym",
"validator_address": "bluzellevaloper15nez235z5wj4e84wnlea9yy45fyd4cc2xp5tpd",
"pubkey": "bluzellevalconspub1zcjduepqd6ztwge4em3sw0lh2ljtggd89rtf7t85nt4tdy32exuwe08jncxs5jks95",
"value": {
"denom": "ubnt",
"amount": "10000000000001"
}
}
}
],
"fee": {
"amount": [],
"gas": "200000"
},
"signatures": [
{
"pub_key": {
"type": "tendermint/PubKeySecp256k1",
"value": "A7ICFvBWgR4rPXM+Au6lRxl9KIzL/6slkThALYX+ow4v"
},
"signature": "zJBTI9EOQ+ZucENI8FzBVCTm7NkqRv2RoYNpd699u9Zc2dbQYeNLGII1PAjbQF1WQ8vH59c7Whxn6Y+SW6IZrw=="
}
],
"memo": "1928c55999d185b69931c04c04cee7fa5c80222c@192.168.0.43:26656"
}
}
]
},
"distribution": {
"params": {
"community_tax": "0.020000000000000000",
"base_proposer_reward": "0.010000000000000000",
"bonus_proposer_reward": "0.040000000000000000",
"withdraw_addr_enabled": true
},
"fee_pool": {
"community_pool": []
},
"delegator_withdraw_infos": [],
"previous_proposer": "",
"outstanding_rewards": [],
"validator_accumulated_commissions": [],
"validator_historical_rewards": [],
"validator_current_rewards": [],
"delegator_starting_infos": [],
"validator_slash_events": []
},
"faucet": null,
"utilityfee": {
"tax": "0.5",
"account_number": "1"
},
"crud": {
"BlzValues": null
},
"bank": {
"send_enabled": true
},
"params": null,
"slashing": {
"params": {
"signed_blocks_window": "100",
"min_signed_per_window": "0.500000000000000000",
"downtime_jail_duration": "600000000000",
"slash_fraction_double_sign": "0.050000000000000000",
"slash_fraction_downtime": "0.010000000000000000"
},
"signing_infos": {},
"missed_blocks": {}
}
}
}
22 changes: 12 additions & 10 deletions x/utilityfee/utilityfee.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ var (
_ FeeTx = (*types.StdTx)(nil) // assert StdTx implements FeeTx
)

const FeeDenom = "ubnt"

type UtilityFee struct {
Tax string `json:"tax"`
AccountNumber string `json:"account_number"`
Expand Down Expand Up @@ -143,10 +145,8 @@ func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
return nil
}

func getUtilityTax(nodeHome string) (float64, sdk.AccAddress) {
genFile := nodeHome + "/config/genesis.json"
func getUtilityTax(genFile string) (float64, sdk.AccAddress) {
cdc := codec.New()

appState, _, err := genutil.GenesisStateFromGenFile(cdc, genFile)
if err != nil {
panic(fmt.Sprintf("%s does not exist, run `init` first", genFile))
Expand Down Expand Up @@ -178,13 +178,17 @@ func getUtilityTax(nodeHome string) (float64, sdk.AccAddress) {
}
}

if ac == nil {
panic(fmt.Sprintf("genesis account number %d does not exist", accountNumber))
}

return tax, ac
}

///////////////////////////////////////////////////////////////////////////////

func NewDeductFeeDecorator(bk bank.Keeper, ak keeper.AccountKeeper, sk types.SupplyKeeper, homeDir string) DeductFeeDecorator {
tax, ua := getUtilityTax(homeDir)
func NewDeductFeeDecorator(bk bank.Keeper, ak keeper.AccountKeeper, sk types.SupplyKeeper, genFile string) DeductFeeDecorator {
tax, ua := getUtilityTax(genFile)
return DeductFeeDecorator{
bk: bk,
ak: ak,
Expand Down Expand Up @@ -234,13 +238,11 @@ func DeductFees(supplyKeeper types.SupplyKeeper, bk bank.Keeper, ctx sdk.Context
"insufficient funds to pay for fees; %s < %s", coins, fees)
}

// Validate the account has enough "spendable" coins as this will cover cases
// such as vesting accounts.
// Validate the account has enough "spendable" coins...
spendableCoins := acc.SpendableCoins(blockTime)

// TODO: don't specify ubnt!
utilityFee := int64(tax * 0.01 * float64(fees.AmountOf("ubnt").Int64()))
utilityCoins := sdk.NewCoins(sdk.NewCoin("ubnt", sdk.NewInt(utilityFee)))
utilityFee := int64(tax * 0.01 * float64(fees.AmountOf(FeeDenom).Int64()))
utilityCoins := sdk.NewCoins(sdk.NewCoin(FeeDenom, sdk.NewInt(utilityFee)))

if _, hasNeg := spendableCoins.SafeSub(utilityCoins); hasNeg {
return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds,
Expand Down

0 comments on commit 2c36f7e

Please sign in to comment.