Skip to content

Commit

Permalink
Changed the ontology from a triple to a double and added context and …
Browse files Browse the repository at this point in the history
…location range checks
  • Loading branch information
Karl authored and Karl committed Jun 14, 2022
1 parent 384acf2 commit b0ee402
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 47 deletions.
10 changes: 3 additions & 7 deletions consensus/blake3/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -848,11 +848,7 @@ func verifyInsideLocation(location []byte, number []*big.Int, config *params.Cha
zoneLocation := int(location[1])

switch {
/* case config.IsLovelace(number[0]): // Lovelace = [3,4,4]
return checkInsideCurrent(regionLocation, zoneLocation, params.LovelaceOntology)
case config.IsTuring(number[0]): // Turing = [3,3,4]
return checkInsideCurrent(regionLocation, zoneLocation, params.TuringOntology) */
case config.IsFuller(number[0]): // Fuller = [3,3,3]
case config.IsFuller(number[0]): // Fuller = [3,3]
return checkInsideCurrent(regionLocation, zoneLocation, params.FullerOntology)
default:
return consensus.ErrInvalidOntology
Expand All @@ -861,10 +857,10 @@ func verifyInsideLocation(location []byte, number []*big.Int, config *params.Cha

// Verifies that Location is valid inside current MapContext ontology.
func checkInsideCurrent(regionLoc int, zoneLoc int, ontology []int) error {
if len(ontology) < regionLoc {
if regionLoc < 0 || regionLoc > ontology[0] {
return consensus.ErrInvalidOntology
}
if ontology[regionLoc-1] < zoneLoc {
if zoneLoc < 0 || zoneLoc > ontology[1] {
return consensus.ErrInvalidOntology
}
return nil
Expand Down
4 changes: 0 additions & 4 deletions consensus/misc/verify_quai.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@ func BlockOntology(number []*big.Int) ([]int, error) {
forkNumber := number[0]

switch {
/* case forkNumber.Cmp(params.LovelaceMapContext) >= 0: // Lovelace = MaxInt
return params.LovelaceOntology
case forkNumber.Cmp(params.TuringMapContext) >= 0: // Turing = MaxInt
return params.TuringOntology */
case forkNumber.Cmp(params.FullerMapContext) >= 0:
return params.FullerOntology, nil
default:
Expand Down
19 changes: 19 additions & 0 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -3375,3 +3375,22 @@ func (bc *BlockChain) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscript
func (bc *BlockChain) SubscribeBlockProcessingEvent(ch chan<- bool) event.Subscription {
return bc.scope.Track(bc.blockProcFeed.Subscribe(ch))
}

// CheckContextAndOrderRange checks to make sure the range of a context or order is valid
func (bc *BlockChain) CheckContextAndOrderRange(context int) error {
if context < 0 || context > len(params.FullerOntology) {
return errors.New("the provided path is outside the allowable range")
}
return nil
}

// CheckLocationRange checks to make sure the range of a context or order is valid
func (bc *BlockChain) CheckLocationRange(location []byte) error {
if int(location[0]) < 0 || int(location[0]) > params.FullerOntology[0] {
return errors.New("the provided path is outside the allowable region range")
}
if int(location[1]) < 0 || int(location[1]) > params.FullerOntology[1] {
return errors.New("the provided path is outside the allowable zone range")
}
return nil
}
4 changes: 0 additions & 4 deletions core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -774,10 +774,6 @@ func currentBlockOntology(number []*big.Int) ([]int, error) {
forkNumber := number[0]

switch {
/* case forkNumber.Cmp(params.LovelaceMapContext) >= 0: // Lovelace = MaxInt
return params.LovelaceOntology
case forkNumber.Cmp(params.TuringMapContext) >= 0: // Turing = MaxInt
return params.TuringOntology */
case forkNumber.Cmp(params.FullerMapContext) >= 0:
return params.FullerOntology, nil
default:
Expand Down
29 changes: 0 additions & 29 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,9 +791,6 @@ type ChainConfig struct {

// Quai Network Ontology
FullerMapContext *big.Int // Block number effective for Fuller Map Context ontology
// TuringMapContext *big.Int
// LovelaceMapContext *big.Int
// future ontology expansion fields go here
}

// EthashConfig is the consensus engine configs for proof-of-work based sealing.
Expand Down Expand Up @@ -912,18 +909,6 @@ func (c *ChainConfig) IsFuller(num *big.Int) bool {
return isForked(c.FullerMapContext, num)
}

/*
// IsTuring returns whether num is either equal to the Merge fork block or greater.
func (c *ChainConfig) IsTuring(num *big.Int) bool {
return isForked(c.TuringMapContext, num)
}
// IsLovelace returns whether num is either equal to the Merge fork block or greater.
func (c *ChainConfig) IsLovelace(num *big.Int) bool {
return isForked(c.LovelaceMapContext, num)
}
*/

// CheckCompatible checks whether scheduled fork transitions have been imported
// with a mismatching chain configuration.
func (c *ChainConfig) CheckCompatible(newcfg *ChainConfig, height uint64) *ConfigCompatError {
Expand Down Expand Up @@ -964,8 +949,6 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
{name: "berlinBlock", block: c.BerlinBlock},
{name: "londonBlock", block: c.LondonBlock},
{name: "c.FullerMapContext", block: c.FullerMapContext},
/* {name: "TuringMapContext", block: c.TuringMapContext},
{name: "LovelaceMapContext", block: c.LovelaceMapContext}, */
} {
if lastFork.name != "" {
// Next one must be higher number
Expand Down Expand Up @@ -1032,12 +1015,6 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int) *Confi
if isForkIncompatible(c.FullerMapContext, newcfg.FullerMapContext, head) {
return newCompatError("Fuller ontology block", c.FullerMapContext, newcfg.FullerMapContext)
}
/* if isForkIncompatible(c.TuringMapContext, newcfg.TuringMapContext, head) {
return newCompatError("Turing ontology block", c.TuringMapContext, newcfg.TuringMapContext)
}
if isForkIncompatible(c.LovelaceMapContext, newcfg.LovelaceMapContext, head) {
return newCompatError("Lovelace ontology block", c.LovelaceMapContext, newcfg.LovelaceMapContext)
} */
return nil
}

Expand Down Expand Up @@ -1129,8 +1106,6 @@ func (c *ChainConfig) Rules(num *big.Int) Rules {
IsLondon: c.IsLondon(num),
IsCatalyst: c.IsCatalyst(num),
IsFuller: c.IsFuller(num),
/* IsTuring: c.IsTuring(num),
IsLovelace: c.IsLovelace(num), */
}
}

Expand Down Expand Up @@ -1259,10 +1234,6 @@ func (c *ChainConfig) CurrentOntology(number []*big.Int) ([]int, error) {
forkNumber := number[0]

switch {
/* case forkNumber.Cmp(LovelaceMapContext) >= 0: // Lovelace = MaxInt
return LovelaceOntology, nil
case forkNumber.Cmp(TuringMapContext) >= 0: // Turing = MaxInt
return TuringOntology, nil */
case forkNumber.Cmp(c.FullerMapContext) >= 0: // Fuller = 0
return FullerOntology, nil
default:
Expand Down
9 changes: 6 additions & 3 deletions params/protocol_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ var (
MinimumDifficulty = big.NewInt(131072) // The minimum that the difficulty may ever be.
DurationLimits = []*big.Int{big.NewInt(900), big.NewInt(300), big.NewInt(10)} // The decision boundary on the blocktime duration used to determine whether difficulty should go up or not.
TargetUncles = []int{10, 30, 100} // The bound divisor of the gas limit, used in update calculations.
MaxContext = 2
)

// Ontology defines the current Quai Network ontology
Expand All @@ -179,10 +180,12 @@ var (
FullerMapContext = big.NewInt(0) // Fork = 0 meaning initial ontology
TuringMapContext = big.NewInt(math.MaxInt) // maxed out for now
LovelaMapContext = big.NewInt(math.MaxInt) // maxed out for now

// Named ontologies
FullerOntology = []int{3, 3, 3} // named after Buckminster Fuller
TuringOntology = []int{4, 4, 4} // named after Alan Turing
LovelaceOntology = []int{5, 5, 5} // named after Ada Lovelace
// This defines the number of allowed regions (r) and zones (z) in the hierarchy (r,z)
FullerOntology = []int{3, 3} // named after Buckminster Fuller
TuringOntology = []int{4, 4} // named after Alan Turing
LovelaceOntology = []int{5, 5} // named after Ada Lovelace
// future ontology expansion markers go here
QuaiOntologies = [][]int{FullerOntology, TuringOntology, LovelaceOntology}
)

0 comments on commit b0ee402

Please sign in to comment.