Skip to content

Commit

Permalink
Merge branch 'miguel/feehistory2' of https://github.com/vechain/thor
Browse files Browse the repository at this point in the history
…into miguel/feehistory3
  • Loading branch information
freemanzMrojo committed Jan 31, 2025
2 parents e125e86 + fd10385 commit 8c5dff4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
4 changes: 2 additions & 2 deletions api/fees/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/vechain/thor/v2/thor"
)

func NewFeesCache(repo *chain.Repository, backtraceLimit uint32, fixedSize uint32) *FeesCache {
func newFeesCache(repo *chain.Repository, backtraceLimit uint32, fixedSize uint32) *FeesCache {
size := int(math.Min(float64(backtraceLimit), float64(fixedSize)))
return &FeesCache{
repo: repo,
Expand Down Expand Up @@ -53,7 +53,7 @@ func (fc *FeesCache) getByRevision(rev *utils.Revision, bft bft.Committer) (*Fee
return fc.get(id)
}

func (fc *FeesCache) Push(header *block.Header) {
func (fc *FeesCache) push(header *block.Header) {
fc.cache.Set(header.ID(), newFeesCacheEntry(header), float64(header.Number()))
}

Expand Down
4 changes: 2 additions & 2 deletions api/fees/fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func New(repo *chain.Repository, bft bft.Committer, backtraceLimit uint32, fixed
return &Fees{
repo: repo,
bft: bft,
cache: NewFeesCache(repo, backtraceLimit, fixedCacheSize),
cache: newFeesCache(repo, backtraceLimit, fixedCacheSize),
done: make(chan struct{}),
}
}
Expand Down Expand Up @@ -205,7 +205,7 @@ func (f *Fees) pushBestBlockToCache() {
select {
case <-ticker.C():
bestBlockSummary := f.repo.BestBlockSummary()
f.cache.Push(bestBlockSummary.Header)
f.cache.push(bestBlockSummary.Header)
case <-f.done:
return
}
Expand Down
13 changes: 3 additions & 10 deletions api/fees/fees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,7 @@ import (

const expectedGasPriceUsedRatio = 0.0021

func TestFees(t *testing.T) {
t.Run("testFeesBacktraceGreaterThanFixedSize", testFeesBacktraceGreaterThanFixedSize)
t.Run("testFeesFixedSizeGreaterThanBacktrace", testFeesFixedSizeGreaterThanBacktrace)
t.Run("testFeesFixedSizeSameAsBacktrace", testFeesFixedSizeSameAsBacktrace)
}


func testFeesBacktraceGreaterThanFixedSize(t *testing.T) {
func TestFeesBacktraceGreaterThanFixedSize(t *testing.T) {
ts, closeFunc := initFeesServer(t, 8, 10, 10)
t.Cleanup(func() {
closeFunc()
Expand All @@ -54,7 +47,7 @@ func testFeesBacktraceGreaterThanFixedSize(t *testing.T) {
}
}

func testFeesFixedSizeGreaterThanBacktrace(t *testing.T) {
func TestFeesFixedSizeGreaterThanBacktrace(t *testing.T) {
ts, closeFunc := initFeesServer(t, 8, 6, 10)
defer func() {
closeFunc()
Expand All @@ -71,7 +64,7 @@ func testFeesFixedSizeGreaterThanBacktrace(t *testing.T) {
}
}

func testFeesFixedSizeSameAsBacktrace(t *testing.T) {
func TestFeesFixedSizeSameAsBacktrace(t *testing.T) {
// Less blocks than the backtrace limit
ts, closeFunc := initFeesServer(t, 11, 11, 10)
defer func() {
Expand Down

0 comments on commit 8c5dff4

Please sign in to comment.