== Server Configuration

By default, the Dshackle looks for config in the following locations:

1. Path specified by _optional_ `--configPath <...>` command line option
2. `/etc/dshackle/dshackle.yaml`
3. `./dshackle.yaml` (i.e. in the current working dir)

If none found the application exists with an error.

.Example dshackle.yaml configuration:
[source,yaml]
----
version: v1
port: 2449
tls:
  enabled: true
  server:
    certificate: "server.crt"
    key: "server.p8.key"
  client:
    require: true
    cas:
      - "ca.crt"

compression:
  grpc:
    server:
      enabled: false
    client:
      enabled: false

cluster:
  include: "upstreams.yaml"
----

It configures following:

- server is listening with gRCP API on `0.0.0.0:2449`
- TLS is enabled
- compression is disabled for gRPC-server (enabled by default)
- compression is disabled for upstream gRPC-client (enabled by default)
- server certificate is located at `server.crt` with the key for it at `server.p8.key`
- the server requires a client authentication by TLS client certificate signed by `ca.crt` certificate.
- no JSON RPC is configured
- upstreams configuration is configured in the file `upstreams.yaml`

.Configuration
|===
| Name | Example | Description

a| `version`
|
| Version of the format of the config

a| `port`
a| `port: 12449`
| Port to bind gRPC server. `2449` by default

a| `tls`
|
| TLS configuration for gRPC.
See link:08-authentication.adoc[Authentication] for details

a| `compression`
|
| Compression configuration

a| `proxy`
|
| Proxy configuration

a| `upstreams`
|
| Upstreams configuration
|===

=== Compression
Compression is enabled by default on the gRPC-server.
Responses will be compressed if a client supports compression
(sends relevant headers), otherwise, communication will be uncompressed.
But if for some reason you need to disable responses compression
forcibly (the server will still be able to accept compressed requests),
add following lines to the config:
[source,yaml]
----
compression:
  grpc:
    server:
      enabled: false
----
Compression is enabled by default for gRPC-requests to upstreams.
If you want to disable it,
(gRPC-client will still be able to accept compressed responses),
add following lines to the config:
[source,yaml]
----
compression:
  grpc:
    client:
      enabled: false
----
Thus, all possible combinations of compression configuration for
interacting dshackle grpc-client and grpc-server look like this:
|===
| Client | Server | Requests | Responses

| enabled
| enabled
| compressed
| compressed

| enabled
| disabled
| compressed
| plain

| disabled
| enabled
| plain
| compressed

| disabled
| disabled
| plain
| plain
|===

=== Enabling JSON RPC proxy

In addition to the gRPC protocol, Dshackle provides access compatible with Bitcoin and Ethereum JSON RPC.
The same server can be accessible as an HTTP JSON RPC and WebSocket JSON RPC.
For Ethereum, besides the standard RPC calls, it provides RPC subscriptions with `eth_subscribe` method.

.Example proxy:
[source,yaml]
----
version: v1
port: 2449

proxy:
  host: 0.0.0.0
  port: 8080
  routes:
    - id: eth
      blockchain: ethereum

cluster:
  include: "upstreams.yaml"
----

With that configuration Dshackle starts a JSON RPC proxy:

- JSON RPC server is listening on `0.0.0.0:8080`
- `http://0.0.0.0:8080/eth` (and `ws://0.0.0.0:8080/eth`) provides access to Ethereum API routed to an available upstream

NOTE: Same URL should be used to access both HTTP RPC and WebSocket RPC

.Full configuration:
[source,yaml]
----
proxy:
  port: 8080
  tls:
    enabled: true
    server:
      certificate: server.crt
      key: server.p8.key
    client:
      require: true
      ca: ca.crt
  routes:
    - id: eth
      blockchain: ethereum
    - id: etc
      blockchain: ethereum_classic
----

.Proxy configuration
|===
| Name | Example | Description

a| `host`
a| `host: 0.0.0.0`
| Host to bind proxy server. `127.0.0.1` by default

a| `port`
a| `port: 8545`
| Port to bind proxy server. `8080` by default

a| `enabled`
a| `enabled: true`
| Enable/disable proxy server

a| `tls`
|
| TLS configuration for proxy.
See link:08-authentication.adoc[Authentication] for details

a| `routes`
|
| List of endpoints to proxy
|===