Skip to content
This repository was archived by the owner on Feb 3, 2023. It is now read-only.

impossible states: EntryWithHeader to ChainItem #946

Open
thedavidmeister opened this issue Feb 3, 2019 · 2 comments · May be fixed by #2006
Open

impossible states: EntryWithHeader to ChainItem #946

thedavidmeister opened this issue Feb 3, 2019 · 2 comments · May be fixed by #2006
Labels
impossible states https://hackmd.io/QPgBfOk4TwOMrZnCCE46ZA?both#Make-invalid-states-impossible-MISI

Comments

@thedavidmeister
Copy link
Contributor

thedavidmeister commented Feb 3, 2019

in the spirit of impossible states

EntryWithHeader is any entry any header

impl EntryWithHeader {
    pub fn new(entry: Entry, header: ChainHeader) -> EntryWithHeader {
        EntryWithHeader { entry, header }
    }
}

we ?always? want a specific header/entry combo (the header in a chain and the entry referenced and hashed by the header)

name suggestions:

  • ChainItem
  • ChainLink
  • ChainPair
  • ChainJoint

a ChainFoo::new() should fail if the ChainHeader.entry_address() does not match Entry.address()

ideally a seq of ChainFoo structs could be validated (individual integrity and valid ordering/references)

a ChainFoo uses a simple tuple structure (for easy destructuring) and is immutable:

pub struct ChainFoo(ChainHeader, Entry);

impl ChainFoo {

  pub fn new(header: ChainHeader, entry: Entry) -> Result<ChainFoo, HolochainError> {
    if header.entry().address() = entry.address() {
      Ok(ChainFoo(header, entry))
    }
    else {
      Err(HolochainError::InternalError("Header/Entry mismatch"))
    }
  }

  pub fn header(&self) -> ChainHeader {
    self.0.clone()
  }

  pub fn entry(&self) -> Entry {
    self.1.clone()
  }

}
@maackle maackle mentioned this issue Feb 3, 2019
4 tasks
@thedavidmeister thedavidmeister added the impossible states https://hackmd.io/QPgBfOk4TwOMrZnCCE46ZA?both#Make-invalid-states-impossible-MISI label Feb 3, 2019
@thedavidmeister thedavidmeister changed the title solidify EntryWithHeader to ChainItem impossible states: EntryWithHeader to ChainItem Feb 3, 2019
@jamesray1
Copy link
Contributor

I'll look into this. I watched this video on impossible states: "Making Impossible States Impossible" by Richard Feldman.

@thedavidmeister
Copy link
Contributor Author

sure, some sanity checks/assertions with useful error messages never hurt anybody :)

@jameschrray jameschrray linked a pull request Dec 21, 2019 that will close this issue
2 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
impossible states https://hackmd.io/QPgBfOk4TwOMrZnCCE46ZA?both#Make-invalid-states-impossible-MISI
Projects
None yet
2 participants