diff --git a/cmd/soroban-rpc/internal/db/ledgerentry.go b/cmd/soroban-rpc/internal/db/ledgerentry.go index 2a0d08a1d..a468d66ec 100644 --- a/cmd/soroban-rpc/internal/db/ledgerentry.go +++ b/cmd/soroban-rpc/internal/db/ledgerentry.go @@ -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 } } diff --git a/cmd/soroban-rpc/internal/db/ledgerentry_test.go b/cmd/soroban-rpc/internal/db/ledgerentry_test.go index e37c6ed4b..74ed51f17 100644 --- a/cmd/soroban-rpc/internal/db/ledgerentry_test.go +++ b/cmd/soroban-rpc/internal/db/ledgerentry_test.go @@ -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) @@ -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) diff --git a/cmd/soroban-rpc/internal/test/simulate_transaction_test.go b/cmd/soroban-rpc/internal/test/simulate_transaction_test.go index c8b0243b9..739b9b1b1 100644 --- a/cmd/soroban-rpc/internal/test/simulate_transaction_test.go +++ b/cmd/soroban-rpc/internal/test/simulate_transaction_test.go @@ -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)