Skip to content

Commit

Permalink
Merge branch 'main' into js-systest
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed Nov 2, 2023
2 parents 4ea1ca2 + 9837a5d commit d0c25ad
Show file tree
Hide file tree
Showing 18 changed files with 146 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/soroban-rpc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ jobs:
env:
SOROBAN_RPC_INTEGRATION_TESTS_ENABLED: true
SOROBAN_RPC_INTEGRATION_TESTS_CAPTIVE_CORE_BIN: /usr/bin/stellar-core
PROTOCOL_20_CORE_DEBIAN_PKG_VERSION: 19.14.1-1529.fcbbad4ce.focal
PROTOCOL_20_CORE_DEBIAN_PKG_VERSION: 19.14.1-1547.f2d06fbce.focal
steps:
- uses: actions/checkout@v3
with:
Expand Down
43 changes: 22 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ version = "20.0.0-rc4"
[workspace.dependencies.soroban-env-host]
version = "20.0.0-rc2"
git = "https://github.com/stellar/rs-soroban-env"
rev = "91f44778389490ad863d61a8a90ac9875ba6d8fd"
rev = "2674d867d7c6aa4212abab05ff30e5804ff1db90"

[workspace.dependencies.soroban-spec]
version = "20.0.0-rc2"
git = "https://github.com/stellar/rs-soroban-sdk"
rev = "729ed3ac5fe8600a3245d5816eadd3c95ab2eb54"
rev = "fb422beae0d4944dc0e83559a8940b31f5ebd89d"
# path = "../rs-soroban-sdk/soroban-spec"

[workspace.dependencies.soroban-spec-rust]
version = "20.0.0-rc2"
git = "https://github.com/stellar/rs-soroban-sdk"
rev = "729ed3ac5fe8600a3245d5816eadd3c95ab2eb54"
rev = "fb422beae0d4944dc0e83559a8940b31f5ebd89d"
# path = "../rs-soroban-sdk/soroban-spec-rust"

[workspace.dependencies.soroban-spec-json]
Expand All @@ -45,12 +45,12 @@ path = "./cmd/crates/soroban-spec-tools"
[workspace.dependencies.soroban-sdk]
version = "20.0.0-rc2"
git = "https://github.com/stellar/rs-soroban-sdk"
rev = "729ed3ac5fe8600a3245d5816eadd3c95ab2eb54"
rev = "fb422beae0d4944dc0e83559a8940b31f5ebd89d"

[workspace.dependencies.soroban-ledger-snapshot]
version = "20.0.0-rc2"
git = "https://github.com/stellar/rs-soroban-sdk"
rev = "729ed3ac5fe8600a3245d5816eadd3c95ab2eb54"
rev = "fb422beae0d4944dc0e83559a8940b31f5ebd89d"

