Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dot/state): gossamer_storage_tries_cached_total gauge metric #2272

Merged
merged 2 commits into from
Feb 24, 2022
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
3 changes: 2 additions & 1 deletion dot/rpc/modules/dev_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ func newState(t *testing.T) (*state.BlockState, *state.EpochState) {
db := state.NewInMemoryDB(t)

_, genesisTrie, genesisHeader := genesis.NewTestGenesisWithTrieAndHeader(t)
tries := state.NewTries(genesisTrie)
tries, err := state.NewTries(genesisTrie)
require.NoError(t, err)
bs, err := state.NewBlockStateFromGenesis(db, tries, genesisHeader, telemetryMock)
require.NoError(t, err)
es, err := state.NewEpochStateFromGenesis(db, bs, genesisBABEConfig)
Expand Down
25 changes: 23 additions & 2 deletions dot/state/block_finalisation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"testing"

"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/trie"
"github.com/golang/mock/gomock"

"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -61,7 +64,16 @@ func TestHighestRoundAndSetID(t *testing.T) {
}

func TestBlockState_SetFinalisedHash(t *testing.T) {
bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty())
ctrl := gomock.NewController(t)

triesGauge := NewMockGauge(ctrl)
triesGauge.EXPECT().Set(0.00)
tries := &Tries{
rootToTrie: make(map[common.Hash]*trie.Trie),
triesGauge: triesGauge,
}

bs := newTestBlockState(t, testGenesisHeader, tries)
h, err := bs.GetFinalisedHash(0, 0)
require.NoError(t, err)
require.Equal(t, testGenesisHeader.Hash(), h)
Expand Down Expand Up @@ -97,7 +109,16 @@ func TestBlockState_SetFinalisedHash(t *testing.T) {
}

func TestSetFinalisedHash_setFirstSlotOnFinalisation(t *testing.T) {
bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty())
ctrl := gomock.NewController(t)

triesGauge := NewMockGauge(ctrl)
triesGauge.EXPECT().Set(0.00).Times(2)
tries := &Tries{
rootToTrie: make(map[common.Hash]*trie.Trie),
triesGauge: triesGauge,
}

bs := newTestBlockState(t, testGenesisHeader, tries)
firstSlot := uint64(42069)

digest := types.NewDigest()
Expand Down
34 changes: 27 additions & 7 deletions dot/state/block_notify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ import (
"time"

"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/runtime"
runtimemocks "github.com/ChainSafe/gossamer/lib/runtime/mocks"
"github.com/ChainSafe/gossamer/lib/trie"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
)

var testMessageTimeout = time.Second * 3

func TestImportChannel(t *testing.T) {
bs := newTestBlockState(t, testGenesisHeader, NewTries(trie.NewEmptyTrie()))
bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty())
ch := bs.GetImportedBlockNotifierChannel()

defer bs.FreeImportedBlockNotifierChannel(ch)
Expand All @@ -36,7 +38,7 @@ func TestImportChannel(t *testing.T) {
}

func TestFreeImportedBlockNotifierChannel(t *testing.T) {
bs := newTestBlockState(t, testGenesisHeader, NewTries(trie.NewEmptyTrie()))
bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty())
ch := bs.GetImportedBlockNotifierChannel()
require.Equal(t, 1, len(bs.imported))

Expand All @@ -45,7 +47,16 @@ func TestFreeImportedBlockNotifierChannel(t *testing.T) {
}

