diff --git a/internal/database/snapshot.go b/internal/database/snapshot.go index 1065f9596..9c4d4a4cd 100644 --- a/internal/database/snapshot.go +++ b/internal/database/snapshot.go @@ -226,9 +226,10 @@ func (db *Database) collectMessages(w *snapshot.Writer, index *badger.DB, opts * return errors.UnknownError.WithFormat("collect %x: %w", hash, err) } - // Collect the transaction status (which is the only part of the - // transaction entity that is still used by exec v2) - err = records.Collect(batch.newTransaction(transactionKey{Hash: hash}).newStatus(), copts) + // Collect the transaction's records. Executor v2 only uses the + // transaction status, but transactions and signatures from v1 are still + // stored here, so they should be collected. + err = records.Collect(batch.newTransaction(transactionKey{Hash: hash}), copts) if err != nil { return errors.UnknownError.WithFormat("collect %x status: %w", hash, err) } diff --git a/internal/database/snapshot_test.go b/internal/database/snapshot_test.go index 96a6ab370..69a99e0a6 100644 --- a/internal/database/snapshot_test.go +++ b/internal/database/snapshot_test.go @@ -227,3 +227,37 @@ func TestCollectAndRestore(t *testing.T) { Txn(st.TxID).Succeeds(), Txn(st.TxID).Produced().Succeeds()) } + +func TestPreservationOfOldTransactions(t *testing.T) { + // Some random transaction + env, err := build.Transaction().For("alice", "tokens").BurnTokens(1, 0). + SignWith("alice", "book", "1").Version(1).Timestamp(1).PrivateKey(make([]byte, 64)). + Done() + require.NoError(t, err) + + // Store it in a database + txn := env.Transaction[0] + db := database.OpenInMemory(nil) + db.SetObserver(execute.NewDatabaseObserver()) + batch := db.Begin(true) + defer batch.Discard() + require.NoError(t, batch.Transaction(txn.GetHash()).Main().Put(&database.SigOrTxn{Transaction: txn})) + require.NoError(t, batch.Account(txn.Header.Principal).MainChain().Inner().AddHash(txn.GetHash(), false)) + require.NoError(t, batch.Commit()) + + // Collect a snapshot + buf := new(ioutil.Buffer) + require.NoError(t, db.Collect(buf, nil, nil)) + + // Restore the snapshot + db = database.OpenInMemory(nil) + db.SetObserver(execute.NewDatabaseObserver()) + require.NoError(t, db.Restore(buf, nil)) + + // Verify the transaction still exists + batch = db.Begin(false) + defer batch.Discard() + txn2, err := batch.Transaction(txn.GetHash()).Main().Get() + require.NoError(t, err) + require.True(t, txn.Equal(txn2.Transaction)) +}