Skip to content

Commit

Permalink
Merge branch 'feature/bump-version-to-1.5.0' of https://github.com/ni…
Browse files Browse the repository at this point in the history
…uxiaojie89/PlatON-Go into feature/bump-version-to-1.5.0
  • Loading branch information
niuxiaojie81 committed Mar 12, 2024
2 parents f56eb8f + bdda821 commit 7945b70
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 22 deletions.
24 changes: 12 additions & 12 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ type BlockChain struct {

shouldPreserve func(*types.Block) bool // Function used to determine whether should preserve the given block.

cleaner *Cleaner
//cleaner *Cleaner
}

// NewBlockChain returns a fully initialised block chain using information
Expand Down Expand Up @@ -393,7 +393,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
}

log.Debug("DB config", "DBDisabledGC", bc.cacheConfig.DBDisabledGC, "DBGCInterval", bc.cacheConfig.DBGCInterval, "DBGCTimeout", bc.cacheConfig.DBGCTimeout, "DBGCMpt", bc.cacheConfig.DBGCMpt)
bc.cleaner = NewCleaner(bc, bc.cacheConfig.DBGCInterval, bc.cacheConfig.DBGCTimeout, bc.cacheConfig.DBGCMpt)
//bc.cleaner = NewCleaner(bc, bc.cacheConfig.DBGCInterval, bc.cacheConfig.DBGCTimeout, bc.cacheConfig.DBGCMpt)