[workspace.dependencies.soroban-cli]
version = "20.0.0-rc4"
Expand Down
2 changes: 2 additions & 0 deletions cmd/crates/soroban-test/tests/it/integration/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pub fn deploy_contract(sandbox: &TestEnv, wasm: &Wasm) -> String {
.arg("install")
.arg("--wasm")
.arg(wasm.path())
.arg("--ignore-checks")
.assert()
.success()
.stdout(format!("{hash}\n"));
Expand All @@ -80,6 +81,7 @@ pub fn deploy_contract(sandbox: &TestEnv, wasm: &Wasm) -> String {
.arg(&format!("{hash}"))
.arg("--salt")
.arg(TEST_SALT)
.arg("--ignore-checks")
.assert()
.success()
.stdout(format!("{TEST_CONTRACT_ID}\n"));
Expand Down
4 changes: 4 additions & 0 deletions cmd/soroban-cli/src/commands/contract/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ pub struct Cmd {
config: config::Args,
#[command(flatten)]
pub fee: crate::fee::Args,
#[arg(long, short = 'i', default_value = "false")]
/// Whether to ignore safety checks when deploying contracts
pub ignore_checks: bool,
}

#[derive(thiserror::Error, Debug)]
Expand Down Expand Up @@ -97,6 +100,7 @@ impl Cmd {
wasm: wasm::Args { wasm: wasm.clone() },
config: self.config.clone(),
fee: self.fee.clone(),
ignore_checks: self.ignore_checks,
}
.run_and_get_hash()
.await?;
Expand Down
53 changes: 51 additions & 2 deletions cmd/soroban-cli/src/commands/contract/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ use std::num::ParseIntError;
use clap::{command, Parser};
use soroban_env_host::xdr::{
Error as XdrError, Hash, HostFunction, InvokeHostFunctionOp, Memo, MuxedAccount, Operation,
OperationBody, Preconditions, SequenceNumber, Transaction, TransactionExt, TransactionResult,
TransactionResultResult, Uint256, VecM,
OperationBody, Preconditions, ScMetaEntry, ScMetaV0, SequenceNumber, Transaction,
TransactionExt, TransactionResult, TransactionResultResult, Uint256, VecM,
};

use super::restore;
use crate::key;
use crate::rpc::{self, Client};
use crate::{commands::config, utils, wasm};

const CONTRACT_META_SDK_KEY: &str = "rssdkver";

#[derive(Parser, Debug, Clone)]
#[group(skip)]
pub struct Cmd {
Expand All @@ -23,6 +25,9 @@ pub struct Cmd {
pub fee: crate::fee::Args,
#[command(flatten)]
pub wasm: wasm::Args,
#[arg(long, short = 'i', default_value = "false")]
/// Whether to ignore safety checks when deploying contracts
pub ignore_checks: bool,
}

#[derive(thiserror::Error, Debug)]
Expand All @@ -45,6 +50,16 @@ pub enum Error {
UnexpectedSimulateTransactionResultSize { length: usize },
#[error(transparent)]
Restore(#[from] restore::Error),
#[error("cannot parse WASM file {wasm}: {error}")]
CannotParseWasm {
wasm: std::path::PathBuf,
error: wasm::Error,
},
#[error("the deployed smart contract {wasm} was built with Soroban Rust SDK v{version}, a release candidate version not intended for use with the Stellar Public Network. To deploy anyway, use --ignore-checks")]
ContractCompiledWithReleaseCandidateSdk {
wasm: std::path::PathBuf,
version: String,
},
}

impl Cmd {
Expand All @@ -55,6 +70,20 @@ impl Cmd {
}

pub async fn run_and_get_hash(&self) -> Result<Hash, Error> {
let wasm_spec = &self.wasm.parse().map_err(|e| Error::CannotParseWasm {
wasm: self.wasm.wasm.clone(),
error: e,
})?;
if let Some(rs_sdk_ver) = get_contract_meta_sdk_version(wasm_spec) {
if rs_sdk_ver.contains("rc") && !self.ignore_checks {
return Err(Error::ContractCompiledWithReleaseCandidateSdk {
wasm: self.wasm.wasm.clone(),
version: rs_sdk_ver,
});
} else if rs_sdk_ver.contains("rc") {
tracing::warn!("the deployed smart contract {path} was built with Soroban Rust SDK v{rs_sdk_ver}, a release candidate version not intended for use with the Stellar Public Network", path = self.wasm.wasm.display());
}
}
self.run_against_rpc_server(&self.wasm.read()?).await
}

Expand Down Expand Up @@ -117,6 +146,26 @@ impl Cmd {
}
}

fn get_contract_meta_sdk_version(wasm_spec: &utils::contract_spec::ContractSpec) -> Option<String> {
let rs_sdk_version_option = if let Some(_meta) = &wasm_spec.meta_base64 {
wasm_spec.meta.iter().find(|entry| match entry {
ScMetaEntry::ScMetaV0(ScMetaV0 { key, .. }) => {
key.to_string_lossy().contains(CONTRACT_META_SDK_KEY)
}
})
} else {
None
};
if let Some(rs_sdk_version_entry) = &rs_sdk_version_option {
match rs_sdk_version_entry {
ScMetaEntry::ScMetaV0(ScMetaV0 { val, .. }) => {
return Some(val.to_string_lossy());
}
}
}
None
}

pub(crate) fn build_install_contract_code_tx(
source_code: &[u8],
sequence: i64,
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-rpc/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.20-bullseye as build
FROM golang:1.21-bullseye as build
ARG RUST_TOOLCHAIN_VERSION=stable
ARG REPOSITORY_VERSION

Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-rpc/internal/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (cfg *Config) options() ConfigOptions {
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,
DefaultValue: true,
},
{
TomlKey: strutils.KebabToConstantCase("request-backlog-global-queue-limit"),
Expand Down
6 changes: 4 additions & 2 deletions cmd/soroban-rpc/internal/daemon/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ type CoreClientWithMetrics struct {
func newCoreClientWithMetrics(client stellarcore.Client, registry *prometheus.Registry) *CoreClientWithMetrics {
submitMetric := prometheus.NewSummaryVec(prometheus.SummaryOpts{
Namespace: prometheusNamespace, Subsystem: "txsub", Name: "submission_duration_seconds",
Help: "submission durations to Stellar-Core, sliding window = 10m",
Help: "submission durations to Stellar-Core, sliding window = 10m",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
}, []string{"status"})
opCountMetric := prometheus.NewSummaryVec(prometheus.SummaryOpts{
Namespace: prometheusNamespace, Subsystem: "txsub", Name: "operation_count",
Help: "number of operations included in a transaction, sliding window = 10m",
Help: "number of operations included in a transaction, sliding window = 10m",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
}, []string{"status"})
registry.MustRegister(submitMetric, opCountMetric)

Expand Down
6 changes: 4 additions & 2 deletions cmd/soroban-rpc/internal/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,16 @@ func NewMemoryStore(daemon interfaces.Daemon, networkPassphrase string, retentio
// eventsDurationMetric is a metric for measuring latency of event store operations
eventsDurationMetric := prometheus.NewSummaryVec(prometheus.SummaryOpts{
Namespace: daemon.MetricsNamespace(), Subsystem: "events", Name: "operation_duration_seconds",
Help: "event store operation durations, sliding window = 10m",
Help: "event store operation durations, sliding window = 10m",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
},
[]string{"operation"},
)

eventCountMetric := prometheus.NewSummary(prometheus.SummaryOpts{
Namespace: daemon.MetricsNamespace(), Subsystem: "events", Name: "count",
Help: "count of events ingested, sliding window = 10m",
Help: "count of events ingested, sliding window = 10m",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
})
daemon.MetricsRegistry().MustRegister(eventCountMetric, eventsDurationMetric)
return &MemoryStore{
Expand Down
18 changes: 14 additions & 4 deletions cmd/soroban-rpc/internal/ingest/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/stellar/go/historyarchive"
"github.com/stellar/go/ingest"
backends "github.com/stellar/go/ingest/ledgerbackend"
supportdb "github.com/stellar/go/support/db"
"github.com/stellar/go/support/log"
"github.com/stellar/go/xdr"

Expand Down Expand Up @@ -52,7 +53,8 @@ func newService(cfg Config) *Service {
// ingestionDurationMetric is a metric for measuring the latency of ingestion
ingestionDurationMetric := prometheus.NewSummaryVec(prometheus.SummaryOpts{
Namespace: cfg.Daemon.MetricsNamespace(), Subsystem: "ingest", Name: "ledger_ingestion_duration_seconds",
Help: "ledger ingestion durations, sliding window = 10m",
Help: "ledger ingestion durations, sliding window = 10m",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
},
[]string{"type"},
)
Expand Down Expand Up @@ -208,9 +210,14 @@ func (s *Service) fillEntriesFromCheckpoint(ctx context.Context, archive history
if err != nil {
return err
}
transactionCommitted := false
defer func() {
if err := tx.Rollback(); err != nil {
s.logger.WithError(err).Warn("could not rollback fillEntriesFromCheckpoint write transactions")
if !transactionCommitted {
// Internally, we might already have rolled back the transaction. We should
// not generate benign error/warning here in case the transaction was already rolled back.
if rollbackErr := tx.Rollback(); rollbackErr != nil && rollbackErr != supportdb.ErrAlreadyRolledback {
s.logger.WithError(rollbackErr).Warn("could not rollback fillEntriesFromCheckpoint write transactions")
}
}
}()

Expand All @@ -222,9 +229,12 @@ func (s *Service) fillEntriesFromCheckpoint(ctx context.Context, archive history
}

s.logger.Info("committing checkpoint ledger entries")
if err := tx.Commit(checkpointLedger); err != nil {
err = tx.Commit(checkpointLedger)
transactionCommitted = true
if err != nil {
return err
}

s.logger.Info("finished checkpoint processing")
return nil
}
Expand Down
Loading

0 comments on commit d0c25ad

Please sign in to comment.