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
2 changes: 1 addition & 1 deletion ledger/accountdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ var accountsResetExprs = []string{
// accountDBVersion is the database version that this binary would know how to support and how to upgrade to.
// details about the content of each of the versions can be found in the upgrade functions upgradeDatabaseSchemaXXXX
// and their descriptions.
var accountDBVersion = int32(8)
var accountDBVersion = int32(9)

// persistedAccountData is used for representing a single account stored on the disk. In addition to the
// basics.AccountData, it also stores complete referencing information used to maintain the base accounts
Expand Down
2 changes: 2 additions & 0 deletions ledger/catchupaccessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,8 @@ func (c *catchpointCatchupAccessorImpl) finishBalances(ctx context.Context) (err
tp := trackerDBParams{
initAccounts: c.ledger.GenesisAccounts(),
initProto: c.ledger.GenesisProtoVersion(),
genesisHash: c.ledger.GenesisHash(),
fromCatchpoint: true,
catchpointEnabled: c.ledger.catchpoint.catchpointEnabled(),
dbPathPrefix: c.ledger.catchpoint.dbDirectory,
blockDb: c.ledger.blockDBs,
Expand Down
2 changes: 2 additions & 0 deletions ledger/ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2230,6 +2230,8 @@ func TestLedgerReloadTxTailHistoryAccess(t *testing.T) {
tp := trackerDBParams{
initAccounts: l.GenesisAccounts(),
initProto: l.GenesisProtoVersion(),
genesisHash: l.GenesisHash(),
fromCatchpoint: true,
catchpointEnabled: l.catchpoint.catchpointEnabled(),
dbPathPrefix: l.catchpoint.dbDirectory,
blockDb: l.blockDBs,
Expand Down
25 changes: 25 additions & 0 deletions ledger/trackerdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"time"

"github.com/algorand/go-algorand/config"
"github.com/algorand/go-algorand/crypto"

"github.com/algorand/go-algorand/crypto/merkletrie"
"github.com/algorand/go-algorand/data/basics"
Expand All @@ -38,6 +39,8 @@ import (
type trackerDBParams struct {
initAccounts map[basics.Address]basics.AccountData
initProto protocol.ConsensusVersion
genesisHash crypto.Digest
fromCatchpoint bool
catchpointEnabled bool
dbPathPrefix string
blockDb db.Pair
Expand Down Expand Up @@ -80,6 +83,8 @@ func trackerDBInitialize(l ledgerForTracker, catchpointEnabled bool, dbPathPrefi
tp := trackerDBParams{
initAccounts: l.GenesisAccounts(),
initProto: l.GenesisProtoVersion(),
genesisHash: l.GenesisHash(),
fromCatchpoint: false,
catchpointEnabled: catchpointEnabled,
dbPathPrefix: dbPathPrefix,
blockDb: bdbs,
Expand Down Expand Up @@ -189,6 +194,12 @@ func runMigrations(ctx context.Context, tx *sql.Tx, params trackerDBParams, log
tu.log.Warnf("trackerDBInitialize failed to upgrade accounts database (ledger.tracker.sqlite) from schema 7 : %v", err)
return
}
case 8:
err = tu.upgradeDatabaseSchema8(ctx, tx)
if err != nil {
tu.log.Warnf("trackerDBInitialize failed to upgrade accounts database (ledger.tracker.sqlite) from schema 8 : %v", err)
return
}
default:
return trackerDBInitParams{}, fmt.Errorf("trackerDBInitialize unable to upgrade database from schema version %d", tu.schemaVersion)
}
Expand Down Expand Up @@ -519,6 +530,20 @@ func (tu *trackerDBSchemaInitializer) upgradeDatabaseSchema7(ctx context.Context
return tu.setVersion(ctx, tx, 8)
}

// upgradeDatabaseSchema8 upgrades the database schema from version 8 to version 9,
// forcing a rebuild of the accounthashes table on betanet nodes. Otherwise it has no effect.
func (tu *trackerDBSchemaInitializer) upgradeDatabaseSchema8(ctx context.Context, tx *sql.Tx) (err error) {
betanetGenesisHash, _ := crypto.DigestFromString("TBMBVTC7W24RJNNUZCF7LWZD2NMESGZEQSMPG5XQD7JY4O7JKVWQ")
if tu.genesisHash == betanetGenesisHash && !tu.fromCatchpoint {
// reset hash round to 0, forcing catchpointTracker.initializeHashes to rebuild accounthashes
err = updateAccountsHashRound(ctx, tx, 0)
if err != nil {
return fmt.Errorf("upgradeDatabaseSchema8 unable to reset acctrounds table 'hashbase' round : %v", err)
}
}
return tu.setVersion(ctx, tx, 9)
}

// isDirEmpty returns if a given directory is empty or not.
func isDirEmpty(path string) (bool, error) {
dir, err := os.Open(path)
Expand Down