Skip to content

Commit

Permalink
Merge pull request #580 from frankcrypto2023/dev/1.2-diff
Browse files Browse the repository at this point in the history
Modify difficulty adjustment
  • Loading branch information
dindinw authored Dec 11, 2023
2 parents da23aa3 + 0616789 commit b3c9421
Show file tree
Hide file tree
Showing 15 changed files with 784 additions and 461 deletions.
3 changes: 2 additions & 1 deletion consensus/consensus.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package consensus

import (
"sync"

"github.com/Qitmeer/qng/common/hash"
"github.com/Qitmeer/qng/config"
"github.com/Qitmeer/qng/consensus/model"
Expand All @@ -13,7 +15,6 @@ import (
"github.com/Qitmeer/qng/node/service"
"github.com/Qitmeer/qng/params"
"github.com/Qitmeer/qng/services/index"
"sync"
)

type consensus struct {
Expand Down
1 change: 1 addition & 0 deletions consensus/model/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ type Block interface {
GetOrder() uint
HasParents() bool
GetMainParent() uint
GetHeight() uint
}
16 changes: 16 additions & 0 deletions consensus/model/difficulty_manager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package model

import (
"math/big"
"time"

"github.com/Qitmeer/qng/core/types/pow"
)

// DifficultyManager provides a method to resolve the
// difficulty value of a block
type DifficultyManager interface {
RequiredDifficulty(block Block, newBlockTime time.Time, powInstance pow.IPow) (uint32, error)
CalcEasiestDifficulty(bits uint32, duration time.Duration, powInstance pow.IPow) uint32
GetCurrentPowDiff(ib Block, powType pow.PowType) *big.Int
}
13 changes: 9 additions & 4 deletions core/blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ package blockchain
import (
"container/list"
"fmt"
"sort"
"sync"
"time"

"github.com/Qitmeer/qng/common/hash"
"github.com/Qitmeer/qng/common/roughtime"
"github.com/Qitmeer/qng/common/system"
Expand All @@ -18,6 +22,7 @@ import (
"github.com/Qitmeer/qng/core/state"
"github.com/Qitmeer/qng/core/types"
"github.com/Qitmeer/qng/core/types/pow"
"github.com/Qitmeer/qng/core/types/pow/difficultymanager"
"github.com/Qitmeer/qng/database/common"
"github.com/Qitmeer/qng/engine/txscript"
l "github.com/Qitmeer/qng/log"
Expand All @@ -28,9 +33,6 @@ import (
"github.com/Qitmeer/qng/params"
"github.com/Qitmeer/qng/services/progresslog"
"github.com/schollz/progressbar/v3"
"sort"
"sync"
"time"
)

const (
Expand Down Expand Up @@ -135,7 +137,8 @@ type BlockChain struct {
wg sync.WaitGroup
quit chan struct{}

meerChain *meer.MeerChain
meerChain *meer.MeerChain
difficultyManager model.DifficultyManager
}

func (b *BlockChain) Init() error {
Expand Down Expand Up @@ -169,6 +172,8 @@ func (b *BlockChain) Init() error {
for _, v := range tips {
log.Info(fmt.Sprintf("hash=%s,order=%s,height=%d", v.GetHash(), meerdag.GetOrderLogStr(v.GetOrder()), v.GetHeight()))
}

b.difficultyManager = difficultymanager.NewDiffManager(b.Consensus().BlockChain(), b.params)
return nil
}

Expand Down
Loading

0 comments on commit b3c9421

Please sign in to comment.