Skip to content

Commit

Permalink
cmd/thor: changes due to underlying pkg update
Browse files Browse the repository at this point in the history
  • Loading branch information
qianbin committed Feb 2, 2024
1 parent 904bbec commit 5c9e18a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 43 deletions.
10 changes: 5 additions & 5 deletions cmd/thor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/vechain/thor/v2/api"
"github.com/vechain/thor/v2/bft"
"github.com/vechain/thor/v2/cmd/thor/node"
"github.com/vechain/thor/v2/cmd/thor/optimizer"
"github.com/vechain/thor/v2/cmd/thor/pruner"
"github.com/vechain/thor/v2/cmd/thor/solo"
"github.com/vechain/thor/v2/genesis"
"github.com/vechain/thor/v2/logdb"
Expand Down Expand Up @@ -223,8 +223,8 @@ func defaultAction(ctx *cli.Context) error {
}
defer p2pcom.Stop()

optimizer := optimizer.New(mainDB, repo, !ctx.Bool(disablePrunerFlag.Name))
defer func() { log.Info("stopping optimizer..."); optimizer.Stop() }()
pruner := pruner.New(mainDB, repo, !ctx.Bool(disablePrunerFlag.Name))
defer func() { log.Info("stopping pruner..."); pruner.Stop() }()

return node.New(
master,
Expand Down Expand Up @@ -317,8 +317,8 @@ func soloAction(ctx *cli.Context) error {

printSoloStartupMessage(gene, repo, instanceDir, apiURL, forkConfig)

optimizer := optimizer.New(mainDB, repo, !ctx.Bool(disablePrunerFlag.Name))
defer func() { log.Info("stopping optimizer..."); optimizer.Stop() }()
pruner := pruner.New(mainDB, repo, !ctx.Bool(disablePrunerFlag.Name))
defer func() { log.Info("stopping pruner..."); pruner.Stop() }()

return solo.New(repo,
state.NewStater(mainDB),
Expand Down
21 changes: 9 additions & 12 deletions cmd/thor/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,16 @@ func (n *Node) processBlock(newBlock *block.Block, stats *blockStats) (bool, err
return errors.Wrap(err, "commit state")
}

// sync the log-writing task
if logEnabled {
if err := n.logWorker.Sync(); err != nil {
log.Warn("failed to write logs", "err", err)
n.logDBFailed = true
}
}

// add the new block into repository
if err := n.repo.AddBlock(newBlock, receipts, conflicts); err != nil {
if err := n.repo.AddBlock(newBlock, receipts, conflicts, becomeNewBest); err != nil {
return errors.Wrap(err, "add block")
}

Expand All @@ -375,18 +383,7 @@ func (n *Node) processBlock(newBlock *block.Block, stats *blockStats) (bool, err

realElapsed := mclock.Now() - startTime

// sync the log-writing task
if logEnabled {
if err := n.logWorker.Sync(); err != nil {
log.Warn("failed to write logs", "err", err)
n.logDBFailed = true
}
}

if becomeNewBest {
if err := n.repo.SetBestBlockID(newBlock.Header().ID()); err != nil {
return err
}
n.processFork(newBlock, oldBest.Header.ID())
}

Expand Down
22 changes: 9 additions & 13 deletions cmd/thor/node/packer_loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,16 @@ func (n *Node) pack(flow *packer.Flow) error {
return errors.Wrap(err, "commit state")
}

// sync the log-writing task
if logEnabled {
if err := n.logWorker.Sync(); err != nil {
log.Warn("failed to write logs", "err", err)
n.logDBFailed = true
}
}

// add the new block into repository
if err := n.repo.AddBlock(newBlock, receipts, conflicts); err != nil {
if err := n.repo.AddBlock(newBlock, receipts, conflicts, true); err != nil {
return errors.Wrap(err, "add block")
}

Expand All @@ -176,18 +184,6 @@ func (n *Node) pack(flow *packer.Flow) error {
}
realElapsed := mclock.Now() - startTime

// sync the log-writing task
if logEnabled {
if err := n.logWorker.Sync(); err != nil {
log.Warn("failed to write logs", "err", err)
n.logDBFailed = true
}
}

if err := n.repo.SetBestBlockID(newBlock.Header().ID()); err != nil {
return err
}

n.processFork(newBlock, oldBest.Header.ID())
commitElapsed := mclock.Now() - startTime - execElapsed

Expand Down
16 changes: 6 additions & 10 deletions cmd/thor/solo/solo.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,6 @@ func (s *Solo) packing(pendingTxs tx.Transactions, onDemand bool) error {
return errors.WithMessage(err, "commit state")
}

// ignore fork when solo
if err := s.repo.AddBlock(b, receipts, 0); err != nil {
return errors.WithMessage(err, "commit block")
}
realElapsed := mclock.Now() - startTime

if err := s.repo.SetBestBlockID(b.Header().ID()); err != nil {
return errors.WithMessage(err, "set best block")
}

if !s.skipLogs {
w := s.logDB.NewWriter()
if err := w.Write(b, receipts); err != nil {
Expand All @@ -179,6 +169,12 @@ func (s *Solo) packing(pendingTxs tx.Transactions, onDemand bool) error {
}
}

// ignore fork when solo
if err := s.repo.AddBlock(b, receipts, 0, true); err != nil {
return errors.WithMessage(err, "commit block")
}
realElapsed := mclock.Now() - startTime

commitElapsed := mclock.Now() - startTime - execElapsed

if v, updated := s.bandwidth.Update(b.Header(), time.Duration(realElapsed)); updated {
Expand Down
4 changes: 1 addition & 3 deletions cmd/thor/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,7 @@ func openMainDB(ctx *cli.Context, dir string) (*muxdb.MuxDB, error) {

opts := muxdb.Options{
TrieNodeCacheSizeMB: cacheMB,
TrieRootCacheCapacity: 256,
TrieCachedNodeTTL: 30, // 5min
TrieLeafBankSlotCapacity: 256,
TrieDedupedPartitionFactor: math.MaxUint32,
TrieWillCleanHistory: !ctx.Bool(disablePrunerFlag.Name),
OpenFilesCacheCapacity: fdCache,
Expand All @@ -286,7 +284,7 @@ func openMainDB(ctx *cli.Context, dir string) (*muxdb.MuxDB, error) {
debug.SetGCPercent(int(gogc))

if opts.TrieWillCleanHistory {
opts.TrieHistPartitionFactor = 1000
opts.TrieHistPartitionFactor = 100
} else {
opts.TrieHistPartitionFactor = 500000
}
Expand Down

0 comments on commit 5c9e18a

Please sign in to comment.