Skip to content

Commit

Permalink
consensus/ethash,miner: Fixed issue with coinbase setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-jhjin authored and sadoci committed Aug 31, 2023
1 parent d5fb55b commit ed0f316
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
31 changes: 31 additions & 0 deletions metadium/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,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 = metaminer.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, isPangyo bool) (coinbase common.Address, nodeId, sig []byte, err error) {
if admin == nil {
err = metaminer.ErrNotInitialized
Expand Down Expand Up @@ -1865,6 +1895,7 @@ func init() {
metaminer.SuggestGasPriceFunc = suggestGasPrice
metaminer.CalculateRewardsFunc = calculateRewards
metaminer.VerifyRewardsFunc = verifyRewards
metaminer.GetCoinbaseFunc = getCoinbase
metaminer.SignBlockFunc = signBlock
metaminer.VerifyBlockSigFunc = verifyBlockSig
metaminer.RequirePendingTxsFunc = requirePendingTxs
Expand Down
10 changes: 10 additions & 0 deletions metadium/miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var (
LogBlockFunc func(int64, common.Hash)
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, isPangyo bool) (coinbase common.Address, nodeId, sig []byte, err error)
VerifyBlockSigFunc func(height *big.Int, coinbase common.Address, nodeId []byte, hash common.Hash, sig []byte, isPangyo bool) bool
RequirePendingTxsFunc func() bool
Expand Down Expand Up @@ -110,6 +111,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, isPangyo bool) (coinbase common.Address, nodeId, sig []byte, err error) {
if SignBlockFunc == nil {
err = ErrNotInitialized
Expand Down
5 changes: 5 additions & 0 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1646,6 +1646,11 @@ func (w *worker) commitWork(interrupt *int32, noempty bool, timestamp int64) {
}

if !metaminer.IsPoW() { // Metadium
parent := w.chain.CurrentBlock()
getCoinbase, err := metaminer.GetCoinbase(parent.Number())
if err == nil {
work.coinbase = getCoinbase
}
if !w.commitTransactionsEx(work, interrupt, start) {
w.commitEx(work, w.fullTaskHook, true, start)
}
Expand Down

0 comments on commit ed0f316

Please sign in to comment.