diff --git a/Cargo.lock b/Cargo.lock index 46c86038..81f5b629 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1562,6 +1562,7 @@ dependencies = [ [[package]] name = "soroban-builtin-sdk-macros" version = "20.2.2" +source = "git+https://github.com/stellar/rs-soroban-env?rev=8c9ab83c406bd86f56d52eae3e39dccf6b45b3da#8c9ab83c406bd86f56d52eae3e39dccf6b45b3da" dependencies = [ "itertools 0.11.0", "proc-macro2", @@ -1589,6 +1590,7 @@ dependencies = [ [[package]] name = "soroban-env-common" version = "20.2.2" +source = "git+https://github.com/stellar/rs-soroban-env?rev=8c9ab83c406bd86f56d52eae3e39dccf6b45b3da#8c9ab83c406bd86f56d52eae3e39dccf6b45b3da" dependencies = [ "arbitrary", "crate-git-revision", @@ -1640,6 +1642,7 @@ dependencies = [ [[package]] name = "soroban-env-host" version = "20.2.2" +source = "git+https://github.com/stellar/rs-soroban-env?rev=8c9ab83c406bd86f56d52eae3e39dccf6b45b3da#8c9ab83c406bd86f56d52eae3e39dccf6b45b3da" dependencies = [ "backtrace", "curve25519-dalek", @@ -1680,6 +1683,7 @@ dependencies = [ [[package]] name = "soroban-env-macros" version = "20.2.2" +source = "git+https://github.com/stellar/rs-soroban-env?rev=8c9ab83c406bd86f56d52eae3e39dccf6b45b3da#8c9ab83c406bd86f56d52eae3e39dccf6b45b3da" dependencies = [ "itertools 0.11.0", "proc-macro2", @@ -1775,6 +1779,7 @@ dependencies = [ [[package]] name = "soroban-simulation" version = "20.2.2" +source = "git+https://github.com/stellar/rs-soroban-env?rev=8c9ab83c406bd86f56d52eae3e39dccf6b45b3da#8c9ab83c406bd86f56d52eae3e39dccf6b45b3da" dependencies = [ "anyhow", "rand", diff --git a/Cargo.toml b/Cargo.toml index 5b50130a..ea1490c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,15 +13,15 @@ rust-version = "1.74.0" [workspace.dependencies.soroban-env-host] version = "=20.2.2" -# git = "https://github.com/stellar/rs-soroban-env" -# rev = "1bfc0f2a2ee134efc1e1b0d5270281d0cba61c2e" -path = "../rs-soroban-env/soroban-env-host" +git = "https://github.com/stellar/rs-soroban-env" +rev = "8c9ab83c406bd86f56d52eae3e39dccf6b45b3da" +# path = "../rs-soroban-env/soroban-env-host" [workspace.dependencies.soroban-simulation] version = "=20.2.2" -# git = "https://github.com/stellar/rs-soroban-env" -# rev = "1bfc0f2a2ee134efc1e1b0d5270281d0cba61c2e" -path = "../rs-soroban-env/soroban-simulation" +git = "https://github.com/stellar/rs-soroban-env" +rev = "8c9ab83c406bd86f56d52eae3e39dccf6b45b3da" +# path = "../rs-soroban-env/soroban-simulation" [workspace.dependencies.soroban-spec] version = "=20.3.1" diff --git a/cmd/soroban-rpc/internal/preflight/preflight.go b/cmd/soroban-rpc/internal/preflight/preflight.go index 584c47d6..e5cf0d05 100644 --- a/cmd/soroban-rpc/internal/preflight/preflight.go +++ b/cmd/soroban-rpc/internal/preflight/preflight.go @@ -2,7 +2,6 @@ package preflight import ( "context" - "errors" "fmt" "runtime/cgo" "time" @@ -150,6 +149,23 @@ func GetPreflight(ctx context.Context, params PreflightParameters) (Preflight, e } } +func getLedgerInfo(params PreflightParameters) (C.ledger_info_t, error) { + simulationLedgerSeq, err := getSimulationLedgerSeq(params.LedgerEntryReadTx) + if err != nil { + return C.ledger_info_t{}, err + } + + 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, + } + return li, nil +} + func getFootprintTtlPreflight(params PreflightParameters) (Preflight, error) { opBodyXDR, err := params.OpBody.MarshalBinary() if err != nil { @@ -164,17 +180,16 @@ func getFootprintTtlPreflight(params PreflightParameters) (Preflight, error) { handle := cgo.NewHandle(snapshotSourceHandle{params.LedgerEntryReadTx, params.Logger}) defer handle.Delete() - simulationLedgerSeq, err := getSimulationLedgerSeq(params.LedgerEntryReadTx) + li, err := getLedgerInfo(params) if err != nil { return Preflight{}, err } res := C.preflight_footprint_ttl_op( C.uintptr_t(handle), - C.uint64_t(params.BucketListSize), opBodyCXDR, footprintCXDR, - C.uint32_t(simulationLedgerSeq), + li, ) FreeGoXDR(opBodyCXDR) @@ -206,46 +221,19 @@ func getInvokeHostFunctionPreflight(params PreflightParameters) (Preflight, erro return Preflight{}, err } sourceAccountCXDR := CXDR(sourceAccountXDR) - - hasConfig, stateArchivalConfig, _, err := db.GetLedgerEntry(params.LedgerEntryReadTx, xdr.LedgerKey{ - Type: xdr.LedgerEntryTypeConfigSetting, - ConfigSetting: &xdr.LedgerKeyConfigSetting{ - ConfigSettingId: xdr.ConfigSettingIdConfigSettingStateArchival, - }, - }) - if err != nil { - return Preflight{}, err - } - if !hasConfig { - return Preflight{}, errors.New("state archival config setting missing in ledger storage") - } - - simulationLedgerSeq, err := getSimulationLedgerSeq(params.LedgerEntryReadTx) + li, err := getLedgerInfo(params) if err != nil { return Preflight{}, err } - stateArchival := stateArchivalConfig.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_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}) defer handle.Delete() resourceConfig := C.resource_config_t{ instruction_leeway: C.uint64_t(params.ResourceConfig.InstructionLeeway), } + res := C.preflight_invoke_hf_op( C.uintptr_t(handle), - C.uint64_t(params.BucketListSize), invokeHostFunctionCXDR, sourceAccountCXDR, li,