Skip to content

Commit

Permalink
Removed the address allocation for prime and region
Browse files Browse the repository at this point in the history
Spread the address space around all zones
  • Loading branch information
gameofpointers committed Apr 27, 2023
1 parent 387c28b commit 6422b1a
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 124 deletions.
7 changes: 6 additions & 1 deletion cmd/go-quai/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"gopkg.in/urfave/cli.v1"

"github.com/dominant-strategies/go-quai/cmd/utils"
"github.com/dominant-strategies/go-quai/common"
"github.com/dominant-strategies/go-quai/core/vm"
"github.com/dominant-strategies/go-quai/eth/ethconfig"
"github.com/dominant-strategies/go-quai/internal/quaiapi"
Expand Down Expand Up @@ -114,6 +115,7 @@ func defaultNodeConfig() node.Config {

// makeConfigNode loads quai configuration and creates a blank node instance.
func makeConfigNode(ctx *cli.Context) (*node.Node, quaiConfig) {
nodeCtx := common.NodeLocation.Context()
// Load defaults.
cfg := quaiConfig{
Eth: ethconfig.Defaults,
Expand All @@ -140,7 +142,10 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, quaiConfig) {
cfg.Ethstats.URL = ctx.GlobalString(utils.QuaiStatsURLFlag.Name)
}
applyMetricConfig(ctx, &cfg)
vm.InitializePrecompiles()
// Onlt initialize the precompile for the zone chain
if nodeCtx == common.ZONE_CTX {
vm.InitializePrecompiles()
}
return stack, cfg
}

Expand Down
33 changes: 19 additions & 14 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,15 @@ var (
)

func init() {
locationToPrefixRange["prime"] = NewRange(0, 9)
locationToPrefixRange["cyprus"] = NewRange(10, 19)
locationToPrefixRange["cyprus1"] = NewRange(20, 29)
locationToPrefixRange["cyprus2"] = NewRange(30, 39)
locationToPrefixRange["cyprus3"] = NewRange(40, 49)
locationToPrefixRange["paxos"] = NewRange(50, 59)
locationToPrefixRange["paxos1"] = NewRange(60, 69)
locationToPrefixRange["paxos2"] = NewRange(70, 79)
locationToPrefixRange["paxos3"] = NewRange(80, 89)
locationToPrefixRange["hydra"] = NewRange(90, 99)
locationToPrefixRange["hydra1"] = NewRange(100, 109)
locationToPrefixRange["hydra2"] = NewRange(110, 119)
locationToPrefixRange["hydra3"] = NewRange(120, 129)
locationToPrefixRange["cyprus1"] = NewRange(0, 29)
locationToPrefixRange["cyprus2"] = NewRange(30, 58)
locationToPrefixRange["cyprus3"] = NewRange(59, 87)
locationToPrefixRange["paxos1"] = NewRange(88, 115)
locationToPrefixRange["paxos2"] = NewRange(116, 143)
locationToPrefixRange["paxos3"] = NewRange(144, 171)
locationToPrefixRange["hydra1"] = NewRange(172, 199)
locationToPrefixRange["hydra2"] = NewRange(200, 227)
locationToPrefixRange["hydra3"] = NewRange(228, 255)
}

// UnprefixedAddress allows marshaling an Address without 0x prefix.
Expand Down Expand Up @@ -461,6 +457,10 @@ func (loc Location) CommonDom(cmp Location) Location {
}

func (l Location) ContainsAddress(a Address) bool {
// ContainAddress can only be called for a zone chain
if l.Context() != ZONE_CTX {
return false
}
prefix := a.Bytes()[0]
prefixRange, ok := locationToPrefixRange[l.Name()]
if !ok {
Expand All @@ -480,6 +480,11 @@ func (l Location) RPCMarshal() []hexutil.Uint64 {
}

func IsInChainScope(b []byte) bool {
nodeCtx := NodeLocation.Context()
// IsInChainScope only be called for a zone chain
if nodeCtx != ZONE_CTX {
return false
}
if BytesToHash(b) == ZeroAddr.Hash() {
return true
}
Expand All @@ -499,7 +504,7 @@ func OrderToString(order int) string {
case REGION_CTX:
return "Region"
case ZONE_CTX:
return "Zone"
return "Zone"
default:
return "Invalid"
}
Expand Down
2 changes: 1 addition & 1 deletion core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
return ErrKnownBlock
}
}
header := block.Header()
// Subordinate manifest must match ManifestHash in subordinate context, _iff_
// we have a subordinate (i.e. if we are not a zone)
if nodeCtx != common.ZONE_CTX {
Expand All @@ -80,7 +81,6 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
}
} else {
// Header validity is known at this point, check the uncles and transactions
header := block.Header()
if err := v.engine.VerifyUncles(v.hc, block); err != nil {
return err
}
Expand Down
170 changes: 63 additions & 107 deletions core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,6 @@ func InitializePrecompiles() {

func init() {

PrecompiledAddresses["prime"] = []common.Address{
common.BytesToAddress([]byte{1}),
common.BytesToAddress([]byte{2}),
common.BytesToAddress([]byte{3}),
common.BytesToAddress([]byte{4}),
common.BytesToAddress([]byte{5}),
common.BytesToAddress([]byte{6}),
common.BytesToAddress([]byte{7}),
common.BytesToAddress([]byte{8}),
common.BytesToAddress([]byte{9}),
}
PrecompiledAddresses["cyprus"] = []common.Address{
common.HexToAddress("0x0A00000000000000000000000000000000000001"),
common.HexToAddress("0x0A00000000000000000000000000000000000002"),
common.HexToAddress("0x0A00000000000000000000000000000000000003"),
common.HexToAddress("0x0A00000000000000000000000000000000000004"),
common.HexToAddress("0x0A00000000000000000000000000000000000005"),
common.HexToAddress("0x0A00000000000000000000000000000000000006"),
common.HexToAddress("0x0A00000000000000000000000000000000000007"),
common.HexToAddress("0x0A00000000000000000000000000000000000008"),
common.HexToAddress("0x0A00000000000000000000000000000000000009"),
}
PrecompiledAddresses["cyprus1"] = []common.Address{
common.HexToAddress("0x1400000000000000000000000000000000000001"),
common.HexToAddress("0x1400000000000000000000000000000000000002"),
Expand All @@ -106,72 +84,28 @@ func init() {
common.HexToAddress("0x1400000000000000000000000000000000000009"),
}
PrecompiledAddresses["cyprus2"] = []common.Address{
common.HexToAddress("0x1E00000000000000000000000000000000000001"),
common.HexToAddress("0x1E00000000000000000000000000000000000002"),
common.HexToAddress("0x1E00000000000000000000000000000000000003"),
common.HexToAddress("0x1E00000000000000000000000000000000000004"),
common.HexToAddress("0x1E00000000000000000000000000000000000005"),
common.HexToAddress("0x1E00000000000000000000000000000000000006"),
common.HexToAddress("0x1E00000000000000000000000000000000000007"),
common.HexToAddress("0x1E00000000000000000000000000000000000008"),
common.HexToAddress("0x1E00000000000000000000000000000000000009"),
common.HexToAddress("0x2000000000000000000000000000000000000001"),
common.HexToAddress("0x2000000000000000000000000000000000000002"),
common.HexToAddress("0x2000000000000000000000000000000000000003"),
common.HexToAddress("0x2000000000000000000000000000000000000004"),
common.HexToAddress("0x2000000000000000000000000000000000000005"),
common.HexToAddress("0x2000000000000000000000000000000000000006"),
common.HexToAddress("0x2000000000000000000000000000000000000007"),
common.HexToAddress("0x2000000000000000000000000000000000000008"),
common.HexToAddress("0x2000000000000000000000000000000000000009"),
}
PrecompiledAddresses["cyprus3"] = []common.Address{
common.HexToAddress("0x2800000000000000000000000000000000000001"),
common.HexToAddress("0x2800000000000000000000000000000000000002"),
common.HexToAddress("0x2800000000000000000000000000000000000003"),
common.HexToAddress("0x2800000000000000000000000000000000000004"),
common.HexToAddress("0x2800000000000000000000000000000000000005"),
common.HexToAddress("0x2800000000000000000000000000000000000006"),
common.HexToAddress("0x2800000000000000000000000000000000000007"),
common.HexToAddress("0x2800000000000000000000000000000000000008"),
common.HexToAddress("0x2800000000000000000000000000000000000009"),
}
PrecompiledAddresses["paxos"] = []common.Address{
common.HexToAddress("0x3200000000000000000000000000000000000001"),
common.HexToAddress("0x3200000000000000000000000000000000000002"),
common.HexToAddress("0x3200000000000000000000000000000000000003"),
common.HexToAddress("0x3200000000000000000000000000000000000004"),
common.HexToAddress("0x3200000000000000000000000000000000000005"),
common.HexToAddress("0x3200000000000000000000000000000000000006"),
common.HexToAddress("0x3200000000000000000000000000000000000007"),
common.HexToAddress("0x3200000000000000000000000000000000000008"),
common.HexToAddress("0x3200000000000000000000000000000000000009"),
common.HexToAddress("0x3E00000000000000000000000000000000000001"),
common.HexToAddress("0x3E00000000000000000000000000000000000002"),
common.HexToAddress("0x3E00000000000000000000000000000000000003"),
common.HexToAddress("0x3E00000000000000000000000000000000000004"),
common.HexToAddress("0x3E00000000000000000000000000000000000005"),
common.HexToAddress("0x3E00000000000000000000000000000000000006"),
common.HexToAddress("0x3E00000000000000000000000000000000000007"),
common.HexToAddress("0x3E00000000000000000000000000000000000008"),
common.HexToAddress("0x3E00000000000000000000000000000000000009"),
}
PrecompiledAddresses["paxos1"] = []common.Address{
common.HexToAddress("0x3C00000000000000000000000000000000000001"),
common.HexToAddress("0x3C00000000000000000000000000000000000002"),
common.HexToAddress("0x3C00000000000000000000000000000000000003"),
common.HexToAddress("0x3C00000000000000000000000000000000000004"),
common.HexToAddress("0x3C00000000000000000000000000000000000005"),
common.HexToAddress("0x3C00000000000000000000000000000000000006"),
common.HexToAddress("0x3C00000000000000000000000000000000000007"),
common.HexToAddress("0x3C00000000000000000000000000000000000008"),
common.HexToAddress("0x3C00000000000000000000000000000000000009"),
}
PrecompiledAddresses["paxos2"] = []common.Address{
common.HexToAddress("0x4600000000000000000000000000000000000001"),
common.HexToAddress("0x4600000000000000000000000000000000000002"),
common.HexToAddress("0x4600000000000000000000000000000000000003"),
common.HexToAddress("0x4600000000000000000000000000000000000004"),
common.HexToAddress("0x4600000000000000000000000000000000000005"),
common.HexToAddress("0x4600000000000000000000000000000000000006"),
common.HexToAddress("0x4600000000000000000000000000000000000007"),
common.HexToAddress("0x4600000000000000000000000000000000000008"),
common.HexToAddress("0x4600000000000000000000000000000000000009"),
}
PrecompiledAddresses["paxos3"] = []common.Address{
common.HexToAddress("0x5000000000000000000000000000000000000001"),
common.HexToAddress("0x5000000000000000000000000000000000000002"),
common.HexToAddress("0x5000000000000000000000000000000000000003"),
common.HexToAddress("0x5000000000000000000000000000000000000004"),
common.HexToAddress("0x5000000000000000000000000000000000000005"),
common.HexToAddress("0x5000000000000000000000000000000000000006"),
common.HexToAddress("0x5000000000000000000000000000000000000007"),
common.HexToAddress("0x5000000000000000000000000000000000000008"),
common.HexToAddress("0x5000000000000000000000000000000000000009"),
}
PrecompiledAddresses["hydra"] = []common.Address{
common.HexToAddress("0x5A00000000000000000000000000000000000001"),
common.HexToAddress("0x5A00000000000000000000000000000000000002"),
common.HexToAddress("0x5A00000000000000000000000000000000000003"),
Expand All @@ -182,29 +116,7 @@ func init() {
common.HexToAddress("0x5A00000000000000000000000000000000000008"),
common.HexToAddress("0x5A00000000000000000000000000000000000009"),
}
PrecompiledAddresses["hydra1"] = []common.Address{
common.HexToAddress("0x6400000000000000000000000000000000000001"),
common.HexToAddress("0x6400000000000000000000000000000000000002"),
common.HexToAddress("0x6400000000000000000000000000000000000003"),
common.HexToAddress("0x6400000000000000000000000000000000000004"),
common.HexToAddress("0x6400000000000000000000000000000000000005"),
common.HexToAddress("0x6400000000000000000000000000000000000006"),
common.HexToAddress("0x6400000000000000000000000000000000000007"),
common.HexToAddress("0x6400000000000000000000000000000000000008"),
common.HexToAddress("0x6400000000000000000000000000000000000009"),
}
PrecompiledAddresses["hydra2"] = []common.Address{
common.HexToAddress("0x6E00000000000000000000000000000000000001"),
common.HexToAddress("0x6E00000000000000000000000000000000000002"),
common.HexToAddress("0x6E00000000000000000000000000000000000003"),
common.HexToAddress("0x6E00000000000000000000000000000000000004"),
common.HexToAddress("0x6E00000000000000000000000000000000000005"),
common.HexToAddress("0x6E00000000000000000000000000000000000006"),
common.HexToAddress("0x6E00000000000000000000000000000000000007"),
common.HexToAddress("0x6E00000000000000000000000000000000000008"),
common.HexToAddress("0x6E00000000000000000000000000000000000009"),
}
PrecompiledAddresses["hydra3"] = []common.Address{
PrecompiledAddresses["paxos2"] = []common.Address{
common.HexToAddress("0x7800000000000000000000000000000000000001"),
common.HexToAddress("0x7800000000000000000000000000000000000002"),
common.HexToAddress("0x7800000000000000000000000000000000000003"),
Expand All @@ -215,6 +127,50 @@ func init() {
common.HexToAddress("0x7800000000000000000000000000000000000008"),
common.HexToAddress("0x7800000000000000000000000000000000000009"),
}
PrecompiledAddresses["paxos3"] = []common.Address{
common.HexToAddress("0x9600000000000000000000000000000000000001"),
common.HexToAddress("0x9600000000000000000000000000000000000002"),
common.HexToAddress("0x9600000000000000000000000000000000000003"),
common.HexToAddress("0x9600000000000000000000000000000000000004"),
common.HexToAddress("0x9600000000000000000000000000000000000005"),
common.HexToAddress("0x9600000000000000000000000000000000000006"),
common.HexToAddress("0x9600000000000000000000000000000000000007"),
common.HexToAddress("0x9600000000000000000000000000000000000008"),
common.HexToAddress("0x9600000000000000000000000000000000000009"),
}
PrecompiledAddresses["hydra1"] = []common.Address{
common.HexToAddress("0xB400000000000000000000000000000000000001"),
common.HexToAddress("0xB400000000000000000000000000000000000002"),
common.HexToAddress("0xB400000000000000000000000000000000000003"),
common.HexToAddress("0xB400000000000000000000000000000000000004"),
common.HexToAddress("0xB400000000000000000000000000000000000005"),
common.HexToAddress("0xB400000000000000000000000000000000000006"),
common.HexToAddress("0xB400000000000000000000000000000000000007"),
common.HexToAddress("0xB400000000000000000000000000000000000008"),
common.HexToAddress("0xB400000000000000000000000000000000000009"),
}
PrecompiledAddresses["hydra2"] = []common.Address{
common.HexToAddress("0xD200000000000000000000000000000000000001"),
common.HexToAddress("0xD200000000000000000000000000000000000002"),
common.HexToAddress("0xD200000000000000000000000000000000000003"),
common.HexToAddress("0xD200000000000000000000000000000000000004"),
common.HexToAddress("0xD200000000000000000000000000000000000005"),
common.HexToAddress("0xD200000000000000000000000000000000000006"),
common.HexToAddress("0xD200000000000000000000000000000000000007"),
common.HexToAddress("0xD200000000000000000000000000000000000008"),
common.HexToAddress("0xD200000000000000000000000000000000000009"),
}
PrecompiledAddresses["hydra3"] = []common.Address{
common.HexToAddress("0xF000000000000000000000000000000000000001"),
common.HexToAddress("0xF000000000000000000000000000000000000002"),
common.HexToAddress("0xF000000000000000000000000000000000000003"),
common.HexToAddress("0xF000000000000000000000000000000000000004"),
common.HexToAddress("0xF000000000000000000000000000000000000005"),
common.HexToAddress("0xF000000000000000000000000000000000000006"),
common.HexToAddress("0xF000000000000000000000000000000000000007"),
common.HexToAddress("0xF000000000000000000000000000000000000008"),
common.HexToAddress("0xF000000000000000000000000000000000000009"),
}
}

// ActivePrecompiles returns the precompiles enabled with the current configuration.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ require (
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324
gopkg.in/urfave/cli.v1 v1.20.0
lukechampine.com/blake3 v1.1.7
modernc.org/mathutil v1.5.0
)

require (
Expand All @@ -63,5 +64,4 @@ require (
golang.org/x/text v0.3.6 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
gotest.tools v2.2.0+incompatible // indirect
modernc.org/mathutil v1.5.0 // indirect
)

0 comments on commit 6422b1a

Please sign in to comment.