parallelchain-io / hotstuff_rs

Rust implementation of the HotStuff consensus algorithm.
38 stars 5 forks source link

Event Handling and Logging #19

Closed karolinagrzeszkiewicz closed 11 months ago

karolinagrzeszkiewicz commented 11 months ago

This PR introduces the event handling feature for hotstuff-rs, as well as logging rewritten as a set of possible default event handlers. The major contributions include:

  1. events.rs: definitions of key blockchain and protocol events
  2. event_bus.rs: EventHandlers struct for storing handlers for each event type, including a method to add default logging handlers, event_bus thread for receiving events from algorithmand sync_server threads and triggering the execution of appropriate handlers stored in its instance of the EventHandlers struct
  3. logging.rs: Logger trait with a required method get_logger() which returns an object's default handler for logging, implementations of the Logger trait for all event types from events.rs
  4. replica.rs: log_events: bool and a vector of handlers for each event type passed as parameters to Replica.start(), creating an EventHandlers struct based on provided handlers and log_events, if the struct instance is not empty then Replica.start() launches an extra thread event_bus for triggering the execution of event handlers upon receiving events
  5. algorithm.rs, state.rs, sync_server.rs: relevant functions now publish events by sending them on the event_publisher end of the channel. The events are published after the corresponding action is completed, in particular events that modify the block tree are only published after the event takes effect, i.e, the change is written to the block tree (rather than a write batch)