Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating with latest master #3488

Merged
merged 6 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions agreement/persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func restore(log logging.Logger, crash db.Accessor) (raw []byte, err error) {
// the above call was completed sucecssfully, which means that we've just created the table ( which wasn't there ! ).
// in that case, the table is guaranteed to be empty, and therefore we can return right here.
log.Infof("restore (agreement): crash state table initialized")
noCrashState = true // this is a normal case (we don't have crash state)
err = errNoCrashStateAvailable
return
}
Expand Down
6 changes: 6 additions & 0 deletions catchup/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,12 @@ func (s *Service) fetchAndWrite(r basics.Round, prevFetchCompleteChan chan bool,
// if the context expired, just exit.
return false
}
if errNSBE, ok := err.(ledgercore.ErrNonSequentialBlockEval); ok && errNSBE.EvaluatorRound <= errNSBE.LatestRound {
// the block was added to the ledger from elsewhere after fetching it here
// only the agreement could have added this block into the ledger, catchup is complete
s.log.Infof("fetchAndWrite(%d): after fetching the block, it is already in the ledger. The catchup is complete", r)
return false
}
s.log.Warnf("fetchAndWrite(%d): failed to validate block : %v", r, err)
return false
}
Expand Down
5 changes: 5 additions & 0 deletions config/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@ type ConsensusParams struct {
// MaxProposedExpiredOnlineAccounts is the maximum number of online accounts, which need
// to be taken offline, that would be proposed to be taken offline.
MaxProposedExpiredOnlineAccounts int

// When rewards rate changes, use the new value immediately.
RewardsCalculationFix bool
}

// PaysetCommitType enumerates possible ways for the block header to commit to
Expand Down Expand Up @@ -1054,6 +1057,8 @@ func initConsensusProtocols() {

vFuture.MaxProposedExpiredOnlineAccounts = 32

vFuture.RewardsCalculationFix = true

Consensus[protocol.ConsensusFuture] = vFuture
}

Expand Down
2 changes: 1 addition & 1 deletion daemon/algod/api/server/v2/test/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func TestGetBlockJsonEncoding(t *testing.T) {
Round: l.Latest() + 1,
Branch: genBlk.Hash(),
TimeStamp: 0,
RewardsState: genBlk.NextRewardsState(l.Latest()+1, proto, poolBal.MicroAlgos, totalRewardUnits),
RewardsState: genBlk.NextRewardsState(l.Latest()+1, proto, poolBal.MicroAlgos, totalRewardUnits, logging.Base()),
UpgradeState: genBlk.UpgradeState,
}

Expand Down
25 changes: 16 additions & 9 deletions data/bookkeeping/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,17 +285,17 @@ func (block *Block) Seed() committee.Seed {
// NextRewardsState computes the RewardsState of the subsequent round
// given the subsequent consensus parameters, along with the incentive pool
// balance and the total reward units in the system as of the current round.
func (s RewardsState) NextRewardsState(nextRound basics.Round, nextProto config.ConsensusParams, incentivePoolBalance basics.MicroAlgos, totalRewardUnits uint64) (res RewardsState) {
func (s RewardsState) NextRewardsState(nextRound basics.Round, nextProto config.ConsensusParams, incentivePoolBalance basics.MicroAlgos, totalRewardUnits uint64, log logging.Logger) (res RewardsState) {
res = s

if nextRound == s.RewardsRecalculationRound {
if nextRound == res.RewardsRecalculationRound {
maxSpentOver := nextProto.MinBalance
overflowed := false

if nextProto.PendingResidueRewards {
maxSpentOver, overflowed = basics.OAdd(maxSpentOver, s.RewardsResidue)
maxSpentOver, overflowed = basics.OAdd(maxSpentOver, res.RewardsResidue)
if overflowed {
logging.Base().Errorf("overflowed when trying to accumulate MinBalance(%d) and RewardsResidue(%d) for round %d (state %+v)", nextProto.MinBalance, s.RewardsResidue, nextRound, s)
log.Errorf("overflowed when trying to accumulate MinBalance(%d) and RewardsResidue(%d) for round %d (state %+v)", nextProto.MinBalance, res.RewardsResidue, nextRound, s)
// this should never happen, but if it does, adjust the maxSpentOver so that we will have no rewards.
maxSpentOver = incentivePoolBalance.Raw
}
Expand All @@ -304,7 +304,7 @@ func (s RewardsState) NextRewardsState(nextRound basics.Round, nextProto config.
// it is time to refresh the rewards rate
newRate, overflowed := basics.OSub(incentivePoolBalance.Raw, maxSpentOver)
if overflowed {
logging.Base().Errorf("overflowed when trying to refresh RewardsRate for round %v (state %+v)", nextRound, s)
log.Errorf("overflowed when trying to refresh RewardsRate for round %v (state %+v)", nextRound, s)
newRate = 0
}

Expand All @@ -317,14 +317,21 @@ func (s RewardsState) NextRewardsState(nextRound basics.Round, nextProto config.
return
}

var rewardsRate uint64
if nextProto.RewardsCalculationFix {
rewardsRate = res.RewardsRate
} else {
rewardsRate = s.RewardsRate
}

var ot basics.OverflowTracker
rewardsWithResidue := ot.Add(s.RewardsRate, s.RewardsResidue)
nextRewardLevel := ot.Add(s.RewardsLevel, rewardsWithResidue/totalRewardUnits)
rewardsWithResidue := ot.Add(rewardsRate, res.RewardsResidue)
nextRewardLevel := ot.Add(res.RewardsLevel, rewardsWithResidue/totalRewardUnits)
nextResidue := rewardsWithResidue % totalRewardUnits

if ot.Overflowed {
logging.Base().Errorf("could not compute next reward level (current level %v, adding %v MicroAlgos in total, number of reward units %v) using old level",
s.RewardsLevel, s.RewardsRate, totalRewardUnits)
log.Errorf("could not compute next reward level (current level %v, adding %v MicroAlgos in total, number of reward units %v) using old level",
res.RewardsLevel, rewardsRate, totalRewardUnits)
return
}

Expand Down
Loading