Skip to content

Commit

Permalink
Revert "Added primeTermini array to Termini struct with helpers"
Browse files Browse the repository at this point in the history
This reverts commit b8f3921.
  • Loading branch information
gameofpointers committed Sep 1, 2023
1 parent c280279 commit c5dbc44
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 60 deletions.
57 changes: 9 additions & 48 deletions core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -1020,9 +1020,8 @@ type extPendingHeader struct {

func (t Termini) RPCMarshalTermini() map[string]interface{} {
result := map[string]interface{}{
"domTerminus": t.DomTerminus(),
"subTermini": t.SubTermini(),
"primeTermini": t.PrimeTermini(),
"domTerminus": t.DomTerminus(),
"subTermini": t.SubTermini(),
}
return result
}
Expand All @@ -1047,13 +1046,9 @@ func (p PendingHeader) EncodeRLP(w io.Writer) error {

// Termini stores the dom terminus (i.e the previous dom block) and
// subTermini(i.e the dom blocks that have occured in the subordinate chains)
// primeTermini(i.e the prime blocks have occured in a region for each of the zones in region)
// - prime termini is used to control the liveliness of the primes in slices
// using the PrimeEntropyThreshold
type Termini struct {
domTerminus common.Hash `json:"domTerminus"`
subTermini []common.Hash `json:"subTermini"`
primeTermini []common.Hash `json:"primeTermini"`
domTerminus common.Hash `json:"domTerminus"`
subTermini []common.Hash `json:"subTermini"`
}

func CopyTermini(termini Termini) Termini {
Expand All @@ -1062,16 +1057,12 @@ func CopyTermini(termini Termini) Termini {
for i, t := range termini.subTermini {
newTermini.SetSubTerminiAtIndex(t, i)
}
for i, t := range termini.primeTermini {
newTermini.SetPrimeTerminiAtIndex(t, i)
}
return newTermini
}

func EmptyTermini() Termini {
termini := Termini{}
termini.subTermini = make([]common.Hash, common.HierarchyDepth)
termini.primeTermini = make([]common.Hash, common.NumZonesInRegion)
return termini
}

Expand All @@ -1083,24 +1074,13 @@ func (t Termini) SubTermini() []common.Hash {
return t.subTermini
}

func (t Termini) PrimeTermini() []common.Hash {
return t.primeTermini
}

func (t Termini) SubTerminiAtIndex(args ...int) common.Hash {
if len(args) == 0 {
panic("cannot access sub termini at index with the index")
}
return t.subTermini[args[0]]
}

func (t Termini) PrimeTerminiAtIndex(args ...int) common.Hash {
if len(args) == 0 {
panic("cannot access prime termini at index with the index")
}
return t.primeTermini[args[0]]
}

func (t *Termini) SetDomTerminus(domTerminus common.Hash) {
t.domTerminus = domTerminus
}
Expand All @@ -1112,45 +1092,27 @@ func (t *Termini) SetSubTermini(subTermini []common.Hash) {
}
}

func (t *Termini) SetPrimeTermini(primeTermini []common.Hash) {
t.primeTermini = make([]common.Hash, len(primeTermini))
for i := 0; i < len(primeTermini); i++ {
t.primeTermini[i] = primeTermini[i]
}
}

func (t *Termini) SetSubTerminiAtIndex(val common.Hash, args ...int) {
if len(args) == 0 {
panic("index cannot be empty for the sub termini")
}
t.subTermini[args[0]] = val
}

func (t *Termini) SetPrimeTerminiAtIndex(val common.Hash, args ...int) {
if len(args) == 0 {
panic("index cannot be empty for the prime termini")
}
t.primeTermini[args[0]] = val
}

func (t *Termini) IsValid() bool {
if t == nil {
return false
}
if len(t.subTermini) != common.HierarchyDepth {
return false
}
if len(t.primeTermini) != common.NumZonesInRegion {
return false
}
return true
}

// "external termini" pending header encoding. used for rlp
type extTermini struct {
DomTerminus common.Hash
SubTermini []common.Hash
PrimeTermini []common.Hash
DomTerminus common.Hash
SubTermini []common.Hash
}

// DecodeRLP decodes the Quai RLP encoding into pending header format.
Expand All @@ -1159,16 +1121,15 @@ func (t *Termini) DecodeRLP(s *rlp.Stream) error {
if err := s.Decode(&et); err != nil {
return err
}
t.domTerminus, t.subTermini, t.primeTermini = et.DomTerminus, et.SubTermini, et.PrimeTermini
t.domTerminus, t.subTermini = et.DomTerminus, et.SubTermini
return nil
}

// EncodeRLP serializes b into the Quai RLP format.
func (t Termini) EncodeRLP(w io.Writer) error {
return rlp.Encode(w, extTermini{
DomTerminus: t.domTerminus,
SubTermini: t.subTermini,
PrimeTermini: t.primeTermini,
DomTerminus: t.domTerminus,
SubTermini: t.subTermini,
})
}

Expand Down
17 changes: 5 additions & 12 deletions core/types/gen_header_json.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c5dbc44

Please sign in to comment.