Skip to content

Commit

Permalink
Added Participation Key Expiration Check (#2924)
Browse files Browse the repository at this point in the history
## Summary

Resolves #2738

Adds the following:

- consensus.go: Adds the default MaxExpiredAccountsToProcess value for
  the new consensus protocol
- block.go: Adds necessary block header entries
- eval.go: Scans for expired accounts, modifies them to be offline and adds
  validation for this use case
- eval_test.go: Basic unit tests
- participationExpiration_test.go: Added e2e tests that verify that
  different consensus protocols behave differently

## Test Plan

Unit test and e2e tests added
  • Loading branch information
AlgoStephenAkiki authored Oct 7, 2021
1 parent 6887d0e commit c59326f
Show file tree
Hide file tree
Showing 12 changed files with 2,233 additions and 828 deletions.
1,283 changes: 756 additions & 527 deletions agreement/msgp_gen.go

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions config/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,10 @@ type ConsensusParams struct {
EnableKeyregCoherencyCheck bool

EnableExtraPagesOnAppUpdate bool

// MaxProposedExpiredOnlineAccounts is the maximum number of online accounts, which need
// to be taken offline, that would be proposed to be taken offline.
MaxProposedExpiredOnlineAccounts int
}

// PaysetCommitType enumerates possible ways for the block header to commit to
Expand Down Expand Up @@ -465,6 +469,10 @@ var MaxExtraAppProgramLen int
//supported supported by any of the consensus protocols. used for decoding purposes.
var MaxAvailableAppProgramLen int

// MaxProposedExpiredOnlineAccounts is the maximum number of online accounts, which need
// to be taken offline, that would be proposed to be taken offline.
var MaxProposedExpiredOnlineAccounts int

func checkSetMax(value int, curMax *int) {
if value > *curMax {
*curMax = value
Expand Down Expand Up @@ -501,6 +509,7 @@ func checkSetAllocBounds(p ConsensusParams) {
// Its value is much larger than any possible reasonable MaxLogCalls value in future
checkSetMax(p.MaxAppProgramLen, &MaxLogCalls)
checkSetMax(p.MaxInnerTransactions, &MaxInnerTransactions)
checkSetMax(p.MaxProposedExpiredOnlineAccounts, &MaxProposedExpiredOnlineAccounts)
}

// SaveConfigurableConsensus saves the configurable protocols file to the provided data directory.
Expand Down Expand Up @@ -1045,6 +1054,8 @@ func initConsensusProtocols() {
// Enable TEAL 6 / AVM 1.1
vFuture.LogicSigVersion = 6

vFuture.MaxProposedExpiredOnlineAccounts = 32

Consensus[protocol.ConsensusFuture] = vFuture
}

Expand Down
10 changes: 10 additions & 0 deletions data/basics/userBalance.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,16 @@ func MakeAccountData(status Status, algos MicroAlgos) AccountData {
return AccountData{Status: status, MicroAlgos: algos}
}

// ClearOnlineState resets the account's fields to indicate that the account is an offline account
func (u *AccountData) ClearOnlineState() {
u.Status = Offline
u.VoteFirstValid = Round(0)
u.VoteLastValid = Round(0)
u.VoteKeyDilution = 0
u.VoteID = crypto.OneTimeSignatureVerifier{}
u.SelectionID = crypto.VRFVerifier{}
}

// Money returns the amount of MicroAlgos associated with the user's account
func (u AccountData) Money(proto config.ConsensusParams, rewardsLevel uint64) (money MicroAlgos, rewards MicroAlgos) {
e := u.WithUpdatedRewards(proto, rewardsLevel)
Expand Down
15 changes: 15 additions & 0 deletions data/bookkeeping/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,21 @@ type (
// for multiple types of certs.
//msgp:sort protocol.CompactCertType protocol.SortCompactCertType
CompactCert map[protocol.CompactCertType]CompactCertState `codec:"cc,allocbound=protocol.NumCompactCertTypes"`

// ParticipationUpdates contains the information needed to mark
// certain accounts offline because their participation keys expired
ParticipationUpdates
}

// ParticipationUpdates represents participation account data that
// needs to be checked/acted on by the network
ParticipationUpdates struct {
_struct struct{} `codec:",omitempty,omitemptyarray"`

// ExpiredParticipationAccounts contains a list of online accounts
// that needs to be converted to offline since their
// participation key expired.
ExpiredParticipationAccounts []basics.Address `codec:"partupdrmv,allocbound=config.MaxProposedExpiredOnlineAccounts"`
}

// RewardsState represents the global parameters controlling the rate
Expand Down
Loading

0 comments on commit c59326f

Please sign in to comment.