github.com/unicornultrafoundation/go-u2u@v1.0.0-rc1.0.20240205080301-e74a83d3fadc/gossip/store_activation_heights.go (about) 1 package gossip 2 3 import ( 4 "github.com/unicornultrafoundation/go-u2u/u2u" 5 ) 6 7 func (s *Store) AddUpgradeHeight(h u2u.UpgradeHeight) { 8 orig := s.GetUpgradeHeights() 9 // allocate new memory to avoid race condition in cache 10 cp := make([]u2u.UpgradeHeight, 0, len(orig)+1) 11 cp = append(append(cp, orig...), h) 12 13 s.rlp.Set(s.table.UpgradeHeights, []byte{}, cp) 14 s.cache.UpgradeHeights.Store(cp) 15 } 16 17 func (s *Store) GetUpgradeHeights() []u2u.UpgradeHeight { 18 if v := s.cache.UpgradeHeights.Load(); v != nil { 19 return v.([]u2u.UpgradeHeight) 20 } 21 hh, ok := s.rlp.Get(s.table.UpgradeHeights, []byte{}, &[]u2u.UpgradeHeight{}).(*[]u2u.UpgradeHeight) 22 if !ok { 23 return []u2u.UpgradeHeight{} 24 } 25 s.cache.UpgradeHeights.Store(*hh) 26 return *hh 27 }