-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use custom temp dir for gsfa * Flush based on performance * Fix tmpDir * Max is 1000 * Remove /health and /metrics req logging; closes #127 * Move metrics to metrics package * Prometheus for index and car lookups; closes #126 * Cleanup metrics; closes #128 * gsfa: include pubkeys from address lookup tables * Miner info: use exponential retry * Fix tests
- Loading branch information
1 parent
69c6bf9
commit dd83ea1
Showing
7 changed files
with
285 additions
and
37 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
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,72 @@ | ||
package gsfa | ||
|
||
import ( | ||
"slices" | ||
"sort" | ||
|
||
"github.com/gagliardetto/solana-go" | ||
"github.com/tidwall/hashmap" | ||
) | ||
|
||
type rollingRankOfTopPerformers struct { | ||
rankListSize int | ||
maxValue int | ||
minValue int | ||
set hashmap.Map[solana.PublicKey, int] | ||
} | ||
|
||
func newRollingRankOfTopPerformers(rankListSize int) *rollingRankOfTopPerformers { | ||
return &rollingRankOfTopPerformers{ | ||
rankListSize: rankListSize, | ||
} | ||
} | ||
|
||
func (r *rollingRankOfTopPerformers) Incr(key solana.PublicKey, delta int) int { | ||
value, ok := r.set.Get(key) | ||
if !ok { | ||
value = 0 | ||
} | ||
value = value + delta | ||
r.set.Set(key, value) | ||
if value > r.maxValue { | ||
r.maxValue = value | ||
} | ||
if value < r.minValue { | ||
r.minValue = value | ||
} | ||
return value | ||
} | ||
|
||
func (r *rollingRankOfTopPerformers) Get(key solana.PublicKey) (int, bool) { | ||
value, ok := r.set.Get(key) | ||
return value, ok | ||
} | ||
|
||
// purge will remove all keys by the lowest values until the rankListSize is reached. | ||
// keys with equivalent values are kept. | ||
func (r *rollingRankOfTopPerformers) purge() { | ||
values := r.set.Values() | ||
sort.Ints(values) | ||
values = slices.Compact(values) | ||
if len(values) <= r.rankListSize { | ||
return | ||
} | ||
|
||
// remove the lowest values | ||
for _, value := range values[:len(values)-r.rankListSize] { | ||
for _, key := range r.set.Keys() { | ||
if v, _ := r.set.Get(key); v == value { | ||
r.set.Delete(key) | ||
} | ||
} | ||
} | ||
|
||
// update the min and max values | ||
r.minValue = values[len(values)-r.rankListSize] | ||
r.maxValue = values[len(values)-1] | ||
} | ||
|
||
func (r *rollingRankOfTopPerformers) has(key solana.PublicKey) bool { | ||
_, ok := r.set.Get(key) | ||
return ok | ||
} |
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,55 @@ | ||
package gsfa | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gagliardetto/solana-go" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestPopRank(t *testing.T) { | ||
// Test the rollingRankOfTopPerformers type: | ||
{ | ||
// Create a new rollingRankOfTopPerformers: | ||
r := newRollingRankOfTopPerformers(5) | ||
if r == nil { | ||
t.Fatal("expected non-nil rollingRankOfTopPerformers") | ||
} | ||
// Test the Incr method: | ||
{ | ||
key := solana.SysVarRentPubkey | ||
delta := 1 | ||
value := r.Incr(key, delta) | ||
require.Equal(t, 1, value) | ||
} | ||
// Test the purge method: | ||
{ | ||
r.purge() | ||
// the value should still be 1 | ||
value, ok := r.Get(solana.SysVarRentPubkey) | ||
require.True(t, ok) | ||
require.Equal(t, 1, value) | ||
} | ||
{ | ||
// now add a few more values: | ||
r.Incr(solana.SysVarClockPubkey, 6) | ||
r.Incr(solana.SysVarEpochSchedulePubkey, 5) | ||
r.Incr(solana.SysVarFeesPubkey, 4) | ||
r.Incr(solana.SysVarInstructionsPubkey, 3) | ||
r.Incr(solana.SysVarRewardsPubkey, 2) | ||
|
||
// there should be 6 values now | ||
require.Equal(t, 6, r.set.Len()) | ||
|
||
// purge should remove the lowest values | ||
r.purge() | ||
|
||
// there should be 5 values now (equivalent values are kept) | ||
require.Equal(t, 5, r.set.Len()) | ||
|
||
// the lowest value should be 2 | ||
require.Equal(t, 2, r.minValue) | ||
require.Equal(t, 6, r.maxValue) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.