backport of https://github.com/paritytech/parity-bridges-common/pull/2821 (see detailed description there)