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

genesis: add GenesisAccountData type for use in GenesisAllocation #5463

Merged
merged 3 commits into from
Jun 13, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/incorporate/incorporate.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func parseInput() (genesis bookkeeping.Genesis) {
alloc := bookkeeping.GenesisAllocation{
Address: record.Address,
Comment: record.Comment,
State: basics.AccountData{
State: bookkeeping.GenesisAccountData{
Status: record.Status,
MicroAlgos: basics.MicroAlgos{Raw: record.Algos * 1e6},
VoteID: record.VoteID,
Expand Down
33 changes: 31 additions & 2 deletions data/bookkeeping/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/algorand/go-algorand/config"
"github.com/algorand/go-algorand/crypto"
"github.com/algorand/go-algorand/crypto/merklesignature"
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/data/committee"
"github.com/algorand/go-algorand/data/transactions"
Expand Down Expand Up @@ -120,7 +121,7 @@ func (genesis Genesis) Balances() (GenesisBalances, error) {
return GenesisBalances{}, fmt.Errorf("repeated allocation to %s", entry.Address)
}

genalloc[addr] = entry.State
genalloc[addr] = entry.State.AccountData()
}

feeSink, err := basics.UnmarshalChecksumAddress(genesis.FeeSink)
Expand Down Expand Up @@ -159,7 +160,7 @@ type GenesisAllocation struct {

Address string `codec:"addr"`
Comment string `codec:"comment"`
State basics.AccountData `codec:"state"`
State GenesisAccountData `codec:"state"`
}

// ToBeHashed impements the crypto.Hashable interface.
Expand All @@ -175,6 +176,34 @@ type GenesisBalances struct {
Timestamp int64
}

// GenesisAccountData contains a subset of account information that is present in the genesis file.
type GenesisAccountData struct {
_struct struct{} `codec:",omitempty,omitemptyarray"`

Status basics.Status `codec:"onl"`
MicroAlgos basics.MicroAlgos `codec:"algo"`
VoteID crypto.OneTimeSignatureVerifier `codec:"vote"`
StateProofID merklesignature.Commitment `codec:"stprf"`
SelectionID crypto.VRFVerifier `codec:"sel"`
VoteFirstValid basics.Round `codec:"voteFst"`
VoteLastValid basics.Round `codec:"voteLst"`
VoteKeyDilution uint64 `codec:"voteKD"`
}

// AccountData returns a basics.AccountData type for this genesis account.
func (ga *GenesisAccountData) AccountData() basics.AccountData {
return basics.AccountData{
Status: ga.Status,
MicroAlgos: ga.MicroAlgos,
VoteID: ga.VoteID,
StateProofID: ga.StateProofID,
SelectionID: ga.SelectionID,
VoteFirstValid: ga.VoteFirstValid,
VoteLastValid: ga.VoteLastValid,
VoteKeyDilution: ga.VoteKeyDilution,
}
}

// MakeGenesisBalances returns the information needed to bootstrap the ledger based on the current time
func MakeGenesisBalances(balances map[basics.Address]basics.AccountData, feeSink, rewardsPool basics.Address) GenesisBalances {
return MakeTimestampedGenesisBalances(balances, feeSink, rewardsPool, time.Now().Unix())
Expand Down
8 changes: 4 additions & 4 deletions data/bookkeeping/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestGenesis_Balances(t *testing.T) {
_struct: struct{}{},
Address: addr,
Comment: "",
State: basics.AccountData{
State: GenesisAccountData{
MicroAlgos: basics.MicroAlgos{Raw: algos},
},
}
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestGenesis_Balances(t *testing.T) {
},
want: GenesisBalances{
Balances: map[basics.Address]basics.AccountData{
mustAddr(allocation1.Address): allocation1.State,
mustAddr(allocation1.Address): allocation1.State.AccountData(),
},
FeeSink: goodAddr,
RewardsPool: goodAddr,
Expand All @@ -96,8 +96,8 @@ func TestGenesis_Balances(t *testing.T) {
},
want: GenesisBalances{
Balances: map[basics.Address]basics.AccountData{
mustAddr(allocation1.Address): allocation1.State,
mustAddr(allocation2.Address): allocation2.State,
mustAddr(allocation1.Address): allocation1.State.AccountData(),
mustAddr(allocation2.Address): allocation2.State.AccountData(),
},
FeeSink: goodAddr,
RewardsPool: goodAddr,
Expand Down
275 changes: 275 additions & 0 deletions data/bookkeeping/msgp_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.