-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
81 lines (73 loc) · 1.9 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Package operationfeestats provides useful utilities concerning operation fee
// stats within stellar,specifically as a central location to store a cached snapshot
// of the state of network per operation fees and surge pricing. This package is
// intended to be at the lowest levels of orbitr's dependency tree, please keep
// it free of dependencies to other orbitr packages.
package operationfeestats
import (
"sync"
)
// State represents a snapshot of orbitr's view of the state of operation fee's
// on the network.
type State struct {
FeeChargedMax int64
FeeChargedMin int64
FeeChargedMode int64
FeeChargedP10 int64
FeeChargedP20 int64
FeeChargedP30 int64
FeeChargedP40 int64
FeeChargedP50 int64
FeeChargedP60 int64
FeeChargedP70 int64
FeeChargedP80 int64
FeeChargedP90 int64
FeeChargedP95 int64
FeeChargedP99 int64
// MaxFee
MaxFeeMax int64
MaxFeeMin int64
MaxFeeMode int64
MaxFeeP10 int64
MaxFeeP20 int64
MaxFeeP30 int64
MaxFeeP40 int64
MaxFeeP50 int64
MaxFeeP60 int64
MaxFeeP70 int64
MaxFeeP80 int64
MaxFeeP90 int64
MaxFeeP95 int64
MaxFeeP99 int64
LastBaseFee int64
LastLedger uint32
LedgerCapacityUsage string
}
// CurrentState returns the cached snapshot of operation fee state and a boolean indicating
// if the cache has been populated
func CurrentState() (State, bool) {
lock.RLock()
ret := current
ok := present
lock.RUnlock()
return ret, ok
}
// SetState updates the cached snapshot of the operation fee state
func SetState(next State) {
lock.Lock()
// in case of one query taking longer than another, this makes
// sure we don't overwrite the latest fee stats with old stats
if current.LastLedger < next.LastLedger {
current = next
}
present = true
lock.Unlock()
}
// ResetState is used only for testing purposes
func ResetState() {
current = State{}
present = false
}
var current State
var present bool
var lock sync.RWMutex