hashgraph / hedera-sdk-rust

The Hedera™ Rust SDK
Apache License 2.0
42 stars 14 forks source link

feat(config): Make gRPC http connections configurable #832

Open iamjpotts opened 2 months ago

iamjpotts commented 2 months ago

Description: Make characteristics of the gRPC connections, such as keep alives and timeouts, configurable via ClientBuilder.

All of the Client constructor methods now return Result<Self, _> instead of simply Self - this is due to the delayed parsing of the keys of HashMap<String, AccountId> into HostPort, and could be avoided if usage of HashMap<String, AccountId> were replaced with HashMap<HostPort, AccountId> (or HashMap<HostPort, EntityId>).

Related issue(s):

https://github.com/hashgraph/hedera-sdk-rust/issues/833 https://github.com/hashgraph/hedera-sdk-rust/issues/834

Notes for reviewer:

The node endpoint configuration capability is applicable to any combination of network nodes - both the preconfigured networks (mainnet, testnet, and previewnet), and custom networks. It would be possible, but inconvenient, to add a means to set endpoint configuration on either a Client instance or on one of the Client constructor methods.

Instead, this PR makes ClientBuilder public and adds a method to the builder to override the default endpoint configuration.

Tonic's Endpoint instances are setup when NodeConnection creates a channel:

https://github.com/hashgraph/hedera-sdk-rust/blob/40cc835628347772ca1cc71b9d860e2a4c3b1214/src/client/network/mod.rs#L587-L598

Each NodeConnection is created in either NetworkData::from_addresses or NetworkData::with_address_book

Constructor call sites

NetworkData::from_addresses is typically called during initial creation of a Client via a constructor method on Client

Example: https://github.com/hashgraph/hedera-sdk-rust/blob/40cc835628347772ca1cc71b9d860e2a4c3b1214/src/client/mod.rs#L285-L290

Dynamic network update call sites

NetworkData::with_address_book is a part of the dynamic network update process where a client can periodically alter its preferred choice of nodes, though it can also be called via Client::set_network_from_address_book on a client instance.

Checklist