forked from stellar/go
/
main.go
59 lines (52 loc) · 1.43 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
// 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 horizon's dependency tree, please keep
// it free of dependencies to other horizon packages.
package operationfeestats
import (
"sync"
)
// State represents a snapshot of horizon's view of the state of operation fee's
// on the network.
type State struct {
FeeMin int64
FeeMode int64
FeeP10 int64
FeeP20 int64
FeeP30 int64
FeeP40 int64
FeeP50 int64
FeeP60 int64
FeeP70 int64
FeeP80 int64
FeeP90 int64
FeeP95 int64
FeeP99 int64
LastBaseFee int64
LastLedger int64
LedgerCapacityUsage string
}
// CurrentState returns the cached snapshot of operation fee state
func CurrentState() State {
lock.RLock()
ret := current
lock.RUnlock()
return ret
}
// 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
}
lock.Unlock()
}
// ResetState is used only for testing purposes
func ResetState() {
current = State{}
}
var current State
var lock sync.RWMutex