Skip to content

Commit

Permalink
go/staking/api: Rename Accounts() method to Addresses()
Browse files Browse the repository at this point in the history
  • Loading branch information
tjanez committed Jun 3, 2020
1 parent dc0e670 commit e25ed97
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 37 deletions.
8 changes: 4 additions & 4 deletions go/consensus/tendermint/apps/staking/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,21 +287,21 @@ func (sq *stakingQuerier) Genesis(ctx context.Context) (*staking.Genesis, error)
return nil, err
}

accounts, err := sq.state.Accounts(ctx)
addresses, err := sq.state.Addresses(ctx)
if err != nil {
return nil, err
}
ledger := make(map[staking.Address]*staking.Account)
for _, acctID := range accounts {
for _, addr := range addresses {
var acct *staking.Account
acct, err = sq.state.Account(ctx, acctID)
acct, err = sq.state.Account(ctx, addr)
if err != nil {
return nil, fmt.Errorf("tendermint/staking: failed to fetch account: %w", err)
}
// Make sure that export resets the stake accumulator state as that should be re-initialized
// during genesis (a genesis document with non-empty stake accumulator is invalid).
acct.Escrow.StakeAccumulator = staking.StakeAccumulator{}
ledger[acctID] = acct
ledger[addr] = acct
}

delegations, err := sq.state.Delegations(ctx)
Expand Down
6 changes: 3 additions & 3 deletions go/consensus/tendermint/apps/staking/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Query interface {
LastBlockFees(context.Context) (*quantity.Quantity, error)
Threshold(context.Context, staking.ThresholdKind) (*quantity.Quantity, error)
DebondingInterval(context.Context) (epochtime.EpochTime, error)
Accounts(context.Context) ([]staking.Address, error)
Addresses(context.Context) ([]staking.Address, error)
AccountInfo(context.Context, staking.Address) (*staking.Account, error)
Delegations(context.Context, staking.Address) (map[staking.Address]*staking.Delegation, error)
DebondingDelegations(context.Context, staking.Address) (map[staking.Address][]*staking.DebondingDelegation, error)
Expand Down Expand Up @@ -72,8 +72,8 @@ func (sq *stakingQuerier) DebondingInterval(ctx context.Context) (epochtime.Epoc
return sq.state.DebondingInterval(ctx)
}

func (sq *stakingQuerier) Accounts(ctx context.Context) ([]staking.Address, error) {
return sq.state.Accounts(ctx)
func (sq *stakingQuerier) Addresses(ctx context.Context) ([]staking.Address, error) {
return sq.state.Addresses(ctx)
}

func (sq *stakingQuerier) AccountInfo(ctx context.Context, addr staking.Address) (*staking.Account, error) {
Expand Down
8 changes: 4 additions & 4 deletions go/consensus/tendermint/apps/staking/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,23 +165,23 @@ func (s *ImmutableState) Thresholds(ctx context.Context) (map[staking.ThresholdK
return params.Thresholds, nil
}

func (s *ImmutableState) Accounts(ctx context.Context) ([]staking.Address, error) {
func (s *ImmutableState) Addresses(ctx context.Context) ([]staking.Address, error) {
it := s.is.NewIterator(ctx)
defer it.Close()

var accounts []staking.Address
var addresses []staking.Address
for it.Seek(accountKeyFmt.Encode()); it.Valid(); it.Next() {
var addr staking.Address
if !accountKeyFmt.Decode(it.Key(), &addr) {
break
}

accounts = append(accounts, addr)
addresses = append(addresses, addr)
}
if it.Err() != nil {
return nil, abciAPI.UnavailableStateError(it.Err())
}
return accounts, nil
return addresses, nil
}

func (s *ImmutableState) Account(ctx context.Context, id staking.Address) (*staking.Account, error) {
Expand Down
22 changes: 11 additions & 11 deletions go/consensus/tendermint/apps/supplementarysanity/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,19 @@ func checkStaking(ctx *abciAPI.Context, now epochtime.EpochTime) error {
// Check if the total supply adds up (common pool + all balances in the ledger).
// Check all commission schedules.
var total quantity.Quantity
accounts, err := st.Accounts(ctx)
addresses, err := st.Addresses(ctx)
if err != nil {
return fmt.Errorf("Accounts: %w", err)
return fmt.Errorf("Addresses: %w", err)
}
var acct *staking.Account
for _, id := range accounts {
acct, err = st.Account(ctx, id)
for _, addr := range addresses {
acct, err = st.Account(ctx, addr)
if err != nil {
return fmt.Errorf("Account: %w", err)
}
err = staking.SanityCheckAccount(&total, parameters, now, id, acct)
err = staking.SanityCheckAccount(&total, parameters, now, addr, acct)
if err != nil {
return fmt.Errorf("SanityCheckAccount %s: %w", id, err)
return fmt.Errorf("SanityCheckAccount %s: %w", addr, err)
}
}

Expand Down Expand Up @@ -183,12 +183,12 @@ func checkStaking(ctx *abciAPI.Context, now epochtime.EpochTime) error {
}

// Check the above two invariants for each account as well.
for _, id := range accounts {
acct, err = st.Account(ctx, id)
for _, addr := range addresses {
acct, err = st.Account(ctx, addr)
if err != nil {
return fmt.Errorf("Account: %w", err)
}
if err = staking.SanityCheckAccountShares(id, acct, delegationses[id], debondingDelegationses[id]); err != nil {
if err = staking.SanityCheckAccountShares(addr, acct, delegationses[addr], debondingDelegationses[addr]); err != nil {
return err
}
}
Expand Down Expand Up @@ -266,9 +266,9 @@ func checkStakeClaims(ctx *abciAPI.Context, now epochtime.EpochTime) error {
}
// Get staking accounts.
accounts := make(map[staking.Address]*staking.Account)
addresses, err := stakingSt.Accounts(ctx)
addresses, err := stakingSt.Addresses(ctx)
if err != nil {
return fmt.Errorf("failed to get staking accounts: %w", err)
return fmt.Errorf("failed to get staking addresses: %w", err)
}
for _, addr := range addresses {
accounts[addr], err = stakingSt.Account(ctx, addr)
Expand Down
4 changes: 2 additions & 2 deletions go/consensus/tendermint/staking/staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ func (tb *tendermintBackend) Threshold(ctx context.Context, query *api.Threshold
return q.Threshold(ctx, query.Kind)
}

func (tb *tendermintBackend) Accounts(ctx context.Context, height int64) ([]api.Address, error) {
func (tb *tendermintBackend) Addresses(ctx context.Context, height int64) ([]api.Address, error) {
q, err := tb.querier.QueryAt(ctx, height)
if err != nil {
return nil, err
}

return q.Accounts(ctx)
return q.Addresses(ctx)
}

func (tb *tendermintBackend) AccountInfo(ctx context.Context, query *api.OwnerQuery) (*api.Account, error) {
Expand Down
10 changes: 5 additions & 5 deletions go/oasis-node/cmd/debug/txsource/workload/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,19 +284,19 @@ func (q *queries) doStakingQueries(ctx context.Context, rng *rand.Rand, height i
return fmt.Errorf("Invalid treshold")
}

accounts, err := q.staking.Accounts(ctx, height)
addresses, err := q.staking.Addresses(ctx, height)
if err != nil {
return fmt.Errorf("staking.Accounts: %w", err)
}

// Make sure total supply matches sum of all balances and fees.
var accSum, totalSum quantity.Quantity
for _, sig := range accounts {
acc, err := q.staking.AccountInfo(ctx, &staking.OwnerQuery{Owner: sig, Height: height})
for _, addr := range addresses {
acc, err := q.staking.AccountInfo(ctx, &staking.OwnerQuery{Owner: addr, Height: height})
if err != nil {
q.logger.Error("Error querying AcccountInfo",
"height", height,
"owner", sig,
"address", addr,
"err", err,
)
return fmt.Errorf("staking.AccountInfo: %w", err)
Expand All @@ -317,7 +317,7 @@ func (q *queries) doStakingQueries(ctx context.Context, rng *rand.Rand, height i
"accounts_sum", accSum,
"total_sum", totalSum,
"total", total,
"accounts", len(accounts),
"n_addresses", len(addresses),
)
return fmt.Errorf("staking total supply mismatch")
}
Expand Down
4 changes: 2 additions & 2 deletions go/oasis-node/cmd/stake/stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ func doList(cmd *cobra.Command, args []string) {
ctx := context.Background()

var addrs []api.Address
doWithRetries(cmd, "query accounts", func() error {
doWithRetries(cmd, "query addresses", func() error {
var err error
addrs, err = client.Accounts(ctx, consensus.HeightLatest)
addrs, err = client.Addresses(ctx, consensus.HeightLatest)
return err
})

Expand Down
6 changes: 3 additions & 3 deletions go/staking/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ type Backend interface {
// Threshold returns the specific staking threshold by kind.
Threshold(ctx context.Context, query *ThresholdQuery) (*quantity.Quantity, error)

// Accounts returns the addresses of all accounts with a non-zero general or
// escrow balance.
Accounts(ctx context.Context, height int64) ([]Address, error)
// Addresses returns the addresses of all accounts with a non-zero general
// or escrow balance.
Addresses(ctx context.Context, height int64) ([]Address, error)

// AccountInfo returns the account descriptor for the given account.
AccountInfo(ctx context.Context, query *OwnerQuery) (*Account, error)
Expand Down
6 changes: 3 additions & 3 deletions go/staking/api/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,14 @@ func handlerAccounts( // nolint: golint
return nil, err
}
if interceptor == nil {
return srv.(Backend).Accounts(ctx, height)
return srv.(Backend).Addresses(ctx, height)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: methodAccounts.FullName(),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(Backend).Accounts(ctx, req.(int64))
return srv.(Backend).Addresses(ctx, req.(int64))
}
return interceptor(ctx, height, info, handler)
}
Expand Down Expand Up @@ -527,7 +527,7 @@ func (c *stakingClient) Threshold(ctx context.Context, query *ThresholdQuery) (*
return &rsp, nil
}

func (c *stakingClient) Accounts(ctx context.Context, height int64) ([]Address, error) {
func (c *stakingClient) Addresses(ctx context.Context, height int64) ([]Address, error) {
var rsp []Address
if err := c.conn.Invoke(ctx, methodAccounts.FullName(), height, &rsp); err != nil {
return nil, err
Expand Down

0 comments on commit e25ed97

Please sign in to comment.