Truffle

松露永遠掛在與 PoA 的同等地位

  • March 31, 2022

我正在嘗試使用parity(PoA)創建一個私有鏈,truffle但是當我這樣做時,truffle migrate它會永遠掛起並顯示以下輸出:

  > [
  >   {
  >     "jsonrpc": "2.0",
  >     "id": 24,
  >     "method": "eth_getFilterChanges",
  >     "params": [
  >       "0x0"
  >     ]
  >   }
  > ]
<   [
<     {
<       "jsonrpc": "2.0",
<       "result": [],
<       "id": 24
<     }
<   ]  

重現步驟

使用以下內容創建一個鏈custom_chain.json

{
   "name": "DemoPoA",
   "engine": {
       "authorityRound": {
           "params": {
               "stepDuration": "5",
               "validators" : {
                   "list": [
                   ]
               }
           }
       }
   },
   "params": {
       "gasLimitBoundDivisor": "0x400",
       "maximumExtraDataSize": "0x20",
       "minGasLimit": "0x1388",
       "networkID" : "0x2323"
   },
   "genesis": {
       "seal": {
           "authorityRound": {
               "step": "0x0",
               "signature": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
           }
       },
       "difficulty": "0x20000",
       "gasLimit": "0x5B8D80"
   },
   "accounts": {
       "0x0000000000000000000000000000000000000001": { "balance": "1", "builtin": { "name": "ecrecover", "pricing": { "linear": { "base": 3000, "word": 0 } } } },
       "0x0000000000000000000000000000000000000002": { "balance": "1", "builtin": { "name": "sha256", "pricing": { "linear": { "base": 60, "word": 12 } } } },
       "0x0000000000000000000000000000000000000003": { "balance": "1", "builtin": { "name": "ripemd160", "pricing": { "linear": { "base": 600, "word": 120 } } } },
       "0x0000000000000000000000000000000000000004": { "balance": "1", "builtin": { "name": "identity", "pricing": { "linear": { "base": 15, "word": 3 } } } }
   }
}

.. 配置文件note0.toml

[parity]
chain = "custom_chain.json"
base_path = "./"
[network]
port = 30300
[rpc]
port = 8540
apis = ["web3", "eth", "net", "personal", "parity", "parity_set", "traces", "rpc", "parity_accounts"]
[ui]
port = 8180
[websockets]
port = 8450

..和命令:

parity --config node0.toml

然後創建兩個使用者:

curl --data '{"jsonrpc":"2.0","method":"parity_newAccountFromPhrase","params":["node0", "node0"],"id":0}' -H "Content-Typ e: application/json" -X POST localhost:8540

curl --data '{"jsonrpc":"2.0","method":"parity_newAccountFromPhrase","params":["user", "user"],"id":0}' -H "Content-Typ e: application/json" -X POST localhost:8540

..並使用以下命令重新啟動節點custom_chain.json

{
   "name": "DemoPoA",
   "engine": {
       "authorityRound": {
           "params": {
               "stepDuration": "5",
               "validators" : {
                   "list": [
                       "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e"
                   ]
               }
           }
       }
   },
   "params": {
       "gasLimitBoundDivisor": "0x400",
       "maximumExtraDataSize": "0x20",
       "minGasLimit": "0x1388",
       "networkID" : "0x2323"
   },
   "genesis": {
       "seal": {
           "authorityRound": {
               "step": "0x0",
               "signature": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
           }
       },
       "difficulty": "0x20000",
       "gasLimit": "0x5B8D80"
   },
   "accounts": {
       "0x0000000000000000000000000000000000000001": { "balance": "1", "builtin": { "name": "ecrecover", "pricing": { "linear": { "base": 3000, "word": 0 } } } },
       "0x0000000000000000000000000000000000000002": { "balance": "1", "builtin": { "name": "sha256", "pricing": { "linear": { "base": 60, "word": 12 } } } },
       "0x0000000000000000000000000000000000000003": { "balance": "1", "builtin": { "name": "ripemd160", "pricing": { "linear": { "base": 600, "word": 120 } } } },
       "0x0000000000000000000000000000000000000004": { "balance": "1", "builtin": { "name": "identity", "pricing": { "linear": { "base": 15, "word": 3 } } } },
       "0x004ec07d2329997267Ec62b4166639513386F32E": { "balance": "10000000000000000000000" }
   }
}

.. node0.toml:

[parity]
chain = "custom_chain.json"
base_path = "./"
[network]
port = 30300
[rpc]
port = 8540
apis = ["web3", "eth", "net", "personal", "parity", "parity_set", "traces", "rpc", "parity_accounts"]
[ui]
port = 8180
[websockets]
port = 8450
[account]
password = ["node.pwds"]
[mining]
engine_signer = "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e"
reseal_on_txs = "none"

.. node.pwds:

node0

..和命令:

parity --config node0.toml

然後解鎖使用者帳戶:

curl --data '{"method":"personal_unlockAccount","params":["0x004ec07d2329997267Ec62b4166639513386F32E","user",null],"id": 1,"jsonrpc":"2.0"}' -H "Content-Type: application/json" -X POST localhost:8540

並嘗試truffle compile && truffle migrate使用以下truffle.js文件進行連接:

module.exports = {
 networks: {
   development: {
     host: "localhost",
     port: 8540,
     network_id: "0x2323",
     from: "0x004ec07d2329997267Ec62b4166639513386F32E"
   }
 }
};

預期行為

truffle進行初始遷移

實際結果

永遠掛著。

環境

  • 作業系統:Windows 10
  • 乙太坊客戶端:parity1.9.4
  • 松露版本 ( truffle version): 4.3.1
  • 節點版本(node --version):8.1.3
  • npm 版本 ( npm --version): 4.1.1

PS我有類似的問題,geth但我連接到IPC套接字並打電話miner.start()- 它有幫助。這裡沒有礦工對象,因為沒有 PoW(我正在嘗試為我的 dapp 使用並需要 PoA)。

https://gist.github.com/Godtide/1a84c98d1dc7ec434672bed17f3dd09c

如需更多說明。

/*
* NB: since truffle-hdwallet-provider 0.0.5 you must wrap HDWallet providers in a
* function when declaring them. Failure to do so will cause commands to hang. ex:
* ```
* mainnet: {
*     provider: function() {
*       return new HDWalletProvider(mnemonic, 'https://mainnet.infura.io/<infura-key>')
*     },
*     network_id: '1',
*     gas: 4500000,
*     gasPrice: 10000000000,
*   },
*/

在松露配置中配置您的網路。請注意,truffle 期望網路 ID 為十進制值。最好不要將私鑰儲存在項目文件中。

嘗試這樣的事情:

require('dotenv').config();

let PrivateKeyProvider = require("truffle-privatekey-provider");

module.exports = {
   networks: {
       development: {
           host: "127.0.0.1",
           port: 8545,
           network_id: "*",
           gas: 8000000
       },
       mynetwork: {
           provider: new PrivateKeyProvider(process.env.PK, process.env.PROVIDER),
           network_id: "8995", // 0x2323
           from: process.env.ACCOUNT,
           gas: 8000000
       }
   }
};

.env 文件應如下所示(注意私鑰沒有前導 0x 字元串。):

PROVIDER=http://127.0.0.1:8540
ACCOUNT=0x0####################################
PK=341##########################################################

遷移到您的區塊鏈:

$ truffle migrate --network mynetwork

引用自:https://ethereum.stackexchange.com/questions/43023