Skip to content

Commit

Permalink
soroban-rpc: Fix ledgerentry visibility bug (#871)
Browse files Browse the repository at this point in the history
* Fix ledgerentry visibility bug from #846

* Fix test output
  • Loading branch information
Paul Bellamy authored Aug 21, 2023
1 parent 08de7d5 commit 06b48ad
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion cmd/soroban-rpc/internal/db/ledgerentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ func (l *ledgerEntryReadTx) GetLedgerEntry(key xdr.LedgerKey, includeExpired boo
if err != nil {
return false, xdr.LedgerEntry{}, err
}
if expirationLedgerSeq < xdr.Uint32(latestClosedLedger) {
currentLedger := latestClosedLedger + 1
if expirationLedgerSeq < xdr.Uint32(currentLedger) {
return false, xdr.LedgerEntry{}, nil
}
}
Expand Down
14 changes: 10 additions & 4 deletions cmd/soroban-rpc/internal/db/ledgerentry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,18 @@ func TestGetLedgerEntryHidesExpiredContractDataEntries(t *testing.T) {
}{
{21, true},
{22, true},
{23, true},
{23, false},
{24, false},
{25, false},
} {
// ffwd to the ledger sequence
tx, err := NewReadWriter(db, 0, 15).NewTx(context.Background())
assert.NoError(t, err)
// Close the ledger N
assert.NoError(t, tx.Commit(c.ledgerSequence))

// Now, ledger N is our latestClosedLedger, so any preflights should act as
// though it is currently ledger N+1

// Try to read the entry back, and check it disappears when expected
present, _, obtainedLedgerSequence := getLedgerEntryAndLatestLedgerSequence(t, db, key)
assert.Equal(t, c.ledgerSequence, obtainedLedgerSequence)
Expand Down Expand Up @@ -404,15 +407,18 @@ func TestGetLedgerEntryHidesExpiredContractCodeEntries(t *testing.T) {
}{
{21, true},
{22, true},
{23, true},
{23, false},
{24, false},
{25, false},
} {
// ffwd to the ledger sequence
tx, err := NewReadWriter(db, 0, 15).NewTx(context.Background())
assert.NoError(t, err)
// Close the ledger N
assert.NoError(t, tx.Commit(c.ledgerSequence))

// Now, ledger N is our latestClosedLedger, so any preflights should act as
// though it is currently ledger N+1

// Try to read the entry back, and check it disappears when expected
present, _, obtainedLedgerSequence := getLedgerEntryAndLatestLedgerSequence(t, db, key)
assert.Equal(t, c.ledgerSequence, obtainedLedgerSequence)
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-rpc/internal/test/simulate_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ func TestSimulateTransactionBumpAndRestoreFootprint(t *testing.T) {
break
}
assert.NoError(t, xdr.SafeUnmarshalBase64(getLedgerEntryResult.XDR, &entry))
t.Log("waiting for ledger entry to expire at ledger", entry.MustContractData().ExpirationLedgerSeq+1)
t.Log("waiting for ledger entry to expire at ledger", entry.MustContractData().ExpirationLedgerSeq)
time.Sleep(time.Second)
}
require.True(t, expired)
Expand Down

0 comments on commit 06b48ad

Please sign in to comment.