func TestFinalizedChannel(t *testing.T) {
bs := newTestBlockState(t, testGenesisHeader, NewTries(trie.NewEmptyTrie()))
ctrl := gomock.NewController(t)

triesGauge := NewMockGauge(ctrl)
triesGauge.EXPECT().Set(0.00).Times(3)
tries := &Tries{
rootToTrie: make(map[common.Hash]*trie.Trie),
triesGauge: triesGauge,
}

bs := newTestBlockState(t, testGenesisHeader, tries)

ch := bs.GetFinalisedNotifierChannel()

Expand All @@ -67,7 +78,7 @@ func TestFinalizedChannel(t *testing.T) {
}

func TestImportChannel_Multi(t *testing.T) {
bs := newTestBlockState(t, testGenesisHeader, NewTries(trie.NewEmptyTrie()))
bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty())

num := 5
chs := make([]chan *types.Block, num)
Expand Down Expand Up @@ -100,7 +111,16 @@ func TestImportChannel_Multi(t *testing.T) {
}

func TestFinalizedChannel_Multi(t *testing.T) {
bs := newTestBlockState(t, testGenesisHeader, NewTries(trie.NewEmptyTrie()))
ctrl := gomock.NewController(t)

triesGauge := NewMockGauge(ctrl)
triesGauge.EXPECT().Set(0.00)
tries := &Tries{
rootToTrie: make(map[common.Hash]*trie.Trie),
triesGauge: triesGauge,
}

bs := newTestBlockState(t, testGenesisHeader, tries)

num := 5
chs := make([]chan *types.FinalisationInfo, num)
Expand Down Expand Up @@ -137,7 +157,7 @@ func TestFinalizedChannel_Multi(t *testing.T) {
}

func TestService_RegisterUnRegisterRuntimeUpdatedChannel(t *testing.T) {
bs := newTestBlockState(t, testGenesisHeader, NewTries(trie.NewEmptyTrie()))
bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty())
ch := make(chan<- runtime.Version)
chID, err := bs.RegisterRuntimeUpdatedChannel(ch)
require.NoError(t, err)
Expand All @@ -148,7 +168,7 @@ func TestService_RegisterUnRegisterRuntimeUpdatedChannel(t *testing.T) {
}

func TestService_RegisterUnRegisterConcurrentCalls(t *testing.T) {
bs := newTestBlockState(t, testGenesisHeader, NewTries(trie.NewEmptyTrie()))
bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty())

go func() {
for i := 0; i < 100; i++ {
Expand Down
2 changes: 1 addition & 1 deletion dot/state/block_race_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestConcurrencySetHeader(t *testing.T) {
dbs[i] = NewInMemoryDB(t)
}

tries := NewTries(trie.NewEmptyTrie()) // not used in this test
tries := (*Tries)(nil) // not used in this test

pend := new(sync.WaitGroup)
pend.Add(threads)
Expand Down
22 changes: 20 additions & 2 deletions dot/state/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,16 @@ func TestAddBlock_BlockNumberToHash(t *testing.T) {
}

func TestFinalization_DeleteBlock(t *testing.T) {
bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty())
ctrl := gomock.NewController(t)

triesGauge := NewMockGauge(ctrl)
triesGauge.EXPECT().Set(0.00).Times(5)
tries := &Tries{
rootToTrie: make(map[common.Hash]*trie.Trie),
triesGauge: triesGauge,
}

bs := newTestBlockState(t, testGenesisHeader, tries)
AddBlocksToState(t, bs, 5, false)

btBefore := bs.bt.DeepCopy()
Expand Down Expand Up @@ -473,7 +482,16 @@ func TestAddBlockToBlockTree(t *testing.T) {
}

func TestNumberIsFinalised(t *testing.T) {
bs := newTestBlockState(t, testGenesisHeader, newTriesEmpty())
ctrl := gomock.NewController(t)

triesGauge := NewMockGauge(ctrl)
triesGauge.EXPECT().Set(0.00).Times(2)
tries := &Tries{
rootToTrie: make(map[common.Hash]*trie.Trie),
triesGauge: triesGauge,
}

bs := newTestBlockState(t, testGenesisHeader, tries)
fin, err := bs.NumberIsFinalised(big.NewInt(0))
require.NoError(t, err)
require.True(t, fin)
Expand Down
5 changes: 2 additions & 3 deletions dot/state/epoch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/crypto/sr25519"
"github.com/ChainSafe/gossamer/lib/keystore"
"github.com/ChainSafe/gossamer/lib/trie"
"github.com/ChainSafe/gossamer/pkg/scale"

"github.com/stretchr/testify/require"
Expand All @@ -29,7 +28,7 @@ var genesisBABEConfig = &types.BabeConfiguration{

func newEpochStateFromGenesis(t *testing.T) *EpochState {
db := NewInMemoryDB(t)
blockState := newTestBlockState(t, nil, NewTries(trie.NewEmptyTrie()))
blockState := newTestBlockState(t, nil, newTriesEmpty())
s, err := NewEpochStateFromGenesis(db, blockState, genesisBABEConfig)
require.NoError(t, err)
return s
Expand Down Expand Up @@ -186,7 +185,7 @@ func TestEpochState_SetAndGetSlotDuration(t *testing.T) {

func TestEpochState_GetEpochFromTime(t *testing.T) {
s := newEpochStateFromGenesis(t)
s.blockState = newTestBlockState(t, testGenesisHeader, NewTries(trie.NewEmptyTrie()))
s.blockState = newTestBlockState(t, testGenesisHeader, newTriesEmpty())

epochDuration, err := time.ParseDuration(
fmt.Sprintf("%dms",
Expand Down
5 changes: 4 additions & 1 deletion dot/state/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ func (s *Service) Initialise(gen *genesis.Genesis, header *types.Header, t *trie
return fmt.Errorf("failed to write genesis values to database: %s", err)
}

tries := NewTries(t)
tries, err := NewTries(t)
if err != nil {
return fmt.Errorf("cannot setup tries: %w", err)
}

// create block state from genesis block
blockState, err := NewBlockStateFromGenesis(db, tries, header, s.Telemetry)
Expand Down
160 changes: 160 additions & 0 deletions dot/state/mock_gauge_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading