XDCx: remove unused functions and variables (#1530)

Co-authored-by: wit <wit765765346@gmail>
This commit is contained in:
wit liu 2025-09-21 19:02:21 +08:00 committed by GitHub
parent a663ea311c
commit 607fa3cc90
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 2 additions and 69 deletions

View file

@ -38,7 +38,6 @@ import (
// XDCXTrie is not safe for concurrent use. // XDCXTrie is not safe for concurrent use.
type XDCXTrie struct { type XDCXTrie struct {
trie trie.Trie trie trie.Trie
hashKeyBuf [common.HashLength]byte
secKeyCache map[string][]byte secKeyCache map[string][]byte
secKeyCacheOwner *XDCXTrie // Pointer to self, replace the key cache on mismatch secKeyCacheOwner *XDCXTrie // Pointer to self, replace the key cache on mismatch
} }

View file

@ -18,7 +18,6 @@ package tradingstate
import ( import (
"fmt" "fmt"
"sync"
"github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/ethdb" "github.com/XinFinOrg/XDPoSChain/ethdb"
@ -28,12 +27,6 @@ import (
// Trie cache generation limit after which to evic trie nodes from memory. // Trie cache generation limit after which to evic trie nodes from memory.
var MaxTrieCacheGen = uint16(120) var MaxTrieCacheGen = uint16(120)
const (
// Number of past tries to keep. This value is chosen such that
// reasonable chain reorg depths will hit an existing trie.
maxPastTries = 12
)
// Database wraps access to tries and contract code. // Database wraps access to tries and contract code.
type Database interface { type Database interface {
// OpenTrie opens the main account trie. // OpenTrie opens the main account trie.
@ -81,9 +74,7 @@ func NewDatabase(db ethdb.Database) Database {
} }
type cachingDB struct { type cachingDB struct {
db *trie.Database db *trie.Database
mu sync.Mutex
pastTries []*XDCXTrie
} }
// OpenTrie opens the main account trie. // OpenTrie opens the main account trie.
@ -91,17 +82,6 @@ func (db *cachingDB) OpenTrie(root common.Hash) (Trie, error) {
return NewXDCXTrie(root, db.db) return NewXDCXTrie(root, db.db)
} }
func (db *cachingDB) pushTrie(t *XDCXTrie) {
db.mu.Lock()
defer db.mu.Unlock()
if len(db.pastTries) >= maxPastTries {
copy(db.pastTries, db.pastTries[1:])
db.pastTries[len(db.pastTries)-1] = t
} else {
db.pastTries = append(db.pastTries, t)
}
}
// OpenStorageTrie opens the storage trie of an account. // OpenStorageTrie opens the storage trie of an account.
func (db *cachingDB) OpenStorageTrie(addrHash, root common.Hash) (Trie, error) { func (db *cachingDB) OpenStorageTrie(addrHash, root common.Hash) (Trie, error) {
return NewXDCXTrie(root, db.db) return NewXDCXTrie(root, db.db)

View file

@ -279,13 +279,6 @@ func (o *OrderItem) verifyOrderSide() error {
return nil return nil
} }
func (o *OrderItem) encodedSide() *big.Int {
if o.Side == Bid {
return big.NewInt(0)
}
return big.NewInt(1)
}
// verifyPrice make sure price is a positive number // verifyPrice make sure price is a positive number
func (o *OrderItem) verifyPrice() error { func (o *OrderItem) verifyPrice() error {
if o.Price == nil || o.Price.Sign() <= 0 { if o.Price == nil || o.Price.Sign() <= 0 {

View file

@ -2,9 +2,7 @@ package XDCxDAO
import ( import (
"bytes" "bytes"
"encoding/hex"
"errors" "errors"
"sync"
"github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/core/rawdb" "github.com/XinFinOrg/XDPoSChain/core/rawdb"
@ -19,7 +17,6 @@ type BatchItem struct {
type BatchDatabase struct { type BatchDatabase struct {
db ethdb.Database db ethdb.Database
emptyKey []byte emptyKey []byte
lock sync.RWMutex
cacheLimit int cacheLimit int
Debug bool Debug bool
} }
@ -55,10 +52,6 @@ func (db *BatchDatabase) IsEmptyKey(key []byte) bool {
return len(key) == 0 || bytes.Equal(key, db.emptyKey) return len(key) == 0 || bytes.Equal(key, db.emptyKey)
} }
func (db *BatchDatabase) getCacheKey(key []byte) string {
return hex.EncodeToString(key)
}
func (db *BatchDatabase) HasObject(hash common.Hash, val interface{}) (bool, error) { func (db *BatchDatabase) HasObject(hash common.Hash, val interface{}) (bool, error) {
// for mongodb only // for mongodb only
return false, nil return false, nil

View file

@ -886,19 +886,8 @@ func (db *MongoDatabase) NewBatchWithSize(size int) ethdb.Batch {
return nil return nil
} }
type keyvalue struct {
key []byte
value []byte
}
type Batch struct { type Batch struct {
db *MongoDatabase
collection string collection string
b []keyvalue
size int
}
func (b *Batch) SetCollection(collection string) {
// for levelDB only
} }
func (b *Batch) Put(key, value []byte) error { func (b *Batch) Put(key, value []byte) error {

View file

@ -38,7 +38,6 @@ import (
// XDCXTrie is not safe for concurrent use. // XDCXTrie is not safe for concurrent use.
type XDCXTrie struct { type XDCXTrie struct {
trie trie.Trie trie trie.Trie
hashKeyBuf [common.HashLength]byte
secKeyCache map[string][]byte secKeyCache map[string][]byte
secKeyCacheOwner *XDCXTrie // Pointer to self, replace the key cache on mismatch secKeyCacheOwner *XDCXTrie // Pointer to self, replace the key cache on mismatch
} }

View file

@ -18,7 +18,6 @@ package lendingstate
import ( import (
"fmt" "fmt"
"sync"
"github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/ethdb" "github.com/XinFinOrg/XDPoSChain/ethdb"
@ -28,12 +27,6 @@ import (
// Trie cache generation limit after which to evic trie nodes from memory. // Trie cache generation limit after which to evic trie nodes from memory.
var MaxTrieCacheGen = uint16(120) var MaxTrieCacheGen = uint16(120)
const (
// Number of past tries to keep. This value is chosen such that
// reasonable chain reorg depths will hit an existing trie.
maxPastTries = 12
)
// Database wraps access to tries and contract code. // Database wraps access to tries and contract code.
type Database interface { type Database interface {
// OpenTrie opens the main account trie. // OpenTrie opens the main account trie.
@ -81,9 +74,7 @@ func NewDatabase(db ethdb.Database) Database {
} }
type cachingDB struct { type cachingDB struct {
db *trie.Database db *trie.Database
mu sync.Mutex
pastTries []*XDCXTrie
} }
// OpenTrie opens the main account trie. // OpenTrie opens the main account trie.
@ -91,17 +82,6 @@ func (db *cachingDB) OpenTrie(root common.Hash) (Trie, error) {
return NewXDCXTrie(root, db.db) return NewXDCXTrie(root, db.db)
} }
func (db *cachingDB) pushTrie(t *XDCXTrie) {
db.mu.Lock()
defer db.mu.Unlock()
if len(db.pastTries) >= maxPastTries {
copy(db.pastTries, db.pastTries[1:])
db.pastTries[len(db.pastTries)-1] = t
} else {
db.pastTries = append(db.pastTries, t)
}
}
// OpenStorageTrie opens the storage trie of an account. // OpenStorageTrie opens the storage trie of an account.
func (db *cachingDB) OpenStorageTrie(addrHash, root common.Hash) (Trie, error) { func (db *cachingDB) OpenStorageTrie(addrHash, root common.Hash) (Trie, error) {
return NewXDCXTrie(root, db.db) return NewXDCXTrie(root, db.db)