threefoldtech / rmb-rs

RMB implementation in rust
Apache License 2.0
3 stars 1 forks source link

Listen to chain events and update twin on requests #194

Closed AbdelrahmanElawady closed 2 months ago

AbdelrahmanElawady commented 3 months ago

Description

This PR utilize listening to chain events to update relay cache with the latest twin information. For TwinStored and TwinUpdated events, the event listener get twin information from the event and update local cache. For twins that are neither update nor created after starting events listener they will be fetched from the chain for the first time a request is made but will remain in cache forever until a TwinUpdated is emitted then its data will be updated too.

The time difference between clients calling update_twin and the blocks finalizing led to response failures for up to 6 seconds. So, to mitigate this delay a new optional relays field was introduced to Envelope type. If set it will be considered the source of truth for which relays the twin is using and relays will update local cache based on that (even for federating messages).

This removes all delay for twin updates (if using new field in envelope) and the need for cache warmer.

Issues

AbdelrahmanElawady commented 3 months ago

still missing reconnecting to chain urls for rpc errors in a round robin way

AbdelrahmanElawady commented 3 months ago

Connection error handling was added and tested with gdb and calling manually shutdown() syscall to simulate chain closing connection.