masternode对挖到区块签名

在concensus/ethash/sealer.go中修改

import (
	crand "crypto/rand"
	"math"
	"math/big"
	"math/rand"
	"runtime"
	"sync"
	"crypto/ecdsa"
	"fmt"
	//"io/ioutil"
	//"os"
	//"path/filepath"
	"github.com/ethereum/go-ethereum/crypto"
	"github.com/ethereum/go-ethereum/common"
	"github.com/ethereum/go-ethereum/consensus"
	"github.com/ethereum/go-ethereum/core/types"
	"github.com/ethereum/go-ethereum/log"
)
if new(big.Int).SetBytes(result).Cmp(target) <= 0 {
				// Correct nonce found, create a new header with it
				header = types.CopyHeader(header)
				header.Nonce = types.EncodeNonce(nonce)
				header.MixDigest = common.BytesToHash(digest)
				//extraSeal   := 65
				prv := ethash.NodeKey()
				h := header.HashNoNonce().Bytes()
				sig, err := crypto.Sign(h[:],prv)
				if err != nil{
					return		
				}
				fmt.Println("this is prv",prv)
				fmt.Println("this is sig",sig)
				//copy(header.Extra, sig)
				// Seal and return a block (if still needed)
				select {
unc (ethash *Ethash) NodeKey() *ecdsa.PrivateKey {
	
	keyfile := "/home/flq/blctest/blc/geth/nodekey"
	if key, err := crypto.LoadECDSA(keyfile); err == nil {
		fmt.Println(key)
		return key
	}
	// No persistent key found, generate and store a new one.
	key, err := crypto.GenerateKey()
	if err != nil {
		log.Crit(fmt.Sprintf("Failed to generate node key: %v", err))
	}
	
	
	return key
}

你可能感兴趣的:(以太坊源码分析)