diff --git a/cmd/soroban-rpc/internal/config/config.go b/cmd/soroban-rpc/internal/config/config.go index 1f33ae8fc..b16d02bb6 100644 --- a/cmd/soroban-rpc/internal/config/config.go +++ b/cmd/soroban-rpc/internal/config/config.go @@ -37,6 +37,7 @@ type Config struct { NetworkPassphrase string PreflightWorkerCount uint PreflightWorkerQueueSize uint + PreflightEnableDebug bool SQLiteDBPath string TransactionLedgerRetentionWindow uint32 RequestBacklogGlobalQueueLimit uint diff --git a/cmd/soroban-rpc/internal/config/options.go b/cmd/soroban-rpc/internal/config/options.go index 003e04fad..14f2bd79b 100644 --- a/cmd/soroban-rpc/internal/config/options.go +++ b/cmd/soroban-rpc/internal/config/options.go @@ -13,6 +13,7 @@ import ( "github.com/stellar/go/network" "github.com/stellar/go/support/errors" "github.com/stellar/go/support/strutils" + "github.com/stellar/soroban-tools/cmd/soroban-rpc/internal/ledgerbucketwindow" ) @@ -273,6 +274,12 @@ func (cfg *Config) options() ConfigOptions { DefaultValue: uint(runtime.NumCPU()), Validate: positive, }, + { + Name: "preflight-enable-debug", + Usage: "Enable debug information in preflighting (provides more detailed errors). It should not be enabled in production deployments.", + ConfigKey: &cfg.PreflightEnableDebug, + DefaultValue: false, + }, { TomlKey: strutils.KebabToConstantCase("request-backlog-global-queue-limit"), Usage: "Maximum number of outstanding requests", diff --git a/cmd/soroban-rpc/internal/daemon/daemon.go b/cmd/soroban-rpc/internal/daemon/daemon.go index ad9460087..0f0ab80f8 100644 --- a/cmd/soroban-rpc/internal/daemon/daemon.go +++ b/cmd/soroban-rpc/internal/daemon/daemon.go @@ -229,6 +229,7 @@ func MustNew(cfg *config.Config) *Daemon { daemon, cfg.PreflightWorkerCount, cfg.PreflightWorkerQueueSize, + cfg.PreflightEnableDebug, ledgerEntryReader, cfg.NetworkPassphrase, logger, diff --git a/cmd/soroban-rpc/internal/preflight/pool.go b/cmd/soroban-rpc/internal/preflight/pool.go index ff591ddda..359ebcaa2 100644 --- a/cmd/soroban-rpc/internal/preflight/pool.go +++ b/cmd/soroban-rpc/internal/preflight/pool.go @@ -29,6 +29,7 @@ type workerRequest struct { type PreflightWorkerPool struct { ledgerEntryReader db.LedgerEntryReader networkPassphrase string + enableDebug bool logger *log.Entry isClosed atomic.Bool requestChan chan workerRequest @@ -39,10 +40,11 @@ type PreflightWorkerPool struct { wg sync.WaitGroup } -func NewPreflightWorkerPool(daemon interfaces.Daemon, workerCount uint, jobQueueCapacity uint, ledgerEntryReader db.LedgerEntryReader, networkPassphrase string, logger *log.Entry) *PreflightWorkerPool { +func NewPreflightWorkerPool(daemon interfaces.Daemon, workerCount uint, jobQueueCapacity uint, enableDebug bool, ledgerEntryReader db.LedgerEntryReader, networkPassphrase string, logger *log.Entry) *PreflightWorkerPool { preflightWP := PreflightWorkerPool{ ledgerEntryReader: ledgerEntryReader, networkPassphrase: networkPassphrase, + enableDebug: enableDebug, logger: logger, requestChan: make(chan workerRequest, jobQueueCapacity), } @@ -150,6 +152,7 @@ func (pwp *PreflightWorkerPool) GetPreflight(ctx context.Context, readTx db.Ledg LedgerEntryReadTx: &wrappedTx, BucketListSize: bucketListSize, Footprint: footprint, + EnableDebug: pwp.enableDebug, } resultC := make(chan workerResult) select { diff --git a/cmd/soroban-rpc/internal/preflight/preflight.go b/cmd/soroban-rpc/internal/preflight/preflight.go index dc36810c8..c353252a1 100644 --- a/cmd/soroban-rpc/internal/preflight/preflight.go +++ b/cmd/soroban-rpc/internal/preflight/preflight.go @@ -79,6 +79,7 @@ type PreflightParameters struct { NetworkPassphrase string LedgerEntryReadTx db.LedgerEntryReadTx BucketListSize uint64 + EnableDebug bool } type Preflight struct { @@ -224,6 +225,7 @@ func getInvokeHostFunctionPreflight(params PreflightParameters) (Preflight, erro invokeHostFunctionCXDR, sourceAccountCXDR, li, + C.bool(params.EnableDebug), ) FreeGoXDR(invokeHostFunctionCXDR) FreeGoXDR(sourceAccountCXDR) diff --git a/cmd/soroban-rpc/internal/preflight/preflight_test.go b/cmd/soroban-rpc/internal/preflight/preflight_test.go index b3215f49d..d9dc89473 100644 --- a/cmd/soroban-rpc/internal/preflight/preflight_test.go +++ b/cmd/soroban-rpc/internal/preflight/preflight_test.go @@ -326,6 +326,7 @@ func getPreflightParameters(t testing.TB, dbConfig *preflightParametersDBConfig) } argSymbol := xdr.ScSymbol("world") params := PreflightParameters{ + EnableDebug: true, Logger: log.New(), SourceAccount: xdr.MustAddress("GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H"), OpBody: xdr.OperationBody{Type: xdr.OperationTypeInvokeHostFunction, diff --git a/cmd/soroban-rpc/internal/test/integration.go b/cmd/soroban-rpc/internal/test/integration.go index bdd3e4474..9521dfc75 100644 --- a/cmd/soroban-rpc/internal/test/integration.go +++ b/cmd/soroban-rpc/internal/test/integration.go @@ -131,6 +131,7 @@ func (i *Test) launchDaemon(coreBinaryPath string) { config.EventLedgerRetentionWindow = ledgerbucketwindow.DefaultEventLedgerRetentionWindow config.CheckpointFrequency = checkpointFrequency config.MaxHealthyLedgerLatency = time.Second * 10 + config.PreflightEnableDebug = true i.daemon = daemon.MustNew(&config) go i.daemon.Run() diff --git a/cmd/soroban-rpc/lib/preflight.h b/cmd/soroban-rpc/lib/preflight.h index fc01d9f45..faf77699b 100644 --- a/cmd/soroban-rpc/lib/preflight.h +++ b/cmd/soroban-rpc/lib/preflight.h @@ -2,6 +2,7 @@ // this header automatically from your Rust code. But for now, we'll just write it by hand. #include +#include typedef struct ledger_info_t { uint32_t protocol_version; @@ -41,7 +42,8 @@ preflight_result_t *preflight_invoke_hf_op(uintptr_t handle, // Go Handle to for uint64_t bucket_list_size, // Bucket list size of current ledger const xdr_t invoke_hf_op, // InvokeHostFunctionOp XDR const xdr_t source_account, // AccountId XDR - const ledger_info_t ledger_info); + const ledger_info_t ledger_info, + bool enable_debug); preflight_result_t *preflight_footprint_expiration_op(uintptr_t handle, // Go Handle to forward to SnapshotSourceGet uint64_t bucket_list_size, // Bucket list size of current ledger diff --git a/cmd/soroban-rpc/lib/preflight/src/lib.rs b/cmd/soroban-rpc/lib/preflight/src/lib.rs index 18a1976a8..f2f98f287 100644 --- a/cmd/soroban-rpc/lib/preflight/src/lib.rs +++ b/cmd/soroban-rpc/lib/preflight/src/lib.rs @@ -133,6 +133,7 @@ pub extern "C" fn preflight_invoke_hf_op( invoke_hf_op: CXDR, // InvokeHostFunctionOp XDR in base64 source_account: CXDR, // AccountId XDR in base64 ledger_info: CLedgerInfo, + enable_debug: bool, ) -> *mut CPreflightResult { catch_preflight_panic(Box::new(move || { preflight_invoke_hf_op_or_maybe_panic( @@ -141,6 +142,7 @@ pub extern "C" fn preflight_invoke_hf_op( invoke_hf_op, source_account, ledger_info, + enable_debug, ) })) } @@ -151,6 +153,7 @@ fn preflight_invoke_hf_op_or_maybe_panic( invoke_hf_op: CXDR, // InvokeHostFunctionOp XDR in base64 source_account: CXDR, // AccountId XDR in base64 ledger_info: CLedgerInfo, + enable_debug: bool, ) -> Result { let invoke_hf_op = InvokeHostFunctionOp::from_xdr(from_c_xdr(invoke_hf_op)).unwrap(); let source_account = AccountId::from_xdr(from_c_xdr(source_account)).unwrap(); @@ -162,6 +165,7 @@ fn preflight_invoke_hf_op_or_maybe_panic( invoke_hf_op, source_account, LedgerInfo::from(ledger_info), + enable_debug, )?; Ok(result.into()) } diff --git a/cmd/soroban-rpc/lib/preflight/src/preflight.rs b/cmd/soroban-rpc/lib/preflight/src/preflight.rs index c6c5ac0e4..35b024884 100644 --- a/cmd/soroban-rpc/lib/preflight/src/preflight.rs +++ b/cmd/soroban-rpc/lib/preflight/src/preflight.rs @@ -40,6 +40,7 @@ pub(crate) fn preflight_invoke_hf_op( invoke_hf_op: InvokeHostFunctionOp, source_account: AccountId, ledger_info: LedgerInfo, + enable_debug: bool, ) -> Result { let ledger_storage_rc = Rc::new(ledger_storage); let budget = get_budget_from_network_config_params(&ledger_storage_rc) @@ -48,8 +49,10 @@ pub(crate) fn preflight_invoke_hf_op( let host = Host::with_storage_and_budget(storage, budget); host.set_source_account(source_account.clone()) .context("cannot set source account")?; - host.set_diagnostic_level(DiagnosticLevel::Debug) - .context("cannot set debug diagnostic level")?; + if enable_debug { + host.set_diagnostic_level(DiagnosticLevel::Debug) + .context("cannot set debug diagnostic level")?; + } host.set_ledger_info(ledger_info.clone()) .context("cannot set ledger info")?; host.set_base_prng_seed(rand::Rng::gen(&mut rand::thread_rng())) diff --git a/go.mod b/go.mod index c150f42c0..a6ec4990e 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,8 @@ module github.com/stellar/soroban-tools -go 1.20 +go 1.21 + +toolchain go1.21.1 require ( github.com/Masterminds/squirrel v1.5.4