New matcher API facilitating the building of XCM barriers

Owing to how critical barriers are when it comes to preventing spam and attacks from malicious actors, I have devised a new API to write barrier conditions, which would hopefully be a lot more maintainable and auditable: Introduce XCM matcher for writing barriers by KiChjang · Pull Request #6756 · paritytech/polkadot · GitHub

The way that I imagine most people to use this API would look similar to the following:

// `msg` is usually passed in as a parameter to barriers
msg.matcher()
    .assert_remaining_insts(1)?
    .match_next_inst(|inst| match inst {
        Instruction::<()>::ClearOrigin => Ok(()),
        _ => Err(()),
    });

With this new API, one could then go call-by-call or line-by-line to ensure that each instruction is being matched exactly as one has intended, thereby making it easier to audit, maintain and extend.

Please have a look at it and leave me your suggestions and comments on it!

4 Likes

API here looks really clean.