From 607fa3cc903445e68ee70dda2b6722001247e0d1 Mon Sep 17 00:00:00 2001 From: wit liu <765765346@qq.com> Date: Sun, 21 Sep 2025 19:02:21 +0800 Subject: [PATCH] XDCx: remove unused functions and variables (#1530) Co-authored-by: wit --- XDCx/tradingstate/XDCx_trie.go | 1 - XDCx/tradingstate/database.go | 22 +--------------------- XDCx/tradingstate/orderitem.go | 7 ------- XDCxDAO/leveldb.go | 7 ------- XDCxDAO/mongodb.go | 11 ----------- XDCxlending/lendingstate/XDCx_trie.go | 1 - XDCxlending/lendingstate/database.go | 22 +--------------------- 7 files changed, 2 insertions(+), 69 deletions(-) diff --git a/XDCx/tradingstate/XDCx_trie.go b/XDCx/tradingstate/XDCx_trie.go index d965dd3a18..202a9f62cf 100644 --- a/XDCx/tradingstate/XDCx_trie.go +++ b/XDCx/tradingstate/XDCx_trie.go @@ -38,7 +38,6 @@ import ( // XDCXTrie is not safe for concurrent use. type XDCXTrie struct { trie trie.Trie - hashKeyBuf [common.HashLength]byte secKeyCache map[string][]byte secKeyCacheOwner *XDCXTrie // Pointer to self, replace the key cache on mismatch } diff --git a/XDCx/tradingstate/database.go b/XDCx/tradingstate/database.go index 2fe2193243..53e872732e 100644 --- a/XDCx/tradingstate/database.go +++ b/XDCx/tradingstate/database.go @@ -18,7 +18,6 @@ package tradingstate import ( "fmt" - "sync" "github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/ethdb" @@ -28,12 +27,6 @@ import ( // Trie cache generation limit after which to evic trie nodes from memory. 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. type Database interface { // OpenTrie opens the main account trie. @@ -81,9 +74,7 @@ func NewDatabase(db ethdb.Database) Database { } type cachingDB struct { - db *trie.Database - mu sync.Mutex - pastTries []*XDCXTrie + db *trie.Database } // OpenTrie opens the main account trie. @@ -91,17 +82,6 @@ func (db *cachingDB) OpenTrie(root common.Hash) (Trie, error) { 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. func (db *cachingDB) OpenStorageTrie(addrHash, root common.Hash) (Trie, error) { return NewXDCXTrie(root, db.db) diff --git a/XDCx/tradingstate/orderitem.go b/XDCx/tradingstate/orderitem.go index fb3c749db4..8f7633d9a6 100644 --- a/XDCx/tradingstate/orderitem.go +++ b/XDCx/tradingstate/orderitem.go @@ -279,13 +279,6 @@ func (o *OrderItem) verifyOrderSide() error { 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 func (o *OrderItem) verifyPrice() error { if o.Price == nil || o.Price.Sign() <= 0 { diff --git a/XDCxDAO/leveldb.go b/XDCxDAO/leveldb.go index d46f24d080..780202381d 100644 --- a/XDCxDAO/leveldb.go +++ b/XDCxDAO/leveldb.go @@ -2,9 +2,7 @@ package XDCxDAO import ( "bytes" - "encoding/hex" "errors" - "sync" "github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/core/rawdb" @@ -19,7 +17,6 @@ type BatchItem struct { type BatchDatabase struct { db ethdb.Database emptyKey []byte - lock sync.RWMutex cacheLimit int Debug bool } @@ -55,10 +52,6 @@ func (db *BatchDatabase) IsEmptyKey(key []byte) bool { 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) { // for mongodb only return false, nil diff --git a/XDCxDAO/mongodb.go b/XDCxDAO/mongodb.go index 59cfb8c217..f1b9da4554 100644 --- a/XDCxDAO/mongodb.go +++ b/XDCxDAO/mongodb.go @@ -886,19 +886,8 @@ func (db *MongoDatabase) NewBatchWithSize(size int) ethdb.Batch { return nil } -type keyvalue struct { - key []byte - value []byte -} type Batch struct { - db *MongoDatabase collection string - b []keyvalue - size int -} - -func (b *Batch) SetCollection(collection string) { - // for levelDB only } func (b *Batch) Put(key, value []byte) error { diff --git a/XDCxlending/lendingstate/XDCx_trie.go b/XDCxlending/lendingstate/XDCx_trie.go index 4c2a2def4b..4c0bd56674 100644 --- a/XDCxlending/lendingstate/XDCx_trie.go +++ b/XDCxlending/lendingstate/XDCx_trie.go @@ -38,7 +38,6 @@ import ( // XDCXTrie is not safe for concurrent use. type XDCXTrie struct { trie trie.Trie - hashKeyBuf [common.HashLength]byte secKeyCache map[string][]byte secKeyCacheOwner *XDCXTrie // Pointer to self, replace the key cache on mismatch } diff --git a/XDCxlending/lendingstate/database.go b/XDCxlending/lendingstate/database.go index 7c4934bc7f..5f63ddf992 100644 --- a/XDCxlending/lendingstate/database.go +++ b/XDCxlending/lendingstate/database.go @@ -18,7 +18,6 @@ package lendingstate import ( "fmt" - "sync" "github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/ethdb" @@ -28,12 +27,6 @@ import ( // Trie cache generation limit after which to evic trie nodes from memory. 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. type Database interface { // OpenTrie opens the main account trie. @@ -81,9 +74,7 @@ func NewDatabase(db ethdb.Database) Database { } type cachingDB struct { - db *trie.Database - mu sync.Mutex - pastTries []*XDCXTrie + db *trie.Database } // OpenTrie opens the main account trie. @@ -91,17 +82,6 @@ func (db *cachingDB) OpenTrie(root common.Hash) (Trie, error) { 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. func (db *cachingDB) OpenStorageTrie(addrHash, root common.Hash) (Trie, error) { return NewXDCXTrie(root, db.db)