Skip to content

Commit

Permalink
rpc: add commandline flag to parameterize (opt-in) preflight debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
2opremio committed Oct 20, 2023
1 parent f41b84e commit ab67ed8
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions cmd/soroban-rpc/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Config struct {
NetworkPassphrase string
PreflightWorkerCount uint
PreflightWorkerQueueSize uint
PreflightEnableDebug bool
SQLiteDBPath string
TransactionLedgerRetentionWindow uint32
RequestBacklogGlobalQueueLimit uint
Expand Down
7 changes: 7 additions & 0 deletions cmd/soroban-rpc/internal/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions cmd/soroban-rpc/internal/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ func MustNew(cfg *config.Config) *Daemon {
daemon,
cfg.PreflightWorkerCount,
cfg.PreflightWorkerQueueSize,
cfg.PreflightEnableDebug,
ledgerEntryReader,
cfg.NetworkPassphrase,
logger,
Expand Down
5 changes: 4 additions & 1 deletion cmd/soroban-rpc/internal/preflight/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
}
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions cmd/soroban-rpc/internal/preflight/preflight.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type PreflightParameters struct {
NetworkPassphrase string
LedgerEntryReadTx db.LedgerEntryReadTx
BucketListSize uint64
EnableDebug bool
}

type Preflight struct {
Expand Down Expand Up @@ -224,6 +225,7 @@ func getInvokeHostFunctionPreflight(params PreflightParameters) (Preflight, erro
invokeHostFunctionCXDR,
sourceAccountCXDR,
li,
C.bool(params.EnableDebug),
)
FreeGoXDR(invokeHostFunctionCXDR)
FreeGoXDR(sourceAccountCXDR)
Expand Down
1 change: 1 addition & 0 deletions cmd/soroban-rpc/internal/preflight/preflight_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions cmd/soroban-rpc/internal/test/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion cmd/soroban-rpc/lib/preflight.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// this header automatically from your Rust code. But for now, we'll just write it by hand.

#include <stdint.h>
#include <stdbool.h>

typedef struct ledger_info_t {
uint32_t protocol_version;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions cmd/soroban-rpc/lib/preflight/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -141,6 +142,7 @@ pub extern "C" fn preflight_invoke_hf_op(
invoke_hf_op,
source_account,
ledger_info,
enable_debug,
)
}))
}
Expand All @@ -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<CPreflightResult> {
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();
Expand All @@ -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())
}
Expand Down
7 changes: 5 additions & 2 deletions cmd/soroban-rpc/lib/preflight/src/preflight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PreflightResult> {
let ledger_storage_rc = Rc::new(ledger_storage);
let budget = get_budget_from_network_config_params(&ledger_storage_rc)
Expand All @@ -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()))
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit ab67ed8

Please sign in to comment.