Skip to content

Commit

Permalink
Don't set atx version in migration 18 (#6011)
Browse files Browse the repository at this point in the history
## Motivation

Speedup the 18th migration of state the DB.
  • Loading branch information
poszu committed Jun 5, 2024
1 parent 7231d6e commit 7316dc9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions sql/atxs/atxs.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,11 @@ func getBlob(ctx context.Context, db sql.Executor, id []byte, blob *sql.Blob) (t
return 0, fmt.Errorf("%w: atx %s", sql.ErrNotFound, types.BytesToATXID(id))
}

// The migration adding the version column does not set it to 1 for existing ATXs.
// Thus, both values 0 and 1 mean V1.
if version == 0 {
version = types.AtxV1
}
return version, nil
}

Expand Down
18 changes: 18 additions & 0 deletions sql/atxs/atxs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,24 @@ func TestLoadBlob(t *testing.T) {
require.Equal(t, []int{len(blob1.Bytes), -1, len(blob2.Bytes)}, blobSizes)
}

func TestLoadBlob_DefaultsToV1(t *testing.T) {
db := sql.InMemory()

sig, err := signing.NewEdSigner()
require.NoError(t, err)
atx := newAtx(t, sig)
atx.AtxBlob.Blob = []byte("blob1")
atx.AtxBlob.Version = 0

require.NoError(t, atxs.Add(db, atx))

var blob sql.Blob
version, err := atxs.LoadBlob(context.Background(), db, atx.ID().Bytes(), &blob)
require.NoError(t, err)
require.Equal(t, types.AtxV1, version)
require.Equal(t, atx.AtxBlob.Blob, blob.Bytes)
}

func TestGetBlobCached(t *testing.T) {
db := sql.InMemory(sql.WithQueryCache(true))
ctx := context.Background()
Expand Down
1 change: 0 additions & 1 deletion sql/migrations/state/0018_atx_blob_version.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
-- Add version column to make it easier to decode the blob
-- to the right version of ATX.
ALTER TABLE atx_blobs ADD COLUMN version INTEGER;
UPDATE atx_blobs SET version = 1;

0 comments on commit 7316dc9

Please sign in to comment.