-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* setup env & testing for shard routing * setup two shard peer nodes * set new .env for sharded nodes * add intervalmap data structure * add parsing of shard env variables * rename HeightShardingProxies -> PruningOrDefaultProxies * implement ShardProxies for shard routing * scaffold new Proxies to handle shards * handle shard routing * update PruningOrDefaultProxies logs to Trace * update failing test for shard routing * add tests for shard backend responses * add unit tests for shard routing proxies * route "earliest" to first shard also, prevent uint64 conversion underflows by routing any other block tag that is encoded to a negative number to the default proxy * configure shard routing in CI tests * document shard-based routing * make shards inclusive of end block * add more validation to shard backend url map parsing will error in cases of: * unordered shards * multiple shards for same endblock
- Loading branch information
1 parent
09b2a83
commit e30b255
Showing
17 changed files
with
748 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package config | ||
|
||
import ( | ||
"net/url" | ||
"sort" | ||
) | ||
|
||
// IntervalURLMap stores URLs associated with a range of numbers. | ||
// The intervals are defined by their endpoints and must not overlap. | ||
// The intervals are inclusive of the endpoints. | ||
type IntervalURLMap struct { | ||
UrlByEndHeight map[uint64]*url.URL | ||
endpoints []uint64 | ||
} | ||
|
||
// NewIntervalURLMap creates a new IntervalMap from a map of interval endpoint => url. | ||
// The intervals are inclusive of their endpoint. | ||
// ie. if the lowest value endpoint in the map is 10, the interval is for all numbers 1 through 10. | ||
func NewIntervalURLMap(urlByEndHeight map[uint64]*url.URL) IntervalURLMap { | ||
endpoints := make([]uint64, 0, len(urlByEndHeight)) | ||
for e := range urlByEndHeight { | ||
endpoints = append(endpoints, e) | ||
} | ||
sort.Slice(endpoints, func(i, j int) bool { return endpoints[i] < endpoints[j] }) | ||
|
||
return IntervalURLMap{ | ||
UrlByEndHeight: urlByEndHeight, | ||
endpoints: endpoints, | ||
} | ||
} | ||
|
||
// Lookup finds the value associated with the interval containing the number, if it exists. | ||
func (im *IntervalURLMap) Lookup(num uint64) (*url.URL, uint64, bool) { | ||
i := sort.Search(len(im.endpoints), func(i int) bool { return im.endpoints[i] >= num }) | ||
|
||
if i < len(im.endpoints) && num <= im.endpoints[i] { | ||
return im.UrlByEndHeight[im.endpoints[i]], im.endpoints[i], true | ||
} | ||
|
||
return nil, 0, false | ||
} |
Oops, something went wrong.