summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHang Su <hang.su@algorand.com>2022-07-13 17:03:35 -0400
committerHang Su <hang.su@algorand.com>2022-07-13 17:43:35 -0400
commit4e71c308c3ab7656080dcfcff6d801026ad4e11b (patch)
tree2816dbdd085b4dd86e44a5277c12b0033f203788
parent491b936d3ffa04b690551a96da4d95ea9e71cbbc (diff)
seems migration is tested somewhere elsekvstore-create
-rw-r--r--ledger/accountdb.go28
-rw-r--r--ledger/accountdb_test.go44
-rw-r--r--ledger/acctupdates.go9
-rw-r--r--ledger/ledger_test.go3
4 files changed, 15 insertions, 69 deletions
diff --git a/ledger/accountdb.go b/ledger/accountdb.go
index 1199aef05..3473f0762 100644
--- a/ledger/accountdb.go
+++ b/ledger/accountdb.go
@@ -2523,6 +2523,18 @@ func accountsInitDbQueries(q db.Queryable) (*accountsDbQueries, error) {
return nil, err
}
+ if accountDBVersion > int32(7) {
+ qs.lookupKvPairStmt, err = q.Prepare("SELECT acctrounds.rnd, kvstore.value FROM acctrounds LEFT JOIN kvstore ON key = ? WHERE id='acctbase';")
+ if err != nil {
+ return nil, err
+ }
+
+ qs.lookupKeysByPrefixStmt, err = q.Prepare("SELECT acctrounds.rnd, kvstore.key FROM acctrounds LEFT JOIN kvstore ON SUBSTR (kvstore.key, 1, ?) = ? WHERE id='acctbase'")
+ if err != nil {
+ return nil, err
+ }
+ }
+
qs.lookupCreatorStmt, err = q.Prepare("SELECT acctrounds.rnd, assetcreators.creator FROM acctrounds LEFT JOIN assetcreators ON asset = ? AND ctype = ? WHERE id='acctbase'")
if err != nil {
return nil, err
@@ -2547,22 +2559,6 @@ func onlineAccountsInitDbQueries(r db.Queryable) (*onlineAccountsDbQueries, erro
return qs, nil
}
-func accountsBoxesDbQueries(r db.Queryable, qs *accountsDbQueries) error {
- var err error
-
- qs.lookupKvPairStmt, err = r.Prepare("SELECT acctrounds.rnd, kvstore.value FROM acctrounds LEFT JOIN kvstore ON key = ? WHERE id='acctbase';")
- if err != nil {
- return err
- }
-
- qs.lookupKeysByPrefixStmt, err = r.Prepare("SELECT acctrounds.rnd, kvstore.key FROM acctrounds LEFT JOIN kvstore ON SUBSTR (kvstore.key, 1, ?) = ? WHERE id='acctbase'")
- if err != nil {
- return err
- }
-
- return nil
-}
-
// listCreatables returns an array of CreatableLocator which have CreatableIndex smaller or equal to maxIdx and are of the provided CreatableType.
func (qs *accountsDbQueries) listCreatables(maxIdx basics.CreatableIndex, maxResults uint64, ctype basics.CreatableType) (results []basics.CreatableLocator, dbRound basics.Round, err error) {
err = db.Retry(func() error {
diff --git a/ledger/accountdb_test.go b/ledger/accountdb_test.go
index 642c538f5..eccccfb31 100644
--- a/ledger/accountdb_test.go
+++ b/ledger/accountdb_test.go
@@ -4024,47 +4024,3 @@ func TestRemoveOfflineStateProofID(t *testing.T) {
}
}
}
-
-// TestTrackerDBSchemaVer8BringKVStore checks that if an earlier DB (without kvstore table)
-// can be updated with kvstore table, once accountDBVersion >= 8
-func TestTrackerDBSchemaVer8BringKVStore(t *testing.T) {
- partitiontest.PartitionTest(t)
-
- // Don't think we can do parallel test, for it gets involved with `accountDBVersion`
- prevAccountDBVersion := accountDBVersion
- accountDBVersion = int32(7)
-
- // bring up a ledger, and do something with
- dbName := fmt.Sprintf("%s.%d", t.Name(), crypto.RandUint64())
- genesisInitState := getInitState()
- const inMem = true
- cfg := config.GetDefaultLocal()
- cfg.Archival = true
- log := logging.TestingLog(t)
- l, err := OpenLedger(log, dbName, inMem, genesisInitState, cfg)
- require.NoError(t, err)
- defer l.Close()
-
- // kvstore table from box-storage, should not exist in earlier accountDBVersion
- tx, err := l.trackerDBs.Rdb.Handle.Begin()
- var exists bool
- err = tx.QueryRow("SELECT 1 FROM pragma_table_info('kvstore') WHERE name='key'").Scan(&exists)
- require.Error(t, err, sql.ErrNoRows)
- err = tx.Commit()
- require.NoError(t, err)
-
- // and set accountDBVersion to 8, then start trackDBInitialize in `l.reloadLedger()`
- accountDBVersion = int32(8)
- err = l.reloadLedger()
- require.NoError(t, err)
-
- // and see if new table kvstore is there
- tx, err = l.trackerDBs.Rdb.Handle.Begin()
- require.NoError(t, err)
- err = tx.QueryRow("SELECT 1 FROM pragma_table_info('kvstore') WHERE name='key'").Scan(&exists)
- require.NoError(t, err)
- err = tx.Commit()
- require.NoError(t, err)
-
- accountDBVersion = prevAccountDBVersion
-}
diff --git a/ledger/acctupdates.go b/ledger/acctupdates.go
index f41ff2edb..a5760049f 100644
--- a/ledger/acctupdates.go
+++ b/ledger/acctupdates.go
@@ -815,7 +815,7 @@ func (aul *accountUpdatesLedgerEvaluator) CheckDup(config.ConsensusParams, basic
return fmt.Errorf("accountUpdatesLedgerEvaluator: tried to check for dup during accountUpdates initialization ")
}
-// lookupWithoutRewards returns the account balance for a given address at a given round, without the reward
+// LookupWithoutRewards returns the account balance for a given address at a given round, without the reward
func (aul *accountUpdatesLedgerEvaluator) LookupWithoutRewards(rnd basics.Round, addr basics.Address) (ledgercore.AccountData, basics.Round, error) {
data, validThrough, _, _, err := aul.au.lookupWithoutRewards(rnd, addr, false /*don't sync*/)
if err != nil {
@@ -894,13 +894,6 @@ func (au *accountUpdates) initializeFromDisk(l ledgerForTracker, lastBalancesRou
return
}
- if accountDBVersion >= int32(8) {
- err = accountsBoxesDbQueries(au.dbs.Rdb.Handle, au.accountsq)
- if err != nil {
- return
- }
- }
-
hdr, err := l.BlockHdr(lastBalancesRound)
if err != nil {
return
diff --git a/ledger/ledger_test.go b/ledger/ledger_test.go
index 09a1cbc88..5408d9aaf 100644
--- a/ledger/ledger_test.go
+++ b/ledger/ledger_test.go
@@ -1974,9 +1974,10 @@ func TestLedgerReloadShrinkDeltas(t *testing.T) {
func TestLedgerMigrateV6ShrinkDeltas(t *testing.T) {
partitiontest.PartitionTest(t)
+ prevAccountDBVersion := accountDBVersion
accountDBVersion = 6
defer func() {
- accountDBVersion = 7
+ accountDBVersion = prevAccountDBVersion
}()
dbName := fmt.Sprintf("%s.%d", t.Name(), crypto.RandUint64())
testProtocolVersion := protocol.ConsensusVersion("test-protocol-migrate-shrink-deltas")