Skip to content

Commit

Permalink
Update soroban-rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
2opremio committed Oct 16, 2023
1 parent 357dd09 commit 71aaf13
Show file tree
Hide file tree
Showing 22 changed files with 253 additions and 257 deletions.
4 changes: 2 additions & 2 deletions cmd/soroban-rpc/internal/db/ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

func createLedger(ledgerSequence uint32) xdr.LedgerCloseMeta {
return xdr.LedgerCloseMeta{
V: 2,
V2: &xdr.LedgerCloseMetaV2{
V: 1,
V1: &xdr.LedgerCloseMetaV1{
LedgerHeader: xdr.LedgerHeaderHistoryEntry{
Hash: xdr.Hash{},
Header: xdr.LedgerHeader{
Expand Down
12 changes: 6 additions & 6 deletions cmd/soroban-rpc/internal/db/ledgerentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ type LedgerEntryReader interface {
}

type LedgerKeyAndEntry struct {
Key xdr.LedgerKey
Entry xdr.LedgerEntry
ExpirationLedgerSeq *uint32 // optional expiration ledger seq, when applicable.
Key xdr.LedgerKey
Entry xdr.LedgerEntry
LiveUntilLedgerSeq *uint32 // optional live-until ledger seq, when applicable.
}

type LedgerEntryReadTx interface {
Expand Down Expand Up @@ -228,7 +228,7 @@ func GetLedgerEntry(tx LedgerEntryReadTx, key xdr.LedgerKey) (bool, xdr.LedgerEn
return false, xdr.LedgerEntry{}, nil, nil
case 1:
// expected length
return true, keyEntries[0].Entry, keyEntries[0].ExpirationLedgerSeq, nil
return true, keyEntries[0].Entry, keyEntries[0].LiveUntilLedgerSeq, nil
default:
return false, xdr.LedgerEntry{}, nil, fmt.Errorf("multiple entries (%d) for key %v", len(keyEntries), key)
}
Expand Down Expand Up @@ -314,8 +314,8 @@ func (l *ledgerEntryReadTx) GetLedgerEntries(keys ...xdr.LedgerKey) ([]LedgerKey
if err := xdr.SafeUnmarshal([]byte(encodedExpEntry), &expEntry); err != nil {
return nil, errors.Wrap(err, "cannot decode expiration ledger entry from DB")
}
expSeq := uint32(expEntry.Data.Expiration.ExpirationLedgerSeq)
result = append(result, LedgerKeyAndEntry{key, entry, &expSeq})
liveUntilSeq := uint32(expEntry.Data.Ttl.LiveUntilLedgerSeq)
result = append(result, LedgerKeyAndEntry{key, entry, &liveUntilSeq})
}

return result, nil
Expand Down
20 changes: 10 additions & 10 deletions cmd/soroban-rpc/internal/db/ledgerentry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ func TestGoldenPath(t *testing.T) {
ledgerSequence := uint32(23)
assert.NoError(t, tx.Commit(ledgerSequence))

present, obtainedEntry, obtainedLedgerSequence, expSeq := getLedgerEntryAndLatestLedgerSequence(t, db, key)
present, obtainedEntry, obtainedLedgerSequence, liveUntilSeq := getLedgerEntryAndLatestLedgerSequence(t, db, key)
assert.True(t, present)
assert.Equal(t, ledgerSequence, obtainedLedgerSequence)
require.NotNil(t, expSeq)
assert.Equal(t, uint32(expLegerEntry.Data.Expiration.ExpirationLedgerSeq), *expSeq)
require.NotNil(t, liveUntilSeq)
assert.Equal(t, uint32(expLegerEntry.Data.Ttl.LiveUntilLedgerSeq), *liveUntilSeq)
assert.Equal(t, obtainedEntry.Data.Type, xdr.LedgerEntryTypeContractData)
assert.Equal(t, xdr.Hash{0xca, 0xfe}, *obtainedEntry.Data.ContractData.Contract.ContractId)
assert.Equal(t, six, *obtainedEntry.Data.ContractData.Val.U32)
Expand All @@ -108,9 +108,9 @@ func TestGoldenPath(t *testing.T) {
ledgerSequence = uint32(24)
assert.NoError(t, tx.Commit(ledgerSequence))

present, obtainedEntry, obtainedLedgerSequence, expSeq = getLedgerEntryAndLatestLedgerSequence(t, db, key)
present, obtainedEntry, obtainedLedgerSequence, liveUntilSeq = getLedgerEntryAndLatestLedgerSequence(t, db, key)
assert.True(t, present)
require.NotNil(t, expSeq)
require.NotNil(t, liveUntilSeq)
assert.Equal(t, ledgerSequence, obtainedLedgerSequence)
assert.Equal(t, eight, *obtainedEntry.Data.ContractData.Val.U32)

Expand All @@ -124,9 +124,9 @@ func TestGoldenPath(t *testing.T) {
ledgerSequence = uint32(25)
assert.NoError(t, tx.Commit(ledgerSequence))

present, _, obtainedLedgerSequence, expSeq = getLedgerEntryAndLatestLedgerSequence(t, db, key)
present, _, obtainedLedgerSequence, liveUntilSeq = getLedgerEntryAndLatestLedgerSequence(t, db, key)
assert.False(t, present)
assert.Nil(t, expSeq)
assert.Nil(t, liveUntilSeq)
assert.Equal(t, ledgerSequence, obtainedLedgerSequence)

obtainedLedgerSequence, err = NewLedgerEntryReader(db).GetLatestLedgerSequence(context.Background())
Expand Down Expand Up @@ -194,9 +194,9 @@ func getContractDataLedgerEntry(t require.TestingT, data xdr.ContractDataEntry)

func getExpirationLedgerEntry(key xdr.LedgerKey) xdr.LedgerEntry {
var expLegerEntry xdr.LedgerEntry
expLegerEntry.Data.Expiration = &xdr.ExpirationEntry{
KeyHash: key.Expiration.KeyHash,
ExpirationLedgerSeq: 100,
expLegerEntry.Data.Ttl = &xdr.TtlEntry{
KeyHash: key.Ttl.KeyHash,
LiveUntilLedgerSeq: 100,
}
expLegerEntry.Data.Type = key.Type
return expLegerEntry
Expand Down
4 changes: 2 additions & 2 deletions cmd/soroban-rpc/internal/ingest/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ func TestIngestion(t *testing.T) {
},
}
ledger := xdr.LedgerCloseMeta{
V: 2,
V2: &xdr.LedgerCloseMetaV2{
V: 1,
V1: &xdr.LedgerCloseMetaV1{
LedgerHeader: xdr.LedgerHeaderHistoryEntry{Header: xdr.LedgerHeader{LedgerVersion: 10}},
TxSet: xdr.GeneralizedTransactionSet{
V: 1,
Expand Down
4 changes: 2 additions & 2 deletions cmd/soroban-rpc/internal/methods/get_events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1121,8 +1121,8 @@ func ledgerCloseMetaWithEvents(sequence uint32, closeTimestamp int64, txMeta ...
}

return xdr.LedgerCloseMeta{
V: 2,
V2: &xdr.LedgerCloseMetaV2{
V: 1,
V1: &xdr.LedgerCloseMetaV1{
LedgerHeader: xdr.LedgerHeaderHistoryEntry{
Hash: xdr.Hash{},
Header: xdr.LedgerHeader{
Expand Down
4 changes: 2 additions & 2 deletions cmd/soroban-rpc/internal/methods/get_latest_ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func (ledgerReader *ConstantLedgerReader) StreamAllLedgers(ctx context.Context,

func createLedger(ledgerSequence uint32, protocolVersion uint32, hash byte) xdr.LedgerCloseMeta {
return xdr.LedgerCloseMeta{
V: 2,
V2: &xdr.LedgerCloseMetaV2{
V: 1,
V1: &xdr.LedgerCloseMetaV1{
LedgerHeader: xdr.LedgerHeaderHistoryEntry{
Hash: xdr.Hash{hash},
Header: xdr.LedgerHeader{
Expand Down
6 changes: 3 additions & 3 deletions cmd/soroban-rpc/internal/methods/get_ledger_entries.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ func NewGetLedgerEntriesHandler(logger *log.Entry, ledgerEntryReader db.LedgerEn
Message: fmt.Sprintf("cannot unmarshal key value %s at index %d", requestKey, i),
}
}
if ledgerKey.Type == xdr.LedgerEntryTypeExpiration {
if ledgerKey.Type == xdr.LedgerEntryTypeTtl {
logger.WithField("request", request).
Infof("could not provide ledger expiration entry %s at index %d from getLedgerEntries request", requestKey, i)
Infof("could not provide ledger ttl entry %s at index %d from getLedgerEntries request", requestKey, i)
return GetLedgerEntriesResponse{}, &jrpc2.Error{
Code: jrpc2.InvalidParams,
Message: ErrLedgerExpirationEntriesCannotBeQueriedDirectly,
Expand Down Expand Up @@ -124,7 +124,7 @@ func NewGetLedgerEntriesHandler(logger *log.Entry, ledgerEntryReader db.LedgerEn
Key: request.Keys[i],
XDR: ledgerXDR,
LastModifiedLedger: int64(ledgerKeyAndEntry.Entry.LastModifiedLedgerSeq),
ExpirationLedger: ledgerKeyAndEntry.ExpirationLedgerSeq,
ExpirationLedger: ledgerKeyAndEntry.LiveUntilLedgerSeq,
})
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-rpc/internal/methods/get_ledger_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func NewGetLedgerEntryHandler(logger *log.Entry, ledgerEntryReader db.LedgerEntr
return GetLedgerEntryResponse{}, invalidLedgerKeyXdrError
}

if key.Type == xdr.LedgerEntryTypeExpiration {
if key.Type == xdr.LedgerEntryTypeTtl {
return GetLedgerEntryResponse{}, &jrpc2.Error{
Code: jrpc2.InvalidParams,
Message: ErrLedgerExpirationEntriesCannotBeQueriedDirectly,
Expand Down
13 changes: 7 additions & 6 deletions cmd/soroban-rpc/internal/methods/get_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/stretchr/testify/assert"

"github.com/stellar/go/network"

"github.com/stellar/soroban-tools/cmd/soroban-rpc/internal/daemon/interfaces"
"github.com/stellar/soroban-tools/cmd/soroban-rpc/internal/transactions"
)
Expand Down Expand Up @@ -70,8 +71,8 @@ func txMeta(acctSeq uint32, successful bool) xdr.LedgerCloseMeta {
},
}
return xdr.LedgerCloseMeta{
V: 2,
V2: &xdr.LedgerCloseMetaV2{
V: 1,
V1: &xdr.LedgerCloseMetaV1{
LedgerHeader: xdr.LedgerHeaderHistoryEntry{
Header: xdr.LedgerHeader{
ScpValue: xdr.StellarValue{
Expand Down Expand Up @@ -134,11 +135,11 @@ func TestGetTransaction(t *testing.T) {
tx, err = GetTransaction(store, GetTransactionRequest{hash})
assert.NoError(t, err)

expectedTxResult, err := xdr.MarshalBase64(meta.V2.TxProcessing[0].Result.Result)
expectedTxResult, err := xdr.MarshalBase64(meta.V1.TxProcessing[0].Result.Result)
assert.NoError(t, err)
expectedEnvelope, err := xdr.MarshalBase64(txEnvelope(1))
assert.NoError(t, err)
expectedTxMeta, err := xdr.MarshalBase64(meta.V2.TxProcessing[0].TxApplyProcessing)
expectedTxMeta, err := xdr.MarshalBase64(meta.V1.TxProcessing[0].TxApplyProcessing)
assert.NoError(t, err)
assert.Equal(t, GetTransactionResponse{
Status: TransactionStatusSuccess,
Expand Down Expand Up @@ -182,11 +183,11 @@ func TestGetTransaction(t *testing.T) {
xdrHash = txHash(2)
hash = hex.EncodeToString(xdrHash[:])

expectedTxResult, err = xdr.MarshalBase64(meta.V2.TxProcessing[0].Result.Result)
expectedTxResult, err = xdr.MarshalBase64(meta.V1.TxProcessing[0].Result.Result)
assert.NoError(t, err)
expectedEnvelope, err = xdr.MarshalBase64(txEnvelope(2))
assert.NoError(t, err)
expectedTxMeta, err = xdr.MarshalBase64(meta.V2.TxProcessing[0].TxApplyProcessing)
expectedTxMeta, err = xdr.MarshalBase64(meta.V1.TxProcessing[0].TxApplyProcessing)
assert.NoError(t, err)

tx, err = GetTransaction(store, GetTransactionRequest{hash})
Expand Down
8 changes: 4 additions & 4 deletions cmd/soroban-rpc/internal/methods/simulate_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ func NewSimulateTransactionHandler(logger *log.Entry, ledgerEntryReader db.Ledge
footprint := xdr.LedgerFootprint{}
switch op.Body.Type {
case xdr.OperationTypeInvokeHostFunction:
case xdr.OperationTypeBumpFootprintExpiration, xdr.OperationTypeRestoreFootprint:
case xdr.OperationTypeExtendFootprintTtl, xdr.OperationTypeRestoreFootprint:
if txEnvelope.Type != xdr.EnvelopeTypeEnvelopeTypeTx && txEnvelope.V1.Tx.Ext.V != 1 {
return SimulateTransactionResponse{
Error: "To perform a SimulateTransaction for BumpFootprintExpiration or RestoreFootprint operations, SorobanTransactionData must be provided",
Error: "To perform a SimulateTransaction for ExtendFootprintTtl or RestoreFootprint operations, SorobanTransactionData must be provided",
}
}
footprint = txEnvelope.V1.Tx.Ext.SorobanData.Resources.Footprint
Expand Down Expand Up @@ -177,8 +177,8 @@ func getBucketListSize(ctx context.Context, ledgerReader db.LedgerReader, latest
if !ok {
return 0, fmt.Errorf("missing meta for latest ledger (%d)", latestLedger)
}
if closeMeta.V != 2 {
if closeMeta.V != 1 {
return 0, fmt.Errorf("latest ledger (%d) meta has unexpected verion (%d)", latestLedger, closeMeta.V)
}
return uint64(closeMeta.V2.TotalByteSizeOfBucketList), nil
return uint64(closeMeta.V1.TotalByteSizeOfBucketList), nil
}
22 changes: 11 additions & 11 deletions cmd/soroban-rpc/internal/preflight/preflight.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func SnapshotSourceGet(handle C.uintptr_t, cLedgerKey C.xdr_t) C.xdr_t {
if err := xdr.SafeUnmarshal(ledgerKeyXDR, &ledgerKey); err != nil {
panic(err)
}
// TODO : the expiration sequence here is being ignored for now; it should be passed downstream.
// TODO : the live-until sequence here is being ignored for now; it should be passed downstream.
present, entry, _, err := db.GetLedgerEntry(h.readTx, ledgerKey)
if err != nil {
h.logger.WithError(err).Error("SnapshotSourceGet(): GetLedgerEntry() failed")
Expand Down Expand Up @@ -118,7 +118,7 @@ func GetPreflight(ctx context.Context, params PreflightParameters) (Preflight, e
switch params.OpBody.Type {
case xdr.OperationTypeInvokeHostFunction:
return getInvokeHostFunctionPreflight(params)
case xdr.OperationTypeBumpFootprintExpiration, xdr.OperationTypeRestoreFootprint:
case xdr.OperationTypeExtendFootprintTtl, xdr.OperationTypeRestoreFootprint:
return getFootprintExpirationPreflight(params)
default:
return Preflight{}, fmt.Errorf("unsupported operation type: %s", params.OpBody.Type.String())
Expand All @@ -144,7 +144,7 @@ func getFootprintExpirationPreflight(params PreflightParameters) (Preflight, err
return Preflight{}, err
}

res := C.preflight_footprint_expiration_op(
res := C.preflight_footprint_ttl_op(
C.uintptr_t(handle),
C.uint64_t(params.BucketListSize),
opBodyCXDR,
Expand Down Expand Up @@ -182,16 +182,16 @@ func getInvokeHostFunctionPreflight(params PreflightParameters) (Preflight, erro
}
sourceAccountCXDR := CXDR(sourceAccountXDR)

hasConfig, stateExpirationConfig, expSeq, err := db.GetLedgerEntry(params.LedgerEntryReadTx, xdr.LedgerKey{
hasConfig, stateExpirationConfig, liveUntilSeq, err := db.GetLedgerEntry(params.LedgerEntryReadTx, xdr.LedgerKey{
Type: xdr.LedgerEntryTypeConfigSetting,
ConfigSetting: &xdr.LedgerKeyConfigSetting{
ConfigSettingId: xdr.ConfigSettingIdConfigSettingStateExpiration,
ConfigSettingId: xdr.ConfigSettingIdConfigSettingStateArchival,
},
})
if err != nil {
return Preflight{}, err
}
if expSeq != nil {
if liveUntilSeq != nil {
return Preflight{}, errors.New("configuration setting are not expected to be expiring, yet, an expiration ledger sequence was found for ledger entry")
}
if !hasConfig {
Expand All @@ -203,17 +203,17 @@ func getInvokeHostFunctionPreflight(params PreflightParameters) (Preflight, erro
return Preflight{}, err
}

stateExpiration := stateExpirationConfig.Data.MustConfigSetting().MustStateExpirationSettings()
stateArchival := stateExpirationConfig.Data.MustConfigSetting().MustStateArchivalSettings()
li := C.ledger_info_t{
network_passphrase: C.CString(params.NetworkPassphrase),
sequence_number: C.uint32_t(simulationLedgerSeq),
protocol_version: 20,
timestamp: C.uint64_t(time.Now().Unix()),
// Current base reserve is 0.5XLM (in stroops)
base_reserve: 5_000_000,
min_temp_entry_expiration: C.uint(stateExpiration.MinTempEntryExpiration),
min_persistent_entry_expiration: C.uint(stateExpiration.MinPersistentEntryExpiration),
max_entry_expiration: C.uint(stateExpiration.MaxEntryExpiration),
base_reserve: 5_000_000,
min_temp_entry_ttl: C.uint(stateArchival.MinTemporaryTtl),
min_persistent_entry_ttl: C.uint(stateArchival.MinPersistentTtl),
max_entry_ttl: C.uint(stateArchival.MaxEntryTtl),
}

handle := cgo.NewHandle(snapshotSourceHandle{params.LedgerEntryReadTx, params.Logger})
Expand Down
20 changes: 10 additions & 10 deletions cmd/soroban-rpc/internal/preflight/preflight_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,14 @@ var mockLedgerEntriesWithoutExpirations = []xdr.LedgerEntry{
Data: xdr.LedgerEntryData{
Type: xdr.LedgerEntryTypeConfigSetting,
ConfigSetting: &xdr.ConfigSettingEntry{
ConfigSettingId: xdr.ConfigSettingIdConfigSettingStateExpiration,
StateExpirationSettings: &xdr.StateExpirationSettings{
MaxEntryExpiration: 100,
MinTempEntryExpiration: 100,
MinPersistentEntryExpiration: 100,
ConfigSettingId: xdr.ConfigSettingIdConfigSettingStateArchival,
StateArchivalSettings: &xdr.StateArchivalSettings{
MaxEntryTtl: 100,
MinTemporaryTtl: 100,
MinPersistentTtl: 100,
PersistentRentRateDenominator: 100,
TempRentRateDenominator: 100,
MaxEntriesToExpire: 100,
MaxEntriesToArchive: 100,
BucketListSizeWindowSampleSize: 100,
EvictionScanSize: 100,
},
Expand Down Expand Up @@ -210,11 +210,11 @@ var mockLedgerEntries = func() []xdr.LedgerEntry {
expirationEntry := xdr.LedgerEntry{
LastModifiedLedgerSeq: entry.LastModifiedLedgerSeq,
Data: xdr.LedgerEntryData{
Type: xdr.LedgerEntryTypeExpiration,
Expiration: &xdr.ExpirationEntry{
Type: xdr.LedgerEntryTypeTtl,
Ttl: &xdr.TtlEntry{
KeyHash: sha256.Sum256(bin),
// Make sure it doesn't expire
ExpirationLedgerSeq: 1000,
// Make sure it doesn't ttl
LiveUntilLedgerSeq: 1000,
},
},
}
Expand Down
11 changes: 6 additions & 5 deletions cmd/soroban-rpc/internal/test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ import (
"github.com/stellar/go/strkey"
"github.com/stellar/go/txnbuild"
"github.com/stellar/go/xdr"
"github.com/stellar/soroban-tools/cmd/soroban-rpc/internal/methods"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gotest.tools/v3/icmd"

"github.com/stellar/soroban-tools/cmd/soroban-rpc/internal/methods"
)

func cargoTest(t *testing.T, name string) {
Expand Down Expand Up @@ -218,7 +219,7 @@ func TestCLIRestore(t *testing.T) {
assert.Equal(t, fmt.Sprintf("New expiration ledger: %d", newExpirationSeq), restoreOutput)

// test to see that we get an error when requesting the expiration ledger entry explicitly.
ledgerExpirationEntry := getExpirationKey(t, getCounterLedgerKey(parseContractStrKey(t, strkeyContractID)))
ledgerExpirationEntry := getTtlKey(t, getCounterLedgerKey(parseContractStrKey(t, strkeyContractID)))
ledgerExpirationEntryB64, err := xdr.MarshalBase64(ledgerExpirationEntry)
require.NoError(t, err)
var getLedgerEntryResult methods.GetLedgerEntryResponse
Expand All @@ -237,13 +238,13 @@ func TestCLIRestore(t *testing.T) {
require.Contains(t, err.Error(), methods.ErrLedgerExpirationEntriesCannotBeQueriedDirectly)
}

func getExpirationKey(t *testing.T, key xdr.LedgerKey) xdr.LedgerKey {
func getTtlKey(t *testing.T, key xdr.LedgerKey) xdr.LedgerKey {
assert.True(t, key.Type == xdr.LedgerEntryTypeContractCode || key.Type == xdr.LedgerEntryTypeContractData)
binKey, err := key.MarshalBinary()
assert.NoError(t, err)
return xdr.LedgerKey{
Type: xdr.LedgerEntryTypeExpiration,
Expiration: &xdr.LedgerKeyExpiration{
Type: xdr.LedgerEntryTypeTtl,
Ttl: &xdr.LedgerKeyTtl{
KeyHash: sha256.Sum256(binKey),
},
}
Expand Down
Loading

0 comments on commit 71aaf13

Please sign in to comment.