使用以太坊源码,搭建联盟链

下载文件:

go get github.com/ethereum/go-ethereum

到cmd/geth目录中执行:

go build

会在当前文件中生成geth可执行文件目录添加到配置文件:

export GETH=/data/myddz/server/src/github.com/ethereum/go-ethereum/cmd/geth

export PATH=$PATH:$GETH

之后在/data/geth中创建创始文件,genesis.json,文件配置如下:

{
 "alloc": {},
 "config": {
   "chainID": 72,
   "homesteadBlock": 0,
   "eip155Block": 0,
   "eip158Block": 0
 },
 "nonce": "0x0000000000000000",
 "difficulty": "0x4000",
 "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
 "coinbase": "0x0000000000000000000000000000000000000000",
 "timestamp": "0x00",
 "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
 "extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
 "gasLimit": "0xffffffff"
}

创建两个目录,存放两个节点

mkdir data-node1
mkdir data-node2

启动命令如下:

geth --datadir ./data-node1 --rpc --rpcaddr "0.0.0.0" --rpcport "8545" --rpcapi "personal,db,eth,net,web3,miner" --networkid 88 --nodiscover console


geth --datadir ./data-node2 --rpc --rpcaddr "0.0.0.0" --rpcport "8546" --rpcapi "personal,db,eth,net,web3,miner" --port 30306 --networkid 88 --nodiscover console

所有操作文档可按照:https://blog.csdn.net/wo541075754/article/details/78926177

修改挖矿难度

文件路径:

github.com/ethereum/go-ethereum/consensus/ethash/consensus.go

修改:

313 func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Header) *big.Int {
314         next := new(big.Int).Add(parent.Number, big1)
315         switch {
316         case config.IsConstantinople(next):
317                 return calcDifficultyConstantinople(time, parent)
318         case config.IsByzantium(next):
319                 return calcDifficultyByzantium(time, parent)
320         case config.IsHomestead(next):
321                 return calcDifficultyHomestead(time, parent)
322         default:
323                 return calcDifficultyFrontier(time, parent)
324         }
325 }

修改为:

func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Header) *big.Int {
        return big.NewInt(0x400)
}