Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
cheng762 committed Sep 7, 2023
1 parent 3a12db2 commit 0284539
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
7 changes: 5 additions & 2 deletions core/snapshotdb/current.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the PlatON-Go library. If not, see <http://www.gnu.org/licenses/>.


package snapshotdb

import (
Expand Down Expand Up @@ -113,7 +112,7 @@ func (c *current) Valid() error {
return nil
}

//the current highest must not greater than block chain current
// the current highest must not greater than block chain current
func (c *current) resetHighestByChainCurrentHeader(currentHead *types.Header, baseDB *leveldb.DB) error {
if c.base.Num.Cmp(currentHead.Number) > 0 {
return fmt.Errorf("base num %v can't be greater than currentHead Number %v", c.base.Num, currentHead.Number)
Expand Down Expand Up @@ -206,6 +205,10 @@ func (c *current) EncodeBase() []byte {
return base
}

func (c *current) String() string {
return fmt.Sprintf("base:%d,hight:%d,%s,", c.base.Num, c.highest.Num, c.highest.Hash)
}

type CurrentHighest struct {
Num *big.Int `rlp:"nil"`
Hash common.Hash
Expand Down
2 changes: 1 addition & 1 deletion core/snapshotdb/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestRecover(t *testing.T) {
return
}
for _, value := range baseDBArr {
v, err := ch.db.baseDB.Get(value.key, nil)
v, err := ch.db.Get(ch.db.current.highest.Hash, value.key)
if err != nil {
t.Error("should be nil", err)
return
Expand Down
12 changes: 6 additions & 6 deletions core/snapshotdb/snapshotdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,11 +593,11 @@ func TestSnapshotDB_Ranking4(t *testing.T) {
itr.Release()
return o
}
v := f(common.ZeroHash, "aaa", 1000)
v := f(ch.db.current.highest.Hash, "aaa", 1000)
if err := v.compareWithkvs(generatekvs); err != nil {
t.Error(err)
}
v2 := f(common.ZeroHash, "aaa", 0)
v2 := f(ch.db.current.highest.Hash, "aaa", 0)
if err := v2.compareWithkvs(generatekvs); err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -755,8 +755,8 @@ func TestSnapshotDB_WalkBaseDB(t *testing.T) {
t.Run("kv should compare", func(t *testing.T) {
var kvGetFromWalk kvs
f := func(num *big.Int, iter iterator.Iterator) error {
if num.Int64() != 2 {
return fmt.Errorf("basenum is wrong:%v,should be 2", num)
if num.Int64() != 1 {
return fmt.Errorf("basenum is wrong:%v,should be 1", num)
}
for iter.Next() {
k, v := make([]byte, len(iter.Key())), make([]byte, len(iter.Value()))
Expand Down Expand Up @@ -858,7 +858,7 @@ func TestSnapshotDB_Compaction_del(t *testing.T) {
}
delkey := baseDBkv[0].key
delVal := baseDBkv[0].value
v, err := ch.db.GetBaseDB(delkey)
v, err := ch.db.Get(ch.db.current.highest.Hash, delkey)
if err != nil {
t.Error(err)
return
Expand All @@ -872,7 +872,7 @@ func TestSnapshotDB_Compaction_del(t *testing.T) {
t.Error(err)
}

_, err = ch.db.GetBaseDB(delkey)
_, err = ch.db.Get(ch.db.current.highest.Hash, delkey)
if err != ErrNotFound {
t.Error(err)
return
Expand Down
10 changes: 5 additions & 5 deletions eth/downloader/downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ func (dlp *downloadTesterPeer) RequestNodeData(hashes []common.Hash) error {
return nil
}

func (dlp *downloadTesterPeer) RequestPPOSStorage() error {
func (dlp *downloadTesterPeer) RequestPPOSStorage(num uint64) error {
dlp.dl.lock.RLock()
defer dlp.dl.lock.RUnlock()
Pivot := dlp.chain.headerm[dlp.chain.chain[dlp.chain.baseNum]]
Expand All @@ -516,14 +516,14 @@ func (dlp *downloadTesterPeer) RequestPPOSStorage() error {
KVNum++
count++
if count >= eth.PPOSStorageKVSizeFetch {
if err := dlp.dl.downloader.DeliverPposStorage(dlp.id, ps, false, KVNum); err != nil {
if err := dlp.dl.downloader.DeliverPposStorage(dlp.id, ps, false, KVNum, nil, 0); err != nil {
logger.Error("[GetPPOSStorageMsg]send ppos meassage fail", "error", err, "kvnum", KVNum)
return err
}
count = 0
ps = make([][2][]byte, 0)
}
if err := dlp.dl.downloader.DeliverPposStorage(dlp.id, ps, true, KVNum); err != nil {
if err := dlp.dl.downloader.DeliverPposStorage(dlp.id, ps, true, KVNum, nil, 0); err != nil {
logger.Error("[GetPPOSStorageMsg]send last ppos meassage fail", "error", err)
return err
}
Expand Down Expand Up @@ -1592,8 +1592,8 @@ func (ftp *floodingTestPeer) RequestNodeData(hashes []common.Hash) error {
return ftp.peer.RequestNodeData(hashes)
}

func (ftp *floodingTestPeer) RequestPPOSStorage() error {
return ftp.peer.RequestPPOSStorage()
func (ftp *floodingTestPeer) RequestPPOSStorage(num uint64) error {
return ftp.peer.RequestPPOSStorage(num)
}

func (ftp *floodingTestPeer) RequestOriginAndPivotByCurrent(d uint64) error {
Expand Down

0 comments on commit 0284539

Please sign in to comment.