Skip to content

Commit

Permalink
Merge branch 'develop' into release/v0.30.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cwgoes committed Jan 24, 2019
2 parents a5b08c4 + af60c75 commit 5ab7440
Show file tree
Hide file tree
Showing 22 changed files with 263 additions and 74 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

# Build
vendor
vendor-deps
.vendor-new
build
tools/bin/*
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ BREAKING CHANGES
* [\#3249\(https://github.com/cosmos/cosmos-sdk/issues/3249) `tendermint`'s `show-validator` and `show-address` `--json` flags removed in favor of `--output-format=json`.

* SDK
* [distribution] \#3359 Always round down when calculating rewards-to-be-withdrawn in F1 fee distribution
* [#3336](https://github.com/cosmos/cosmos-sdk/issues/3336) Ensure all SDK
messages have their signature bytes contain canonical fields `value` and `type`.
* [\#3333](https://github.com/cosmos/cosmos-sdk/issues/3333) - F1 storage efficiency improvements - automatic withdrawals when unbonded, historical reward reference counting
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ else
go build $(BUILD_FLAGS) -o build/gaiakeyutil ./cmd/gaia/cmd/gaiakeyutil
endif

build-linux:
build-linux: vendor-deps
LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build

update_gaia_lite_docs:
@statik -src=client/lcd/swagger-ui -dest=client/lcd -f

install: check-ledger update_gaia_lite_docs
install: vendor-deps check-ledger update_gaia_lite_docs
go install $(BUILD_FLAGS) ./cmd/gaia/cmd/gaiad
go install $(BUILD_FLAGS) ./cmd/gaia/cmd/gaiacli
go install $(BUILD_FLAGS) ./cmd/gaia/cmd/gaiareplay
Expand Down Expand Up @@ -156,15 +156,15 @@ test_sim_gaia_fast:

test_sim_gaia_import_export:
@echo "Running Gaia import/export simulation. This may take several minutes..."
@bash scripts/multisim.sh 50 TestGaiaImportExport
@bash scripts/multisim.sh 50 5 TestGaiaImportExport

test_sim_gaia_simulation_after_import:
@echo "Running Gaia simulation-after-import. This may take several minutes..."
@bash scripts/multisim.sh 50 TestGaiaSimulationAfterImport
@bash scripts/multisim.sh 50 5 TestGaiaSimulationAfterImport

test_sim_gaia_multi_seed:
@echo "Running multi-seed Gaia simulation. This may take awhile!"
@bash scripts/multisim.sh 400 TestFullGaiaSimulation
@bash scripts/multisim.sh 400 5 TestFullGaiaSimulation

SIM_NUM_BLOCKS ?= 500
SIM_BLOCK_SIZE ?= 200
Expand Down
33 changes: 26 additions & 7 deletions cmd/gaia/app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,13 @@ type GenesisAccount struct {
Coins sdk.Coins `json:"coins"`
Sequence uint64 `json:"sequence_number"`
AccountNumber uint64 `json:"account_number"`
Vesting bool `json:"vesting"`
StartTime int64 `json:"start_time"`
EndTime int64 `json:"end_time"`

// vesting account fields
OriginalVesting sdk.Coins `json:"original_vesting"` // total vesting coins upon initialization
DelegatedFree sdk.Coins `json:"delegated_free"` // delegated vested coins at time of delegation
DelegatedVesting sdk.Coins `json:"delegated_vesting"` // delegated vesting coins at time of delegation
StartTime int64 `json:"start_time"` // vesting start time
EndTime int64 `json:"end_time"` // vesting end time
}

func NewGenesisAccount(acc *auth.BaseAccount) GenesisAccount {
Expand All @@ -88,7 +92,9 @@ func NewGenesisAccountI(acc auth.Account) GenesisAccount {

vacc, ok := acc.(auth.VestingAccount)
if ok {
gacc.Vesting = true
gacc.OriginalVesting = vacc.GetOriginalVesting()
gacc.DelegatedFree = vacc.GetDelegatedFree()
gacc.DelegatedVesting = vacc.GetDelegatedVesting()
gacc.StartTime = vacc.GetStartTime()
gacc.EndTime = vacc.GetEndTime()
}
Expand All @@ -105,11 +111,24 @@ func (ga *GenesisAccount) ToAccount() auth.Account {
Sequence: ga.Sequence,
}

if ga.Vesting {
if !ga.OriginalVesting.IsZero() {
baseVestingAcc := &auth.BaseVestingAccount{
BaseAccount: bacc,
OriginalVesting: ga.OriginalVesting,
DelegatedFree: ga.DelegatedFree,
DelegatedVesting: ga.DelegatedVesting,
EndTime: ga.EndTime,
}

if ga.StartTime != 0 && ga.EndTime != 0 {
return auth.NewContinuousVestingAccount(bacc, ga.StartTime, ga.EndTime)
return &auth.ContinuousVestingAccount{
BaseVestingAccount: baseVestingAcc,
StartTime: ga.StartTime,
}
} else if ga.EndTime != 0 {
return auth.NewDelayedVestingAccount(bacc, ga.EndTime)
return &auth.DelayedVestingAccount{
BaseVestingAccount: baseVestingAcc,
}
} else {
panic(fmt.Sprintf("invalid genesis vesting account: %+v", ga))
}
Expand Down
1 change: 1 addition & 0 deletions cmd/gaia/app/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func TestToAccount(t *testing.T) {
priv := ed25519.GenPrivKey()
addr := sdk.AccAddress(priv.PubKey().Address())
authAcc := auth.NewBaseAccountWithAddress(addr)
authAcc.SetCoins(sdk.Coins{sdk.NewInt64Coin(bondDenom, 150)})
genAcc := NewGenesisAccount(&authAcc)
acc := genAcc.ToAccount()
require.IsType(t, &auth.BaseAccount{}, acc)
Expand Down
6 changes: 4 additions & 2 deletions cmd/gaia/app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,10 @@ func TestGaiaImportExport(t *testing.T) {
storeB := ctxB.KVStore(storeKeyB)
kvA, kvB, count, equal := sdk.DiffKVStores(storeA, storeB, prefixes)
fmt.Printf("Compared %d key/value pairs between %s and %s\n", count, storeKeyA, storeKeyB)
require.True(t, equal, "unequal stores: %s / %s:\nstore A %s (%X) => %s (%X)\nstore B %s (%X) => %s (%X)",
storeKeyA, storeKeyB, kvA.Key, kvA.Key, kvA.Value, kvA.Value, kvB.Key, kvB.Key, kvB.Value, kvB.Value)
require.True(t, equal,
"unequal stores: %s / %s:\nstore A %X => %X\nstore B %X => %X",
storeKeyA, storeKeyB, kvA.Key, kvA.Value, kvB.Key, kvB.Value,
)
}

}
Expand Down
11 changes: 6 additions & 5 deletions docs/spec/auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ This module will be used in the Cosmos Hub.
1. **[State](state.md)**
1. [Accounts](state.md#accounts)
1. [Account Interface](state.md#account-interface)
1. [Base Account](state.md#baseaccount)
1. [Vesting Account](state.md#vestingaccount)
2. [Base Account](state.md#baseaccount)
3. [Vesting Account](state.md#vestingaccount)
1. **[Types](types.md)**
1. [StdFee](types.md#stdfee)
1. [StdSignature](types.md#stdsignature)
1. [StdTx](types.md#stdtx)
1. [StdSignDoc](types.md#stdsigndoc)
2. [StdSignature](types.md#stdsignature)
3. [StdTx](types.md#stdtx)
4. [StdSignDoc](types.md#stdsigndoc)
1. **[Keepers](keepers.md)**
1. [AccountKeeper](keepers.md#account-keeper)
1. **[Handlers](handlers.md)**
1. [Ante Handler](handlers.md#ante-handler)
1. **[Gas & Fees](gas_fees.md)**
28 changes: 28 additions & 0 deletions docs/spec/auth/gas_fees.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Gas & Fees

Fees serve two purposes for an operator of the network.

Fees limit the growth of the state stored by every full node and allow for
general purpose censorship of transactions of little economic value. Fees
are best suited as an anti-spam mechanism where validators are disinterested in
the use of the network and identities of users.

Fees are determined by the gas limits and gas prices transactions provide.
Operators should set minimum gas prices when starting their nodes. They must set
the unit costs of gas in each token denomination they wish to support:

`gaiad start ... --minimum-gas-prices=0.00001steak,0.05photinos`

When adding transactions to mempool or gossipping transactions, validators check
if the transaction's gas prices, which are determined by the provided fees, meet
any of the validator's minimum gas prices. In other words, a transaction must
provide a fee of at least one denomination that matches a validator's minimum
gas price.

Tendermint does not currently provide fee based mempool prioritization, and fee
based mempool filtering is local to node and not part of consensus. But with
minimum gas prices set, such a mechanism could be implemented by node operators.

Because the market value for tokens will fluctuate, validators are expected to
dynamically adjust their minimum gas prices to a level that would encourage the
use of the network.
15 changes: 9 additions & 6 deletions docs/spec/auth/vesting.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,19 +316,22 @@ and return the correct accounts accordingly based off of these new fields.
type GenesisAccount struct {
// ...

Vesting bool
EndTime int64
StartTime int64
// vesting account fields
OriginalVesting sdk.Coins `json:"original_vesting"`
DelegatedFree sdk.Coins `json:"delegated_free"`
DelegatedVesting sdk.Coins `json:"delegated_vesting"`
StartTime int64 `json:"start_time"`
EndTime int64 `json:"end_time"`
}

func ToAccount(gacc GenesisAccount) Account {
bacc := NewBaseAccount(gacc)

if gacc.Vesting {
if gacc.OriginalVesting > 0 {
if ga.StartTime != 0 && ga.EndTime != 0 {
return NewContinuousVestingAccount(bacc, gacc.StartTime, gacc.EndTime)
// return a continuous vesting account
} else if ga.EndTime != 0 {
return NewDelayedVestingAccount(bacc, gacc.EndTime)
// return a delayed vesting account
} else {
// invalid genesis vesting account provided
panic()
Expand Down
2 changes: 1 addition & 1 deletion scripts/multisim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ sim() {
file="$tmpdir/gaia-simulation-seed-$seed-date-$(date -u +"%Y-%m-%dT%H:%M:%S+00:00").stdout"
echo "Writing stdout to $file..."
go test ./cmd/gaia/app -run $testname -SimulationEnabled=true -SimulationNumBlocks=$blocks \
-SimulationVerbose=true -SimulationCommit=true -SimulationSeed=$seed -SimulationPeriod=$period -v -timeout 24h | tee $file
-SimulationVerbose=true -SimulationCommit=true -SimulationSeed=$seed -SimulationPeriod=$period -v -timeout 24h > $file
}

i=0
Expand Down
26 changes: 26 additions & 0 deletions types/dec_coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,19 @@ func (coins DecCoins) MulDec(d Dec) DecCoins {
return res
}

// multiply all the coins by a decimal, truncating
func (coins DecCoins) MulDecTruncate(d Dec) DecCoins {
res := make([]DecCoin, len(coins))
for i, coin := range coins {
product := DecCoin{
Denom: coin.Denom,
Amount: coin.Amount.MulTruncate(d),
}
res[i] = product
}
return res
}

// divide all the coins by a decimal
func (coins DecCoins) QuoDec(d Dec) DecCoins {
res := make([]DecCoin, len(coins))
Expand All @@ -214,6 +227,19 @@ func (coins DecCoins) QuoDec(d Dec) DecCoins {
return res
}

// divide all the coins by a decimal, truncating
func (coins DecCoins) QuoDecTruncate(d Dec) DecCoins {
res := make([]DecCoin, len(coins))
for i, coin := range coins {
quotient := DecCoin{
Denom: coin.Denom,
Amount: coin.Amount.QuoTruncate(d),
}
res[i] = quotient
}
return res
}

// returns the amount of a denom from deccoins
func (coins DecCoins) AmountOf(denom string) Dec {
switch len(coins) {
Expand Down
27 changes: 27 additions & 0 deletions types/decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,17 @@ func (d Dec) Mul(d2 Dec) Dec {
return Dec{chopped}
}

// multiplication truncate
func (d Dec) MulTruncate(d2 Dec) Dec {
mul := new(big.Int).Mul(d.Int, d2.Int)
chopped := chopPrecisionAndTruncate(mul)

if chopped.BitLen() > 255+DecimalPrecisionBits {
panic("Int overflow")
}
return Dec{chopped}
}

// multiplication
func (d Dec) MulInt(i Int) Dec {
mul := new(big.Int).Mul(d.Int, i.i)
Expand All @@ -254,6 +265,22 @@ func (d Dec) Quo(d2 Dec) Dec {
return Dec{chopped}
}

// quotient truncate
func (d Dec) QuoTruncate(d2 Dec) Dec {

// multiply precision twice
mul := new(big.Int).Mul(d.Int, precisionReuse)
mul.Mul(mul, precisionReuse)

quo := new(big.Int).Quo(mul, d2.Int)
chopped := chopPrecisionAndTruncate(quo)

if chopped.BitLen() > 255+DecimalPrecisionBits {
panic("Int overflow")
}
return Dec{chopped}
}

// quotient
func (d Dec) QuoInt(i Int) Dec {
mul := new(big.Int).Quo(d.Int, i.i)
Expand Down
45 changes: 35 additions & 10 deletions x/auth/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ type VestingAccount interface {

GetStartTime() int64
GetEndTime() int64

GetOriginalVesting() sdk.Coins
GetDelegatedFree() sdk.Coins
GetDelegatedVesting() sdk.Coins
}

// AccountDecoder unmarshals account bytes
Expand Down Expand Up @@ -179,18 +183,20 @@ type BaseVestingAccount struct {

// String implements fmt.Stringer
func (bva BaseVestingAccount) String() string {
return fmt.Sprintf(`Vesting Account %s:
return fmt.Sprintf(`Vesting Account:
Address: %s
Coins: %s
PubKey: %s
AccountNumber: %d
Sequence: %d
OriginalVesting: %s
DelegatedFree: %s
DelegatedVesting: %s
EndTime: %d `, bva.Address, bva.Coins,
bva.PubKey.Address(), bva.AccountNumber, bva.Sequence,
EndTime: %d `,
bva.Address, bva.Coins,
bva.AccountNumber, bva.Sequence,
bva.OriginalVesting, bva.DelegatedFree,
bva.DelegatedVesting, bva.EndTime)
bva.DelegatedVesting, bva.EndTime,
)
}

// spendableCoins returns all the spendable coins for a vesting account given a
Expand Down Expand Up @@ -342,6 +348,23 @@ func (bva *BaseVestingAccount) TrackUndelegation(amount sdk.Coins) {
}
}

// GetOriginalVesting returns a vesting account's original vesting amount
func (bva BaseVestingAccount) GetOriginalVesting() sdk.Coins {
return bva.OriginalVesting
}

// GetDelegatedFree returns a vesting account's delegation amount that is not
// vesting.
func (bva BaseVestingAccount) GetDelegatedFree() sdk.Coins {
return bva.DelegatedFree
}

// GetDelegatedVesting returns a vesting account's delegation amount that is
// still vesting.
func (bva BaseVestingAccount) GetDelegatedVesting() sdk.Coins {
return bva.DelegatedVesting
}

//-----------------------------------------------------------------------------
// Continuous Vesting Account

Expand Down Expand Up @@ -372,19 +395,21 @@ func NewContinuousVestingAccount(
}

func (cva ContinuousVestingAccount) String() string {
return fmt.Sprintf(`Vesting Account %s:
return fmt.Sprintf(`Continuous Vesting Account:
Address: %s
Coins: %s
PubKey: %s
AccountNumber: %d
Sequence: %d
OriginalVesting: %s
DelegatedFree: %s
DelegatedVesting: %s
StartTime: %d
EndTime: %d `, cva.Address, cva.Coins,
cva.PubKey.Address(), cva.AccountNumber, cva.Sequence,
EndTime: %d `,
cva.Address, cva.Coins,
cva.AccountNumber, cva.Sequence,
cva.OriginalVesting, cva.DelegatedFree,
cva.DelegatedVesting, cva.StartTime, cva.EndTime)
cva.DelegatedVesting, cva.StartTime, cva.EndTime,
)
}

// GetVestedCoins returns the total number of vested coins. If no coins are vested,
Expand Down
Loading

0 comments on commit 5ab7440

Please sign in to comment.