Skip to content

Commit 9cdcb39

Browse files
authored
Minimum Account Balance in Algod (#3287)
1 parent b73265c commit 9cdcb39

File tree

17 files changed

+590
-258
lines changed

17 files changed

+590
-258
lines changed

cmd/goal/account.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,8 @@ func printAccountInfo(client libgoal.Client, address string, account generatedV2
696696
fmt.Fprintf(report, "\tID %d, local state used %d/%d uints, %d/%d byte slices\n", localState.Id, usedInts, allocatedInts, usedBytes, allocatedBytes)
697697
}
698698

699+
fmt.Fprintf(report, "Minimum Balance:\t%v microAlgos\n", account.MinBalance)
700+
699701
if hasError {
700702
fmt.Fprint(os.Stderr, errorReport.String())
701703
}

cmd/tealdbg/local_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"strings"
2727
"testing"
2828

29+
"github.com/algorand/go-algorand/config"
2930
v2 "github.com/algorand/go-algorand/daemon/algod/api/server/v2"
3031
"github.com/algorand/go-algorand/data/basics"
3132
"github.com/algorand/go-algorand/data/transactions"
@@ -984,7 +985,7 @@ func TestLocalBalanceAdapterIndexer(t *testing.T) {
984985
case strings.HasPrefix(r.URL.Path, accountPath):
985986
w.WriteHeader(200)
986987
if r.URL.Path[len(accountPath):] == brs.Addr.String() {
987-
account, err := v2.AccountDataToAccount(brs.Addr.String(), &brs.AccountData, map[basics.AssetIndex]string{}, 100, basics.MicroAlgos{Raw: 0})
988+
account, err := v2.AccountDataToAccount(brs.Addr.String(), &brs.AccountData, map[basics.AssetIndex]string{}, 100, &config.ConsensusParams{MinBalance: 100000}, basics.MicroAlgos{Raw: 0})
988989
a.NoError(err)
989990
accountResponse := AccountIndexerResponse{Account: account, CurrentRound: 100}
990991
response, err := json.Marshal(accountResponse)

daemon/algod/api/algod.oas2.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1354,7 +1354,8 @@
13541354
"pending-rewards",
13551355
"amount-without-pending-rewards",
13561356
"rewards",
1357-
"status"
1357+
"status",
1358+
"min-balance"
13581359
],
13591360
"properties": {
13601361
"address": {
@@ -1365,6 +1366,10 @@
13651366
"description": "\\[algo\\] total number of MicroAlgos in the account",
13661367
"type": "integer"
13671368
},
1369+
"min-balance": {
1370+
"description": "MicroAlgo balance required by the account.\n\nThe requirement grows based on asset and application usage.",
1371+
"type": "integer"
1372+
},
13681373
"amount-without-pending-rewards": {
13691374
"description": "specifies the amount of MicroAlgos in the account, without the pending rewards.",
13701375
"type": "integer"

daemon/algod/api/algod.oas3.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,10 @@
726726
},
727727
"type": "array"
728728
},
729+
"min-balance": {
730+
"description": "MicroAlgo balance required by the account.\n\nThe requirement grows based on asset and application usage.",
731+
"type": "integer"
732+
},
729733
"participation": {
730734
"$ref": "#/components/schemas/AccountParticipation"
731735
},
@@ -763,6 +767,7 @@
763767
"address",
764768
"amount",
765769
"amount-without-pending-rewards",
770+
"min-balance",
766771
"pending-rewards",
767772
"rewards",
768773
"round",

daemon/algod/api/server/v2/account.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"math"
2323
"sort"
2424

25+
"github.com/algorand/go-algorand/config"
2526
"github.com/algorand/go-algorand/crypto"
2627
"github.com/algorand/go-algorand/daemon/algod/api/server/v2/generated"
2728
"github.com/algorand/go-algorand/data/basics"
@@ -30,7 +31,8 @@ import (
3031
// AccountDataToAccount converts basics.AccountData to v2.generated.Account
3132
func AccountDataToAccount(
3233
address string, record *basics.AccountData, assetsCreators map[basics.AssetIndex]string,
33-
lastRound basics.Round, amountWithoutPendingRewards basics.MicroAlgos,
34+
lastRound basics.Round, consensus *config.ConsensusParams,
35+
amountWithoutPendingRewards basics.MicroAlgos,
3436
) (generated.Account, error) {
3537

3638
assets := make([]generated.AssetHolding, 0, len(record.Assets))
@@ -108,6 +110,8 @@ func AccountDataToAccount(
108110
return generated.Account{}, errors.New("overflow on pending reward calculation")
109111
}
110112

113+
minBalance := record.MinBalance(consensus)
114+
111115
return generated.Account{
112116
SigType: nil,
113117
Round: uint64(lastRound),
@@ -126,6 +130,7 @@ func AccountDataToAccount(
126130
AppsLocalState: &appsLocalState,
127131
AppsTotalSchema: &totalAppSchema,
128132
AppsTotalExtraPages: numOrNil(totalExtraPages),
133+
MinBalance: minBalance.Raw,
129134
}, nil
130135
}
131136

daemon/algod/api/server/v2/account_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func TestAccount(t *testing.T) {
102102
b := a.WithUpdatedRewards(proto, 100)
103103

104104
addr := basics.Address{}.String()
105-
conv, err := AccountDataToAccount(addr, &b, map[basics.AssetIndex]string{}, round, a.MicroAlgos)
105+
conv, err := AccountDataToAccount(addr, &b, map[basics.AssetIndex]string{}, round, &proto, a.MicroAlgos)
106106
require.NoError(t, err)
107107
require.Equal(t, addr, conv.Address)
108108
require.Equal(t, b.MicroAlgos.Raw, conv.Amount)
@@ -196,7 +196,7 @@ func TestAccount(t *testing.T) {
196196
// convert the same account a few more times to make sure we always
197197
// produce the same generated.Account
198198
for i := 0; i < 10; i++ {
199-
anotherConv, err := AccountDataToAccount(addr, &b, map[basics.AssetIndex]string{}, round, a.MicroAlgos)
199+
anotherConv, err := AccountDataToAccount(addr, &b, map[basics.AssetIndex]string{}, round, &proto, a.MicroAlgos)
200200
require.NoError(t, err)
201201

202202
require.Equal(t, protocol.EncodeJSON(conv), protocol.EncodeJSON(anotherConv))

daemon/algod/api/server/v2/generated/private/routes.go

Lines changed: 77 additions & 76 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

daemon/algod/api/server/v2/generated/private/types.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)