Skip to content

Commit

Permalink
Merge pull request #280 from coinbase/patrick/find-transaction-regres…
Browse files Browse the repository at this point in the history
…sion

[bug][storage] Fix `FindTransaction` Regression
  • Loading branch information
patrick-ogrady committed Dec 14, 2020
2 parents beb8dbd + 0d2ec18 commit 23200e5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion storage/modules/block_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ func (b *BlockStorage) FindTransaction(
return nil, nil, nil
}

head, err := b.GetHeadBlockIdentifier(ctx)
head, err := b.GetHeadBlockIdentifierTransactional(ctx, txn)
if err != nil {
return nil, nil, err
}
Expand Down
24 changes: 14 additions & 10 deletions storage/modules/block_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,21 @@ func TestBlock(t *testing.T) {
err = storage.SeeBlock(ctx, newBlock)
assert.NoError(t, err)

err = storage.AddBlock(ctx, newBlock)
// Ensure we can FindTransaction in add block transaction.
transaction := storage.db.WriteTransaction(ctx, blockSyncIdentifier, true)
err = storage.storeBlock(ctx, transaction, newBlock.BlockIdentifier)
assert.NoError(t, err)

newestBlock, newestTransaction, err := storage.FindTransaction(
ctx,
newBlock.Transactions[0].TransactionIdentifier,
transaction,
)
assert.NoError(t, err)
assert.Equal(t, newBlock.BlockIdentifier, newestBlock)
assert.Equal(t, newBlock.Transactions[0], newestTransaction)

assert.NoError(t, transaction.Commit(ctx))

block, err := storage.GetBlock(
ctx,
Expand All @@ -381,15 +394,6 @@ func TestBlock(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, newBlock.BlockIdentifier, head)

newestBlock, transaction, err := findTransactionWithDbTransaction(
ctx,
storage,
newBlock.Transactions[0].TransactionIdentifier,
)
assert.NoError(t, err)
assert.Equal(t, newBlock.BlockIdentifier, newestBlock)
assert.Equal(t, newBlock.Transactions[0], transaction)

oldestIndex, err := storage.GetOldestBlockIndex(ctx)
assert.Equal(t, int64(0), oldestIndex)
assert.NoError(t, err)
Expand Down

0 comments on commit 23200e5

Please sign in to comment.