kaspanet / rusty-kaspa

Kaspa full-node and related libraries in the Rust programming language. This is a Beta version at the final testing phases.
ISC License
350 stars 105 forks source link

Subscription context with a network type #458

Open tiram88 opened 3 weeks ago

tiram88 commented 3 weeks ago

Adds a network type to the subscription context and a corresponding address prefix to the address tracker.

The tracker prefix is used for validating addresses in register/unregister operations. It also allows a fully contextualized conversion of indexes to addresses.

The dependency between Tracker and the indexers CounterMap and Indexes is reversed by encapsulating a reference to the tracker in every indexer. The new architecture is much more robust. It guarantees an accurate index reference counting in the tracker, notably on indexers Clone and Drop and alleviates the need to carry a subscription context in many functions dealing with indexers.

It remained some rare cases of UtxosChangedScope mutations where a back and forth conversion of indexes to addresses could occur. This is now optimized by refactoring UtxosChangedScope into an enum accepting either addresses or indexes which removes the need for those costly and redundant conversions.

Both gRPC and wRPC clients, when configured with a subscription context, query the network type of the server they connect to and configure their context accordingly. Note that this operation may fail if the subscription context of the client has already a defined network type and the server provides a different type.

This PR addresses the technological debts intentionally left behind in #427 (see)