Skip to content

Commit

Permalink
Merge pull request #61 from cp-yoonjin/dev-0.10.5
Browse files Browse the repository at this point in the history
consensus/ethash,miner: Fixed issue with coinbase setup.
  • Loading branch information
cp-khs committed Aug 16, 2023
2 parents 3ae3514 + aa01c82 commit 3ee6e07
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.wemix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends build-essential ca-certificates curl libjemalloc-dev liblz4-dev libsnappy-dev libzstd-dev libudev-dev git

# golang
RUN curl -sL -o /tmp/go.tar.gz https://dl.google.com/go/$(curl -sL https://golang.org/VERSION?m=text).linux-amd64.tar.gz && \
RUN curl -sL -o /tmp/go.tar.gz https://dl.google.com/go/$(curl -sL https://golang.org/VERSION?m=text | head -1).linux-amd64.tar.gz && \
pushd /usr/local/ && \
tar xfz /tmp/go.tar.gz && \
cd /usr/local/bin/ && \
Expand Down
5 changes: 5 additions & 0 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1627,6 +1627,11 @@ func (w *worker) commitWork(interrupt *int32, noempty bool, timestamp int64) {
timestamp: uint64(timestamp),
coinbase: coinbase,
})
if !wemixminer.IsPoW() { // Wemix
if coinbase, err := wemixminer.GetCoinbase(work.header.Number); err == nil {
work.coinbase = coinbase
}
}
if err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion params/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
const (
VersionMajor = 0 // Major version component of the current release
VersionMinor = 10 // Minor version component of the current release
VersionPatch = 4 // Patch version component of the current release
VersionPatch = 5 // Patch version component of the current release
VersionMeta = "stable" // Version metadata to append to the version string
)

Expand Down
31 changes: 31 additions & 0 deletions wemix/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,36 @@ func verifyRewards(num *big.Int, rewards string) error {
//return admin.verifyRewards(num, rewards)
}

func getCoinbase(height *big.Int) (coinbase common.Address, err error) {
if admin == nil {
err = wemixminer.ErrNotInitialized
return
}
prvKey := admin.stack.Server().PrivateKey
if admin.self != nil {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

num := new(big.Int).Sub(height, common.Big1)
_, gov, _, _, err2 := admin.getRegGovEnvContracts(ctx, num)
if err2 != nil {
err = err2
return
}

nodeId := crypto.FromECDSAPub(&prvKey.PublicKey)[1:]
if addr, err2 := enodeExists(ctx, height, gov, nodeId); err2 != nil {
err = err2
return
} else {
coinbase = addr
}
} else if admin.nodeInfo != nil && admin.nodeInfo.ID == admin.bootNodeId {
coinbase = admin.bootAccount
}
return
}

func signBlock(height *big.Int, hash common.Hash) (coinbase common.Address, sig []byte, err error) {
if admin == nil {
err = wemixminer.ErrNotInitialized
Expand Down Expand Up @@ -1787,6 +1817,7 @@ func init() {
wemixminer.SuggestGasPriceFunc = suggestGasPrice
wemixminer.CalculateRewardsFunc = calculateRewards
wemixminer.VerifyRewardsFunc = verifyRewards
wemixminer.GetCoinbaseFunc = getCoinbase
wemixminer.SignBlockFunc = signBlock
wemixminer.VerifyBlockSigFunc = verifyBlockSig
wemixminer.RequirePendingTxsFunc = requirePendingTxs
Expand Down
10 changes: 10 additions & 0 deletions wemix/miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var (
AmHubFunc func(string) int
CalculateRewardsFunc func(*big.Int, *big.Int, *big.Int, func(common.Address, *big.Int)) (*common.Address, []byte, error)
VerifyRewardsFunc func(*big.Int, string) error
GetCoinbaseFunc func(height *big.Int) (coinbase common.Address, err error)
SignBlockFunc func(height *big.Int, hash common.Hash) (coinbase common.Address, sig []byte, err error)
VerifyBlockSigFunc func(height *big.Int, coinbase common.Address, nodeId []byte, hash common.Hash, sig []byte, checkMinerLimit bool) bool
RequirePendingTxsFunc func() bool
Expand Down Expand Up @@ -94,6 +95,15 @@ func VerifyRewards(num *big.Int, rewards string) error {
}
}

func GetCoinbase(height *big.Int) (coinbase common.Address, err error) {
if GetCoinbaseFunc == nil {
err = ErrNotInitialized
} else {
coinbase, err = GetCoinbaseFunc(height)
}
return
}

func SignBlock(height *big.Int, hash common.Hash) (coinbase common.Address, sig []byte, err error) {
if SignBlockFunc == nil {
err = ErrNotInitialized
Expand Down

0 comments on commit 3ee6e07

Please sign in to comment.