-
Notifications
You must be signed in to change notification settings - Fork 188
#683 keychain sdk configure multiple nodes endpoints #810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7b6d2d2
8e48821
eefa6f1
cd821e6
50fffb0
dc209fd
f53b2ea
90d8ca5
ab22126
9b4c3a7
b1fe1de
fcd8167
31bbb3a
3980feb
5ba8904
a23df86
bf12a7d
6b4ea38
b5923b8
d4c3937
57bd353
6a545f3
3b7404f
3642a15
ce27189
d725e0e
e07e452
5b954a5
85f1619
8971782
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package main | ||
|
|
||
| type HealthCheckResponse struct { | ||
| // Online is the number of nodes that are online | ||
| Online uint `json:"online"` | ||
|
|
||
| // Total is the total number of nodes | ||
| Total uint `json:"total"` | ||
|
|
||
| // Threshold is the consensus threshold | ||
| Threshold uint8 `json:"threshold"` | ||
|
|
||
| // Nodes is a node statuses collection | ||
| Nodes []NodeStatus `json:"nodes"` | ||
| } | ||
|
|
||
| type NodeStatus struct { | ||
| // Address is the address of the node | ||
| Address string `json:"address"` | ||
|
|
||
| // Status is the status of the node | ||
| Status string `json:"status"` | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,35 +1,72 @@ | ||||||
| package tracker | ||||||
|
|
||||||
| import ( | ||||||
| "errors" | ||||||
| "sync" | ||||||
| ) | ||||||
|
|
||||||
| type Action int | ||||||
backsapc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
| const ( | ||||||
| ActionSkip Action = iota | ||||||
| ActionProcess | ||||||
| ) | ||||||
|
|
||||||
| type stringSet map[string]struct{} | ||||||
|
|
||||||
| // add safely adds a string to the set. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there's no "safety" here, i suggest we rephrase it like this:
Suggested change
|
||||||
| func (s stringSet) add(str string) bool { | ||||||
| if _, exists := s[str]; exists { | ||||||
| return false | ||||||
| } | ||||||
| s[str] = struct{}{} | ||||||
| return true | ||||||
| } | ||||||
|
|
||||||
| type T struct { | ||||||
| rw sync.RWMutex | ||||||
| ingested map[uint64]struct{} | ||||||
| threshold uint8 | ||||||
| rw sync.RWMutex | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like we no longer need to use a |
||||||
| ingested map[uint64]stringSet | ||||||
| } | ||||||
|
|
||||||
| func New() *T { | ||||||
| func New(threshold uint8) *T { | ||||||
| return &T{ | ||||||
| ingested: make(map[uint64]struct{}), | ||||||
| threshold: threshold, | ||||||
| ingested: make(map[uint64]stringSet), | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| func (t *T) IsNew(id uint64) bool { | ||||||
| t.rw.RLock() | ||||||
| defer t.rw.RUnlock() | ||||||
| _, ok := t.ingested[id] | ||||||
| return !ok | ||||||
| } | ||||||
|
|
||||||
| func (t *T) Ingested(id uint64) { | ||||||
| func (t *T) Ingest(id uint64, ingesterId string) (Action, error) { | ||||||
| t.rw.Lock() | ||||||
| defer t.rw.Unlock() | ||||||
| t.ingested[id] = struct{}{} | ||||||
|
|
||||||
| value := t.ingestTracker(id) | ||||||
|
|
||||||
| if !value.add(ingesterId) { | ||||||
| return ActionSkip, errors.New("already ingested") | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not an error, as it is expected to ingest the same id multiple times from the same source |
||||||
| } | ||||||
|
|
||||||
| if uint64(len(value)) < uint64(t.threshold) { | ||||||
| return ActionSkip, nil | ||||||
| } | ||||||
|
|
||||||
| return ActionProcess, nil | ||||||
| } | ||||||
|
|
||||||
| func (t *T) Done(id uint64) { | ||||||
| t.rw.Lock() | ||||||
| defer t.rw.Unlock() | ||||||
|
|
||||||
| delete(t.ingested, id) | ||||||
| } | ||||||
|
|
||||||
| func (t *T) ingestTracker(id uint64) stringSet { | ||||||
| value, ok := t.ingested[id] | ||||||
| if !ok { | ||||||
| t.ingested[id] = make(stringSet) | ||||||
|
|
||||||
| return t.ingested[id] | ||||||
| } | ||||||
|
|
||||||
| return value | ||||||
| } | ||||||
Uh oh!
There was an error while loading. Please reload this page.