// Load any existing snapshot, regenerating it if loading failed
if bc.cacheConfig.SnapshotLimit > 0 {
Expand Down Expand Up @@ -870,7 +870,7 @@ func (bc *BlockChain) Stop() {
close(bc.quit)
bc.StopInsert()

bc.cleaner.Stop()
//bc.cleaner.Stop()

// Now wait for all chain modifications to end and persistent goroutines to exit.
//
Expand Down Expand Up @@ -1191,9 +1191,9 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
// Write downloaded chain data and corresponding receipt chain data
if len(ancientBlocks) > 0 {
// fast同步的时候不会写入回执
//if n, err := writeAncient(ancientBlocks, ancientReceipts); err != nil {
if n, err := writeAncient(ancientBlocks, nil); err != nil {
if err == errInsertionInterrupted {
if n, err := writeAncient(ancientBlocks, ancientReceipts); err != nil {
//if n, err := writeAncient(ancientBlocks, nil); err != nil {
if errors.Is(err, errInsertionInterrupted) {
return 0, nil
}
return n, err
Expand All @@ -1214,9 +1214,9 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
}
if len(liveBlocks) > 0 {
// fast同步的时候不会写入回执
// if n, err := writeLive(liveBlocks, liveReceipts); err != nil {
if n, err := writeLive(liveBlocks, nil); err != nil {
if err == errInsertionInterrupted {
if n, err := writeLive(liveBlocks, liveReceipts); err != nil {
// if n, err := writeLive(liveBlocks, nil); err != nil {
if errors.Is(err, errInsertionInterrupted) {
return 0, nil
}
return n, err
Expand Down Expand Up @@ -1462,9 +1462,9 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.

bc.hc.SetCurrentHeader(block.Header())
// Cleanup storage
if !bc.cacheConfig.DBDisabledGC.IsSet() && bc.cleaner.NeedCleanup() {
bc.cleaner.Cleanup()
}
//if !bc.cacheConfig.DBDisabledGC.IsSet() && bc.cleaner.NeedCleanup() {
// bc.cleaner.Cleanup()
//}

bc.BlockFeed.Send(block)

Expand Down
2 changes: 2 additions & 0 deletions core/snapshotdb/db_cron_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ func (s *snapshotDB) schedule() {
if counter.get() >= 60 || s.current.GetHighest(false).Num.Uint64()-s.current.GetBase(false).Num.Uint64() >= MaxCommitBlock {
//only one compaction can execute
if atomic.CompareAndSwapInt32(&s.snapshotLockC, snapshotUnLock, snapshotLock) {
s.jobWait.Add(1)
if err := s.Compaction(); err != nil {
logger.Error("compaction fail", "err", err)
s.dbError = err
s.corn.Stop()
}
counter.reset()
atomic.StoreInt32(&s.snapshotLockC, snapshotUnLock)
s.jobWait.Done()
return
}
logger.Info("snapshotDB is still Compaction Lock,wait for next schedule")
Expand Down
13 changes: 9 additions & 4 deletions core/snapshotdb/snapshotdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ import (
"container/heap"
"errors"
"fmt"
"github.com/PlatONnetwork/PlatON-Go/rlp"
"github.com/syndtr/goleveldb/leveldb/storage"
"golang.org/x/net/context"
"math/big"
"os"
"sort"
"sync"

"github.com/syndtr/goleveldb/leveldb/storage"
"golang.org/x/net/context"

"github.com/PlatONnetwork/PlatON-Go/rlp"

"github.com/PlatONnetwork/PlatON-Go/metrics"

"github.com/syndtr/goleveldb/leveldb/filter"
Expand Down Expand Up @@ -162,7 +164,8 @@ type snapshotDB struct {
walLoopCancel context.CancelFunc
walSync sync.WaitGroup

corn *cron.Cron
corn *cron.Cron
jobWait sync.WaitGroup

closed bool

Expand Down Expand Up @@ -1038,6 +1041,8 @@ func (s *snapshotDB) Close() error {
s.walLoopCancel()
}

s.jobWait.Wait()

if s.baseDB != nil {
if err := s.baseDB.Close(); err != nil {
return fmt.Errorf("[snapshotdb]close base db fail:%v", err)
Expand Down
2 changes: 1 addition & 1 deletion core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
}

if vmerr != nil {
log.Error("VM returned with error", "blockNumber", st.evm.Context.BlockNumber, "txHash", st.evm.StateDB.TxHash().TerminalString(), "err", vmerr)
log.Info("VM returned with error", "blockNumber", st.evm.Context.BlockNumber, "txHash", st.evm.StateDB.TxHash().TerminalString(), "err", vmerr)
// A possible consensus-error would be if there wasn't
// sufficient balance to make the transfer happen. The first
// balance transfer may never fail.
Expand Down
2 changes: 1 addition & 1 deletion eth/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -1715,7 +1715,7 @@ func (d *Downloader) commitFastSyncData(results []*fetchResult, stateSync *state
func (d *Downloader) commitPivotBlock(result *fetchResult) error {
block := types.NewBlockWithHeader(result.Header).WithBody(result.Transactions, result.ExtraData)
//TODO: 临时改为Error级,方便升级时判断fast同步信息
log.Debug("Committing fast sync pivot as new head", "number", block.Number(), "hash", block.Hash())
log.Error("Committing fast sync pivot as new head", "number", block.Number(), "hash", block.Hash())

// Commit the pivot block as the new head, will require full sync from here on
if _, err := d.blockchain.InsertReceiptChain([]*types.Block{block}, []types.Receipts{result.Receipts}, d.ancientLimit); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions eth/downloader/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func newFetchResult(header *types.Header, fastSync bool) *fetchResult {
// item.pending |= (1 << bodyType)
//}
if fastSync && !header.EmptyReceipts() {
//item.pending |= (1 << receiptType) // The receipt is not synchronized in PlatON SnapSync mode, so comment here
item.pending |= (1 << receiptType) // The receipt is not synchronized in PlatON SnapSync mode, so comment here
}
return item
}
Expand Down Expand Up @@ -328,8 +328,8 @@ func (q *queue) Schedule(headers []*types.Header, from uint64) []*types.Header {
if _, ok := q.receiptTaskPool[hash]; ok {
log.Warn("Header already scheduled for receipt fetch", "number", header.Number, "hash", hash)
} else {
//q.receiptTaskPool[hash] = header
//q.receiptTaskQueue.Push(header, -int64(header.Number.Uint64()))
q.receiptTaskPool[hash] = header
q.receiptTaskQueue.Push(header, -int64(header.Number.Uint64()))
}
}
inserts = append(inserts, header)
Expand Down
2 changes: 1 addition & 1 deletion eth/protocols/eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func nodeInfo(chain *core.BlockChain, network uint64) *NodeInfo {
func Handle(backend Backend, peer *Peer) error {
for {
if err := handleMessage(backend, peer); err != nil {
peer.Log().Error("Message handling failed in `eth`", "err", err)
peer.Log().Debug("Message handling failed in `eth`", "err", err)
return err
}
}
Expand Down

0 comments on commit 7945b70

Please sign in to comment.