diff --git a/metadium/admin.go b/metadium/admin.go index 04279d21c406..b549331be021 100644 --- a/metadium/admin.go +++ b/metadium/admin.go @@ -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 @@ -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 diff --git a/metadium/miner/miner.go b/metadium/miner/miner.go index aac041bc49a1..ba3cda494349 100644 --- a/metadium/miner/miner.go +++ b/metadium/miner/miner.go @@ -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 @@ -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 diff --git a/miner/worker.go b/miner/worker.go index b4e429847274..f46aefb5ba8a 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -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) }