Goland编译调试go-ethereum项目
在运行配置里面运行种类选软件包。然后包路劲使用github.com/ethereum/go-ethereum/cmd/geth
,输出目录与工作目录使用C:\Users\lcq\go\src\github.com\ethereum\go-ethereum\build\bin
。
call 调用提示insufficient funds for gas * price + value
使用账户余额为0的账号发送call调用,也会提示 insufficient funds for gas * price + value
,如果要解决此问题,发送的时候不要指定gas以及gasPrice。参考 https://github.com/ethereum/go-ethereum/pull/23027
一个无法完成的call调用JSON如下:
{
"jsonrpc":"2.0",
"id":359,
"method":"eth_call",
"params":[
{
"from":"0xd794617a1f1143da3bd081736ce3badf338a4b19",
"data":"0x95d89b41",
"gasPrice":"0x77359400",
"gas":"0x9f5cbd",
"to":"0xa238f5e0bc072b766899b2ece8261b3a5a7f9eb0"
},
"latest"
]
}
想要正确调用只要去掉params中的gas,gasPrice即可。
geth在dev模式下面无法出块
使用 geth --datadir ./data --networkid 1337 --nodiscover --http --http.corsdomain * --http.addr 0.0.0.0 --http.port 41230 --http.api eth,net,web3,personal,admin,miner,txpool --log.debug --dev --allow-insecure-unlock
命令启动geth,发现有的时候发送交易区块链不会出块。
正常出块的日志如下:
INFO [06-22|10:04:34.303|internal/ethapi/api.go:1629] Submitted transaction hash=0xffbddf66746da928857e548f9923eb6dfba2b856f87688e9cac18445833a7e8f from=0xE169A4717F17E220E243B339dFac96d35243979d nonce=1 recipient=0x55a58d806C2993fb49260dBb85a600eef45D201d value=1,000,000,000,000,000,000
INFO [06-22|10:04:34.304|miner/worker.go:1018] Commit new mining work number=2 sealhash=250fea..d2a9fd uncles=0 txs=1 gas=21000 fees=4.913478234e-06 elapsed="516.9µs"
INFO [06-22|10:04:34.304|miner/worker.go:631] Successfully sealed new block number=2 sealhash=250fea..d2a9fd hash=ad1618..889c73 elapsed="656.1µs"
INFO [06-22|10:04:34.304|miner/unconfirmed.go:85] ? mined potential block number=2 hash=ad1618..889c73
INFO [06-22|10:04:34.304|miner/worker.go:1018] Commit new mining work number=3 sealhash=328130..2208f0 uncles=0 txs=0 gas=0 fees=0 elapsed=0s
INFO [06-22|10:04:34.304|consensus/clique/clique.go:609] Sealing paused, waiting for transactions
不出快的日志如下:
INFO [06-22|10:01:20.021|internal/ethapi/api.go:1629] Submitted transaction hash=0xd1fa193e96436b9233952e42dc5c7c0374ef9eda5475fa7c29e8b615c062c07e from=0xF0268f4803935017Dc1D5434048e78A672156852 nonce=3 recipient=0x6cB8d485AA81ECd891efaD1C708CD10fFEc3a687 value=0
INFO [06-22|10:01:20.021|miner/worker.go:1018] Commit new mining work number=3 sealhash=6bf13a..ec9115 uncles=0 txs=0 gas=0 fees=0 elapsed=0s
INFO [06-22|10:01:20.021|consensus/clique/clique.go:609] Sealing paused, waiting for transactions
关键代码:core/gaspool.go 第40行
func (gp *GasPool) SubGas(amount uint64) error {
log.Warn("SubGas", "gp", uint64(*gp), "amount", amount, "gap", uint64(*gp) - amount)
if uint64(*gp) < amount {
return ErrGasLimitReached
}
*(*uint64)(gp) -= amount
return nil
}
amount 前面是交易指定的gasLimit,运行一段时间之后,后面指定gasLimit不会再改变,一直是一个恒定的值。
发现在txs列表里面,还存在以前未打包的交易。按照先进先出的原则,拿到的是旧交易。因为旧交易的gasLimit我拿的是当时区块的gasLimit,但是最新的区块的gasLimit是要小于旧区块的gasLimit的,导致拿出来的交易指定的gasLimit大于最新区块的gasLimit,所以无法打包。但是目前未知,为啥旧交易没有落盘写入levelDB里面,而是依然在交易队列里面。
暂时解决方法:从日志可以看到,区块的gasLimit当减到8000000的时候,不再减少。所以指定所有的交易的gasLimit不大于8000000即可。参考链接:Simply Explained: Ethereum Gas
WARN [06-23|09:32:28.938|core/gaspool.go:41] SubGas gp=10,059,440 amount=10,037,704 gap=21736
WARN [06-23|09:32:29.321|core/gaspool.go:41] SubGas gp=10,049,618 amount=10,037,704 gap=11914
WARN [06-23|09:32:29.537|core/gaspool.go:41] SubGas gp=10,039,805 amount=10,037,704 gap=2101
WARN [06-23|09:32:29.763|core/gaspool.go:41] SubGas gp=10,030,002 amount=10,037,704 gap=18,446,744,073,709,543,914
log日志打印格式
log.xxx("msg", "key1", value1, "key2", value2, ...);