From f437c590c206c067130938cae3814f3877e29f73 Mon Sep 17 00:00:00 2001 From: Hussam Date: Mon, 13 Jan 2025 16:42:06 -0600 Subject: [PATCH] lots of WIP --- cmd/utils/flags.go | 1 + core/bodydb.go | 8 ++- core/core.go | 7 +- core/headerchain.go | 2 +- core/rawdb/accessors_chain_indexes_test.go | 41 +++-------- core/rawdb/accessors_indexes.go | 45 ++++-------- core/rawdb/db.pb.go | 81 ++++++++-------------- core/rawdb/db.proto | 8 +-- core/rawdb/schema.go | 19 ++--- core/slice.go | 2 +- core/state_processor.go | 31 +++++---- quai/backend.go | 2 +- 12 files changed, 87 insertions(+), 160 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 920a1ff4f4..15b645dd42 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1385,6 +1385,7 @@ func SetQuaiConfig(stack *node.Node, cfg *quaiconfig.Config, slicesRunning []com } if viper.IsSet(TxLookupLimitFlag.Name) { cfg.TxLookupLimit = viper.GetUint64(TxLookupLimitFlag.Name) + log.Global.WithField("lookuplimit", cfg.TxLookupLimit).Print("Txlookup limit defaults") } if viper.IsSet(CacheFlag.Name) || viper.IsSet(CacheTrieFlag.Name) { cfg.TrieCleanCache = viper.GetInt(CacheFlag.Name) * viper.GetInt(CacheTrieFlag.Name) / 100 diff --git a/core/bodydb.go b/core/bodydb.go index 305969d9b7..08e9698ced 100644 --- a/core/bodydb.go +++ b/core/bodydb.go @@ -47,7 +47,7 @@ type BodyDb struct { logger *log.Logger } -func NewBodyDb(db ethdb.Database, engine consensus.Engine, hc *HeaderChain, chainConfig *params.ChainConfig, cacheConfig *CacheConfig, txLookupLimit *uint64, vmConfig vm.Config, slicesRunning []common.Location) (*BodyDb, error) { +func NewBodyDb(db ethdb.Database, engine consensus.Engine, hc *HeaderChain, chainConfig *params.ChainConfig, cacheConfig *CacheConfig, txLookupLimit uint64, vmConfig vm.Config, slicesRunning []common.Location) (*BodyDb, error) { nodeCtx := chainConfig.Location.Context() bc := &BodyDb{ @@ -69,7 +69,11 @@ func NewBodyDb(db ethdb.Database, engine consensus.Engine, hc *HeaderChain, chai // only start the state processor in zone if nodeCtx == common.ZONE_CTX && bc.ProcessingState() { - bc.processor = NewStateProcessor(chainConfig, hc, engine, vmConfig, cacheConfig, txLookupLimit) + processor, err := NewStateProcessor(chainConfig, hc, engine, vmConfig, cacheConfig, txLookupLimit) + if err != nil { + return nil, err + } + bc.processor = processor vm.InitializePrecompiles(chainConfig.Location) } diff --git a/core/core.go b/core/core.go index c491bfa198..5f2910a9f8 100644 --- a/core/core.go +++ b/core/core.go @@ -81,7 +81,7 @@ type Core struct { logger *log.Logger } -func NewCore(db ethdb.Database, config *Config, isLocalBlock func(block *types.WorkObject) bool, txConfig *TxPoolConfig, txLookupLimit *uint64, chainConfig *params.ChainConfig, slicesRunning []common.Location, currentExpansionNumber uint8, genesisBlock *types.WorkObject, engine consensus.Engine, cacheConfig *CacheConfig, vmConfig vm.Config, genesis *Genesis, logger *log.Logger) (*Core, error) { +func NewCore(db ethdb.Database, config *Config, isLocalBlock func(block *types.WorkObject) bool, txConfig *TxPoolConfig, txLookupLimit uint64, chainConfig *params.ChainConfig, slicesRunning []common.Location, currentExpansionNumber uint8, genesisBlock *types.WorkObject, engine consensus.Engine, cacheConfig *CacheConfig, vmConfig vm.Config, genesis *Genesis, logger *log.Logger) (*Core, error) { slice, err := NewSlice(db, config, txConfig, txLookupLimit, isLocalBlock, chainConfig, slicesRunning, currentExpansionNumber, genesisBlock, engine, cacheConfig, vmConfig, genesis, logger) if err != nil { return nil, err @@ -1104,7 +1104,8 @@ func (c *Core) Snapshots() *snapshot.Tree { } func (c *Core) TxLookupLimit() uint64 { - return c.Processor().txLookupLimit + // return c.Processor().txLookupLimit + return 0 } func (c *Core) SetExtra(extra []byte) error { @@ -1217,7 +1218,7 @@ func (c *Core) GetVMConfig() *vm.Config { // GetTransactionLookup retrieves the lookup associate with the given transaction // hash from the cache or database. -func (c *Core) GetTransactionLookup(hash common.Hash) *rawdb.LegacyTxLookupEntry { +func (c *Core) GetTransactionLookup(hash common.Hash) *rawdb.TxLookupEntry { return c.sl.hc.bc.processor.GetTransactionLookup(hash) } diff --git a/core/headerchain.go b/core/headerchain.go index b7babeaf6f..6d17e65d6b 100644 --- a/core/headerchain.go +++ b/core/headerchain.go @@ -103,7 +103,7 @@ type HeaderChain struct { // NewHeaderChain creates a new HeaderChain structure. ProcInterrupt points // to the parent's interrupt semaphore. -func NewHeaderChain(db ethdb.Database, engine consensus.Engine, pEtxsRollupFetcher getPendingEtxsRollup, pEtxsFetcher getPendingEtxs, primeBlockFetcher getPrimeBlock, kQuaiAndUpdateBitGetter getKQuaiAndUpdateBit, chainConfig *params.ChainConfig, cacheConfig *CacheConfig, txLookupLimit *uint64, vmConfig vm.Config, slicesRunning []common.Location, currentExpansionNumber uint8, logger *log.Logger) (*HeaderChain, error) { +func NewHeaderChain(db ethdb.Database, engine consensus.Engine, pEtxsRollupFetcher getPendingEtxsRollup, pEtxsFetcher getPendingEtxs, primeBlockFetcher getPrimeBlock, kQuaiAndUpdateBitGetter getKQuaiAndUpdateBit, chainConfig *params.ChainConfig, cacheConfig *CacheConfig, txLookupLimit uint64, vmConfig vm.Config, slicesRunning []common.Location, currentExpansionNumber uint8, logger *log.Logger) (*HeaderChain, error) { nodeCtx := chainConfig.Location.Context() diff --git a/core/rawdb/accessors_chain_indexes_test.go b/core/rawdb/accessors_chain_indexes_test.go index 229cfdd829..3f2d2b4693 100644 --- a/core/rawdb/accessors_chain_indexes_test.go +++ b/core/rawdb/accessors_chain_indexes_test.go @@ -9,17 +9,16 @@ import ( "github.com/dominant-strategies/go-quai/ethdb" "github.com/dominant-strategies/go-quai/log" "github.com/stretchr/testify/require" - "google.golang.org/protobuf/proto" ) func TestTxLookupStorage(t *testing.T) { db := NewMemoryDatabase(log.Global) - if entry := ReadTxLookupEntry(db, common.Hash{1}); entry != nil { + if entry, err := ReadTxLookupEntry(db, common.Hash{1}); err == nil { t.Fatalf("Non existent tx lookup returned: %v", entry) } - if entry := ReadTxLookupEntry(db, common.Hash{2}); entry != nil { + if entry, err := ReadTxLookupEntry(db, common.Hash{2}); err == nil { t.Fatalf("Non existent tx lookup returned: %v", entry) } @@ -34,58 +33,34 @@ func TestTxLookupStorage(t *testing.T) { WriteTxLookupEntriesByBlock(db, block, common.ZONE_CTX) - if entry := ReadTxLookupEntry(db, common.Hash{1}); *entry != 1 { + if entry, _ := ReadTxLookupEntry(db, common.Hash{1}); entry != 1 { t.Fatal("Wrong tx lookup returned for hash 1") } - if entry := ReadTxLookupEntry(db, common.Hash{2}); *entry != 1 { + if entry, _ := ReadTxLookupEntry(db, common.Hash{2}); entry != 1 { t.Fatal("Wrong tx lookup returned for hash 2") } DeleteTxLookupEntries(db, hashes) // check deleted tx lookups - if entry := ReadTxLookupEntry(db, common.Hash{1}); entry != nil { + if _, err := ReadTxLookupEntry(db, common.Hash{1}); err == nil { t.Fatal("Deleted lookup returned for hash 1") } - if entry := ReadTxLookupEntry(db, common.Hash{2}); entry != nil { + if _, err := ReadTxLookupEntry(db, common.Hash{2}); err == nil { t.Fatal("Deleted lookup returned for hash 2") } // txs writen by block - if entry := ReadTxLookupEntry(db, tx1.Hash()); *entry != block.NumberU64(common.ZONE_CTX) { + if entry, _ := ReadTxLookupEntry(db, tx1.Hash()); entry != block.NumberU64(common.ZONE_CTX) { t.Fatal("Wrong tx lookup returned for tx1 hash") } - if entry := ReadTxLookupEntry(db, tx2.Hash()); *entry != block.NumberU64(common.ZONE_CTX) { + if entry, _ := ReadTxLookupEntry(db, tx2.Hash()); entry != block.NumberU64(common.ZONE_CTX) { t.Fatal("Wrong tx lookup returned for tx2 hash") } - //v4-v5 tx lookup - v4Hash := common.Hash{4} - v4Number := uint64(3) - WriteHeaderNumber(db, v4Hash, v4Number) - writeTxLookupEntry(db, v4Hash, v4Hash.Bytes()) - - if entry := ReadTxLookupEntry(db, v4Hash); *entry != v4Number { - t.Fatal("Wrong tx lookup returned for v4 hash") - } - - //v3 tx lookup - v3Hash := common.Hash{5} - v3ProtoHash := &common.ProtoHash{Value: v3Hash.Bytes()} - v3Number := uint64(4) - v3entry, err := proto.Marshal(&ProtoLegacyTxLookupEntry{BlockIndex: v3Number, Hash: v3ProtoHash}) - if err != nil { - t.Fatalf("Failed to marshal ProtoLegacyTxLookupEntry, err %s", err) - } - writeTxLookupEntry(db, v3Hash, v3entry) - - if entry := ReadTxLookupEntry(db, v3Hash); *entry != v3Number { - t.Fatal("Wrong tx lookup returned for v4 hash") - } - } func TestReadTransaction(t *testing.T) { diff --git a/core/rawdb/accessors_indexes.go b/core/rawdb/accessors_indexes.go index 1eb319eaa5..0c5551c29a 100644 --- a/core/rawdb/accessors_indexes.go +++ b/core/rawdb/accessors_indexes.go @@ -18,45 +18,24 @@ package rawdb import ( "bytes" + "errors" "math/big" "github.com/dominant-strategies/go-quai/common" "github.com/dominant-strategies/go-quai/core/types" "github.com/dominant-strategies/go-quai/ethdb" "github.com/dominant-strategies/go-quai/log" - "google.golang.org/protobuf/proto" ) // ReadTxLookupEntry retrieves the positional metadata associated with a transaction // hash to allow retrieving the transaction or receipt by hash. -func ReadTxLookupEntry(db ethdb.Reader, hash common.Hash) *uint64 { - data, _ := db.Get(txLookupKey(hash)) - if len(data) == 0 { - return nil - } - // Database v6 tx lookup just stores the block number - if len(data) < common.HashLength { - number := new(big.Int).SetBytes(data).Uint64() - return &number - } - // Database v4-v5 tx lookup format just stores the hash - if len(data) == common.HashLength { - return ReadHeaderNumber(db, common.BytesToHash(data)) - } - // Finally try database v3 tx lookup format - protoLegacyTxLookupEntry := new(ProtoLegacyTxLookupEntry) - err := proto.Unmarshal(data, protoLegacyTxLookupEntry) +func ReadTxLookupEntry(db ethdb.Reader, hash common.Hash) (uint64, error) { + data, err := db.Get(txLookupKey(hash)) if err != nil { - db.Logger().WithFields(log.Fields{ - "hash": hash, - "blob": data, - "err": err, - }).Error("Invalid transaction lookup entry protobuf") - return nil + return 0, errors.New("unable to find tx in database") } - entry := new(LegacyTxLookupEntry) - entry.ProtoDecode(protoLegacyTxLookupEntry) - return &entry.BlockIndex + number := new(big.Int).SetBytes(data).Uint64() + return number, nil } // writeTxLookupEntry stores a positional metadata for a transaction, @@ -102,15 +81,15 @@ func DeleteTxLookupEntries(db ethdb.KeyValueWriter, hashes []common.Hash) { // ReadTransaction retrieves a specific transaction from the database, along with // its added positional metadata. func ReadTransaction(db ethdb.Reader, hash common.Hash) (*types.Transaction, common.Hash, uint64, uint64) { - blockNumber := ReadTxLookupEntry(db, hash) - if blockNumber == nil { + blockNumber, err := ReadTxLookupEntry(db, hash) + if err != nil { return nil, common.Hash{}, 0, 0 } - blockHash := ReadCanonicalHash(db, *blockNumber) + blockHash := ReadCanonicalHash(db, blockNumber) if blockHash == (common.Hash{}) { return nil, common.Hash{}, 0, 0 } - wo := ReadWorkObject(db, *blockNumber, blockHash, types.BlockObject) + wo := ReadWorkObject(db, blockNumber, blockHash, types.BlockObject) if wo == nil { db.Logger().WithFields(log.Fields{ "number": blockNumber, @@ -120,11 +99,11 @@ func ReadTransaction(db ethdb.Reader, hash common.Hash) (*types.Transaction, com } for txIndex, tx := range wo.Body().Transactions() { if tx.Hash() == hash { - return tx, blockHash, *blockNumber, uint64(txIndex) + return tx, blockHash, blockNumber, uint64(txIndex) } } db.Logger().WithFields(log.Fields{ - "number": *blockNumber, + "number": blockNumber, "hash": blockHash, "txhash": hash, }).Error("Transaction not found") diff --git a/core/rawdb/db.pb.go b/core/rawdb/db.pb.go index bb2cf95137..20c4e210ca 100644 --- a/core/rawdb/db.pb.go +++ b/core/rawdb/db.pb.go @@ -7,7 +7,6 @@ package rawdb import ( - common "github.com/dominant-strategies/go-quai/common" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" @@ -66,29 +65,27 @@ func (x *ProtoNumber) GetNumber() uint64 { return 0 } -type ProtoLegacyTxLookupEntry struct { +type ProtoTxLookupEntry struct { state protoimpl.MessageState `protogen:"open.v1"` - Hash *common.ProtoHash `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"` - BlockIndex uint64 `protobuf:"varint,2,opt,name=block_index,json=blockIndex,proto3" json:"block_index,omitempty"` - Index uint64 `protobuf:"varint,3,opt,name=index,proto3" json:"index,omitempty"` + BlockIndex uint64 `protobuf:"varint,1,opt,name=block_index,json=blockIndex,proto3" json:"block_index,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } -func (x *ProtoLegacyTxLookupEntry) Reset() { - *x = ProtoLegacyTxLookupEntry{} +func (x *ProtoTxLookupEntry) Reset() { + *x = ProtoTxLookupEntry{} mi := &file_core_rawdb_db_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } -func (x *ProtoLegacyTxLookupEntry) String() string { +func (x *ProtoTxLookupEntry) String() string { return protoimpl.X.MessageStringOf(x) } -func (*ProtoLegacyTxLookupEntry) ProtoMessage() {} +func (*ProtoTxLookupEntry) ProtoMessage() {} -func (x *ProtoLegacyTxLookupEntry) ProtoReflect() protoreflect.Message { +func (x *ProtoTxLookupEntry) ProtoReflect() protoreflect.Message { mi := &file_core_rawdb_db_proto_msgTypes[1] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -100,53 +97,33 @@ func (x *ProtoLegacyTxLookupEntry) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use ProtoLegacyTxLookupEntry.ProtoReflect.Descriptor instead. -func (*ProtoLegacyTxLookupEntry) Descriptor() ([]byte, []int) { +// Deprecated: Use ProtoTxLookupEntry.ProtoReflect.Descriptor instead. +func (*ProtoTxLookupEntry) Descriptor() ([]byte, []int) { return file_core_rawdb_db_proto_rawDescGZIP(), []int{1} } -func (x *ProtoLegacyTxLookupEntry) GetHash() *common.ProtoHash { - if x != nil { - return x.Hash - } - return nil -} - -func (x *ProtoLegacyTxLookupEntry) GetBlockIndex() uint64 { +func (x *ProtoTxLookupEntry) GetBlockIndex() uint64 { if x != nil { return x.BlockIndex } return 0 } -func (x *ProtoLegacyTxLookupEntry) GetIndex() uint64 { - if x != nil { - return x.Index - } - return 0 -} - var File_core_rawdb_db_proto protoreflect.FileDescriptor var file_core_rawdb_db_proto_rawDesc = string([]byte{ 0x0a, 0x13, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x72, 0x61, 0x77, 0x64, 0x62, 0x2f, 0x64, 0x62, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x02, 0x64, 0x62, 0x1a, 0x19, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, - 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x5f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x25, 0x0a, 0x0b, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x4e, 0x75, 0x6d, - 0x62, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x04, 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x78, 0x0a, 0x18, 0x50, - 0x72, 0x6f, 0x74, 0x6f, 0x4c, 0x65, 0x67, 0x61, 0x63, 0x79, 0x54, 0x78, 0x4c, 0x6f, 0x6f, 0x6b, - 0x75, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x25, 0x0a, 0x04, 0x68, 0x61, 0x73, 0x68, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x50, - 0x72, 0x6f, 0x74, 0x6f, 0x48, 0x61, 0x73, 0x68, 0x52, 0x04, 0x68, 0x61, 0x73, 0x68, 0x12, 0x1f, - 0x0a, 0x0b, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x04, 0x52, 0x0a, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x12, - 0x14, 0x0a, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, - 0x69, 0x6e, 0x64, 0x65, 0x78, 0x42, 0x33, 0x5a, 0x31, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, - 0x63, 0x6f, 0x6d, 0x2f, 0x64, 0x6f, 0x6d, 0x69, 0x6e, 0x61, 0x6e, 0x74, 0x2d, 0x73, 0x74, 0x72, - 0x61, 0x74, 0x65, 0x67, 0x69, 0x65, 0x73, 0x2f, 0x67, 0x6f, 0x2d, 0x71, 0x75, 0x61, 0x69, 0x2f, - 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x72, 0x61, 0x77, 0x64, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x02, 0x64, 0x62, 0x22, 0x25, 0x0a, 0x0b, 0x50, 0x72, 0x6f, + 0x74, 0x6f, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, + 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, + 0x22, 0x35, 0x0a, 0x12, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x54, 0x78, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, + 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x1f, 0x0a, 0x0b, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, + 0x69, 0x6e, 0x64, 0x65, 0x78, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0a, 0x62, 0x6c, 0x6f, + 0x63, 0x6b, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x42, 0x33, 0x5a, 0x31, 0x67, 0x69, 0x74, 0x68, 0x75, + 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x64, 0x6f, 0x6d, 0x69, 0x6e, 0x61, 0x6e, 0x74, 0x2d, 0x73, + 0x74, 0x72, 0x61, 0x74, 0x65, 0x67, 0x69, 0x65, 0x73, 0x2f, 0x67, 0x6f, 0x2d, 0x71, 0x75, 0x61, + 0x69, 0x2f, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x72, 0x61, 0x77, 0x64, 0x62, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, }) var ( @@ -163,17 +140,15 @@ func file_core_rawdb_db_proto_rawDescGZIP() []byte { var file_core_rawdb_db_proto_msgTypes = make([]protoimpl.MessageInfo, 2) var file_core_rawdb_db_proto_goTypes = []any{ - (*ProtoNumber)(nil), // 0: db.ProtoNumber - (*ProtoLegacyTxLookupEntry)(nil), // 1: db.ProtoLegacyTxLookupEntry - (*common.ProtoHash)(nil), // 2: common.ProtoHash + (*ProtoNumber)(nil), // 0: db.ProtoNumber + (*ProtoTxLookupEntry)(nil), // 1: db.ProtoTxLookupEntry } var file_core_rawdb_db_proto_depIdxs = []int32{ - 2, // 0: db.ProtoLegacyTxLookupEntry.hash:type_name -> common.ProtoHash - 1, // [1:1] is the sub-list for method output_type - 1, // [1:1] is the sub-list for method input_type - 1, // [1:1] is the sub-list for extension type_name - 1, // [1:1] is the sub-list for extension extendee - 0, // [0:1] is the sub-list for field type_name + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name } func init() { file_core_rawdb_db_proto_init() } diff --git a/core/rawdb/db.proto b/core/rawdb/db.proto index b74c0ca002..4fc0f088d7 100644 --- a/core/rawdb/db.proto +++ b/core/rawdb/db.proto @@ -3,12 +3,8 @@ syntax = "proto3"; package db; option go_package = "github.com/dominant-strategies/go-quai/core/rawdb"; -import "common/proto_common.proto"; - message ProtoNumber { uint64 number = 1; } -message ProtoLegacyTxLookupEntry { - common.ProtoHash hash = 1; - uint64 block_index = 2; - uint64 index = 3; +message ProtoTxLookupEntry { + uint64 block_index = 1; } diff --git a/core/rawdb/schema.go b/core/rawdb/schema.go index 7695a959f3..71481a94c0 100644 --- a/core/rawdb/schema.go +++ b/core/rawdb/schema.go @@ -142,28 +142,21 @@ var FreezerNoSnappy = map[string]bool{ freezerDifficultyTable: true, } -// LegacyTxLookupEntry is the legacy TxLookupEntry definition with some unnecessary -// fields. -type LegacyTxLookupEntry struct { - BlockHash common.Hash +type TxLookupEntry struct { BlockIndex uint64 + BlockHash common.Hash Index uint64 } -func (l LegacyTxLookupEntry) ProtoEncode() (ProtoLegacyTxLookupEntry, error) { - blockHash := l.BlockHash.ProtoEncode() - return ProtoLegacyTxLookupEntry{ - Hash: blockHash, +// Only the block index is encoded to save data (pursuant to database V6) +func (l TxLookupEntry) ProtoEncode() (ProtoTxLookupEntry, error) { + return ProtoTxLookupEntry{ BlockIndex: l.BlockIndex, - Index: l.Index, }, nil } -func (l *LegacyTxLookupEntry) ProtoDecode(data *ProtoLegacyTxLookupEntry) error { - l.BlockHash = common.Hash{} - l.BlockHash.ProtoDecode(data.Hash) +func (l *TxLookupEntry) ProtoDecode(data *ProtoTxLookupEntry) error { l.BlockIndex = data.BlockIndex - l.Index = data.Index return nil } diff --git a/core/slice.go b/core/slice.go index 69317d2ce6..71064e1d82 100644 --- a/core/slice.go +++ b/core/slice.go @@ -104,7 +104,7 @@ type Slice struct { recomputeRequired bool } -func NewSlice(db ethdb.Database, config *Config, txConfig *TxPoolConfig, txLookupLimit *uint64, isLocalBlock func(block *types.WorkObject) bool, chainConfig *params.ChainConfig, slicesRunning []common.Location, currentExpansionNumber uint8, genesisBlock *types.WorkObject, engine consensus.Engine, cacheConfig *CacheConfig, vmConfig vm.Config, genesis *Genesis, logger *log.Logger) (*Slice, error) { +func NewSlice(db ethdb.Database, config *Config, txConfig *TxPoolConfig, txLookupLimit uint64, isLocalBlock func(block *types.WorkObject) bool, chainConfig *params.ChainConfig, slicesRunning []common.Location, currentExpansionNumber uint8, genesisBlock *types.WorkObject, engine consensus.Engine, cacheConfig *CacheConfig, vmConfig vm.Config, genesis *Genesis, logger *log.Logger) (*Slice, error) { nodeCtx := chainConfig.Location.Context() sl := &Slice{ config: chainConfig, diff --git a/core/state_processor.go b/core/state_processor.go index 2d164f12d9..5926d7985b 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -116,16 +116,15 @@ type StateProcessor struct { stateCache state.Database // State database to reuse between imports (contains state cache) etxCache state.Database // ETX database to reuse between imports (contains ETX cache) receiptsCache *lru.Cache[common.Hash, types.Receipts] // Cache for the most recent receipts per block - txLookupCache *lru.Cache[common.Hash, rawdb.LegacyTxLookupEntry] + txLookupCache *lru.Cache[common.Hash, rawdb.TxLookupEntry] validator Validator // Block and state validator interface prefetcher Prefetcher vmConfig vm.Config minFee, maxFee, avgFee, numElements *big.Int - scope event.SubscriptionScope - wg sync.WaitGroup // chain processing wait group for shutting down - quit chan struct{} // state processor quit channel - txLookupLimit uint64 + scope event.SubscriptionScope + wg sync.WaitGroup // chain processing wait group for shutting down + quit chan struct{} // state processor quit channel snaps *snapshot.Tree triegc *prque.Prque // Priority queue mapping block numbers to tries to gc @@ -134,7 +133,7 @@ type StateProcessor struct { } // NewStateProcessor initialises a new StateProcessor. -func NewStateProcessor(config *params.ChainConfig, hc *HeaderChain, engine consensus.Engine, vmConfig vm.Config, cacheConfig *CacheConfig, txLookupLimit *uint64) *StateProcessor { +func NewStateProcessor(config *params.ChainConfig, hc *HeaderChain, engine consensus.Engine, vmConfig vm.Config, cacheConfig *CacheConfig, txLookupLimit uint64) (*StateProcessor, error) { if cacheConfig == nil { cacheConfig = defaultCacheConfig @@ -162,10 +161,16 @@ func NewStateProcessor(config *params.ChainConfig, hc *HeaderChain, engine conse } sp.validator = NewBlockValidator(config, hc, engine) - receiptsCache, _ := lru.New[common.Hash, types.Receipts](receiptsCacheLimit) + receiptsCache, err := lru.New[common.Hash, types.Receipts](receiptsCacheLimit) + if err != nil { + return nil, err + } sp.receiptsCache = receiptsCache - txLookupCache, _ := lru.New[common.Hash, rawdb.LegacyTxLookupEntry](txLookupCacheLimit) + txLookupCache, err := lru.New[common.Hash, rawdb.TxLookupEntry](txLookupCacheLimit) + if err != nil { + return nil, err + } sp.txLookupCache = txLookupCache // Load any existing snapshot, regenerating it if loading failed @@ -174,9 +179,7 @@ func NewStateProcessor(config *params.ChainConfig, hc *HeaderChain, engine conse head := hc.CurrentHeader() sp.snaps, _ = snapshot.New(hc.headerDb, sp.stateCache.TrieDB(), sp.cacheConfig.SnapshotLimit, head.EVMRoot(), true, false, sp.logger) } - if txLookupLimit != nil { - sp.txLookupLimit = *txLookupLimit - } + // sp.txLookupLimit = txLookupLimit // If periodic cache journal is required, spin it up. if sp.cacheConfig.TrieCleanRejournal > 0 { if sp.cacheConfig.TrieCleanRejournal < time.Minute { @@ -203,7 +206,7 @@ func NewStateProcessor(config *params.ChainConfig, hc *HeaderChain, engine conse etxTrieDb.SaveCachePeriodically(sp.cacheConfig.ETXTrieCleanJournal, sp.cacheConfig.TrieCleanRejournal, sp.quit) }() } - return sp + return sp, nil } type UtxosCreatedDeleted struct { @@ -2019,7 +2022,7 @@ func (p *StateProcessor) GetReceiptsByHash(hash common.Hash) types.Receipts { // GetTransactionLookup retrieves the lookup associate with the given transaction // hash from the cache or database. -func (p *StateProcessor) GetTransactionLookup(hash common.Hash) *rawdb.LegacyTxLookupEntry { +func (p *StateProcessor) GetTransactionLookup(hash common.Hash) *rawdb.TxLookupEntry { // Short circuit if the txlookup already in the cache, retrieve otherwise if lookup, exist := p.txLookupCache.Get(hash); exist { return &lookup @@ -2028,7 +2031,7 @@ func (p *StateProcessor) GetTransactionLookup(hash common.Hash) *rawdb.LegacyTxL if tx == nil { return nil } - lookup := &rawdb.LegacyTxLookupEntry{BlockHash: blockHash, BlockIndex: blockNumber, Index: txIndex} + lookup := &rawdb.TxLookupEntry{BlockHash: blockHash, BlockIndex: blockNumber, Index: txIndex} p.txLookupCache.Add(hash, *lookup) return lookup } diff --git a/quai/backend.go b/quai/backend.go index d9b774709a..f21a3f886a 100644 --- a/quai/backend.go +++ b/quai/backend.go @@ -248,7 +248,7 @@ func New(stack *node.Node, p2p NetworkingAPI, config *quaiconfig.Config, nodeCtx config.TxPool.Journal = stack.ResolvePath(config.TxPool.Journal) } - quai.core, err = core.NewCore(chainDb, &config.Miner, quai.isLocalBlock, &config.TxPool, &config.TxLookupLimit, chainConfig, quai.config.SlicesRunning, currentExpansionNumber, genesisBlock, quai.engine, cacheConfig, vmConfig, config.Genesis, logger) + quai.core, err = core.NewCore(chainDb, &config.Miner, quai.isLocalBlock, &config.TxPool, config.TxLookupLimit, chainConfig, quai.config.SlicesRunning, currentExpansionNumber, genesisBlock, quai.engine, cacheConfig, vmConfig, config.Genesis, logger) if err != nil { return nil, err }