Witnessing and prewitnessing external events
The engine starts separate threads that listen for external events happening on supported chains (BTC, ETH, and Polkadot) and that are relevant to Chainflip operation (i.e., filtering for events that only involve supported assets).
External events are acted on twice; a real-time stream is processed to submit prewitness extrinsics to the state chain. These extrinsics are recorded by the state chain and cause an event to be emitted (which can in turn be observed by other nodes monitoring the state chain). However, prewitnesses do not contribute to forming the consensus of what events occurred on external chains. This is the responsibility of the regular witness extrinsic, which is invoked by the engine when it observes an event from a delayed stream. The delay guarantees the event is final, preventing issues such as block reorganizations, which could for instance enable double spending.