Skip to content
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
20 changes: 14 additions & 6 deletions ledger/accountdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,14 +711,18 @@ func accountsReset(tx *sql.Tx) error {
return err
}

// accountsRound returns the tracker balances round number, and the round of the hash tree
// if the hash of the tree doesn't exists, it returns zero.
func accountsRound(tx *sql.Tx) (rnd basics.Round, hashrnd basics.Round, err error) {
// accountsRound returns the tracker balances round number
func accountsRound(tx *sql.Tx) (rnd basics.Round, err error) {
err = tx.QueryRow("SELECT rnd FROM acctrounds WHERE id='acctbase'").Scan(&rnd)
if err != nil {
return
}
return
}

// accountsHashRound returns the round of the hash tree
// if the hash of the tree doesn't exists, it returns zero.
func accountsHashRound(tx *sql.Tx) (hashrnd basics.Round, err error) {
err = tx.QueryRow("SELECT rnd FROM acctrounds WHERE id='hashbase'").Scan(&hashrnd)
if err == sql.ErrNoRows {
hashrnd = basics.Round(0)
Expand Down Expand Up @@ -1228,7 +1232,7 @@ func totalsNewRounds(tx *sql.Tx, updates []ledgercore.AccountDeltas, compactUpda
}

// updates the round number associated with the current account data.
func updateAccountsRound(tx *sql.Tx, rnd basics.Round, hashRound basics.Round) (err error) {
func updateAccountsRound(tx *sql.Tx, rnd basics.Round) (err error) {
res, err := tx.Exec("UPDATE acctrounds SET rnd=? WHERE id='acctbase' AND rnd<?", rnd, rnd)
if err != nil {
return
Expand All @@ -1254,13 +1258,17 @@ func updateAccountsRound(tx *sql.Tx, rnd basics.Round, hashRound basics.Round) (
return
}
}
return
}

res, err = tx.Exec("INSERT OR REPLACE INTO acctrounds(id,rnd) VALUES('hashbase',?)", hashRound)
// updates the round number associated with the hash of current account data.
func updateAccountsHashRound(tx *sql.Tx, hashRound basics.Round) (err error) {
res, err := tx.Exec("INSERT OR REPLACE INTO acctrounds(id,rnd) VALUES('hashbase',?)", hashRound)
if err != nil {
return
}

aff, err = res.RowsAffected()
aff, err := res.RowsAffected()
if err != nil {
return
}
Expand Down
4 changes: 2 additions & 2 deletions ledger/accountdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import (
)

func checkAccounts(t *testing.T, tx *sql.Tx, rnd basics.Round, accts map[basics.Address]basics.AccountData) {
r, _, err := accountsRound(tx)
r, err := accountsRound(tx)
require.NoError(t, err)
require.Equal(t, r, rnd)

Expand Down Expand Up @@ -268,7 +268,7 @@ func TestAccountDBRound(t *testing.T) {
require.NoError(t, err)
_, err = accountsNewRound(tx, updatesCnt, ctbsWithDeletes, proto, basics.Round(i))
require.NoError(t, err)
err = updateAccountsRound(tx, basics.Round(i), 0)
err = updateAccountsRound(tx, basics.Round(i))
require.NoError(t, err)
checkAccounts(t, tx, basics.Round(i), accts)
checkCreatables(t, tx, i, expectedDbImage)
Expand Down
Loading