Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions lib/block_view_stake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -933,10 +933,6 @@ func TestStakingWithDerivedKey(t *testing.T) {
return fees, nil
}

// Seed a CurrentEpochEntry.
epochUtxoView := newUtxoView()
epochUtxoView._setCurrentEpochEntry(&EpochEntry{EpochNumber: 1, FinalBlockHeight: blockHeight + 10})
require.NoError(t, epochUtxoView.FlushToDb(blockHeight))
currentEpochNumber, err := newUtxoView().GetCurrentEpochNumber()
require.NoError(t, err)

Expand Down
29 changes: 0 additions & 29 deletions lib/block_view_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@ func _testValidatorRegistration(t *testing.T, flushToDB bool) {

m0PKID := DBGetPKIDEntryForPublicKey(db, chain.snapshot, m0PkBytes).PKID

// Seed a CurrentEpochEntry.
epochUtxoView, err := NewUtxoView(db, params, chain.postgres, chain.snapshot)
require.NoError(t, err)
epochUtxoView._setCurrentEpochEntry(&EpochEntry{EpochNumber: 1, FinalBlockHeight: blockHeight + 10})
require.NoError(t, epochUtxoView.FlushToDb(blockHeight))

{
// ParamUpdater set min fee rate
params.ExtraRegtestParamUpdaterKeys[MakePkMapKey(paramUpdaterPkBytes)] = true
Expand Down Expand Up @@ -576,12 +570,6 @@ func TestValidatorRegistrationWithDerivedKey(t *testing.T) {
return nil
}

// Seed a CurrentEpochEntry.
epochUtxoView, err := NewUtxoView(db, params, chain.postgres, chain.snapshot)
require.NoError(t, err)
epochUtxoView._setCurrentEpochEntry(&EpochEntry{EpochNumber: 1, FinalBlockHeight: blockHeight + 10})
require.NoError(t, epochUtxoView.FlushToDb(blockHeight))

{
// ParamUpdater set min fee rate
params.ExtraRegtestParamUpdaterKeys[MakePkMapKey(paramUpdaterPkBytes)] = true
Expand Down Expand Up @@ -750,12 +738,6 @@ func _testGetTopActiveValidatorsByStake(t *testing.T, flushToDB bool) {
m1PKID := DBGetPKIDEntryForPublicKey(db, chain.snapshot, m1PkBytes).PKID
m2PKID := DBGetPKIDEntryForPublicKey(db, chain.snapshot, m2PkBytes).PKID

// Seed a CurrentEpochEntry.
epochUtxoView, err := NewUtxoView(db, params, chain.postgres, chain.snapshot)
require.NoError(t, err)
epochUtxoView._setCurrentEpochEntry(&EpochEntry{EpochNumber: 1, FinalBlockHeight: blockHeight + 10})
require.NoError(t, epochUtxoView.FlushToDb(blockHeight))

{
// ParamUpdater set min fee rate
params.ExtraRegtestParamUpdaterKeys[MakePkMapKey(paramUpdaterPkBytes)] = true
Expand Down Expand Up @@ -1188,12 +1170,6 @@ func _testUpdatingValidatorDisableDelegatedStake(t *testing.T, flushToDB bool) {

m0PKID := DBGetPKIDEntryForPublicKey(db, chain.snapshot, m0PkBytes).PKID

// Seed a CurrentEpochEntry.
epochUtxoView, err := NewUtxoView(db, params, chain.postgres, chain.snapshot)
require.NoError(t, err)
epochUtxoView._setCurrentEpochEntry(&EpochEntry{EpochNumber: 1, FinalBlockHeight: blockHeight + 10})
require.NoError(t, epochUtxoView.FlushToDb(blockHeight))

{
// ParamUpdater set min fee rate
params.ExtraRegtestParamUpdaterKeys[MakePkMapKey(paramUpdaterPkBytes)] = true
Expand Down Expand Up @@ -1384,11 +1360,6 @@ func _testUnregisterAsValidator(t *testing.T, flushToDB bool) {
m0PKID := DBGetPKIDEntryForPublicKey(db, chain.snapshot, m0PkBytes).PKID
m1PKID := DBGetPKIDEntryForPublicKey(db, chain.snapshot, m1PkBytes).PKID

// Seed a CurrentEpochEntry.
epochUtxoView, err := NewUtxoView(db, params, chain.postgres, chain.snapshot)
require.NoError(t, err)
epochUtxoView._setCurrentEpochEntry(&EpochEntry{EpochNumber: 1, FinalBlockHeight: blockHeight + 10})
require.NoError(t, epochUtxoView.FlushToDb(blockHeight))
currentEpochNumber, err := utxoView().GetCurrentEpochNumber()
require.NoError(t, err)

Expand Down
7 changes: 6 additions & 1 deletion lib/pos_epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/dgraph-io/badger/v3"
"github.com/golang/glog"
"github.com/pkg/errors"
"math"
)

//
Expand Down Expand Up @@ -78,8 +79,12 @@ func (bav *UtxoView) GetCurrentEpochEntry() (*EpochEntry, error) {
if epochEntry != nil {
// Cache in the UtxoView.
bav._setCurrentEpochEntry(epochEntry)
return epochEntry, nil
}
return epochEntry, nil

// If still not found, return the GenesisEpochEntry. This will be the
// case prior to the first execution of the OnEpochCompleteHook.
return &EpochEntry{EpochNumber: 0, FinalBlockHeight: math.MaxUint64}, nil
}

func (bav *UtxoView) GetCurrentEpochNumber() (uint64, error) {
Expand Down
7 changes: 5 additions & 2 deletions lib/pos_epoch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package lib

import (
"github.com/stretchr/testify/require"
"math"
"testing"
)

Expand All @@ -23,10 +24,12 @@ func TestCurrentEpoch(t *testing.T) {
// Test that the CurrentEpoch is nil in the UtxoView.
require.Nil(t, utxoView.CurrentEpochEntry)

// Test GetCurrentEpoch().
// Test GetCurrentEpoch() returns the GenesisEpochEntry.
epochEntry, err = utxoView.GetCurrentEpochEntry()
require.NoError(t, err)
require.Nil(t, epochEntry)
require.NotNil(t, epochEntry)
require.Equal(t, epochEntry.EpochNumber, uint64(0))
require.Equal(t, epochEntry.FinalBlockHeight, uint64(math.MaxUint64))

// Set the CurrentEpoch.
epochEntry = &EpochEntry{
Expand Down