Skip to content

Commit

Permalink
Merge pull request ethereum#54 from saddoc/block-coinbase-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wm-jsong1230 authored May 26, 2023
2 parents 523c479 + 866ff83 commit 39beb3d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
20 changes: 18 additions & 2 deletions wemix/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,23 @@ func signBlock(height *big.Int, hash common.Hash) (coinbase common.Address, sig
prvKey := admin.stack.Server().PrivateKey
sig, err = crypto.Sign(data, prvKey)
if admin.self != nil {
coinbase = admin.self.Addr
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
}
Expand Down Expand Up @@ -1244,7 +1260,7 @@ func verifyBlockSig(height *big.Int, coinbase common.Address, nodeId []byte, has
data = append(height.Bytes(), hash.Bytes()...)
data = crypto.Keccak256(data)
} else {
if ok, err := enodeExists(ctx, height, gov, nodeId); err != nil || !ok {
if _, err := enodeExists(ctx, height, gov, nodeId); err != nil {
return false
}
data = hash.Bytes()
Expand Down
9 changes: 5 additions & 4 deletions wemix/miner_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"sort"
"time"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log"
Expand Down Expand Up @@ -108,16 +109,16 @@ func coinbaseExists(ctx context.Context, height *big.Int, gov *metclient.RemoteC
}

// returns true if enode exists in governance at given height-1
func enodeExists(ctx context.Context, height *big.Int, gov *metclient.RemoteContract, enode []byte) (bool, error) {
func enodeExists(ctx context.Context, height *big.Int, gov *metclient.RemoteContract, enode []byte) (common.Address, error) {
e, err := getCoinbaseEnodeCache(ctx, new(big.Int).Sub(height, common.Big1), gov)
if err != nil {
return false, err
return common.Address{}, err
}
ix, ok := e.enode2index[string(enode)]
if !ok {
return false, nil
return common.Address{}, ethereum.NotFound
}
return ix >= 1, nil
return e.nodes[ix-1].Addr, nil
}

// returns wemix nodes at given height
Expand Down

0 comments on commit 39beb3d

Please sign in to comment.