erigon-pulse/migrations/dupsort_state_test.go

128 lines
3.8 KiB
Go
Raw Normal View History

2020-08-12 02:57:55 +00:00
package migrations
import (
"context"
"fmt"
"testing"
"github.com/ledgerwatch/turbo-geth/common"
"github.com/ledgerwatch/turbo-geth/common/dbutils"
"github.com/ledgerwatch/turbo-geth/ethdb"
"github.com/stretchr/testify/require"
)
func TestDupSortHashState(t *testing.T) {
2020-08-12 02:57:55 +00:00
require, db := require.New(t), ethdb.NewMemDatabase()
err := db.KV().Update(context.Background(), func(tx ethdb.Tx) error {
return tx.(ethdb.BucketMigrator).CreateBucket(dbutils.CurrentStateBucketOld1)
2020-08-12 02:57:55 +00:00
})
require.NoError(err)
accKey := string(common.FromHex(fmt.Sprintf("%064x", 0)))
inc := string(common.FromHex("0000000000000001"))
storageKey := accKey + inc + accKey
err = db.Put(dbutils.CurrentStateBucketOld1, []byte(accKey), []byte{1})
require.NoError(err)
err = db.Put(dbutils.CurrentStateBucketOld1, []byte(storageKey), []byte{2})
require.NoError(err)
migrator := NewMigrator()
migrator.Migrations = []Migration{dupSortHashState}
2020-08-12 02:57:55 +00:00
err = migrator.Apply(db, "")
require.NoError(err)
// test high-level data access didn't change
i := 0
err = db.Walk(dbutils.CurrentStateBucket, nil, 0, func(k, v []byte) (bool, error) {
i++
return true, nil
})
require.NoError(err)
require.Equal(2, i)
v, err := db.Get(dbutils.CurrentStateBucket, []byte(accKey))
require.NoError(err)
require.Equal([]byte{1}, v)
v, err = db.Get(dbutils.CurrentStateBucket, []byte(storageKey))
require.NoError(err)
require.Equal([]byte{2}, v)
bitmap indices for logs (#1124) * save progress * try now * don't create bloom inside rlpDecode * don't create bloom inside ApplyTransaction * clean * clean * clean * clean * clean * clean * clean * clean * rename method * print timings * print timings * print timings * sort before flush * fix err lint * clean * move tests to transactions * compressed version * up bound * up bound * more tests * more tests * more tests * more tests * better removal * clean * better performance of get/put methods * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * optimize rpcdaemon * fix test * fix rpcdaemon * fix test * simplify * simplify * fix nil pointer * clean * revert some changes * add some logs * clean * try without optimize * clean * clean * clean * clean * try * move log_index to own stage * move log_index to own stage * integration add log_index stage * integration add log_index stage * clean * clean * print timing * remove duplicates at unwind * extract truncateBitmaps func * try detect * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * add blackList of topics * clean * clean * clean * clean * clean * clean * clean * clean * sharding 1 * sharded 2 * sharded 2 * sharded 2 * sharded 2 * sharded 2 * sharded 2 * sharded 2 * sharded 2 * sharded 2 * sharded 2 * sharded 2 * sharded 2 * sharded 2 * sharded 2 * sharded 2 * sharded 2 * sharded 3 * sharded 3 * sharded 3 * speedup things by putCurrent and putReserve * clean * optimize trim * clean * remove blacklist * add more info to err * ? * clean * clean * clean * clean * clean * working version * switch to cgo version of roaring bitmaps * clean * clean * clean * clean * more docs * clean * clean * fix logs bloom field * Fix debug_getModifiedAccountsByNumber * Try to fix crash * fix problem with "absent block" * fix problem with "absent block" * remove optimize method call * remove roaring iterator * fix problem with rebuild indicess * remove debug prints * tests for eth_getLogs involving topics * add tests for new stage, speparate topics into 2 buckets * version up * remove debug logs * remove debug logs * remove bloom filter implementation * Optimisation * Optimisatin not required, make rpctest lenient to geth errors * Lenient to geth failures Co-authored-by: Alexey Akhunov <akhounov@gmail.com>
2020-09-28 17:18:36 +00:00
tx, err := db.Begin(context.Background())
2020-08-12 02:57:55 +00:00
require.NoError(err)
2020-09-08 19:39:43 +00:00
defer tx.Rollback()
c := tx.(ethdb.HasTx).Tx().CursorDupSort(dbutils.CurrentStateBucket)
// test low-level data layout
2020-08-12 02:57:55 +00:00
require.NoError(err)
2020-09-08 19:39:43 +00:00
v, err = c.SeekExact([]byte(accKey))
2020-08-12 02:57:55 +00:00
require.NoError(err)
require.Equal([]byte{1}, v)
keyLen := common.HashLength + common.IncarnationLength
2020-09-08 19:39:43 +00:00
k, v, err := c.SeekBothRange([]byte(storageKey)[:keyLen], []byte(storageKey)[keyLen:])
2020-08-12 02:57:55 +00:00
require.NoError(err)
require.Equal([]byte(storageKey)[:keyLen], k)
require.Equal([]byte(storageKey)[keyLen:], v[:common.HashLength])
require.Equal([]byte{2}, v[common.HashLength:])
}
func TestDupSortPlainState(t *testing.T) {
require, db := require.New(t), ethdb.NewMemDatabase()
err := db.KV().Update(context.Background(), func(tx ethdb.Tx) error {
return tx.(ethdb.BucketMigrator).CreateBucket(dbutils.PlainStateBucketOld1)
})
require.NoError(err)
accKey := string(common.FromHex(fmt.Sprintf("%040x", 0)))
inc := string(common.FromHex("0000000000000001"))
storageKey := accKey + inc + string(common.FromHex(fmt.Sprintf("%064x", 0)))
err = db.Put(dbutils.PlainStateBucketOld1, []byte(accKey), []byte{1})
require.NoError(err)
err = db.Put(dbutils.PlainStateBucketOld1, []byte(storageKey), []byte{2})
require.NoError(err)
migrator := NewMigrator()
migrator.Migrations = []Migration{dupSortPlainState}
err = migrator.Apply(db, "")
require.NoError(err)
// test high-level data access didn't change
i := 0
err = db.Walk(dbutils.PlainStateBucket, nil, 0, func(k, v []byte) (bool, error) {
i++
return true, nil
})
require.NoError(err)
require.Equal(2, i)
v, err := db.Get(dbutils.PlainStateBucket, []byte(accKey))
require.NoError(err)
require.Equal([]byte{1}, v)
v, err = db.Get(dbutils.PlainStateBucket, []byte(storageKey))
require.NoError(err)
require.Equal([]byte{2}, v)
bitmap indices for logs (#1124) * save progress * try now * don't create bloom inside rlpDecode * don't create bloom inside ApplyTransaction * clean * clean * clean * clean * clean * clean * clean * clean * rename method * print timings * print timings * print timings * sort before flush * fix err lint * clean * move tests to transactions * compressed version * up bound * up bound * more tests * more tests * more tests * more tests * better removal * clean * better performance of get/put methods * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * optimize rpcdaemon * fix test * fix rpcdaemon * fix test * simplify * simplify * fix nil pointer * clean * revert some changes * add some logs * clean * try without optimize * clean * clean * clean * clean * try * move log_index to own stage * move log_index to own stage * integration add log_index stage * integration add log_index stage * clean * clean * print timing * remove duplicates at unwind * extract truncateBitmaps func * try detect * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * add blackList of topics * clean * clean * clean * clean * clean * clean * clean * clean * sharding 1 * sharded 2 * sharded 2 * sharded 2 * sharded 2 * sharded 2 * sharded 2 * sharded 2 * sharded 2 * sharded 2 * sharded 2 * sharded 2 * sharded 2 * sharded 2 * sharded 2 * sharded 2 * sharded 2 * sharded 3 * sharded 3 * sharded 3 * speedup things by putCurrent and putReserve * clean * optimize trim * clean * remove blacklist * add more info to err * ? * clean * clean * clean * clean * clean * working version * switch to cgo version of roaring bitmaps * clean * clean * clean * clean * more docs * clean * clean * fix logs bloom field * Fix debug_getModifiedAccountsByNumber * Try to fix crash * fix problem with "absent block" * fix problem with "absent block" * remove optimize method call * remove roaring iterator * fix problem with rebuild indicess * remove debug prints * tests for eth_getLogs involving topics * add tests for new stage, speparate topics into 2 buckets * version up * remove debug logs * remove debug logs * remove bloom filter implementation * Optimisation * Optimisatin not required, make rpctest lenient to geth errors * Lenient to geth failures Co-authored-by: Alexey Akhunov <akhounov@gmail.com>
2020-09-28 17:18:36 +00:00
tx, err := db.Begin(context.Background())
require.NoError(err)
2020-09-08 19:39:43 +00:00
defer tx.Rollback()
2020-09-08 19:39:43 +00:00
c := tx.(ethdb.HasTx).Tx().CursorDupSort(dbutils.PlainStateBucket)
v, err = c.SeekExact([]byte(accKey))
require.NoError(err)
require.Equal([]byte{1}, v)
keyLen := common.AddressLength + common.IncarnationLength
2020-09-08 19:39:43 +00:00
k, v, err := c.SeekBothRange([]byte(storageKey)[:keyLen], []byte(storageKey)[keyLen:])
require.NoError(err)
require.Equal([]byte(storageKey)[:keyLen], k)
require.Equal([]byte(storageKey)[keyLen:], v[:common.HashLength])
require.Equal([]byte{2}, v[common.HashLength:])
}