go-spacemesh icon indicating copy to clipboard operation
go-spacemesh copied to clipboard

atxs: refactor atx type to avoid struct update

Open dshulyak opened this issue 2 years ago • 0 comments

atx struct is updated in two cases:

  • when received to compute id
  • and will be updated after it was verified, to set correct base_tick_height and tick_count https://github.com/spacemeshos/go-spacemesh/pull/3399

any mistakes can be catched only during runtime and only if we have sufficient test coverage. moreover this is prone to concurrency issues, if fields that are updated will be read concurrently in the other goroutine.

instead we should treat data as data and use different struct when we need more data. for example after atx is verified and verified data is required downstream we should use type:

type VerifiedAtx struct {
     Atx
     BaseTickHeight uint64
     TickCount uint64
}

dshulyak avatar Aug 10 '22 08:08 dshulyak