From 19225fc5d478315db8fc44a37b1cb9bfd1991708 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Mon, 22 Oct 2018 02:42:40 -0700 Subject: [PATCH] Print debugging info --- x/distribution/types/fee_pool.go | 26 +++++++++++++++++++++++++- x/distribution/types/validator_info.go | 13 +++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/x/distribution/types/fee_pool.go b/x/distribution/types/fee_pool.go index ae1d72cc01..759519c9e2 100644 --- a/x/distribution/types/fee_pool.go +++ b/x/distribution/types/fee_pool.go @@ -1,7 +1,10 @@ package types import ( + "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" + cmn "github.com/tendermint/tendermint/libs/common" ) // total accumulation tracker @@ -29,6 +32,27 @@ func (ta TotalAccum) UpdateForNewHeight(height int64, accumCreatedPerBlock sdk.D return ta } +// update total validator accumulation factor for the new height +// CONTRACT: height should be greater than the old height +func (ta TotalAccum) UpdateForNewHeight_DEBUG(height int64, accumCreatedPerBlock sdk.Dec) TotalAccum { + blocks := height - ta.UpdateHeight + if blocks < 0 { + panic("reverse updated for new height") + } + fmt.Println( + cmn.Blue( + fmt.Sprintf("FP Add %v * %v = %v +=> %v", + accumCreatedPerBlock, sdk.NewInt(blocks), + accumCreatedPerBlock.MulInt(sdk.NewInt(blocks)), + ta.Accum.Add(accumCreatedPerBlock.MulInt(sdk.NewInt(blocks))), + ), + ), + ) + ta.Accum = ta.Accum.Add(accumCreatedPerBlock.MulInt(sdk.NewInt(blocks))) + ta.UpdateHeight = height + return ta +} + //___________________________________________________________________________________________ // global fee pool for distribution @@ -41,7 +65,7 @@ type FeePool struct { // update total validator accumulation factor // NOTE: Do not call this except from ValidatorDistInfo.TakeFeePoolRewards(). func (f FeePool) UpdateTotalValAccum(height int64, totalBondedTokens sdk.Dec) FeePool { - f.TotalValAccum = f.TotalValAccum.UpdateForNewHeight(height, totalBondedTokens) + f.TotalValAccum = f.TotalValAccum.UpdateForNewHeight_DEBUG(height, totalBondedTokens) return f } diff --git a/x/distribution/types/validator_info.go b/x/distribution/types/validator_info.go index 1744e3baac..e082c2ee83 100644 --- a/x/distribution/types/validator_info.go +++ b/x/distribution/types/validator_info.go @@ -1,7 +1,10 @@ package types import ( + "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" + cmn "github.com/tendermint/tendermint/libs/common" ) // distribution info for a particular validator @@ -62,6 +65,16 @@ func (vi ValidatorDistInfo) TakeFeePoolRewards(fp FeePool, height int64, totalBo commission := withdrawalTokens.MulDec(commissionRate) afterCommission := withdrawalTokens.Minus(commission) + fmt.Println( + cmn.Red( + fmt.Sprintf("FP Sub %v * %v = %v -=> %v", + vdTokens, sdk.NewInt(blocks), + accum, + fp.TotalValAccum.Accum.Sub(accum), + ), + ), + ) + fp.TotalValAccum.Accum = fp.TotalValAccum.Accum.Sub(accum) fp.Pool = remainingTokens vi.PoolCommission = vi.PoolCommission.Plus(commission)