Merge pull request #2814 from nspcc-dev/startup-time
Optimize startup time and memory usage
This commit is contained in:
commit
3ef66239a8
26 changed files with 328 additions and 252 deletions
|
@ -146,14 +146,15 @@ func TestBlockchain_StartFromExistingDB(t *testing.T) {
|
|||
|
||||
// Corrupt headers hashes batch.
|
||||
cache := storage.NewMemCachedStore(ps) // Extra wrapper to avoid good DB corruption.
|
||||
key := make([]byte, 5)
|
||||
key[0] = byte(storage.IXHeaderHashList)
|
||||
binary.BigEndian.PutUint32(key[1:], 1)
|
||||
cache.Put(key, []byte{1, 2, 3})
|
||||
// Make the chain think we're at 2000+ which will trigger page 0 read.
|
||||
buf := io.NewBufBinWriter()
|
||||
buf.WriteBytes(util.Uint256{}.BytesLE())
|
||||
buf.WriteU32LE(2000)
|
||||
cache.Put([]byte{byte(storage.SYSCurrentHeader)}, buf.Bytes())
|
||||
|
||||
_, _, _, err := chain.NewMultiWithCustomConfigAndStoreNoCheck(t, customConfig, cache)
|
||||
require.Error(t, err)
|
||||
require.True(t, strings.Contains(err.Error(), "failed to read batch of 2000"), err)
|
||||
require.True(t, strings.Contains(err.Error(), "failed to retrieve header hash page"), err)
|
||||
})
|
||||
t.Run("corrupted current header height", func(t *testing.T) {
|
||||
ps = newPS(t)
|
||||
|
@ -1970,12 +1971,12 @@ func TestBlockchain_ResetState(t *testing.T) {
|
|||
neoH := e.NativeHash(t, nativenames.Neo)
|
||||
gasID := e.NativeID(t, nativenames.Gas)
|
||||
neoID := e.NativeID(t, nativenames.Neo)
|
||||
resetBlockHash := bc.GetHeaderHash(int(resetBlockIndex))
|
||||
resetBlockHash := bc.GetHeaderHash(resetBlockIndex)
|
||||
resetBlockHeader, err := bc.GetHeader(resetBlockHash)
|
||||
require.NoError(t, err)
|
||||
topBlockHeight := bc.BlockHeight()
|
||||
topBH := bc.GetHeaderHash(int(bc.BlockHeight()))
|
||||
staleBH := bc.GetHeaderHash(int(resetBlockIndex + 1))
|
||||
topBH := bc.GetHeaderHash(bc.BlockHeight())
|
||||
staleBH := bc.GetHeaderHash(resetBlockIndex + 1)
|
||||
staleB, err := bc.GetBlock(staleBH)
|
||||
require.NoError(t, err)
|
||||
staleTx := staleB.Transactions[0]
|
||||
|
@ -2043,7 +2044,7 @@ func TestBlockchain_ResetState(t *testing.T) {
|
|||
require.Equal(t, uint32(0), bc.GetStateModule().CurrentValidatedHeight())
|
||||
|
||||
// Try to get the latest block\header.
|
||||
bh := bc.GetHeaderHash(int(resetBlockIndex))
|
||||
bh := bc.GetHeaderHash(resetBlockIndex)
|
||||
require.Equal(t, resetBlockHash, bh)
|
||||
h, err := bc.GetHeader(bh)
|
||||
require.NoError(t, err)
|
||||
|
@ -2054,7 +2055,7 @@ func TestBlockchain_ResetState(t *testing.T) {
|
|||
|
||||
// Check that stale blocks/headers/txs/aers/sr are not reachable.
|
||||
for i := resetBlockIndex + 1; i <= topBlockHeight; i++ {
|
||||
hHash := bc.GetHeaderHash(int(i))
|
||||
hHash := bc.GetHeaderHash(i)
|
||||
require.Equal(t, util.Uint256{}, hHash)
|
||||
_, err = bc.GetStateRoot(i)
|
||||
require.Error(t, err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue