Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

soroban-rpc: Fix ledgerentry visibility bug #871

Merged
merged 3 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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