mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-29 18:27:25 +00:00
6e8957b095
* Add filter reload handle
* add RPC, move logging module from cli to tracing
* remove dup fn
* working example
* Update client/rpc-api/src/system/mod.rs
Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
* Prefer "set" to "reload"
* Re-enable the commented out features of the logger
* Remove duplicate code
* cleanup
* unneeded lvar
* Bump to latest patch release
* Add new CLI option to disable log filter reloading,
Move profiling CLI options to SharedParams
* Apply suggestions from code review
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* Applied suggestions from reviews
* Fix calls to init_logger()
* Handle errors when parsing logging directives
* Deny `system_setLogFilter` RPC by default
* One more time
* Don't ignore parse errors for log directives set via CLI or RPC
* Improve docs
* Apply suggestions from code review
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* Update client/cli/src/config.rs
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* fix merge errors
* include default directives with system_setLogFilter RPC,
implement system_rawSetLogFilter RPC to exclude defaults
* docs etc...
* update test
* refactor: rename fn
* Add a test for system_set_log_filter – NOTE: the code should likely change to return an error when bad directives are passed
* Update client/cli/src/lib.rs
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* Address review grumbles
* Add doc note on panicking behaviour
* print all invalid directives before panic
* change RPCs to: addLogFilter and resetLogFilter
* make CLI log directives default
* add comments
* restore previous behaviour to panic when hard-coded directives are invalid
* change/refactor directive parsing
* fix line width
* add test for log filter reloading
* Apply suggestions from code review
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* finish up suggestions from code review
* improve test
* change expect message
* change fn name
* Apply suggestions from code review
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* Apply suggestions from code review
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* add docs, remove unused fn
* propagate Err on invalid log directive
* Update tracing-subscriber version
* Improve docs for `disable_log_reloading` CLI param
* WIP implementation: RPC and trace capturing
* WIP
* fix incorrect number of digest items
* return errors
* add From impl for Values, rename structs
* fixes
* implement option to choose targets for traces
* rename fn
* fix EnvFilter and add root span
* fix root span
* add docs, remove unnecessary traits
* fix regression on parent_id introduced in a9c73113a8
* fix line width
* remove unused
* include block hash, parent hash & targets in response
* move types from sp-tracing into sp-rpc
move block and parent hash into root of BlockTrace
* switch from log::trace to tracing::trace in state-machine
* use unsigned integer type to represent Ext::id in traces
* ensure id is unique by implementing Subscriber
tracing_subscriber::FmtSubscriber does not guarantee
unique ids
* indentation
* fix typo
* update types
* add sp_io::storage events
* Change response format
- update types
- record distinct timestamps
- sort spans by first entered
* convert to HexDisplay, refactor
* Sort out fallout from merge
* Update client/rpc-api/src/state/mod.rs
* Apply suggestions from code review
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* Exit early unless the node runs with --rpc-methods=Unsafe
* Better error handling
* Use wasm-timer
* revert trace alteration in `state-machine` and remove events in `sp_io::storage`
Resolve in follow-up PR
* Review feedback: less collects
* Without Arcs
* Fix span exit
* typo
* cleanup
* Add a few debug messages to tracing module
* Structure traces state-machine/ext; Dispatchable extrinsics spans not working
* Correctly encode Option storage values
* Remove test field for Put and Get
* Try out some changes to dispatch macro
* Add various log messages in dispatch
* Add span dispatch span to new proc macro
* Remove debug messages in dispatch
* Trivial clean up
* Structure remaining state-machine traces (ChangesRoot*)
* Removed unnesecary tracing targets
* Remove log
* New cargo.lock post merge
* Add logging for wasm_overrides
* remove temp logs
* remove temp logs
* remove unused dep
* remove temp logs
* add logging to wasm_overrides
* add logging to state_tracing
* add logging for spans to substrate (includes timings)
* Skip serializing some event fields; Remove most storage traces
* Bring back all ext.rs traces
* Do not skip bool values in events
* Skip serializing span values
* Serialize span values; remove some trace events in ext
* Remove more trace events
* Delete commented out traces
* Remove all unused traces
* Add event filtering
* Fix typo
* wip - change response types to be more efficient
missing import
type
* Serialize struct fields as camelCase
* Add back in event filtering
* Remove name field from event
* Sort spans by time entered
* Sort spans in ASCending order
* Add storage keys target param to rpc
* Limit payload size; improve hash fields; include storage keys
- cleanup event_key_filter
- better block hash representation
- limit payload size
- cleanup based on andrews comments
* Error when serialized payload is to big
* Import MAX_PAYLOAD from rpc-servers
* Clean up ext.rs
* Misc. cleaning and comments
* Strict ordering span Id; no span sort; adjust for rpc base payload
* Add RPC docs to rpc-api/src/state/mod
* Make params bullet points
* Update primitives/rpc/src/tracing.rs
* Put all tracing logic within trace
* Remove attr.record in new_span
* Add back value record in new_span
* restore result collection in ext
* Revert "Add back value record in new_span"
This reverts commit baf1a735f23e5eef1bf6264adfabb788910fa661.
* 🤦
* more 🤦
* Update docs; Try fix line width issues
* Improve docs
* Improve docs
* Remove default key filters + add key recs to docs
* Try restore old traces
* Add back doc comment
* Clean up newlines in ext.rs
* More new line remova;
l
* Use FxHashMap
* Try use EnvFilter directives for event filtering
* Remove directive, filter events by fields
* Use trace metadata correctly
* Try EnvFilter directive with all default targets
* Revert "Try EnvFilter directive with all default targets"
This reverts commit 4cc6ebc721d207c3b846444174f89d45038525ac.
* Clean up clippy warning
* Incorporate Niklas feedback
* Update trace/log macro calls to have better syntx
* Use Ordering::Relaxed
* Improve patch and filter doc comment
* Clean up `BlockSubscriber::new`
* Try optimize `BlockSubscriber::enabled`
* Apply suggestions from code review
Co-authored-by: David <dvdplm@gmail.com>
* Apply suggestions from code review
Co-authored-by: David <dvdplm@gmail.com>
* Use contains_key
* use heuristic for payload size
* Add error tupe for client::tracing::block
* Minor tweaks
* Make a note about `--features with-tracing`
* Add CURL example to RPC docs
* Link to substrate-archibe wasm
* Trivial doc clean up based on David feedback
* Explicit result type name
* Respect line length
* Use the error
* Don't print timings when spans close
* Fix failing sc-rpc-api
* Update sp-tracing inner-line doc
* Update client/tracing/src/block/mod.rs
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* Update client/service/src/client/call_executor.rs
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* Update client/service/src/client/call_executor.rs
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* Update client/tracing/src/block/mod.rs
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* Update client/tracing/src/block/mod.rs
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* Address some review grumbles
* Update primitives/state-machine/src/ext.rs
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* Use result_encoded structure fields in ext.rs
* Use value key for ext put
* Add notes about tracing key names matter
Co-authored-by: Matt <mattrutherford@users.noreply.github.com>
Co-authored-by: David <dvdplm@gmail.com>
Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: emostov <32168567+emostov@users.noreply.github.com>
162 lines
4.9 KiB
Rust
162 lines
4.9 KiB
Rust
// This file is part of Substrate.
|
|
|
|
// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
|
|
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
//! Substrate RPC servers.
|
|
|
|
#![warn(missing_docs)]
|
|
|
|
mod middleware;
|
|
|
|
use std::io;
|
|
use jsonrpc_core::{IoHandlerExtension, MetaIoHandler};
|
|
use log::error;
|
|
use pubsub::PubSubMetadata;
|
|
|
|
/// Maximal payload accepted by RPC servers.
|
|
pub const MAX_PAYLOAD: usize = 15 * 1024 * 1024;
|
|
|
|
/// Default maximum number of connections for WS RPC servers.
|
|
const WS_MAX_CONNECTIONS: usize = 100;
|
|
|
|
/// The RPC IoHandler containing all requested APIs.
|
|
pub type RpcHandler<T> = pubsub::PubSubHandler<T, RpcMiddleware>;
|
|
|
|
pub use self::inner::*;
|
|
pub use middleware::{RpcMiddleware, RpcMetrics};
|
|
|
|
/// Construct rpc `IoHandler`
|
|
pub fn rpc_handler<M: PubSubMetadata>(
|
|
extension: impl IoHandlerExtension<M>,
|
|
rpc_middleware: RpcMiddleware,
|
|
) -> RpcHandler<M> {
|
|
let io_handler = MetaIoHandler::with_middleware(rpc_middleware);
|
|
let mut io = pubsub::PubSubHandler::new(io_handler);
|
|
extension.augment(&mut io);
|
|
|
|
// add an endpoint to list all available methods.
|
|
let mut methods = io.iter().map(|x| x.0.clone()).collect::<Vec<String>>();
|
|
io.add_method("rpc_methods", {
|
|
methods.sort();
|
|
let methods = serde_json::to_value(&methods)
|
|
.expect("Serialization of Vec<String> is infallible; qed");
|
|
|
|
move |_| Ok(serde_json::json!({
|
|
"version": 1,
|
|
"methods": methods.clone(),
|
|
}))
|
|
});
|
|
io
|
|
}
|
|
|
|
#[cfg(not(target_os = "unknown"))]
|
|
mod inner {
|
|
use super::*;
|
|
|
|
/// Type alias for ipc server
|
|
pub type IpcServer = ipc::Server;
|
|
/// Type alias for http server
|
|
pub type HttpServer = http::Server;
|
|
/// Type alias for ws server
|
|
pub type WsServer = ws::Server;
|
|
|
|
/// Start HTTP server listening on given address.
|
|
///
|
|
/// **Note**: Only available if `not(target_os = "unknown")`.
|
|
pub fn start_http<M: pubsub::PubSubMetadata + Default>(
|
|
addr: &std::net::SocketAddr,
|
|
cors: Option<&Vec<String>>,
|
|
io: RpcHandler<M>,
|
|
) -> io::Result<http::Server> {
|
|
http::ServerBuilder::new(io)
|
|
.threads(4)
|
|
.health_api(("/health", "system_health"))
|
|
.allowed_hosts(hosts_filtering(cors.is_some()))
|
|
.rest_api(if cors.is_some() {
|
|
http::RestApi::Secure
|
|
} else {
|
|
http::RestApi::Unsecure
|
|
})
|
|
.cors(map_cors::<http::AccessControlAllowOrigin>(cors))
|
|
.max_request_body_size(MAX_PAYLOAD)
|
|
.start_http(addr)
|
|
}
|
|
|
|
/// Start IPC server listening on given path.
|
|
///
|
|
/// **Note**: Only available if `not(target_os = "unknown")`.
|
|
pub fn start_ipc<M: pubsub::PubSubMetadata + Default>(
|
|
addr: &str,
|
|
io: RpcHandler<M>,
|
|
) -> io::Result<ipc::Server> {
|
|
let builder = ipc::ServerBuilder::new(io);
|
|
#[cfg(target_os = "unix")]
|
|
builder.set_security_attributes({
|
|
let security_attributes = ipc::SecurityAttributes::empty();
|
|
security_attributes.set_mode(0o600)?;
|
|
security_attributes
|
|
});
|
|
builder.start(addr)
|
|
}
|
|
|
|
/// Start WS server listening on given address.
|
|
///
|
|
/// **Note**: Only available if `not(target_os = "unknown")`.
|
|
pub fn start_ws<M: pubsub::PubSubMetadata + From<jsonrpc_core::futures::sync::mpsc::Sender<String>>> (
|
|
addr: &std::net::SocketAddr,
|
|
max_connections: Option<usize>,
|
|
cors: Option<&Vec<String>>,
|
|
io: RpcHandler<M>,
|
|
) -> io::Result<ws::Server> {
|
|
ws::ServerBuilder::with_meta_extractor(io, |context: &ws::RequestContext| context.sender().into())
|
|
.max_payload(MAX_PAYLOAD)
|
|
.max_connections(max_connections.unwrap_or(WS_MAX_CONNECTIONS))
|
|
.allowed_origins(map_cors(cors))
|
|
.allowed_hosts(hosts_filtering(cors.is_some()))
|
|
.start(addr)
|
|
.map_err(|err| match err {
|
|
ws::Error::Io(io) => io,
|
|
ws::Error::ConnectionClosed => io::ErrorKind::BrokenPipe.into(),
|
|
e => {
|
|
error!("{}", e);
|
|
io::ErrorKind::Other.into()
|
|
}
|
|
})
|
|
}
|
|
|
|
fn map_cors<T: for<'a> From<&'a str>>(
|
|
cors: Option<&Vec<String>>
|
|
) -> http::DomainsValidation<T> {
|
|
cors.map(|x| x.iter().map(AsRef::as_ref).map(Into::into).collect::<Vec<_>>()).into()
|
|
}
|
|
|
|
fn hosts_filtering(enable: bool) -> http::DomainsValidation<http::Host> {
|
|
if enable {
|
|
// NOTE The listening address is whitelisted by default.
|
|
// Setting an empty vector here enables the validation
|
|
// and allows only the listening address.
|
|
http::DomainsValidation::AllowOnly(vec![])
|
|
} else {
|
|
http::DomainsValidation::Disabled
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(target_os = "unknown")]
|
|
mod inner {
|
|
}
|