POA私有链无法解锁账户和广播交易

问题描述(POA私有链)

1.在geth交互界面中无法使用clef的personal.unlockAccount解锁账户,但是可以使用personal.listWallets查看账户 2.在终端使用curl命令通过clef签名发送转账交易,有正确交易回显(包含v,r,s,hash等等),但是在geth交互界面中输入txpool.content无法查看到

初始化私有链代码(c.sh)

#!/bin/bash

#cd Work/Chains/

#number of accounts to create
num_accounts=10

#create accounts with passwords in password.txt
declare -a addresses
for i in $(seq 1 $num_accounts)
do
  output=$(geth account new --datadir /root/Work/Chains/node --password password.txt)
  address=$(echo "$output" | grep -oP 'Public address of the key:\s+\K.*')
  addresses+=($address)
done

#create a genesis.json
alloc=""
for i in $(seq 0 $(($num_accounts-1)))
do
  alloc+="\"${addresses[$i]:2}\": { \"balance\": \"300000\" },"
done

#remove trailing comma
alloc=${alloc%?}

genesis="{
  \"config\": {
    \"chainId\": 20240430,
    \"homesteadBlock\": 0,
    \"eip150Block\": 0,
    \"eip155Block\": 0,
    \"eip158Block\": 0,
    \"byzantiumBlock\": 0,
    \"constantinopleBlock\": 0,
    \"petersburgBlock\": 0,
    \"istanbulBlock\": 0,
    \"berlinBlock\": 0,
    \"clique\": {
      \"period\": 12,
      \"epoch\": 30000
    }
  },
  \"difficulty\": \"1\",
  \"gasLimit\": \"1176000\",
  \"extradata\": \"0x0000000000000000000000000000000000000000000000000000000000000000${addresses[0]:2}0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",
  \"alloc\": {
    $alloc
  }
}"

echo "$genesis" > initBlock.json

#initialize the private blockchain
geth --datadir /root/Work/Chains/node --keystore /root/Work/Chains/node/keystore init initBlock.json

在screen中启动clef服务代码(clef.sh)


#!/bin/bash

# 启动一个新的 screen 会话,并在该会话中运行 expect 脚本
screen -dmS clef_session bash -c 'expect -f /root/Work/Chains/t.exp'
echo "Clef service is starting in a new screen session named 'clef_session'."

在screen中启动expect服务实现自动交互(t.exp)


#!/usr/bin/expect -f

# 启动 clef 程序
spawn clef --chainid 20240430 --keystore /root/Work/Chains/node/keystore --configdir /root/Work/Chains/node/clef --http --http.addr 0.0.0.0 --http.port 8550

log_file -a /root/Work/Chains/clef_screen.log
# 处理交互
while {1} {
    expect {
        "Enter 'ok' to proceed:" {
            send "ok\r"
            exp_continue
        }
        "Approve? \\\[y/N\\\]:" {
            send "y\r"
            exp_continue
        }
        "Please enter the password for account 0x" {
            send "123\r"
            exp_continue
        }
        eof {
            break
        }
        default {
            # 处理所有未匹配的情况,避免输出未匹配信息
            exp_continue
        }
    }
}

# 保持交互会话
interact

启动节点代码(g.sh)


# start geth node
localhost_ip=$(hostname -I | awk '{print $1}')
account_count=$(ls -1q /root/Work/Chains/node/keystore | wc -l)
unlock_string=$(seq -s "," 0 $((account_count-1)))
nohup geth \
--datadir /root/Work/Chains/node \
--keystore /root/Work/Chains/node/keystore \
--networkid 20240430 \
--nat extip:$localhost_ip \
--netrestrict 192.168.0.0/16 \
--http \
--http.port 8545 \
--http.api eth,net,txpool,web3,clique,admin,les \
--port "30303" \
--syncmode "full" \
--unlock $unlock_string \
--password password.txt \
--miner.etherbase=${addresses[0]}
--bootnodes "enr:-KO4QNs5G4YVHuSKcVkYH5jkOkKEk04RyPaQqBIqlvdIJNPUd_1Z81qGkAJHn0x8OmSkYO4IhZ2uP0ly8G_9AmKjkwWGAY9H_s3og2V0aMfGhE0s8niAgmlkgnY0gmlwhMCoAASJc2VjcDI1NmsxoQPZTaDrjWqXcLwSVaDDk1CMCJxvGhs5P7SSr0afi-iUO4RzbmFwwIN0Y3CCdl-DdWRwgnZf" \
--allow-insecure-unlock \
--signer=./node/clef/clef.ipc \
--ws.port 8546 \
2>>./node/geth.log &

按照上面贴代码的顺序启动的脚本,c.sh,clef.sh,t.exp,g.sh 只在一个服务器上启动了这些脚本,只有一个节点被启动

图片.png

问题一

在geth交互界面中无法使用clef的personal.unlockAccount解锁账户,但是可以使用personal.listWallets查看账户 这个图片是clef的文档截图 图片.png 根据这个文档的操作

图片.png status的部分是"ok",不清楚代表的是解锁了还是没有解锁,和文档的不一样

对于解锁账户 图片也是来自于clef的文档

图片.png 根据文档的操作

图片.png 这个报错,对于personal.unlockAccount()里面使用其他参数和personal.newAccount()也有 Passphrase输入按照password.txt的来的

问题二

在终端使用curl命令通过clef签名发送转账交易,有正确交易回显(包含v,r,s,hash等等),但是在geth交互界面中输入txpool.content无法查看到 命令及回显

curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"account_signTransaction","params":[{"from":"0x3802dFFC86F4B6D707F398B763775AF24E1FC07f","gas":"0x333","gasPrice":"0x1","nonce":"0x0","to":"0x89e05D9e2efD4E3AC34F84c6b161fd36CF03164F", "value":"0x12345", "data":"0x4401a6e40000000000000000000000000000000000000000000000000000000000000012"},"safeSend(address)"],"id":67}' http://localhost:8550/

图片.png

图片.png 上面这一张是clef的交互界面的交易回显(通过except处理好了交互) 回到geth的交互界面,txpool.content没有交易信息

图片.png (可能是我没有挖矿?但是设置挖矿收益账户也会失败)

请先 登录 后评论
  • 0 关注
  • 0 收藏,967 浏览
  • hard2code 提出于 2024-05-20 22:44