# Proposal of New Event API (sn_routing fired to sn_node) ## Existing Structs (All remain unchanged) ```rust // ------ Within bls_signature_aggreator crate ------ pub struct Proof { pub public_key: bls::PublicKey, pub signature: bls::Signature, } // --------- Within routing crate ------------------- pub struct Proven<T: Serialize> { pub value: T, pub proof: Proof, } pub struct MemberInfo { pub peer: Peer, pub state: PeerState, } pub struct Peer { name: XorName, addr: SocketAddr, reachable: bool, } pub enum PeerState { Joined, Left, Relocated(XorName), } pub struct SectionAuthorityProvider { pub prefix: Prefix, section_key: PublicKey, elders: BTreeMap<XorName, (PublicKeyShare, SocketAddr)>, } pub enum NodeElderChange { Promoted, Demoted, None, } ``` ## Event Struct ```rust pub enum Event { //---------------------- New ----------------------------------- // This event will be fired when: // 1, any membership change (join or left) // 2, any elder list change // 3, section split SectionChanged { // Current SAP could be equal to previous SAP when: // 1, This is the genesis join event. // 2, The event is regarding an adult change. current_section_auth: Proven<SectionAuthorityProvider>, previous_section_auth: Proven<SectionAuthorityProvider>, self_status_change: NodeElderChange, // Being none when: // 1, during split // 2, during elder promotion or demotion member_changed: Option<Proven<MemberInfo>>, adult_list: Vec<Proven<MemberInfo>>, } //---------------------- Removed ------------------------------- // MemberJoined { // name: XorName, // previous_name: Option<XorName>, // age: u8, // }, // MemberLeft { // name: XorName, // age: u8, // }, // SectionSplit { // elders: Elders, // sibling_elders: Elders, // self_status_change: NodeElderChange, // }, // EldersChanged { // elders: Elders, // self_status_change: NodeElderChange, // }, // AdultsChanged { // remaining: BTreeSet<XorName>, // added: BTreeSet<XorName>, // removed: BTreeSet<XorName>, // }, //---------------------- Remain unchanged ---------------------- MessageReceived { content: Bytes, src: SrcLocation, dst: DstLocation, proof: Option<Proof>, proof_chain: Option<SectionChain>, }, RelocationStarted { previous_name: XorName, }, Relocated { previous_name: XorName, new_keypair: Arc<Keypair>, }, RestartRequired, ClientMsgReceived { msg: Box<ClientMsg>, user: EndUser, }, ClientLost(SocketAddr), } ``` ## Naming in confusion ```rust bls_signature_aggregator::Proof -> SigningAuthorityClaim Proven -> SectionSigned pub struct MemberInfo { pub peer: Peer, pub state: PeerState, } pub(crate) struct Section { genesis_key: bls::PublicKey, chain: SectionChain, section_auth: Proven<SectionAuthorityProvider>, members: SectionPeers, } pub(crate) struct SectionPeers { members: BTreeMap<XorName, Proven<MemberInfo>>, } // Sync message is from Elder only. It's an one-to-one direct message. // On receiver side, it only `merge`, not `aggregate` the incoming syncs. Message::Sync { section: Section, network: Network, } // --- Newly proposed churn related Event API --- SectionChanged { current_section_auth: SectionSigned<SectionAuthorityProvider>, previous_section_auth: SectionSigned<SectionAuthorityProvider>, member_changed: Option<SectionSigned<MemberInfo>>, adult_list: Vec<SectionSigned<MemberInfo>>, } // --- Newly proposed Section struct --- pub(crate) struct Section { genesis_key: bls::PublicKey, chain: SectionChain, section_auth: Proven<SectionAuthorityProvider>, adults: SectionAdults, off_nodes: SectionOffNodes, // DeadNodes -> Can never come back here (we killed or relocated them) OffLineNodes -> Can come back but will be relocated. } pub(crate) struct SectionAdults { members: BTreeMap<XorName, Proven<MemberInfo>>, } pub(crate) struct SectionOffNodes { members: BTreeMap<XorName, Proven<MemberInfo>>, } ``` Renaming: ``` bls_signature_aggregator::Proof -> SigningAuthorityClaim Proven -> SectionSigned MemberInfo -> NodeOp ``` Refactoring: ```rust struct Section { genesis_key: bls::PublicKey, chain: SectionChain, section_auth: SectionSigned<SectionAuthorityProvider>, adults: SectionAdults, // Can never come back here (we killed or relocated them) DeadNodes: // Can come back but will be relocated OffLineNodes: } // We make this as a separate struct so that can have // extra utility functions, such as pub(crate) struct SectionPeers { members: BTreeMap<XorName, Proven<MemberInfo>>, } ```